This is an automated email from the ASF dual-hosted git repository. henrib pushed a commit to branch JEXL-382 in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/JEXL-382 by this push: new 60ae3a94 JEXL-382: reorder and complete lists of alphabetic keywords, improve test using keywords in identifiers; 60ae3a94 is described below commit 60ae3a94a73ca50a0df0f7bb60eb43680abb2316 Author: henrib <hen...@apache.org> AuthorDate: Mon Oct 31 10:46:27 2022 +0100 JEXL-382: reorder and complete lists of alphabetic keywords, improve test using keywords in identifiers; --- .../org/apache/commons/jexl3/parser/Parser.jjt | 70 +++++++++++----------- .../org/apache/commons/jexl3/Issues300Test.java | 24 +++++++- 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt index 32b15241..4c5b1b8e 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt +++ b/src/main/java/org/apache/commons/jexl3/parser/Parser.jjt @@ -121,8 +121,8 @@ TOKEN_MGR_DECLS : {} } <DEFAULT> TOKEN : { /* CONDITIONALS */ - < _AND : "and" > - | < _OR: "or" > + < _AND : "and" > + | < _OR: "or" > } <*> TOKEN : { /* COMPARISONS */ @@ -141,12 +141,12 @@ TOKEN_MGR_DECLS : {} } <DEFAULT> TOKEN : { /* COMPARISONS */ - < EQ : "eq" > - | < NE : "ne" > - | < GT : "gt" > - | < GE : "ge" > - | < LT : "lt" > - | < LE : "le" > + < EQ : "eq" > + | < NE : "ne" > + | < GT : "gt" > + | < GE : "ge" > + | < LT : "lt" > + | < LE : "le" > } <*> TOKEN : { /* OPERATORS */ @@ -162,16 +162,14 @@ TOKEN_MGR_DECLS : {} | < rshiftu_assign : ">>>=" > | < rshift_assign : ">>=" > - | < assign : "=" > + | < assign : "=" > | < plus : "+" > | < plusplus : "++" > | < minus : "-" > | < minusminus : "--" > | < mult : "*" > | < div : "/" > - | < DIV : "div" > | < mod : "%" > - | < MOD : "mod" > | < not : "!" > | < and : "&" > | < or : "|" > @@ -185,36 +183,38 @@ TOKEN_MGR_DECLS : {} } <DEFAULT> TOKEN : { /* OPERATORS */ - < NOT : "not" > + < NOT : "not" > + | < DIV : "div" > + | < MOD : "mod" > } <*> TOKEN : /* KEYWORDS */ { - < LAMBDA : "->" > - | < FATARROW : "=>" > - | < RETURN : "return" > - | < BREAK : "break" > - | < CONTINUE : "continue" > - | < PRAGMA : "#pragma" > + < LAMBDA : "->" > + | < FATARROW : "=>" > + | < PRAGMA : "#pragma" > } <DEFAULT> TOKEN : /* KEYWORDS */ { - < IF : "if" > - | < DO : "do" > - | < NEW : "new" > - | < VAR : "var" > - | < LET : "let" > - | < FOR : "for" > - | < ELSE : "else" > + < IF : "if" > + | < ELSE : "else" > + | < DO : "do" > + | < WHILE : "while" > + | < FOR : "for" > + | < BREAK : "break" > + | < CONTINUE : "continue" > + | < FUNCTION : "function" > + | < RETURN : "return" > + | < NEW : "new" > | < SIZE : "size" > - | < NULL : "null" > - | < TRUE : "true" > - | < FALSE : "false" > - | < WHILE : "while" > - | < CONST : "const" > | < EMPTY : "empty" > - | < FUNCTION : "function" > + | < VAR : "var" > + | < LET : "let" > + | < CONST : "const" > + | < NULL : "null" > + | < TRUE : "true" > + | < FALSE : "false" > } /*************************************** @@ -246,7 +246,7 @@ TOKEN_MGR_DECLS : {} < #ESCAPE: "\\" [" ", "'", "\"", "\\"] > } -<DEFAULT> TOKEN : +<DEFAULT> TOKEN : { < REGISTER: "#" (["0"-"9"])+ > } @@ -258,9 +258,9 @@ TOKEN_MGR_DECLS : {} | <HEX_LITERAL> (<INT_SFX>)? | <OCTAL_LITERAL> (<INT_SFX>)? > - | <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])*> + | <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])*> | <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+> - | <#OCTAL_LITERAL: "0" (["0"-"7"])*> + | <#OCTAL_LITERAL: "0" (["0"-"7"])*> | <#INT_SFX : ["l","L","h","H"]> | <FLOAT_LITERAL: @@ -268,7 +268,7 @@ TOKEN_MGR_DECLS : {} | (["0"-"9"])+ (".")? (<FLT_SFX>) | "." (["0"-"9"])+ (<FLT_SFX>) | "#NaN" -> +> | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+> | <#FLT_CLS : ["f","F","d","D","b","B"]> | <#FLT_SFX : <EXPONENT> (<FLT_CLS>)? | <FLT_CLS> > diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java index 9357f5da..fa0f4a53 100644 --- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java +++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java @@ -118,7 +118,29 @@ public class Issues300Test { value = e304.evaluate(context); assertEquals(42, value); - final String allkw = "e304.if.else.do.while.new.true.false.null.var.function.empty.size.not.and.or.ne.eq.le.lt.gt.ge"; + final String[] keywords = new String[]{ + "if", "else", "do", "while", "for", "break", "continue", "function", "return", "new", "size", "empty", + "var", "let", "const", + "null", "true", "false", + "not", "div", "mod", "and", "or", + "eq", "ne", "lt", "gt", "ge", "le", + + }; + for(int i = 0; i < keywords.length; ++i) { + String pkw = "e304." + keywords[i]; + map.put(pkw, 42); + e304 = jexlEngine.createExpression(pkw); + value = e304.evaluate(context); + assertEquals(42, value); + } + for(int i = 0; i < keywords.length; ++i) { + String pkw = "e304." + keywords[i] + "." + keywords[keywords.length - 1 - i]; + map.put(pkw, 42); + e304 = jexlEngine.createExpression(pkw); + value = e304.evaluate(context); + assertEquals(42, value); + } + final String allkw = "e304." + String.join(".", keywords); map.put(allkw, 42); e304 = jexlEngine.createExpression(allkw); value = e304.evaluate(context);