Skip to content

Commit

Permalink
JEXL:
Browse files Browse the repository at this point in the history
Fix JEXL-176: remove foreach...in syntax

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/jexl/trunk@1719270 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
henrib committed Dec 11, 2015
1 parent 0556c09 commit 0c435ea
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ What's new in 3.0:

New features in 3.0:
====================
* JEXL-178: 'Unsolvable property' message to provide details about underlying exception
* JEXL-177: Unified expressions to be used in String literals in JEXL scripts
* JEXL-176: Synonym operator name 'in' for operator =~ // Remove 'foreach...in' syntax
* JEXL-174: Overloadable property access operators
* JEXL-173: Duck-typed java closures
* JEXL-170: Implement assignment operators
* JEXL-178: 'Unsolvable property' message to provide details about underlying exception
* JEXL-164: public getters for high/low properties for IntegerRange and LongRange
* JEXL-152: Extend Range literal to support Long values
* JEXL-149: Set Construction as per EL 3.0 spec
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/org/apache/commons/jexl3/parser/Parser.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ TOKEN_MGR_DECLS : {
< IF : "if" >
| < ELSE : "else" >
| < FOR : "for" >
| < FOREACH : "foreach" > : FOR_EACH_IN
| < WHILE : "while" >
| < NEW : "new" >
| < VAR : "var" >
Expand All @@ -135,11 +134,6 @@ TOKEN_MGR_DECLS : {
| < PRAGMA : "#pragma" >
}

<FOR_EACH_IN> TOKEN : /* foreach in */
{
< IN : "in" > : DEFAULT
}

<*> TOKEN : { /* SEPARATORS */
< LPAREN : "(" >
| < RPAREN : ")" >
Expand Down Expand Up @@ -214,7 +208,7 @@ TOKEN_MGR_DECLS : {
< DOT_IDENTIFIER: ( [ "0"-"9", "a"-"z", "A"-"Z", "_", "$", "@" ])+ > { popDot(); } /* Revert state to default. */
}

<DEFAULT, FOR_EACH_IN, REGISTERS> TOKEN : /* IDENTIFIERS */
<DEFAULT, REGISTERS> TOKEN : /* IDENTIFIERS */
{
< IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
|
Expand Down Expand Up @@ -341,8 +335,6 @@ void Break() #Break : {}
void ForeachStatement() : {}
{
<FOR> <LPAREN> ForEachVar() <COLON> Expression() <RPAREN> { loopCount += 1; } (LOOKAHEAD(1) Block() | Statement()) { loopCount -= 1; }
|
<FOREACH> <LPAREN> ForEachVar() <IN> Expression() <RPAREN> { loopCount += 1; } (LOOKAHEAD(1) Block() | Statement()){ loopCount -= 1; }
}

void ForEachVar() #Reference : {}
Expand Down
3 changes: 3 additions & 0 deletions src/site/xdoc/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<action dev="henrib" type="add" issue="JEXL-177" due-to="Dmitri Blinov">
Unified expressions to be used in String literals in JEXL scripts
</action>
<action dev="henrib" type="add" issue="JEXL-176" due-to="Dmitri Blinov">
Synonym operator name 'in' for operator =~ // Remove 'foreach...in' syntax
</action>
<action dev="henrib" type="add" issue="JEXL-174" due-to="Dmitri Blinov">
Overloadable property access operators
</action>
Expand Down
2 changes: 1 addition & 1 deletion src/site/xdoc/reference/syntax.xml
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@
x = x + item;
}</source>
Where <code>item</code> and <code>list</code> are variables.
The JEXL 1.1 syntax using <code>foreach(item in list)</code> is now <strong>deprecated</strong>.
The JEXL 1.1 syntax using <code>foreach(item in list)</code> is now <strong>unsupported</strong>.
</td>
</tr>
<tr>
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/org/apache/commons/jexl3/ForEachTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testForEachWithArray() throws Exception {

@Test
public void testForEachWithCollection() throws Exception {
JexlScript e = JEXL.createScript("for(item : list) item");
JexlScript e = JEXL.createScript("for(var item : list) item");
JexlContext jc = new MapContext();
jc.set("list", Arrays.asList(new Object[]{"Hello", "World"}));
Object o = e.execute(jc);
Expand All @@ -76,7 +76,7 @@ public void testForEachWithCollection() throws Exception {

@Test
public void testForEachWithEnumeration() throws Exception {
JexlScript e = JEXL.createScript("for(item : list) item");
JexlScript e = JEXL.createScript("for(var item : list) item");
JexlContext jc = new MapContext();
jc.set("list", new StringTokenizer("Hello,World", ","));
Object o = e.execute(jc);
Expand All @@ -85,7 +85,7 @@ public void testForEachWithEnumeration() throws Exception {

@Test
public void testForEachWithIterator() throws Exception {
JexlScript e = JEXL.createScript("for(item : list) item");
JexlScript e = JEXL.createScript("for(var item : list) item");
JexlContext jc = new MapContext();
jc.set("list", Arrays.asList(new Object[]{"Hello", "World"}).iterator());
Object o = e.execute(jc);
Expand All @@ -106,17 +106,13 @@ public void testForEachWithMap() throws Exception {
@Test
public void testForEachWithBlock() throws Exception {
JexlScript exs0 = JEXL.createScript("for(var in : list) { x = x + in; }");
JexlScript exs1 = JEXL.createScript("foreach(item in list) { x = x + item; }");
JexlScript[] exs = {exs0, exs1};
JexlContext jc = new MapContext();
jc.set("list", new Object[]{2, 3});
for (int ex = 0; ex < exs.length; ++ex) {
jc.set("x", new Integer(1));
Object o = exs[ex].execute(jc);
Object o = exs0.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(6), o);
Assert.assertEquals("x is wrong", new Integer(6), jc.get("x"));
}
}

@Test
public void testForEachWithListExpression() throws Exception {
Expand Down

0 comments on commit 0c435ea

Please sign in to comment.