Skip to content
This repository was archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Project cleanup and move to Java 16.
Browse files Browse the repository at this point in the history
  • Loading branch information
andyHa committed Jun 15, 2021
1 parent 77d6619 commit 242dcc1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
parsii
======

If you have questions or are just curious, please feel welcome to join the chat room:
[![Join the chat at https://gitter.im/scireum/sirius-kernel](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/scireum/OpenSource?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
# parsii

Super fast and simple evaluator for mathematical expressions written in Java. More background information can be found in this blog post: http://andreas.haufler.info/2013/12/how-to-write-one-of-fastest-expression.html

Expand All @@ -25,11 +21,11 @@ Check out or micro kernel called SIRIUS: https://github.com/scireum/sirius

## Maven

parsii is available under:
parsii is available under [https://mvn.scireum.com](https://mvn.scireum.com).

<dependency>
<groupId>com.scireum</groupId>
<artifactId>parsii</artifactId>
<version>1.5</version>
<version>...</version>
</dependency>

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.scireum</groupId>
<artifactId>sirius-parent</artifactId>
<version>6.1</version>
<version>8.0.1</version>
</parent>
<artifactId>parsii</artifactId>
<version>DEVELOPMENT-SNAPSHOT</version>
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/parsii/tokenizer/Char.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* @see LookaheadReader
*/
public class Char implements Position {
private char value;
private int line;
private int pos;

private final char value;
private final int line;
private final int pos;

Char(char value, int line, int pos) {
this.value = value;
Expand Down Expand Up @@ -69,7 +70,7 @@ public boolean isLetter() {
*
* @return <tt>true</tt> if the internal value is a whitespace character, <tt>false</tt> otherwise
*/
public boolean isWhitepace() {
public boolean isWhitespace() {
return Character.isWhitespace(value) && !isEndOfInput();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/parsii/tokenizer/LookaheadReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class LookaheadReader extends Lookahead<Char> {

private Reader input;
private final Reader input;
private int line = 1;
private int pos = 0;

Expand Down
16 changes: 8 additions & 8 deletions src/main/java/parsii/tokenizer/Tokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@
/**
* Turns a stream of characters ({@link Reader} into a stream of {@link Token}, supporting lookahead.
* <p>
* Reads from the given input and parses it into a stream of tokens. By default all token types defined by
* Reads from the given input and parses it into a stream of tokens. By default, all token types defined by
* {@link Token} are supported. Most of the features can be further tweaked by changing the default settings.
* <p>
* By default the tokenizer operates as follows:
* <ul>
* <li>Consume and ignore any whitespace characters (see {@link Char#isWhitepace()}</li>
* <li>Consume and ignore any whitespace characters (see {@link Char#isWhitespace()}</li>
* <li>If the current character starts a line comment, read until the end of the line and ignore all characters
* consumed.</li>
* <li>If the current character starts a block comment, read until and end of block comment is detected.</li>
* <li>If the current character is a digit, parse a INTEGER, if a decimal separator is found, switch over to a DECIMAL
* (see {@link Char#isDigit()}. Also if the current character is a '-' and the next is a digit, we try to read
* (see {@link Char#isDigit()}. Also, if the current character is a '-', and the next is a digit, we try to read
* a number.</li>
* <li>If the current character is a letter, parse an ID (see {@link Char#isLetter()}. Once this is complete, check if
* the ID matches one of the supplied keywords, and convert if necessary.</li>
* <li>If the current character is an opening or closing bracket, a SYMBOL for that single character is returned</li>
* <li>If the current character is an opening or a closing bracket, a SYMBOL for that single character is returned</li>
* <li>If the current character is one of the special id starters, all valid ID characters
* ({@link #isIdentifierChar(Char)} are consumed and returned as SPECIAL_ID</li>
* <li>All other characters, especially all operators, will be read and returned as one SYMBOL. Therefore <tt>#++*</tt>
* <li>All other characters, especially all operators, will be read and returned as one SYMBOL. Therefore, <tt>#++*</tt>
* will be returned as a single symbol.</li>
* </ul>
*/
Expand Down Expand Up @@ -82,7 +82,7 @@ public class Tokenizer extends Lookahead<Token> {
* All supported brackets. For obvious reasons, several brackets like (( are treated as two symbols, rather than
* operators like ** which will create one symbol
*/
private char[] brackets = {'(', '[', '{', '}', ']', ')'};
private final char[] brackets = {'(', '[', '{', '}', ']', ')'};
/*
* Determines if a single pipe (this: | ) will be treated as bracket. This could can be used like | a - b |
* However || will be handled as symbol with two characters, as it is often used as "or".
Expand Down Expand Up @@ -139,7 +139,7 @@ protected Token endOfInput() {
@Override
protected Token fetch() {
// Fetch and ignore any whitespace
while (input.current().isWhitepace()) {
while (input.current().isWhitespace()) {
input.consume();
}

Expand Down Expand Up @@ -503,7 +503,7 @@ protected Token fetchSymbol() {
*/
@SuppressWarnings("squid:S1067")
protected boolean isSymbolCharacter(Char ch) {
if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitepace()) {
if (ch.isEndOfInput() || ch.isDigit() || ch.isLetter() || ch.isWhitespace()) {
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/parsii/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@

/**
* Tests the {@link Parser} class.
*
* @author Andreas Haufler ([email protected])
* @since 2013/09
*/
public class ParserTest {

@Test
public void simple() throws ParseException {
assertEquals(-109d, Parser.parse("1 - (10 - -100)").evaluate(), BinaryOperation.EPSILON);
Expand Down

0 comments on commit 242dcc1

Please sign in to comment.