You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pr...@apache.org on 2007/06/02 17:13:06 UTC
svn commit: r543748 - in /jakarta/commons/proper/jexl/trunk/src:
java/org/apache/commons/jexl/ java/org/apache/commons/jexl/parser/
test/org/apache/commons/jexl/
Author: proyal
Date: Sat Jun 2 08:13:05 2007
New Revision: 543748
URL: http://svn.apache.org/viewvc?view=rev&rev=543748
Log:
Add ability to create Map objects via [ key => value, key => value] syntax. Adjust how custom Uberspect is applied, use a setter rather than cxtor as generated parser cxtor's are trickier to patch into.
Added:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java (with props)
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java (with props)
jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java (with props)
Modified:
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParseException.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jj
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jjt
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserConstants.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTokenManager.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTreeConstants.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserVisitor.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleCharStream.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Token.java
jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/TokenMgrError.java
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ExpressionFactory.java Sat Jun 2 08:13:05 2007
@@ -28,8 +28,8 @@
import org.apache.commons.jexl.parser.Parser;
import org.apache.commons.jexl.parser.SimpleNode;
import org.apache.commons.jexl.parser.TokenMgrError;
-import org.apache.commons.jexl.util.introspection.Uberspect;
import org.apache.commons.jexl.util.Introspector;
+import org.apache.commons.jexl.util.introspection.Uberspect;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -57,7 +57,7 @@
/**
* The Log to which all ExpressionFactory messages will be logged.
*/
- protected static Log log =
+ protected static final Log log =
LogFactory.getLog("org.apache.commons.jexl.ExpressionFactory");
/**
@@ -65,27 +65,25 @@
* {@link Parser}.
* When parsing expressions, ExpressionFactory synchronizes on Parser.
*/
- protected static Parser parser =
- new Parser(new StringReader(";"), Introspector.getUberspect() ); //$NON-NLS-1$
-
- private final Parser _parser;
+ protected final Parser parser =
+ new Parser(new StringReader(";") ); //$NON-NLS-1$
/**
* ExpressionFactory is a singleton and this is the private
* instance fufilling that pattern.
*/
- protected static ExpressionFactory ef = new ExpressionFactory();
+ protected static final ExpressionFactory ef = new ExpressionFactory();
/**
* Private constructor, the single instance is always obtained
* with a call to getInstance().
*/
private ExpressionFactory() {
- _parser = parser;
+ this(Introspector.getUberspect());
}
public ExpressionFactory( Uberspect uberspect ) {
- _parser = new Parser(new StringReader(";"), uberspect);
+ parser.setUberspect( uberspect );
}
/**
@@ -127,10 +125,10 @@
// Parse the Expression
SimpleNode tree;
- synchronized (_parser) {
+ synchronized (parser) {
log.debug("Parsing expression: " + expr);
try {
- tree = _parser.parse(new StringReader(expr));
+ tree = parser.parse(new StringReader(expr));
} catch (TokenMgrError tme) {
throw new ParseException(tme.getMessage());
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/ScriptFactory.java Sat Jun 2 08:13:05 2007
@@ -76,7 +76,7 @@
* with a call to getInstance().
*/
private ScriptFactory() {
-
+ parser.setUberspect( Introspector.getUberspect());
}
/**
Added: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java?view=auto&rev=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java (added)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java Sat Jun 2 08:13:05 2007
@@ -0,0 +1,25 @@
+/* Generated By:JJTree: Do not edit this line. ASTMapEntry.java */
+
+package org.apache.commons.jexl.parser;
+
+import org.apache.commons.jexl.JexlContext;
+
+public class ASTMapEntry extends SimpleNode {
+ public ASTMapEntry( int id ) {
+ super( id );
+ }
+
+ public ASTMapEntry( Parser p, int id ) {
+ super( p, id );
+ }
+
+ /** Accept the visitor. * */
+ public Object jjtAccept( ParserVisitor visitor, Object data ) {
+ return visitor.visit( this, data );
+ }
+
+ public Object value( JexlContext context ) throws Exception {
+ return new Object[]{ ( (SimpleNode) jjtGetChild( 0 ) ).value( context ),
+ ( (SimpleNode) jjtGetChild( 1 ) ).value( context ) };
+ }
+}
Propchange: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapEntry.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java?view=auto&rev=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java (added)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java Sat Jun 2 08:13:05 2007
@@ -0,0 +1,35 @@
+/* Generated By:JJTree: Do not edit this line. ASTMapLiteral.java */
+
+package org.apache.commons.jexl.parser;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.jexl.JexlContext;
+
+public class ASTMapLiteral extends SimpleNode {
+ public ASTMapLiteral( int id ) {
+ super( id );
+ }
+
+ public ASTMapLiteral( Parser p, int id ) {
+ super( p, id );
+ }
+
+ /** Accept the visitor. * */
+ public Object jjtAccept( ParserVisitor visitor, Object data ) {
+ return visitor.visit( this, data );
+ }
+
+ public Object value( JexlContext context ) throws Exception {
+ int childCount = jjtGetNumChildren();
+ Map map = new HashMap();
+
+ for ( int i = 0; i < childCount; i++ ) {
+ Object[] entry = (Object[]) ( (SimpleNode) jjtGetChild( i ) ).value( context );
+ map.put( entry[0], entry[1] );
+ }
+
+ return map;
+ }
+}
Propchange: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ASTMapLiteral.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParseException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParseException.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParseException.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParseException.java Sat Jun 2 08:13:05 2007
@@ -1,200 +1,192 @@
-/*
- * 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.
- */
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */
package org.apache.commons.jexl.parser;
/**
- * This exception is thrown when parse errors are encountered. You can
- * explicitly create objects of this exception type by calling the method
- * generateParseException in the generated parser.
- *
- * You can modify this class to customize your error reporting mechanisms so
- * long as you retain the public fields.
+ * This exception is thrown when parse errors are encountered.
+ * You can explicitly create objects of this exception type by
+ * calling the method generateParseException in the generated
+ * parser.
+ *
+ * You can modify this class to customize your error reporting
+ * mechanisms so long as you retain the public fields.
*/
public class ParseException extends Exception {
- /** serialization version id jdk13 generated. */
- static final long serialVersionUID = 654626477565941968L;
-
- /**
- * This constructor is used by the method "generateParseException" in the
- * generated parser. Calling this constructor generates a new object of this
- * type with the fields "currentToken", "expectedTokenSequences", and
- * "tokenImage" set. The boolean flag "specialConstructor" is also set to
- * true to indicate that this constructor was used to create this object.
- * This constructor calls its super class with the empty string to force the
- * "toString" method of parent class "Throwable" to print the error message
- * in the form: ParseException: (result of getMessage)
- */
- public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
- super("");
- specialConstructor = true;
- currentToken = currentTokenVal;
- expectedTokenSequences = expectedTokenSequencesVal;
- tokenImage = tokenImageVal;
+ /**
+ * This constructor is used by the method "generateParseException"
+ * in the generated parser. Calling this constructor generates
+ * a new object of this type with the fields "currentToken",
+ * "expectedTokenSequences", and "tokenImage" set. The boolean
+ * flag "specialConstructor" is also set to true to indicate that
+ * this constructor was used to create this object.
+ * This constructor calls its super class with the empty string
+ * to force the "toString" method of parent class "Throwable" to
+ * print the error message in the form:
+ * ParseException: <result of getMessage>
+ */
+ public ParseException(Token currentTokenVal,
+ int[][] expectedTokenSequencesVal,
+ String[] tokenImageVal
+ )
+ {
+ super("");
+ specialConstructor = true;
+ currentToken = currentTokenVal;
+ expectedTokenSequences = expectedTokenSequencesVal;
+ tokenImage = tokenImageVal;
+ }
+
+ /**
+ * The following constructors are for use by you for whatever
+ * purpose you can think of. Constructing the exception in this
+ * manner makes the exception behave in the normal way - i.e., as
+ * documented in the class "Throwable". The fields "errorToken",
+ * "expectedTokenSequences", and "tokenImage" do not contain
+ * relevant information. The JavaCC generated code does not use
+ * these constructors.
+ */
+
+ public ParseException() {
+ super();
+ specialConstructor = false;
+ }
+
+ public ParseException(String message) {
+ super(message);
+ specialConstructor = false;
+ }
+
+ /**
+ * This variable determines which constructor was used to create
+ * this object and thereby affects the semantics of the
+ * "getMessage" method (see below).
+ */
+ protected boolean specialConstructor;
+
+ /**
+ * This is the last token that has been consumed successfully. If
+ * this object has been created due to a parse error, the token
+ * followng this token will (therefore) be the first error token.
+ */
+ public Token currentToken;
+
+ /**
+ * Each entry in this array is an array of integers. Each array
+ * of integers represents a sequence of tokens (by their ordinal
+ * values) that is expected at this point of the parse.
+ */
+ public int[][] expectedTokenSequences;
+
+ /**
+ * This is a reference to the "tokenImage" array of the generated
+ * parser within which the parse error occurred. This array is
+ * defined in the generated ...Constants interface.
+ */
+ public String[] tokenImage;
+
+ /**
+ * This method has the standard behavior when this object has been
+ * created using the standard constructors. Otherwise, it uses
+ * "currentToken" and "expectedTokenSequences" to generate a parse
+ * error message and returns it. If this object has been created
+ * due to a parse error, and you do not catch it (it gets thrown
+ * from the parser), then this method is called during the printing
+ * of the final stack trace, and hence the correct error message
+ * gets displayed.
+ */
+ public String getMessage() {
+ if (!specialConstructor) {
+ return super.getMessage();
}
-
- /**
- * The following constructors are for use by you for whatever purpose you
- * can think of. Constructing the exception in this manner makes the
- * exception behave in the normal way - i.e., as documented in the class
- * "Throwable". The fields "errorToken", "expectedTokenSequences", and
- * "tokenImage" do not contain relevant information. The JavaCC generated
- * code does not use these constructors.
- */
-
- public ParseException() {
- super();
- specialConstructor = false;
+ StringBuffer expected = new StringBuffer();
+ int maxSize = 0;
+ for (int i = 0; i < expectedTokenSequences.length; i++) {
+ if (maxSize < expectedTokenSequences[i].length) {
+ maxSize = expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < expectedTokenSequences[i].length; j++) {
+ expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" ");
+ }
+ if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
+ expected.append("...");
+ }
+ expected.append(eol).append(" ");
}
-
- public ParseException(String message) {
- super(message);
- specialConstructor = false;
+ String retval = "Encountered \"";
+ Token tok = currentToken.next;
+ for (int i = 0; i < maxSize; i++) {
+ if (i != 0) retval += " ";
+ if (tok.kind == 0) {
+ retval += tokenImage[0];
+ break;
+ }
+ retval += add_escapes(tok.image);
+ tok = tok.next;
}
-
- /**
- * This variable determines which constructor was used to create this object
- * and thereby affects the semantics of the "getMessage" method (see below).
- */
- protected boolean specialConstructor;
-
- /**
- * This is the last token that has been consumed successfully. If this
- * object has been created due to a parse error, the token followng this
- * token will (therefore) be the first error token.
- */
- public Token currentToken;
-
- /**
- * Each entry in this array is an array of integers. Each array of integers
- * represents a sequence of tokens (by their ordinal values) that is
- * expected at this point of the parse.
- */
- public int[][] expectedTokenSequences;
-
- /**
- * This is a reference to the "tokenImage" array of the generated parser
- * within which the parse error occurred. This array is defined in the
- * generated ...Constants interface.
- */
- public String[] tokenImage;
-
- /**
- * This method has the standard behavior when this object has been created
- * using the standard constructors. Otherwise, it uses "currentToken" and
- * "expectedTokenSequences" to generate a parse error message and returns
- * it. If this object has been created due to a parse error, and you do not
- * catch it (it gets thrown from the parser), then this method is called
- * during the printing of the final stack trace, and hence the correct error
- * message gets displayed.
- */
- public String getMessage() {
- if (!specialConstructor) {
- return super.getMessage();
- }
- StringBuffer expected = new StringBuffer();
- int maxSize = 0;
- for (int i = 0; i < expectedTokenSequences.length; i++) {
- if (maxSize < expectedTokenSequences[i].length) {
- maxSize = expectedTokenSequences[i].length;
- }
- for (int j = 0; j < expectedTokenSequences[i].length; j++) {
- expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" ");
- }
- if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
- expected.append("...");
- }
- expected.append(eol).append(" ");
- }
- String retval = "Encountered \"";
- Token tok = currentToken.next;
- for (int i = 0; i < maxSize; i++) {
- if (i != 0)
- retval += " ";
- if (tok.kind == 0) {
- retval += tokenImage[0];
- break;
- }
- retval += add_escapes(tok.image);
- tok = tok.next;
- }
- retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
- retval += "." + eol;
- if (expectedTokenSequences.length == 1) {
- retval += "Was expecting:" + eol + " ";
- } else {
- retval += "Was expecting one of:" + eol + " ";
- }
- retval += expected.toString();
- return retval;
+ retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
+ retval += "." + eol;
+ if (expectedTokenSequences.length == 1) {
+ retval += "Was expecting:" + eol + " ";
+ } else {
+ retval += "Was expecting one of:" + eol + " ";
}
-
- /**
- * The end of line string for this machine.
- */
- protected String eol = System.getProperty("line.separator", "\n");
-
- /**
- * Used to convert raw characters to their escaped version when these raw
- * version cannot be used as part of an ASCII string literal.
- */
- protected String add_escapes(String str) {
- StringBuffer retval = new StringBuffer();
- char ch;
- for (int i = 0; i < str.length(); i++) {
- switch (str.charAt(i)) {
- case 0:
- continue;
- case '\b':
- retval.append("\\b");
- continue;
- case '\t':
- retval.append("\\t");
- continue;
- case '\n':
- retval.append("\\n");
- continue;
- case '\f':
- retval.append("\\f");
- continue;
- case '\r':
- retval.append("\\r");
- continue;
- case '\"':
- retval.append("\\\"");
- continue;
- case '\'':
- retval.append("\\\'");
- continue;
- case '\\':
- retval.append("\\\\");
- continue;
- default:
- if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u").append(s.substring(s.length() - 4, s.length()));
- } else {
- retval.append(ch);
- }
- continue;
- }
+ retval += expected.toString();
+ return retval;
+ }
+
+ /**
+ * The end of line string for this machine.
+ */
+ protected String eol = System.getProperty("line.separator", "\n");
+
+ /**
+ * Used to convert raw characters to their escaped version
+ * when these raw version cannot be used as part of an ASCII
+ * string literal.
+ */
+ protected String add_escapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
}
- return retval.toString();
- }
+ }
+ return retval.toString();
+ }
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jj
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jj?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jj (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jj Sat Jun 2 08:13:05 2007
@@ -1,13 +1,14 @@
-/*
+/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. ./Parser.jj */
+/*@egen*//*
* 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.
@@ -27,6 +28,7 @@
options
{
STATIC=false;
+ UNICODE_INPUT=true;
}
PARSER_BEGIN(Parser)
@@ -36,11 +38,26 @@
import java.io.Reader;
import java.io.ByteArrayInputStream;
+import org.apache.commons.jexl.util.introspection.Uberspect;
+
public class Parser/*@bgen(jjtree)*/implements ParserTreeConstants/*@egen*/
{/*@bgen(jjtree)*/
protected JJTParserState jjtree = new JJTParserState();
/*@egen*/
+
+ private Uberspect uberspect;
+
+ public void setUberspect(Uberspect uberspect)
+ {
+ this.uberspect = uberspect;
+ }
+
+ protected Uberspect getUberspect()
+ {
+ return uberspect;
+ }
+
public SimpleNode parse(Reader reader)
throws Exception
{
@@ -1257,6 +1274,7 @@
{
Literal()
|
+ LOOKAHEAD(3)
Reference()
|
"(" Expression() ")"
@@ -1264,6 +1282,8 @@
EmptyFunction()
|
SizeFunction()
+|
+ MapLiteral()
}
@@ -1433,6 +1453,7 @@
{
";"
|
+ LOOKAHEAD(3)
Block()
|
LOOKAHEAD( Reference() ";" ) ReferenceExpression()
@@ -1638,6 +1659,68 @@
/*@egen*/
}
+void MapLiteral() : {/*@bgen(jjtree) MapLiteral */
+ ASTMapLiteral jjtn000 = new ASTMapLiteral(this, JJTMAPLITERAL);
+ boolean jjtc000 = true;
+ jjtree.openNodeScope(jjtn000);
+/*@egen*/}
+{/*@bgen(jjtree) MapLiteral */
+ try {
+/*@egen*/
+ "[" MapEntry() ( "," MapEntry() )* "]"/*@bgen(jjtree)*/
+ } catch (Throwable jjte000) {
+ if (jjtc000) {
+ jjtree.clearNodeScope(jjtn000);
+ jjtc000 = false;
+ } else {
+ jjtree.popNode();
+ }
+ if (jjte000 instanceof RuntimeException) {
+ throw (RuntimeException)jjte000;
+ }
+ if (jjte000 instanceof ParseException) {
+ throw (ParseException)jjte000;
+ }
+ throw (Error)jjte000;
+ } finally {
+ if (jjtc000) {
+ jjtree.closeNodeScope(jjtn000, true);
+ }
+ }
+/*@egen*/
+}
+
+void MapEntry() : {/*@bgen(jjtree) MapEntry */
+ ASTMapEntry jjtn000 = new ASTMapEntry(this, JJTMAPENTRY);
+ boolean jjtc000 = true;
+ jjtree.openNodeScope(jjtn000);
+/*@egen*/}
+{/*@bgen(jjtree) MapEntry */
+ try {
+/*@egen*/
+ Parameter() "=>" Parameter()/*@bgen(jjtree)*/
+ } catch (Throwable jjte000) {
+ if (jjtc000) {
+ jjtree.clearNodeScope(jjtn000);
+ jjtc000 = false;
+ } else {
+ jjtree.popNode();
+ }
+ if (jjte000 instanceof RuntimeException) {
+ throw (RuntimeException)jjte000;
+ }
+ if (jjte000 instanceof ParseException) {
+ throw (ParseException)jjte000;
+ }
+ throw (Error)jjte000;
+ } finally {
+ if (jjtc000) {
+ jjtree.closeNodeScope(jjtn000, true);
+ }
+ }
+/*@egen*/
+}
+
void Method() : {/*@bgen(jjtree) Method */
ASTMethod jjtn000 = new ASTMethod(this, JJTMETHOD);
boolean jjtc000 = true;
@@ -1725,7 +1808,7 @@
{/*@bgen(jjtree) Reference */
try {
/*@egen*/
- (LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() | Identifier())
+ (LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() | Identifier() | MapLiteral())
(LOOKAHEAD(2) "."
(
LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() |
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jjt?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jjt (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Parser.jjt Sat Jun 2 08:13:05 2007
@@ -5,9 +5,9 @@
* 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.
@@ -30,6 +30,7 @@
STATIC=false;
VISITOR=true;
NODE_USES_PARSER=true;
+ UNICODE_INPUT=true;
}
PARSER_BEGIN(Parser)
@@ -39,8 +40,23 @@
import java.io.Reader;
import java.io.ByteArrayInputStream;
+import org.apache.commons.jexl.util.introspection.Uberspect;
+
public class Parser
{
+
+ private Uberspect uberspect;
+
+ public void setUberspect(Uberspect uberspect)
+ {
+ this.uberspect = uberspect;
+ }
+
+ protected Uberspect getUberspect()
+ {
+ return uberspect;
+ }
+
public SimpleNode parse(Reader reader)
throws Exception
{
@@ -269,6 +285,7 @@
{
Literal()
|
+ LOOKAHEAD(3)
Reference()
|
"(" Expression() ")"
@@ -276,6 +293,8 @@
EmptyFunction()
|
SizeFunction()
+|
+ MapLiteral()
}
@@ -356,6 +375,7 @@
{
";"
|
+ LOOKAHEAD(3)
Block()
|
LOOKAHEAD( Reference() ";" ) ReferenceExpression()
@@ -405,6 +425,16 @@
"foreach" "(" Reference() "in" Reference() ")" Statement()
}
+void MapLiteral() : {}
+{
+ "[" MapEntry() ( "," MapEntry() )* "]"
+}
+
+void MapEntry() : {}
+{
+ Parameter() "=>" Parameter()
+}
+
void Method() : {}
{
Identifier() "("[ Parameter() ( "," Parameter() )* ] ")"
@@ -422,7 +452,7 @@
void Reference() : {}
{
- (LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() | Identifier())
+ (LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() | Identifier() | MapLiteral())
(LOOKAHEAD(2) "."
(
LOOKAHEAD(Identifier() "[" ( Expression() | IntegerLiteral() | Reference()) "]") ArrayAccess() |
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserConstants.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserConstants.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserConstants.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserConstants.java Sat Jun 2 08:13:05 2007
@@ -1,20 +1,4 @@
-/*
- * 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.
- */
-/* Generated By:JavaCC: Do not edit this line. ParserConstants.java */
+/* Generated By:JJTree&JavaCC: Do not edit this line. ParserConstants.java */
package org.apache.commons.jexl.parser;
public interface ParserConstants {
@@ -23,10 +7,10 @@
int COMMENT = 1;
int INTEGER_LITERAL = 7;
int FLOAT_LITERAL = 8;
- int IDENTIFIER = 58;
- int LETTER = 59;
- int DIGIT = 60;
- int STRING_LITERAL = 61;
+ int IDENTIFIER = 59;
+ int LETTER = 60;
+ int DIGIT = 61;
+ int STRING_LITERAL = 62;
int DEFAULT = 0;
@@ -85,9 +69,10 @@
"\"while\"",
"\"foreach\"",
"\"in\"",
- "\",\"",
"\"[\"",
+ "\",\"",
"\"]\"",
+ "\"=>\"",
"\".\"",
"<IDENTIFIER>",
"<LETTER>",
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTokenManager.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTokenManager.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTokenManager.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTokenManager.java Sat Jun 2 08:13:05 2007
@@ -1,27 +1,12 @@
-/*
- * 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.
- */
-/* Generated By:JavaCC: Do not edit this line. ParserTokenManager.java */
+/* Generated By:JJTree&JavaCC: Do not edit this line. ParserTokenManager.java */
package org.apache.commons.jexl.parser;
import java.io.Reader;
import java.io.ByteArrayInputStream;
+import org.apache.commons.jexl.util.introspection.Uberspect;
-public class ParserTokenManager implements ParserConstants {
+public class ParserTokenManager implements ParserConstants
+{
public java.io.PrintStream debugStream = System.out;
-
public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
private final int jjStopStringLiteralDfa_0(int pos, long active0)
{
@@ -30,34 +15,34 @@
case 0:
if ((active0 & 0x3ef285550a4800L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
return 5;
}
return -1;
case 1:
+ if ((active0 & 0x22000555020000L) != 0L)
+ return 5;
if ((active0 & 0x1cf28000084800L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
jjmatchedPos = 1;
return 5;
}
- if ((active0 & 0x22000555020000L) != 0L)
- return 5;
return -1;
case 2:
+ if ((active0 & 0x128000080000L) != 0L)
+ return 5;
if ((active0 & 0x1ce00000004800L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
jjmatchedPos = 2;
return 5;
}
- if ((active0 & 0x128000080000L) != 0L)
- return 5;
return -1;
case 3:
if ((active0 & 0x18800000000800L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
jjmatchedPos = 3;
return 5;
}
@@ -67,7 +52,7 @@
case 4:
if ((active0 & 0x10000000000000L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
jjmatchedPos = 4;
return 5;
}
@@ -77,7 +62,7 @@
case 5:
if ((active0 & 0x10000000000000L) != 0L)
{
- jjmatchedKind = 58;
+ jjmatchedKind = 59;
jjmatchedPos = 5;
return 5;
}
@@ -125,11 +110,11 @@
case 43:
return jjStopAtPos(0, 35);
case 44:
- return jjStopAtPos(0, 54);
+ return jjStopAtPos(0, 55);
case 45:
return jjStopAtPos(0, 36);
case 46:
- return jjStopAtPos(0, 57);
+ return jjStopAtPos(0, 58);
case 47:
return jjStopAtPos(0, 38);
case 59:
@@ -139,12 +124,12 @@
return jjMoveStringLiteralDfa1_0(0x80000000L);
case 61:
jjmatchedKind = 15;
- return jjMoveStringLiteralDfa1_0(0x800000L);
+ return jjMoveStringLiteralDfa1_0(0x200000000800000L);
case 62:
jjmatchedKind = 29;
return jjMoveStringLiteralDfa1_0(0x200000000L);
case 91:
- return jjStopAtPos(0, 55);
+ return jjStopAtPos(0, 54);
case 93:
return jjStopAtPos(0, 56);
case 94:
@@ -211,6 +196,10 @@
else if ((active0 & 0x200000000L) != 0L)
return jjStopAtPos(1, 33);
break;
+ case 62:
+ if ((active0 & 0x200000000000000L) != 0L)
+ return jjStopAtPos(1, 57);
+ break;
case 97:
return jjMoveStringLiteralDfa2_0(active0, 0x800000000000L);
case 101:
@@ -474,8 +463,8 @@
jjCheckNAddTwoStates(7, 8);
else if (curChar == 36)
{
- if (kind > 58)
- kind = 58;
+ if (kind > 59)
+ kind = 59;
jjCheckNAdd(5);
}
else if (curChar == 35)
@@ -496,15 +485,15 @@
case 4:
if (curChar != 36)
break;
- if (kind > 58)
- kind = 58;
+ if (kind > 59)
+ kind = 59;
jjCheckNAdd(5);
break;
case 5:
if ((0x3ff001000000000L & l) == 0L)
break;
- if (kind > 58)
- kind = 58;
+ if (kind > 59)
+ kind = 59;
jjCheckNAdd(5);
break;
case 6:
@@ -516,8 +505,8 @@
jjCheckNAddTwoStates(7, 8);
break;
case 8:
- if (curChar == 34 && kind > 61)
- kind = 61;
+ if (curChar == 34 && kind > 62)
+ kind = 62;
break;
case 9:
if (curChar == 39)
@@ -528,8 +517,8 @@
jjCheckNAddTwoStates(10, 11);
break;
case 11:
- if (curChar == 39 && kind > 61)
- kind = 61;
+ if (curChar == 39 && kind > 62)
+ kind = 62;
break;
case 12:
if ((0x3ff000000000000L & l) == 0L)
@@ -575,8 +564,8 @@
case 5:
if ((0x7fffffe87fffffeL & l) == 0L)
break;
- if (kind > 58)
- kind = 58;
+ if (kind > 59)
+ kind = 59;
jjCheckNAdd(5);
break;
case 1:
@@ -654,13 +643,13 @@
"\154\164", "\76", "\147\164", "\74\75", "\154\145", "\76\75", "\147\145", "\53", "\55",
"\52", "\57", "\144\151\166", "\45", "\155\157\144", "\176", "\41", "\156\157\164",
"\156\165\154\154", "\164\162\165\145", "\146\141\154\163\145", "\73", "\151\146",
-"\145\154\163\145", "\167\150\151\154\145", "\146\157\162\145\141\143\150", "\151\156", "\54",
-"\133", "\135", "\56", null, null, null, null, };
+"\145\154\163\145", "\167\150\151\154\145", "\146\157\162\145\141\143\150", "\151\156", "\133",
+"\54", "\135", "\75\76", "\56", null, null, null, null, };
public static final String[] lexStateNames = {
"DEFAULT",
};
static final long[] jjtoToken = {
- 0x27ffffffffffff81L,
+ 0x4fffffffffffff81L,
};
static final long[] jjtoSkip = {
0x7eL,
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTreeConstants.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTreeConstants.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTreeConstants.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserTreeConstants.java Sat Jun 2 08:13:05 2007
@@ -1,114 +1,101 @@
-/*
- * 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.
- */
-/* Generated By:JJTree: Do not edit this line. ParserTreeConstants.java */
+/* Generated By:JJTree: Do not edit this line. ./ParserTreeConstants.java */
package org.apache.commons.jexl.parser;
-public interface ParserTreeConstants {
- int JJTJEXLSCRIPT = 0;
-
- int JJTBLOCK = 1;
-
- int JJTEMPTYFUNCTION = 2;
-
- int JJTSIZEFUNCTION = 3;
-
- int JJTIDENTIFIER = 4;
-
- int JJTEXPRESSION = 5;
-
- int JJTASSIGNMENT = 6;
-
- int JJTVOID = 7;
-
- int JJTORNODE = 8;
-
- int JJTANDNODE = 9;
-
- int JJTBITWISEORNODE = 10;
-
- int JJTBITWISEXORNODE = 11;
-
- int JJTBITWISEANDNODE = 12;
-
- int JJTEQNODE = 13;
-
- int JJTNENODE = 14;
-
- int JJTLTNODE = 15;
-
- int JJTGTNODE = 16;
-
- int JJTLENODE = 17;
-
- int JJTGENODE = 18;
-
- int JJTADDNODE = 19;
-
- int JJTSUBTRACTNODE = 20;
-
- int JJTMULNODE = 21;
-
- int JJTDIVNODE = 22;
-
- int JJTMODNODE = 23;
-
- int JJTUNARYMINUSNODE = 24;
-
- int JJTBITWISECOMPLNODE = 25;
-
- int JJTNOTNODE = 26;
-
- int JJTNULLLITERAL = 27;
-
- int JJTTRUENODE = 28;
-
- int JJTFALSENODE = 29;
-
- int JJTINTEGERLITERAL = 30;
-
- int JJTFLOATLITERAL = 31;
-
- int JJTSTRINGLITERAL = 32;
-
- int JJTEXPRESSIONEXPRESSION = 33;
-
- int JJTSTATEMENTEXPRESSION = 34;
-
- int JJTREFERENCEEXPRESSION = 35;
-
- int JJTIFSTATEMENT = 36;
-
- int JJTWHILESTATEMENT = 37;
-
- int JJTFOREACHSTATEMENT = 38;
-
- int JJTMETHOD = 39;
-
- int JJTARRAYACCESS = 40;
-
- int JJTSIZEMETHOD = 41;
-
- int JJTREFERENCE = 42;
-
- String[] jjtNodeName = {"JexlScript", "Block", "EmptyFunction", "SizeFunction", "Identifier", "Expression",
- "Assignment", "void", "OrNode", "AndNode", "BitwiseOrNode", "BitwiseXorNode", "BitwiseAndNode", "EQNode",
- "NENode", "LTNode", "GTNode", "LENode", "GENode", "AddNode", "SubtractNode", "MulNode", "DivNode", "ModNode",
- "UnaryMinusNode", "BitwiseComplNode", "NotNode", "NullLiteral", "TrueNode", "FalseNode", "IntegerLiteral",
- "FloatLiteral", "StringLiteral", "ExpressionExpression", "StatementExpression", "ReferenceExpression",
- "IfStatement", "WhileStatement", "ForeachStatement", "Method", "ArrayAccess", "SizeMethod", "Reference", };
+public interface ParserTreeConstants
+{
+ public int JJTJEXLSCRIPT = 0;
+ public int JJTBLOCK = 1;
+ public int JJTEMPTYFUNCTION = 2;
+ public int JJTSIZEFUNCTION = 3;
+ public int JJTIDENTIFIER = 4;
+ public int JJTEXPRESSION = 5;
+ public int JJTASSIGNMENT = 6;
+ public int JJTVOID = 7;
+ public int JJTORNODE = 8;
+ public int JJTANDNODE = 9;
+ public int JJTBITWISEORNODE = 10;
+ public int JJTBITWISEXORNODE = 11;
+ public int JJTBITWISEANDNODE = 12;
+ public int JJTEQNODE = 13;
+ public int JJTNENODE = 14;
+ public int JJTLTNODE = 15;
+ public int JJTGTNODE = 16;
+ public int JJTLENODE = 17;
+ public int JJTGENODE = 18;
+ public int JJTADDNODE = 19;
+ public int JJTSUBTRACTNODE = 20;
+ public int JJTMULNODE = 21;
+ public int JJTDIVNODE = 22;
+ public int JJTMODNODE = 23;
+ public int JJTUNARYMINUSNODE = 24;
+ public int JJTBITWISECOMPLNODE = 25;
+ public int JJTNOTNODE = 26;
+ public int JJTNULLLITERAL = 27;
+ public int JJTTRUENODE = 28;
+ public int JJTFALSENODE = 29;
+ public int JJTINTEGERLITERAL = 30;
+ public int JJTFLOATLITERAL = 31;
+ public int JJTSTRINGLITERAL = 32;
+ public int JJTEXPRESSIONEXPRESSION = 33;
+ public int JJTSTATEMENTEXPRESSION = 34;
+ public int JJTREFERENCEEXPRESSION = 35;
+ public int JJTIFSTATEMENT = 36;
+ public int JJTWHILESTATEMENT = 37;
+ public int JJTFOREACHSTATEMENT = 38;
+ public int JJTMAPLITERAL = 39;
+ public int JJTMAPENTRY = 40;
+ public int JJTMETHOD = 41;
+ public int JJTARRAYACCESS = 42;
+ public int JJTSIZEMETHOD = 43;
+ public int JJTREFERENCE = 44;
+
+
+ public String[] jjtNodeName = {
+ "JexlScript",
+ "Block",
+ "EmptyFunction",
+ "SizeFunction",
+ "Identifier",
+ "Expression",
+ "Assignment",
+ "void",
+ "OrNode",
+ "AndNode",
+ "BitwiseOrNode",
+ "BitwiseXorNode",
+ "BitwiseAndNode",
+ "EQNode",
+ "NENode",
+ "LTNode",
+ "GTNode",
+ "LENode",
+ "GENode",
+ "AddNode",
+ "SubtractNode",
+ "MulNode",
+ "DivNode",
+ "ModNode",
+ "UnaryMinusNode",
+ "BitwiseComplNode",
+ "NotNode",
+ "NullLiteral",
+ "TrueNode",
+ "FalseNode",
+ "IntegerLiteral",
+ "FloatLiteral",
+ "StringLiteral",
+ "ExpressionExpression",
+ "StatementExpression",
+ "ReferenceExpression",
+ "IfStatement",
+ "WhileStatement",
+ "ForeachStatement",
+ "MapLiteral",
+ "MapEntry",
+ "Method",
+ "ArrayAccess",
+ "SizeMethod",
+ "Reference",
+ };
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserVisitor.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserVisitor.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserVisitor.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/ParserVisitor.java Sat Jun 2 08:13:05 2007
@@ -1,107 +1,52 @@
-/*
- * 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.
- */
-/* Generated By:JJTree: Do not edit this line. ParserVisitor.java */
+/* Generated By:JJTree: Do not edit this line. ./ParserVisitor.java */
package org.apache.commons.jexl.parser;
-public interface ParserVisitor {
- Object visit(SimpleNode node, Object data);
-
- Object visit(ASTJexlScript node, Object data);
-
- Object visit(ASTBlock node, Object data);
-
- Object visit(ASTEmptyFunction node, Object data);
-
- Object visit(ASTSizeFunction node, Object data);
-
- Object visit(ASTIdentifier node, Object data);
-
- Object visit(ASTExpression node, Object data);
-
- Object visit(ASTAssignment node, Object data);
-
- Object visit(ASTOrNode node, Object data);
-
- Object visit(ASTAndNode node, Object data);
-
- Object visit(ASTBitwiseOrNode node, Object data);
-
- Object visit(ASTBitwiseXorNode node, Object data);
-
- Object visit(ASTBitwiseAndNode node, Object data);
-
- Object visit(ASTEQNode node, Object data);
-
- Object visit(ASTNENode node, Object data);
-
- Object visit(ASTLTNode node, Object data);
-
- Object visit(ASTGTNode node, Object data);
-
- Object visit(ASTLENode node, Object data);
-
- Object visit(ASTGENode node, Object data);
-
- Object visit(ASTAddNode node, Object data);
-
- Object visit(ASTSubtractNode node, Object data);
-
- Object visit(ASTMulNode node, Object data);
-
- Object visit(ASTDivNode node, Object data);
-
- Object visit(ASTModNode node, Object data);
-
- Object visit(ASTUnaryMinusNode node, Object data);
-
- Object visit(ASTBitwiseComplNode node, Object data);
-
- Object visit(ASTNotNode node, Object data);
-
- Object visit(ASTNullLiteral node, Object data);
-
- Object visit(ASTTrueNode node, Object data);
-
- Object visit(ASTFalseNode node, Object data);
-
- Object visit(ASTIntegerLiteral node, Object data);
-
- Object visit(ASTFloatLiteral node, Object data);
-
- Object visit(ASTStringLiteral node, Object data);
-
- Object visit(ASTExpressionExpression node, Object data);
-
- Object visit(ASTStatementExpression node, Object data);
-
- Object visit(ASTReferenceExpression node, Object data);
-
- Object visit(ASTIfStatement node, Object data);
-
- Object visit(ASTWhileStatement node, Object data);
-
- Object visit(ASTForeachStatement node, Object data);
-
- Object visit(ASTMethod node, Object data);
-
- Object visit(ASTArrayAccess node, Object data);
-
- Object visit(ASTSizeMethod node, Object data);
-
- Object visit(ASTReference node, Object data);
-}
\ No newline at end of file
+public interface ParserVisitor
+{
+ public Object visit(SimpleNode node, Object data);
+ public Object visit(ASTJexlScript node, Object data);
+ public Object visit(ASTBlock node, Object data);
+ public Object visit(ASTEmptyFunction node, Object data);
+ public Object visit(ASTSizeFunction node, Object data);
+ public Object visit(ASTIdentifier node, Object data);
+ public Object visit(ASTExpression node, Object data);
+ public Object visit(ASTAssignment node, Object data);
+ public Object visit(ASTOrNode node, Object data);
+ public Object visit(ASTAndNode node, Object data);
+ public Object visit(ASTBitwiseOrNode node, Object data);
+ public Object visit(ASTBitwiseXorNode node, Object data);
+ public Object visit(ASTBitwiseAndNode node, Object data);
+ public Object visit(ASTEQNode node, Object data);
+ public Object visit(ASTNENode node, Object data);
+ public Object visit(ASTLTNode node, Object data);
+ public Object visit(ASTGTNode node, Object data);
+ public Object visit(ASTLENode node, Object data);
+ public Object visit(ASTGENode node, Object data);
+ public Object visit(ASTAddNode node, Object data);
+ public Object visit(ASTSubtractNode node, Object data);
+ public Object visit(ASTMulNode node, Object data);
+ public Object visit(ASTDivNode node, Object data);
+ public Object visit(ASTModNode node, Object data);
+ public Object visit(ASTUnaryMinusNode node, Object data);
+ public Object visit(ASTBitwiseComplNode node, Object data);
+ public Object visit(ASTNotNode node, Object data);
+ public Object visit(ASTNullLiteral node, Object data);
+ public Object visit(ASTTrueNode node, Object data);
+ public Object visit(ASTFalseNode node, Object data);
+ public Object visit(ASTIntegerLiteral node, Object data);
+ public Object visit(ASTFloatLiteral node, Object data);
+ public Object visit(ASTStringLiteral node, Object data);
+ public Object visit(ASTExpressionExpression node, Object data);
+ public Object visit(ASTStatementExpression node, Object data);
+ public Object visit(ASTReferenceExpression node, Object data);
+ public Object visit(ASTIfStatement node, Object data);
+ public Object visit(ASTWhileStatement node, Object data);
+ public Object visit(ASTForeachStatement node, Object data);
+ public Object visit(ASTMapLiteral node, Object data);
+ public Object visit(ASTMapEntry node, Object data);
+ public Object visit(ASTMethod node, Object data);
+ public Object visit(ASTArrayAccess node, Object data);
+ public Object visit(ASTSizeMethod node, Object data);
+ public Object visit(ASTReference node, Object data);
+}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleCharStream.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleCharStream.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleCharStream.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/SimpleCharStream.java Sat Jun 2 08:13:05 2007
@@ -1,19 +1,3 @@
-/*
- * 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.
- */
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */
package org.apache.commons.jexl.parser;
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Token.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Token.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Token.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/Token.java Sat Jun 2 08:13:05 2007
@@ -1,19 +1,3 @@
-/*
- * 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.
- */
/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */
package org.apache.commons.jexl.parser;
@@ -23,72 +7,75 @@
public class Token {
- /**
- * An integer that describes the kind of this token. This numbering system
- * is determined by JavaCCParser, and a table of these numbers is stored in
- * the file ...Constants.java.
- */
- public int kind;
-
- /**
- * beginLine and beginColumn describe the position of the first character of
- * this token; endLine and endColumn describe the position of the last
- * character of this token.
- */
- public int beginLine, beginColumn, endLine, endColumn;
-
- /**
- * The string image of the token.
- */
- public String image;
-
- /**
- * A reference to the next regular (non-special) token from the input
- * stream. If this is the last token from the input stream, or if the token
- * manager has not read tokens beyond this one, this field is set to null.
- * This is true only if this token is also a regular token. Otherwise, see
- * below for a description of the contents of this field.
- */
- public Token next;
-
- /**
- * This field is used to access special tokens that occur prior to this
- * token, but after the immediately preceding regular (non-special) token.
- * If there are no such special tokens, this field is set to null. When
- * there are more than one such special token, this field refers to the last
- * of these special tokens, which in turn refers to the next previous
- * special token through its specialToken field, and so on until the first
- * special token (whose specialToken field is null). The next fields of
- * special tokens refer to other special tokens that immediately follow it
- * (without an intervening regular token). If there is no such token, this
- * field is null.
- */
- public Token specialToken;
-
- /**
- * Returns the image.
- */
- public final String toString() {
- return image;
- }
-
- /**
- * Returns a new Token object, by default. However, if you want, you can
- * create and return subclass objects based on the value of ofKind. Simply
- * add the cases to the switch for all those special cases. For example, if
- * you have a subclass of Token called IDToken that you want to create if
- * ofKind is ID, simlpy add something like :
- *
- * case MyParserConstants.ID : return new IDToken();
- *
- * to the following switch statement. Then you can cast matchedToken
- * variable to the appropriate type and use it in your lexical actions.
- */
- public static final Token newToken(int ofKind) {
- switch (ofKind) {
- default:
- return new Token();
- }
- }
+ /**
+ * An integer that describes the kind of this token. This numbering
+ * system is determined by JavaCCParser, and a table of these numbers is
+ * stored in the file ...Constants.java.
+ */
+ public int kind;
+
+ /**
+ * beginLine and beginColumn describe the position of the first character
+ * of this token; endLine and endColumn describe the position of the
+ * last character of this token.
+ */
+ public int beginLine, beginColumn, endLine, endColumn;
+
+ /**
+ * The string image of the token.
+ */
+ public String image;
+
+ /**
+ * A reference to the next regular (non-special) token from the input
+ * stream. If this is the last token from the input stream, or if the
+ * token manager has not read tokens beyond this one, this field is
+ * set to null. This is true only if this token is also a regular
+ * token. Otherwise, see below for a description of the contents of
+ * this field.
+ */
+ public Token next;
+
+ /**
+ * This field is used to access special tokens that occur prior to this
+ * token, but after the immediately preceding regular (non-special) token.
+ * If there are no such special tokens, this field is set to null.
+ * When there are more than one such special token, this field refers
+ * to the last of these special tokens, which in turn refers to the next
+ * previous special token through its specialToken field, and so on
+ * until the first special token (whose specialToken field is null).
+ * The next fields of special tokens refer to other special tokens that
+ * immediately follow it (without an intervening regular token). If there
+ * is no such token, this field is null.
+ */
+ public Token specialToken;
+
+ /**
+ * Returns the image.
+ */
+ public String toString()
+ {
+ return image;
+ }
+
+ /**
+ * Returns a new Token object, by default. However, if you want, you
+ * can create and return subclass objects based on the value of ofKind.
+ * Simply add the cases to the switch for all those special cases.
+ * For example, if you have a subclass of Token called IDToken that
+ * you want to create if ofKind is ID, simlpy add something like :
+ *
+ * case MyParserConstants.ID : return new IDToken();
+ *
+ * to the following switch statement. Then you can cast matchedToken
+ * variable to the appropriate type and use it in your lexical actions.
+ */
+ public static final Token newToken(int ofKind)
+ {
+ switch(ofKind)
+ {
+ default : return new Token();
+ }
+ }
}
Modified: jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/TokenMgrError.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/TokenMgrError.java?view=diff&rev=543748&r1=543747&r2=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/TokenMgrError.java (original)
+++ jakarta/commons/proper/jexl/trunk/src/java/org/apache/commons/jexl/parser/TokenMgrError.java Sat Jun 2 08:13:05 2007
@@ -1,104 +1,86 @@
-/*
- * 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.
- */
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */
package org.apache.commons.jexl.parser;
-public class TokenMgrError extends Error {
- /** serialization version id jdk13 generated. */
- static final long serialVersionUID = 2843513002462329650L;
-
- /*
- * Ordinals for various reasons why an Error of this type can be thrown.
- */
-
- /**
- * Lexical error occured.
- */
- static final int LEXICAL_ERROR = 0;
-
- /**
- * An attempt wass made to create a second instance of a static token
- * manager.
- */
- static final int STATIC_LEXER_ERROR = 1;
-
- /**
- * Tried to change to an invalid lexical state.
- */
- static final int INVALID_LEXICAL_STATE = 2;
-
- /**
- * Detected (and bailed out of) an infinite loop in the token manager.
- */
- static final int LOOP_DETECTED = 3;
-
- /**
- * Indicates the reason why the exception is thrown. It will have one of the
- * above 4 values.
- */
- int errorCode;
-
- /**
- * Replaces unprintable characters by their espaced (or unicode escaped)
- * equivalents in the given string
- */
- protected static final String addEscapes(String str) {
- StringBuffer retval = new StringBuffer();
- char ch;
- for (int i = 0; i < str.length(); i++) {
- switch (str.charAt(i)) {
- case 0:
- continue;
- case '\b':
- retval.append("\\b");
- continue;
- case '\t':
- retval.append("\\t");
- continue;
- case '\n':
- retval.append("\\n");
- continue;
- case '\f':
- retval.append("\\f");
- continue;
- case '\r':
- retval.append("\\r");
- continue;
- case '\"':
- retval.append("\\\"");
- continue;
- case '\'':
- retval.append("\\\'");
- continue;
- case '\\':
- retval.append("\\\\");
- continue;
- default:
- if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u" + s.substring(s.length() - 4, s.length()));
- } else {
- retval.append(ch);
- }
- continue;
- }
+public class TokenMgrError extends Error
+{
+ /*
+ * Ordinals for various reasons why an Error of this type can be thrown.
+ */
+
+ /**
+ * Lexical error occured.
+ */
+ static final int LEXICAL_ERROR = 0;
+
+ /**
+ * An attempt wass made to create a second instance of a static token manager.
+ */
+ static final int STATIC_LEXER_ERROR = 1;
+
+ /**
+ * Tried to change to an invalid lexical state.
+ */
+ static final int INVALID_LEXICAL_STATE = 2;
+
+ /**
+ * Detected (and bailed out of) an infinite loop in the token manager.
+ */
+ static final int LOOP_DETECTED = 3;
+
+ /**
+ * Indicates the reason why the exception is thrown. It will have
+ * one of the above 4 values.
+ */
+ int errorCode;
+
+ /**
+ * Replaces unprintable characters by their espaced (or unicode escaped)
+ * equivalents in the given string
+ */
+ protected static final String addEscapes(String str) {
+ StringBuffer retval = new StringBuffer();
+ char ch;
+ for (int i = 0; i < str.length(); i++) {
+ switch (str.charAt(i))
+ {
+ case 0 :
+ continue;
+ case '\b':
+ retval.append("\\b");
+ continue;
+ case '\t':
+ retval.append("\\t");
+ continue;
+ case '\n':
+ retval.append("\\n");
+ continue;
+ case '\f':
+ retval.append("\\f");
+ continue;
+ case '\r':
+ retval.append("\\r");
+ continue;
+ case '\"':
+ retval.append("\\\"");
+ continue;
+ case '\'':
+ retval.append("\\\'");
+ continue;
+ case '\\':
+ retval.append("\\\\");
+ continue;
+ default:
+ if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
+ String s = "0000" + Integer.toString(ch, 16);
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
+ } else {
+ retval.append(ch);
+ }
+ continue;
}
- return retval.toString();
- }
+ }
+ return retval.toString();
+ }
/**
* Returns a detailed message for the Error when it is thrown by the
@@ -112,40 +94,40 @@
* curchar : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
- protected static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn,
- String errorAfter, char curChar) {
- return ("Lexical error at line " + errorLine + ", column " + errorColumn + ". Encountered: "
- + (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int) curChar + "), ")
- + "after : \"" + addEscapes(errorAfter) + "\"");
- }
-
- /**
- * You can also modify the body of this method to customize your error
- * messages. For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE
- * are not of end-users concern, so you can return something like :
- *
- * "Internal Error : Please file a bug report .... "
- *
- * from this method for such cases in the release version of your parser.
- */
- public String getMessage() {
- return super.getMessage();
- }
-
- /*
- * Constructors of various flavors follow.
- */
-
- public TokenMgrError() {
- }
-
- public TokenMgrError(String message, int reason) {
- super(message);
- errorCode = reason;
- }
-
- public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter,
- char curChar, int reason) {
- this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
- }
+ protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
+ return("Lexical error at line " +
+ errorLine + ", column " +
+ errorColumn + ". Encountered: " +
+ (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
+ "after : \"" + addEscapes(errorAfter) + "\"");
+ }
+
+ /**
+ * You can also modify the body of this method to customize your error messages.
+ * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
+ * of end-users concern, so you can return something like :
+ *
+ * "Internal Error : Please file a bug report .... "
+ *
+ * from this method for such cases in the release version of your parser.
+ */
+ public String getMessage() {
+ return super.getMessage();
+ }
+
+ /*
+ * Constructors of various flavors follow.
+ */
+
+ public TokenMgrError() {
+ }
+
+ public TokenMgrError(String message, int reason) {
+ super(message);
+ errorCode = reason;
+ }
+
+ public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+ this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
+ }
}
Added: jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java?view=auto&rev=543748
==============================================================================
--- jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java (added)
+++ jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java Sat Jun 2 08:13:05 2007
@@ -0,0 +1,69 @@
+package org.apache.commons.jexl;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for map literals
+ *
+ * @author Peter Royal
+ * @since 1.2
+ */
+public class MapLiteralTest extends TestCase {
+
+ public void testLiteralWithStrings() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "[ 'foo' => 'bar' ]" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Object o = e.evaluate( jc );
+ assertEquals( Collections.singletonMap( "foo", "bar" ), o );
+ }
+
+ public void testLiteralWithMultipleEntries() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "[ 'foo' => 'bar', 'eat' => 'food' ]" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Map expected = new HashMap();
+ expected.put( "foo", "bar" );
+ expected.put( "eat", "food" );
+
+ Object o = e.evaluate( jc );
+ assertEquals( expected, o );
+ }
+
+ public void testLiteralWithNumbers() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "[ 5 => 10 ]" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Object o = e.evaluate( jc );
+ assertEquals( Collections.singletonMap( new Integer( 5 ), new Integer( 10 ) ), o );
+ }
+
+ public void testSizeOfSimpleMapLiteral() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "size([ 'foo' => 'bar' ])" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Object o = e.evaluate( jc );
+ assertEquals( new Integer( 1 ), o );
+ }
+
+ public void testCallingMethodsOnNewMapLiteral() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "size([ 'foo' => 'bar' ].values())" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Object o = e.evaluate( jc );
+ assertEquals( new Integer( 1 ), o );
+ }
+
+ public void testNotEmptySimpleMapLiteral() throws Exception {
+ Expression e = ExpressionFactory.createExpression( "empty([ 'foo' => 'bar' ])" );
+ JexlContext jc = JexlHelper.createContext();
+
+ Object o = e.evaluate( jc );
+ assertFalse( ( (Boolean) o ).booleanValue() );
+ }
+
+}
Propchange: jakarta/commons/proper/jexl/trunk/src/test/org/apache/commons/jexl/MapLiteralTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org