Skip to content

Commit

Permalink
Merge pull request #178 from killme2008/feature/v4.2.7-dev
Browse files Browse the repository at this point in the history
v4.2.7 dev
  • Loading branch information
killme2008 authored Dec 4, 2019
2 parents cd1cac3 + 0fb5c78 commit cfe333d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.googlecode.aviator.lexer.token.Token.TokenType;
import com.googlecode.aviator.lexer.token.Variable;
import com.googlecode.aviator.parser.AviatorClassLoader;
import com.googlecode.aviator.parser.ExpressionParser;
import com.googlecode.aviator.parser.Parser;
import com.googlecode.aviator.runtime.FunctionArgument;
import com.googlecode.aviator.runtime.LambdaFunctionBootstrap;
Expand Down Expand Up @@ -236,32 +237,6 @@ private boolean isLiteralOperand(final Token<?> token, final TokenType tokenType
}


private boolean isLiteralToken(final Token<?> token) {
switch (token.getType()) {
case Variable:
return token == Variable.TRUE || token == Variable.FALSE || token == Variable.NIL;
case Char:
case Number:
case Pattern:
case String:
return true;
default:
return false;
}
}

private boolean isConstant(final Token<?> token) {
switch (token.getType()) {
case Number:
case Pattern:
case String:
return true;
default:
return false;
}
}


/**
* Get token from executing result
*
Expand Down Expand Up @@ -372,7 +347,7 @@ public Expression getResult() {
Set<Token<?>> constants = new HashSet<>();
for (Token<?> token : this.tokenList) {

if (isConstant(token)) {
if (ExpressionParser.isConstant(token)) {
constants.add(token);
}

Expand Down Expand Up @@ -424,7 +399,7 @@ public Expression getResult() {
exp = new LiteralExpression(this.instance, null, new ArrayList<String>(variables.keySet()));
} else {
final Token<?> lastToken = this.tokenList.get(0);
if (isLiteralToken(lastToken)) {
if (ExpressionParser.isLiteralToken(lastToken)) {
exp = new LiteralExpression(this.instance,
getAviatorObjectFromToken(lastToken).getValue(null),
new ArrayList<String>(variables.keySet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,12 @@ public void unary() {
factor();
}

// FIXME: it's a parser bug here

while (expectChar('[') || expectChar('(')) {
if (isConstant(this.prevToken)) {
break;
}

if (expectChar('[')) {
// (...)[index]
arrayAccess();
Expand Down Expand Up @@ -893,4 +897,29 @@ private void ensureDepthState() {
}
}

public static boolean isConstant(final Token<?> token) {
switch (token.getType()) {
case Number:
case Pattern:
case String:
return true;
default:
return false;
}
}

public static boolean isLiteralToken(final Token<?> token) {
switch (token.getType()) {
case Variable:
return token == Variable.TRUE || token == Variable.FALSE || token == Variable.NIL;
case Char:
case Number:
case Pattern:
case String:
return true;
default:
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public void testIssue162() {
assertEquals(new BigInteger("-2017122615550747128008704"), val);
}

@Test(expected = ExpressionSyntaxErrorException.class)
public void testIssue177() {
AviatorEvaluator.compile("$age >30 ($age < 20)");
}

@Test
public void testIssue175() {
Map<String, Object> env = new HashMap<>();
Expand Down

0 comments on commit cfe333d

Please sign in to comment.