Author: henrib
Date: Sun Mar 28 14:22:06 2010
New Revision: 928405
URL: http://svn.apache.org/viewvc?rev=928405&view=rev
Log:
Updated Parser.jjt to define all acceptable tokens resulting in cleaner lexer.
Added 'register' syntax (#0-9) used by JexlEngine.{s,g}etProperty: syntax only
valid through ALLOW_REGISTER flag and REGISTERS lexical state.
Completed literal handling (array, integer, string, float).
Added:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
(with props)
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
(with props)
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
Sun Mar 28 14:22:06 2010
@@ -181,7 +181,7 @@ public class Interpreter implements Pars
* Sets this interpreter registers for bean access/assign expressions.
* @param theRegisters the array of registers
*/
- protected void setRegisters(Object[] theRegisters) {
+ protected void setRegisters(Object... theRegisters) {
this.registers = theRegisters;
}
@@ -361,13 +361,18 @@ public class Interpreter implements Pars
/** {...@inheritdoc} */
public Object visit(ASTArrayLiteral node, Object data) {
- int childCount = node.jjtGetNumChildren();
- Object[] array = new Object[childCount];
- for (int i = 0; i < childCount; i++) {
- Object entry = node.jjtGetChild(i).jjtAccept(this, data);
- array[i] = entry;
+ Object literal = node.getLiteral();
+ if (literal == null) {
+ int childCount = node.jjtGetNumChildren();
+ Object[] array = new Object[childCount];
+ for (int i = 0; i < childCount; i++) {
+ Object entry = node.jjtGetChild(i).jjtAccept(this, data);
+ array[i] = entry;
+ }
+ literal = arithmetic.narrowArrayType(array);
+ node.setLiteral(literal);
}
- return arithmetic.narrowArrayType(array);
+ return literal;
}
/** {...@inheritdoc} */
@@ -603,12 +608,10 @@ public class Interpreter implements Pars
/** {...@inheritdoc} */
public Object visit(ASTFloatLiteral node, Object data) {
- Object value = node.jjtGetValue();
- if (!(value instanceof Float)) {
- value = Float.valueOf(node.image);
- node.jjtSetValue(value);
+ if (data != null) {
+ return getAttribute(data, node.getLiteral(), node);
}
- return value;
+ return node.getLiteral();
}
/** {...@inheritdoc} */
@@ -677,12 +680,7 @@ public class Interpreter implements Pars
String name = node.image;
if (data == null) {
if (registers != null) {
- if (registers[0].equals(name)) {
- return registers[1];
- }
- if (registers[2].equals(name)) {
- return registers[3];
- }
+ return registers[name.charAt(1) - '0'];
}
Object value = context.get(name);
if (value == null
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
Sun Mar 28 14:22:06 2010
@@ -85,7 +85,8 @@ public class JexlArithmetic {
/**
* The result of +,/,-,*,% when both operands are null.
- * @return null if strict, else Long(0)
+ * @return Integer(0) if lenient
+ * @throws NullPointerException if strict
*/
protected Object controlNullNullOperands() {
if (strict) {
@@ -96,6 +97,7 @@ public class JexlArithmetic {
/**
* Throw a NPE if arithmetic is strict.
+ * @throws NullPointerException if strict
*/
protected void controlNullOperand() {
if (strict) {
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
Sun Mar 28 14:22:06 2010
@@ -514,19 +514,15 @@ public class JexlEngine {
if (context == null) {
context = EMPTY_CONTEXT;
}
- // lets build 1 unique & unused identifiers wrt context
- String r0 = "$0";
- for (int s = 0; context.has(r0); ++s) {
- r0 = r0 + s;
- }
- expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
+ // synthetize expr using register
+ expr = "#0" + (expr.charAt(0) == '[' ? "" : ".") + expr + ";";
try {
+ parser.ALLOW_REGISTERS = true;
JexlNode tree = parse(expr, null);
JexlNode node = tree.jjtGetChild(0);
Interpreter interpreter = createInterpreter(context);
- // ensure 4 objects in register array
- Object[] r = {r0, bean, r0, bean};
- interpreter.setRegisters(r);
+ // set register
+ interpreter.setRegisters(bean);
return node.jjtAccept(interpreter, null);
} catch (JexlException xjexl) {
if (silent) {
@@ -534,6 +530,8 @@ public class JexlEngine {
return null;
}
throw xjexl;
+ } finally {
+ parser.ALLOW_REGISTERS = false;
}
}
@@ -570,23 +568,15 @@ public class JexlEngine {
if (context == null) {
context = EMPTY_CONTEXT;
}
- // lets build 2 unique & unused identifiers wrt context
- String r0 = "$0", r1 = "$1";
- for (int s = 0; context.has(r0); ++s) {
- r0 = r0 + s;
- }
- for (int s = 0; context.has(r1); ++s) {
- r1 = r1 + s;
- }
- // synthetize expr
- expr = r0 + (expr.charAt(0) == '[' ? "" : ".") + expr + "=" + r1 + ";";
+ // synthetize expr using registers
+ expr = "#0" + (expr.charAt(0) == '[' ? "" : ".") + expr + "=" + "#1" +
";";
try {
+ parser.ALLOW_REGISTERS = true;
JexlNode tree = parse(expr, null);
JexlNode node = tree.jjtGetChild(0);
Interpreter interpreter = createInterpreter(context);
// set the registers
- Object[] r = {r0, bean, r1, value};
- interpreter.setRegisters(r);
+ interpreter.setRegisters(bean, value);
node.jjtAccept(interpreter, null);
} catch (JexlException xjexl) {
if (silent) {
@@ -594,6 +584,8 @@ public class JexlEngine {
return;
}
throw xjexl;
+ } finally {
+ parser.ALLOW_REGISTERS = false;
}
}
Added:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java?rev=928405&view=auto
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
(added)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
Sun Mar 28 14:22:06 2010
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl2.parser;
+
+public final class ASTArrayLiteral extends JexlNode implements
JexlNode.Literal<Object> {
+ /** The type literal value. */
+ Object literal = null;
+
+ public ASTArrayLiteral(int id) {
+ super(id);
+ }
+
+ public ASTArrayLiteral(Parser p, int id) {
+ super(p, id);
+ }
+
+ public Object getLiteral() {
+ return literal;
+ }
+
+ public void setLiteral(Object literal) {
+ this.literal = literal;
+ }
+
+ /**
+ * Accept the visitor.
+ * @param visitor the visitor
+ * @param data contextual data
+ * @return result of visit
+ **/
+ @Override
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
+ return visitor.visit(this, data);
+ }
+}
Propchange:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTArrayLiteral.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java?rev=928405&view=auto
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
(added)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
Sun Mar 28 14:22:06 2010
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl2.parser;
+
+public final class ASTFloatLiteral extends JexlNode implements
JexlNode.Literal<Float> {
+ /** The type literal value. */
+ Float literal = null;
+
+ public ASTFloatLiteral(int id) {
+ super(id);
+ }
+
+ public ASTFloatLiteral(Parser p, int id) {
+ super(p, id);
+ }
+
+ public Float getLiteral() {
+ return literal;
+ }
+
+ /**
+ * Accept the visitor.
+ * @param visitor the visitor
+ * @param data contextual data
+ * @return result of visit
+ **/
+ @Override
+ public Object jjtAccept(ParserVisitor visitor, Object data) {
+ return visitor.visit(this, data);
+ }
+}
Propchange:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTFloatLiteral.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTIntegerLiteral.java
Sun Mar 28 14:22:06 2010
@@ -18,7 +18,7 @@ package org.apache.commons.jexl2.parser;
public final class ASTIntegerLiteral extends JexlNode implements
JexlNode.Literal<Integer> {
/** The type literal value. */
- private Integer literal;
+ Integer literal = null;
public ASTIntegerLiteral(int id) {
super(id);
@@ -29,13 +29,15 @@ public final class ASTIntegerLiteral ext
}
public Integer getLiteral() {
- if (literal == null) {
- literal = Integer.valueOf(image);
- }
return literal;
}
- /** Accept the visitor. **/
+ /**
+ * Accept the visitor.
+ * @param visitor the visitor
+ * @param data contextual data
+ * @return result of visit
+ **/
@Override
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/ASTStringLiteral.java
Sun Mar 28 14:22:06 2010
@@ -30,7 +30,12 @@ public final class ASTStringLiteral exte
return image;
}
- /** Accept the visitor. **/
+ /**
+ * Accept the visitor.
+ * @param visitor the visitor
+ * @param data contextual data
+ * @return result of visit
+ **/
@Override
public Object jjtAccept(ParserVisitor visitor, Object data) {
return visitor.visit(this, data);
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/Parser.jjt
Sun Mar 28 14:22:06 2010
@@ -43,9 +43,16 @@ import org.apache.commons.jexl2.JexlInfo
public class Parser extends StringParser
{
+ public boolean ALLOW_REGISTERS = false;
+
public ASTJexlScript parse(Reader reader, JexlInfo info)
- throws ParseException
- {
+ throws ParseException {
+ /*
+ * If registers are allowed, the default parser state has to be
REGISTERS.
+ */
+ if (ALLOW_REGISTERS) {
+ token_source.defaultLexState = REGISTERS;
+ }
ReInit(reader);
/*
* lets do the 'Unique Init' in here to be
@@ -83,24 +90,16 @@ PARSER_END(Parser)
<*> SKIP : /* WHITE SPACE */
{
- <"##" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
-| <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
-| <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
-| " "
-| "\t"
-| "\n"
-| "\r"
-| "\f"
+ <"##" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
+ | <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
+ | <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
+ | " "
+ | "\t"
+ | "\n"
+ | "\r"
+ | "\f"
}
-<*> TOKEN : /* LITERALS */
-{
- < INTEGER_LITERAL: (<DIGIT>)+ >
-|
- < FLOAT_LITERAL: (<DIGIT>)+ "."(<DIGIT>)+ >
-}
-
-
<*> TOKEN : /* KEYWORDS */
{
< IF : "if" >
@@ -116,6 +115,11 @@ PARSER_END(Parser)
| < FALSE : "false" >
}
+<FOR_EACH_IN> TOKEN : /* foreach in */
+{
+ < IN : "in" > : DEFAULT
+}
+
<*> TOKEN : { /* SEPARATORS */
< LPAREN : "(" >
| < RPAREN : ")" >
@@ -126,11 +130,73 @@ PARSER_END(Parser)
| < SEMICOL : ";" >
| < COLON : ":" >
| < COMMA : "," >
+ | <DOT : "." >
}
-<FOR_EACH_IN> TOKEN : /* foreach in */
+<*> TOKEN : { /* CONDITIONALS */
+ < QMARK : "?" >
+ | < ELVIS : "?:" >
+ | < AND : "&&" | "and" >
+ | < OR : "||" | "or" >
+}
+
+<*> TOKEN : { /* COMPARISONS */
+ < eq : "==" | "eq" >
+ | < ne : "!=" | "ne" >
+ | < req : "=~" >
+ | < rne : "!~" >
+ | < gt : ">" | "gt" >
+ | < ge : ">=" | "ge" >
+ | < lt : "<" | "lt" >
+ | < le : "<=" | "le" >
+}
+
+<*> TOKEN : { /* OPERATORS */
+ < assign : "=" >
+ | < mod : "%" | "mod" >
+ | < div : "/" | "div" >
+ | < not : "!" | "not" >
+ | < plus : "+" >
+ | < minus : "-" >
+ | < mult : "*" >
+ | < tilda : "~" >
+ | < and : "&" >
+ | < or : "|" >
+ | < xor : "^" >
+}
+
+/***************************************
+ * Identifier & String tokens
+ ***************************************/
+
+<*> TOKEN : /* IDENTIFIERS */
{
- < IN : "in" > : DEFAULT
+ < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
+|
+ < #LETTER: [ "a"-"z", "A"-"Z", "_", "$" ] >
+|
+ < #DIGIT: [ "0"-"9"] >
+}
+
+<REGISTERS> TOKEN : /* REGISTERS: parser.ALLOW_REGISTER must be set to true
before calling parse */
+{
+ < REGISTER: "#" ["0"-"9"] >
+}
+
+<*> TOKEN : /* LITERALS */
+{
+ < INTEGER_LITERAL: (<DIGIT>)+ >
+|
+ < FLOAT_LITERAL: (<DIGIT>)+ "."(<DIGIT>)+ >
+}
+
+<*> TOKEN :
+{
+ < STRING_LITERAL:
+ "\"" (~["\"","\\","\n","\r","\u2028","\u2029"] | "\\"
~["\n","\r","\u2028","\u2029"])* "\""
+ |
+ "'" (~["'","\\","\n","\r","\u2028","\u2029"] | "\\"
~["\n","\r","\u2028","\u2029"])* "'"
+ >
}
/***************************************
@@ -192,7 +258,7 @@ void ForeachStatement() : {}
void Expression() #void : {}
{
- LOOKAHEAD( Reference() "=" ) Assignment()
+ LOOKAHEAD( Reference() <assign> ) Assignment()
|
ConditionalExpression()
}
@@ -200,7 +266,7 @@ void Expression() #void : {}
void Assignment() #Assignment(2) : {}
{
- Reference() "=" Expression()
+ Reference() <assign> Expression()
}
/***************************************
@@ -211,9 +277,9 @@ void ConditionalExpression() #void : {}
{
ConditionalOrExpression()
(
- "?" Expression() <COLON> Expression() #TernaryNode(3)
+ <QMARK> Expression() <COLON> Expression() #TernaryNode(3)
|
- "?:" Expression() #TernaryNode(2)
+ <ELVIS> Expression() #TernaryNode(2)
)?
}
@@ -222,9 +288,7 @@ void ConditionalOrExpression() #void :
{
ConditionalAndExpression()
(
- "||" ConditionalAndExpression() #OrNode(2)
- |
- "or" ConditionalAndExpression() #OrNode(2)
+ <OR> ConditionalAndExpression() #OrNode(2)
)*
}
@@ -233,9 +297,7 @@ void ConditionalAndExpression() #void :
{
InclusiveOrExpression()
(
- "&&" InclusiveOrExpression() #AndNode(2)
- |
- "and" InclusiveOrExpression() #AndNode(2)
+ <AND> InclusiveOrExpression() #AndNode(2)
)*
}
@@ -243,21 +305,21 @@ void InclusiveOrExpression() #void :
{}
{
ExclusiveOrExpression()
- ( "|" ExclusiveOrExpression() #BitwiseOrNode(2) )*
+ ( <or> ExclusiveOrExpression() #BitwiseOrNode(2) )*
}
void ExclusiveOrExpression() #void :
{}
{
AndExpression()
- ( "^" AndExpression() #BitwiseXorNode(2) )*
+ ( <xor> AndExpression() #BitwiseXorNode(2) )*
}
void AndExpression() #void :
{}
{
EqualityExpression()
- ( "&" EqualityExpression() #BitwiseAndNode(2) )*
+ ( <and> EqualityExpression() #BitwiseAndNode(2) )*
}
void EqualityExpression() #void :
@@ -265,13 +327,9 @@ void EqualityExpression() #void :
{
RelationalExpression()
(
- "==" RelationalExpression() #EQNode(2)
- |
- "eq" RelationalExpression() #EQNode(2)
+ <eq> RelationalExpression() #EQNode(2)
|
- "!=" RelationalExpression() #NENode(2)
- |
- "ne" RelationalExpression() #NENode(2)
+ <ne> RelationalExpression() #NENode(2)
)?
}
@@ -280,25 +338,17 @@ void RelationalExpression() #void :
{
AdditiveExpression()
(
- "<" AdditiveExpression() #LTNode(2)
- |
- "lt" AdditiveExpression() #LTNode(2)
- |
- ">" AdditiveExpression() #GTNode(2)
- |
- "gt" AdditiveExpression() #GTNode(2)
- |
- "<=" AdditiveExpression() #LENode(2)
+ <lt> AdditiveExpression() #LTNode(2)
|
- "le" AdditiveExpression() #LENode(2)
+ <gt> AdditiveExpression() #GTNode(2)
|
- ">=" AdditiveExpression() #GENode(2)
+ <le> AdditiveExpression() #LENode(2)
|
- "ge" AdditiveExpression() #GENode(2)
+ <ge> AdditiveExpression() #GENode(2)
|
- "=~" AdditiveExpression() #ERNode(2) // equals regexp
+ <req> AdditiveExpression() #ERNode(2) // equals regexp
|
- "!~" AdditiveExpression() #NRNode(2) // not equals regexp
+ <rne> AdditiveExpression() #NRNode(2) // not equals regexp
)?
}
@@ -313,36 +363,30 @@ void AdditiveExpression() #AdditiveNode(
void AdditiveOperator() : {}
{
- "+" { jjtThis.image = "+"; }
+ <plus> { jjtThis.image = "+"; }
|
- "-" { jjtThis.image = "-"; }
+ <minus> { jjtThis.image = "-"; }
}
void MultiplicativeExpression() #void : {}
{
UnaryExpression()
(
- "*" UnaryExpression() #MulNode(2)
+ <mult> UnaryExpression() #MulNode(2)
|
- "/" UnaryExpression() #DivNode(2)
+ <div> UnaryExpression() #DivNode(2)
|
- "div" UnaryExpression() #DivNode(2)
- |
- "%" UnaryExpression() #ModNode(2)
- |
- "mod" UnaryExpression() #ModNode(2)
+ <mod> UnaryExpression() #ModNode(2)
)*
}
void UnaryExpression() #void : {}
{
- "-" UnaryExpression() #UnaryMinusNode(1)
-|
- "~" UnaryExpression() #BitwiseComplNode(1)
+ <minus> UnaryExpression() #UnaryMinusNode(1)
|
- "!" UnaryExpression() #NotNode(1)
+ <tilda> UnaryExpression() #BitwiseComplNode(1)
|
- "not" UnaryExpression() #NotNode(1)
+ <not> UnaryExpression() #NotNode(1)
|
PrimaryExpression()
}
@@ -357,8 +401,9 @@ void Identifier() :
Token t;
}
{
- t=<IDENTIFIER>
- { jjtThis.image = t.image; }
+ t=<IDENTIFIER> { jjtThis.image = t.image; }
+|
+ t=<REGISTER> { jjtThis.image = t.image; }
}
void Literal() #void :
@@ -396,7 +441,7 @@ void IntegerLiteral() :
}
{
t=<INTEGER_LITERAL>
- { jjtThis.image = t.image; }
+ { jjtThis.image = t.image; jjtThis.literal = Integer.valueOf(t.image); }
}
void FloatLiteral() :
@@ -405,7 +450,7 @@ void FloatLiteral() :
}
{
t=<FLOAT_LITERAL>
- { jjtThis.image = t.image; }
+ { jjtThis.image = t.image; jjtThis.literal = Float.valueOf(t.image); }
}
void StringLiteral() :
@@ -509,7 +554,7 @@ void ArrayAccess() : {}
void DotReference() #void : {}
{
- ("."
+ (<DOT>
( LOOKAHEAD(Identifier() <LBRACKET> )
ArrayAccess()
|
@@ -541,24 +586,3 @@ void Reference() : {}
LOOKAHEAD(<LBRACKET>) ArrayLiteral() ) DotReference()
}
-/***************************************
- * Identifier & String tokens
- ***************************************/
-
-<*> TOKEN : /* IDENTIFIERS */
-{
- < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
-|
- < #LETTER: [ "a"-"z", "A"-"Z", "_", "$" ] >
-|
- < #DIGIT: [ "0"-"9"] >
-}
-
-<*> TOKEN :
-{
- < STRING_LITERAL:
- "\"" (~["\"","\\","\n","\r","\u2028","\u2029"] | "\\"
~["\n","\r","\u2028","\u2029"])* "\""
- |
- "'" (~["'","\\","\n","\r","\u2028","\u2029"] | "\\"
~["\n","\r","\u2028","\u2029"])* "'"
- >
-}
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java?rev=928405&r1=928404&r2=928405&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
Sun Mar 28 14:22:06 2010
@@ -77,6 +77,7 @@ public class JexlTestCase extends TestCa
return;
}
JexlEngine jdbg = new JexlEngine();
+ jdbg.parser.ALLOW_REGISTERS = true;
Debugger dbg = new Debugger();
// iterate over all expression in cache
Iterator<Map.Entry<String,ASTJexlScript>> inodes =
jexl.cache.entrySet().iterator();