[jboss-cvs] JBossAS SVN: r69450 - in trunk/jbossmq: src/main and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 29 12:38:23 EST 2008
Author: pgier
Date: 2008-01-29 12:38:23 -0500 (Tue, 29 Jan 2008)
New Revision: 69450
Added:
trunk/jbossmq/src/main/javacc/
trunk/jbossmq/src/main/javacc/org/
trunk/jbossmq/src/main/javacc/org/jboss/
trunk/jbossmq/src/main/javacc/org/jboss/mq/
trunk/jbossmq/src/main/javacc/org/jboss/mq/selectors/
trunk/jbossmq/src/main/javacc/org/jboss/mq/selectors/SelectorParser.jj
Removed:
trunk/jbossmq/src/main/org/jboss/mq/selectors/SelectorParser.jj
Modified:
trunk/jbossmq/build.xml
trunk/jbossmq/pom.xml
Log:
Moving SelectorParser.jj into separate directory to work with maven plugin.
Modified: trunk/jbossmq/build.xml
===================================================================
--- trunk/jbossmq/build.xml 2008-01-29 17:30:07 UTC (rev 69449)
+++ trunk/jbossmq/build.xml 2008-01-29 17:38:23 UTC (rev 69450)
@@ -136,7 +136,7 @@
<mkdir dir="${build.parsers}/org/jboss/mq/selectors"/>
<!-- message selector parser -->
- <javacc target="${source.java}/org/jboss/mq/selectors/SelectorParser.jj"
+ <javacc target="${source.java}/javacc/org/jboss/mq/selectors/SelectorParser.jj"
outputdirectory="${build.parsers}/org/jboss/mq/selectors"
javacchome="${sun.javacc.lib}"
static="false"/>
Modified: trunk/jbossmq/pom.xml
===================================================================
--- trunk/jbossmq/pom.xml 2008-01-29 17:30:07 UTC (rev 69449)
+++ trunk/jbossmq/pom.xml 2008-01-29 17:38:23 UTC (rev 69450)
@@ -24,7 +24,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>javacc-maven-plugin</artifactId>
- <version>2.1</version>
+ <version>2.3</version>
<executions>
<execution>
<id>javacc</id>
@@ -32,7 +32,6 @@
<goal>javacc</goal>
</goals>
<configuration>
- <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<packageName>org.jboss.mq.selectors</packageName>
<isStatic>false</isStatic>
</configuration>
Copied: trunk/jbossmq/src/main/javacc/org/jboss/mq/selectors/SelectorParser.jj (from rev 69448, trunk/jbossmq/src/main/org/jboss/mq/selectors/SelectorParser.jj)
===================================================================
--- trunk/jbossmq/src/main/javacc/org/jboss/mq/selectors/SelectorParser.jj (rev 0)
+++ trunk/jbossmq/src/main/javacc/org/jboss/mq/selectors/SelectorParser.jj 2008-01-29 17:38:23 UTC (rev 69450)
@@ -0,0 +1,628 @@
+/*
+ * JBossMQ, the OpenSource JMS implementation
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+
+options {
+ LOOKAHEAD=1;
+/*
+ DEBUG_PARSER=true;
+ DEBUG_LOOKAHEAD=true;
+ DEBUG_TOKEN_MANAGER=true;
+*/
+}
+
+PARSER_BEGIN(SelectorParser)
+
+package org.jboss.mq.selectors;
+
+import java.io.StringReader;
+
+import java.util.HashSet;
+import java.util.HashMap;
+
+/**
+ * A JavaCC 2.0 grammar for the JMS 1.1.0 message selectors.
+ *
+ * @see http://www.webgain.com/products/metamata/java_doc.html
+ *
+ * @author Scott.Stark at jboss.org
+ * @author adrian at jboss.org
+ * @version $Revision$
+ */
+public class SelectorParser
+ implements ISelectorParser
+{
+ private static final String LOFFER_L = "l";
+ private static final String UPPER_L = "L";
+ private static final String OX = "0X";
+ private static final String Ox = "0x";
+ private static final String ZERRO = "0";
+
+ private HashMap identifierMap;
+
+ public SelectorParser()
+ {
+ // keep the parser from feaking out, init using one of
+ // the JavaCC generated constructor
+ this(new StringReader(""));
+ }
+
+ public Object parse(String selector, HashMap identifierMap)
+ throws ParseException
+ {
+ return parse(selector, identifierMap, false);
+ }
+
+ public Object parse(String selector, HashMap identifierMap, boolean trace)
+ throws ParseException
+ {
+ StringReader sr = new StringReader(selector);
+ ReInit(sr);
+
+ // This will have no effect unless the debugging options are true
+ if (trace)
+ {
+ this.enable_tracing();
+ }
+ else
+ {
+ this.disable_tracing();
+ }
+
+ this.identifierMap = identifierMap;
+ return this.expression();
+ }
+
+ /**
+ * Strip off the leading and trailing (quote) chars from the given string
+ * and return it.
+ */
+ private String stripQuotes(String image)
+ {
+ StringBuffer result = new StringBuffer(image.length()-2);
+ int i = 1;
+ boolean escaped = false;
+ while (i < image.length() - 1)
+ {
+ if (escaped)
+ {
+ if (image.charAt(i) == '\'')
+ result.append('\'');
+ else
+ throw new RuntimeException("Invalid uses of quotes: " + image);
+ escaped = false;
+ }
+ else if (image.charAt(i) == '\'')
+ escaped = true;
+ else
+ result.append(image.charAt(i));
+ ++i;
+ }
+ return result.toString();
+ }
+
+ public static Object doParse(String selector, HashMap identifierMap)
+ throws ParseException
+ {
+ return doParse(selector, identifierMap, false);
+ }
+
+ public static Object doParse(String selector, HashMap identifierMap, boolean trace)
+ throws ParseException
+ {
+ SelectorParser parser = new SelectorParser();
+ return parser.parse(selector, identifierMap, trace);
+ }
+}
+
+PARSER_END(SelectorParser)
+
+/* IGNORE WHITESPACE */
+
+SKIP :
+{
+ " "
+ | "\r"
+ | "\t"
+ | "\f"
+ | "\n"
+}
+
+
+/* RESERVED WORDS AND LITERALS */
+
+TOKEN [IGNORE_CASE]:
+{
+ < TRUE: "TRUE" >
+ | < FALSE: "FALSE" >
+ | < NULL: "NULL" >
+ | < AND: "AND" >
+ | < NOT: "NOT" >
+ | < OR: "OR" >
+ | < BETWEEN: "BETWEEN" >
+ | < LIKE: "LIKE" >
+ | < IN: "IN" >
+ | < IS: "IS" >
+ | < ESCAPE: "ESCAPE" >
+ | < LPAREN: "(" >
+ | < RPAREN: ")" >
+ | < SEMICOLON: ";" >
+ | < COMMA: "," >
+
+}
+
+/* OPERATORS */
+
+TOKEN :
+{
+ < MULT: "*" >
+ | < DIV: "/" >
+ | < MINUS: "-" >
+ | < PLUS: "+" >
+ | < GT: ">" >
+ | < GE: ">=" >
+ | < LT: "<" >
+ | < LE: "<=" >
+ | < NE: "<>" >
+ | < EQ: "=" >
+
+}
+
+/* Literals */
+
+<DEFAULT> TOKEN : /* Numeric Literal */
+{
+ < INTEGER_LITERAL:
+ "-9223372036854775808"
+ | "-9223372036854775808l"
+ | "-9223372036854775808L"
+ | <DECIMAL_LITERAL> (["l","L"])?
+ | <HEX_LITERAL> (["l","L"])?
+ | <OCTAL_LITERAL> (["l","L"])?
+ >
+|
+ < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+|
+ < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+|
+ < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+|
+ < FLOATING_POINT_LITERAL:
+ (["+","-"])? (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
+ | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
+ | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
+ | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
+ >
+|
+ < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+}
+
+
+TOKEN :
+{
+ < STRING:
+ "'"
+ ( (~["'","\n","\r"])
+ | ("''")
+ )*
+ "'"
+ >
+}
+
+/* Function names */
+
+TOKEN :
+{
+ < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
+ |
+ < #LETTER: [ "_","$", "a"-"z", "A"-"Z" ] >
+ |
+ < #DIGIT: ["0" - "9"] >
+}
+
+/** Start of the grammar */
+
+Object expression() :
+{
+ Object exp1 = null;
+}
+{
+ exp1=selectorExpression()<EOF>
+ {
+ return exp1;
+ }
+}
+
+Object selectorExpression() :
+{
+ Object exp1 = null;
+ Object exp2 = null;
+}
+{
+ exp1=selectorTerm()
+ (
+ <OR> exp2=selectorTerm()
+ {
+ exp1 = new Operator(Operator.OR, exp1, exp2);
+ }
+ )*
+ {
+ return exp1;
+ }
+}
+
+Object selectorTerm() :
+{
+ Object exp1 = null;
+ Object exp2 = null;
+}
+{
+ exp1=selectorFactor()
+ (
+ <AND> exp2=selectorFactor()
+ {
+ exp1 = new Operator(Operator.AND, exp1, exp2);
+ }
+ )*
+ {
+ return exp1;
+ }
+}
+
+Object selectorFactor() :
+{
+ Object exp1 = null;
+}
+{
+ exp1=conditionalExpression()
+ {
+ return exp1;
+ }
+ | <NOT> exp1=conditionalExpression()
+ {
+ exp1 = new Operator(Operator.NOT, exp1);
+ }
+ {
+ return exp1;
+ }
+}
+
+Object conditionalExpression() :
+{
+ Object exp1 = null;
+}
+{
+ LOOKAHEAD(3)
+ <LPAREN> exp1=selectorExpression() <RPAREN>
+ {
+ return exp1;
+ }
+ |
+ exp1 = comparisonExpression()
+ {
+ return exp1;
+ }
+}
+
+Object comparisonExpression() :
+{
+ int op = -1;
+ HashSet set = null;
+ Object exp1 = null;
+ Object exp2 = null;
+ Object exp3 = null;
+ Object id = null;
+ Token not = null;
+}
+{
+ LOOKAHEAD(2147483647)
+ exp1=identifier() <IS> [ not=<NOT> ] <NULL>
+ {
+ int opCode = not == null ? Operator.IS_NULL : Operator.IS_NOT_NULL;
+ return new Operator(opCode, exp1);
+ }
+ |
+ LOOKAHEAD(2147483647)
+ id=identifier() [ not=<NOT> ] <IN> <LPAREN> { set = new HashSet(); } stringList(set) <RPAREN>
+ {
+ if (not == null)
+ return new Operator(Operator.IN, id, set);
+ else
+ return new Operator(Operator.NOT_IN, id, set);
+ return exp1;
+ }
+ |
+ LOOKAHEAD(2147483647)
+ id=identifier() [ not=<NOT> ] <LIKE> exp1=patternExpression(id)
+ {
+ if (not != null)
+ exp1 = new Operator(Operator.NOT, exp1);
+ return exp1;
+ }
+ |
+ LOOKAHEAD(2147483647)
+ exp1=stringExpression()
+ (
+ <EQ>{ op = Operator.EQUAL;}
+ | <NE>{ op = Operator.DIFFERENT;}
+ ) exp2=stringExpression()
+ {
+ return new Operator(op, exp1, exp2);
+ }
+ |
+ LOOKAHEAD(2147483647)
+ exp1=booleanExpression()
+ (
+ <EQ>{ op = Operator.EQUAL;}
+ | <NE>{ op = Operator.DIFFERENT;}
+ ) exp2=booleanExpression()
+ {
+ return new Operator(op, exp1, exp2);
+ }
+ |
+ LOOKAHEAD(2147483647)
+ exp1=arithExpression()
+ (
+ <EQ>{ op = Operator.EQUAL;}
+ | <NE>{ op = Operator.DIFFERENT;}
+ | <GT>{ op = Operator.GT;}
+ | <GE>{ op = Operator.GE;}
+ | <LT>{ op = Operator.LT;}
+ | <LE>{ op = Operator.LE;}
+ ) exp2=arithExpression()
+ {
+ return new Operator(op, exp1, exp2);
+ }
+ |
+ LOOKAHEAD(2147483647)
+ exp1=arithExpression() [ not=<NOT> ] <BETWEEN> exp2=arithExpression() <AND> exp3=arithExpression()
+ {
+ exp1 = new Operator(Operator.BETWEEN, exp1, exp2, exp3);
+ if (not != null)
+ exp1 = new Operator(Operator.NOT, exp1);
+ return exp1;
+ }
+ | exp1=booleanExpression()
+ {
+ return exp1;
+ }
+}
+
+void stringList(HashSet set) :
+{
+}
+{
+ stringToken(set) ( <COMMA> stringToken(set))*
+}
+
+void stringToken(HashSet set) :
+{
+ Token t = null;
+}
+{
+ [ t=<STRING> ]
+ {
+ if (t != null)
+ set.add(stripQuotes(t.image));
+ }
+}
+
+Object patternExpression(Object exp1) :
+{
+ Object exp2 = null;
+ Token esc = null;
+ Object escChar = null;
+}
+{
+ exp2=stringLiteral() [ esc=<ESCAPE> escChar=stringLiteral() ]
+ {
+ Operator op = null;
+ if (esc == null)
+ op = new Operator(Operator.LIKE, exp1, exp2);
+ else
+ op = new Operator(Operator.LIKE_ESCAPE, exp1, exp2, escChar);
+ return op;
+ }
+}
+
+Object arithExpression() :
+{
+ Object exp1 = null;
+ Object exp2 = null;
+}
+{
+ exp1=arithTerm()
+ (
+ <PLUS> exp2=arithTerm()
+ {
+ exp1 = new Operator(Operator.ADD, exp1, exp2);
+ }
+ | <MINUS> exp2=arithTerm()
+ {
+ exp1 = new Operator(Operator.SUB, exp1, exp2);
+ }
+ )*
+ {
+ return exp1;
+ }
+}
+
+Object arithTerm() :
+{
+ Object exp1 = null;
+ Object exp2 = null;
+}
+{
+ exp1=arithFactor()
+ (
+ <MULT> exp2=arithFactor()
+ {
+ exp1 = new Operator(Operator.MUL, exp1, exp2);
+ }
+ | <DIV> exp2=arithFactor()
+ {
+ exp1 = new Operator(Operator.DIV, exp1, exp2);
+ }
+ )*
+ {
+ return exp1;
+ }
+}
+
+Object arithFactor() :
+{
+ Object exp1 = null;
+ boolean negate = false;
+}
+{
+ [<PLUS>|<MINUS>{ negate = true; }] exp1=numericExpression()
+ {
+ if (negate)
+ exp1 = new Operator(Operator.NEG, exp1);
+ return exp1;
+ }
+}
+
+Object booleanExpression() :
+{
+ Object exp1 = null;
+}
+{
+ (
+ exp1=identifier()
+ | exp1=booleanLiteral()
+ )
+ {
+ return exp1;
+ }
+}
+
+Object booleanLiteral() :
+{
+ boolean isTrue = true;
+}
+{
+ (<TRUE>|<FALSE>{ isTrue = false; })
+ {
+ if (isTrue)
+ return Boolean.TRUE;
+ else
+ return Boolean.FALSE;
+ }
+}
+
+Object stringExpression() :
+{
+ Object exp1 = null;
+}
+{
+ (
+ exp1=identifier()
+ | exp1=stringLiteral()
+ )
+ {
+ return exp1;
+ }
+}
+
+Object stringLiteral() :
+{
+ Token string = null;
+}
+{
+ string=<STRING>
+ {
+ return stripQuotes(string.image);
+ }
+}
+
+Object numericExpression() :
+{
+ Object exp1 = null;
+}
+{
+ (
+ exp1 = numericLiteral()
+ | (<LPAREN> exp1=arithExpression() <RPAREN>)
+ | exp1 = identifier()
+ )
+ {
+ return exp1;
+ }
+}
+Object numericLiteral() :
+{
+ Token literal = null;
+}
+{
+ literal=<FLOATING_POINT_LITERAL>
+ {
+ return new Double(literal.image);
+ }
+ |
+ literal=<INTEGER_LITERAL>
+ {
+ String number = literal.image;
+
+ // long suffix
+ if (number.endsWith(LOFFER_L) || number.endsWith(UPPER_L))
+ {
+ // chop off the suffix
+ return new Long(number.substring(0, number.length() - 1));
+ }
+
+ // hex
+ if (number.startsWith(OX) || number.startsWith(Ox))
+ {
+ // handle literals from 0x8000000000000000L to 0xffffffffffffffffL:
+ // remove sign bit, parse as positive, then calculate the negative
+ // value with the sign bit
+ if(number.length() == 18)
+ {
+ byte first = Byte.decode(number.substring(0, 3)).byteValue();
+ if (first >= 8)
+ {
+ number = Ox + (first - 8) + number.substring(3);
+ return new Long(Long.decode(number).longValue() - Long.MAX_VALUE - 1);
+ }
+ }
+ }
+ else if (number.startsWith(ZERRO))
+ {
+ // octal
+ // handle literals
+ // from 01000000000000000000000L to 01777777777777777777777L
+ // remove sign bit, parse as positive, then calculate the
+ // negative value with the sign bit
+ if (number.length() == 23)
+ {
+ if (number.charAt(1) == '1')
+ {
+ number = ZERRO + number.substring(2);
+ return new Long(Long.decode(number).longValue() - Long.MAX_VALUE - 1);
+ }
+ }
+ }
+ return Long.decode(number);
+ }
+}
+
+Object identifier() :
+{
+ Token id = null;
+}
+{
+ id=<IDENTIFIER>
+ {
+ Identifier identifier = (Identifier) identifierMap.get(id.image);
+ if (identifier == null)
+ {
+ identifier = new Identifier(id.image);
+ identifierMap.put(id.image, identifier);
+ }
+ return identifier;
+ }
+}
Deleted: trunk/jbossmq/src/main/org/jboss/mq/selectors/SelectorParser.jj
===================================================================
--- trunk/jbossmq/src/main/org/jboss/mq/selectors/SelectorParser.jj 2008-01-29 17:30:07 UTC (rev 69449)
+++ trunk/jbossmq/src/main/org/jboss/mq/selectors/SelectorParser.jj 2008-01-29 17:38:23 UTC (rev 69450)
@@ -1,628 +0,0 @@
-/*
- * JBossMQ, the OpenSource JMS implementation
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-
-options {
- LOOKAHEAD=1;
-/*
- DEBUG_PARSER=true;
- DEBUG_LOOKAHEAD=true;
- DEBUG_TOKEN_MANAGER=true;
-*/
-}
-
-PARSER_BEGIN(SelectorParser)
-
-package org.jboss.mq.selectors;
-
-import java.io.StringReader;
-
-import java.util.HashSet;
-import java.util.HashMap;
-
-/**
- * A JavaCC 2.0 grammar for the JMS 1.1.0 message selectors.
- *
- * @see http://www.webgain.com/products/metamata/java_doc.html
- *
- * @author Scott.Stark at jboss.org
- * @author adrian at jboss.org
- * @version $Revision$
- */
-public class SelectorParser
- implements ISelectorParser
-{
- private static final String LOFFER_L = "l";
- private static final String UPPER_L = "L";
- private static final String OX = "0X";
- private static final String Ox = "0x";
- private static final String ZERRO = "0";
-
- private HashMap identifierMap;
-
- public SelectorParser()
- {
- // keep the parser from feaking out, init using one of
- // the JavaCC generated constructor
- this(new StringReader(""));
- }
-
- public Object parse(String selector, HashMap identifierMap)
- throws ParseException
- {
- return parse(selector, identifierMap, false);
- }
-
- public Object parse(String selector, HashMap identifierMap, boolean trace)
- throws ParseException
- {
- StringReader sr = new StringReader(selector);
- ReInit(sr);
-
- // This will have no effect unless the debugging options are true
- if (trace)
- {
- this.enable_tracing();
- }
- else
- {
- this.disable_tracing();
- }
-
- this.identifierMap = identifierMap;
- return this.expression();
- }
-
- /**
- * Strip off the leading and trailing (quote) chars from the given string
- * and return it.
- */
- private String stripQuotes(String image)
- {
- StringBuffer result = new StringBuffer(image.length()-2);
- int i = 1;
- boolean escaped = false;
- while (i < image.length() - 1)
- {
- if (escaped)
- {
- if (image.charAt(i) == '\'')
- result.append('\'');
- else
- throw new RuntimeException("Invalid uses of quotes: " + image);
- escaped = false;
- }
- else if (image.charAt(i) == '\'')
- escaped = true;
- else
- result.append(image.charAt(i));
- ++i;
- }
- return result.toString();
- }
-
- public static Object doParse(String selector, HashMap identifierMap)
- throws ParseException
- {
- return doParse(selector, identifierMap, false);
- }
-
- public static Object doParse(String selector, HashMap identifierMap, boolean trace)
- throws ParseException
- {
- SelectorParser parser = new SelectorParser();
- return parser.parse(selector, identifierMap, trace);
- }
-}
-
-PARSER_END(SelectorParser)
-
-/* IGNORE WHITESPACE */
-
-SKIP :
-{
- " "
- | "\r"
- | "\t"
- | "\f"
- | "\n"
-}
-
-
-/* RESERVED WORDS AND LITERALS */
-
-TOKEN [IGNORE_CASE]:
-{
- < TRUE: "TRUE" >
- | < FALSE: "FALSE" >
- | < NULL: "NULL" >
- | < AND: "AND" >
- | < NOT: "NOT" >
- | < OR: "OR" >
- | < BETWEEN: "BETWEEN" >
- | < LIKE: "LIKE" >
- | < IN: "IN" >
- | < IS: "IS" >
- | < ESCAPE: "ESCAPE" >
- | < LPAREN: "(" >
- | < RPAREN: ")" >
- | < SEMICOLON: ";" >
- | < COMMA: "," >
-
-}
-
-/* OPERATORS */
-
-TOKEN :
-{
- < MULT: "*" >
- | < DIV: "/" >
- | < MINUS: "-" >
- | < PLUS: "+" >
- | < GT: ">" >
- | < GE: ">=" >
- | < LT: "<" >
- | < LE: "<=" >
- | < NE: "<>" >
- | < EQ: "=" >
-
-}
-
-/* Literals */
-
-<DEFAULT> TOKEN : /* Numeric Literal */
-{
- < INTEGER_LITERAL:
- "-9223372036854775808"
- | "-9223372036854775808l"
- | "-9223372036854775808L"
- | <DECIMAL_LITERAL> (["l","L"])?
- | <HEX_LITERAL> (["l","L"])?
- | <OCTAL_LITERAL> (["l","L"])?
- >
-|
- < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
-|
- < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
-|
- < #OCTAL_LITERAL: "0" (["0"-"7"])* >
-|
- < FLOATING_POINT_LITERAL:
- (["+","-"])? (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
- | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
- | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
- | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
- >
-|
- < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
-}
-
-
-TOKEN :
-{
- < STRING:
- "'"
- ( (~["'","\n","\r"])
- | ("''")
- )*
- "'"
- >
-}
-
-/* Function names */
-
-TOKEN :
-{
- < IDENTIFIER: <LETTER> (<LETTER>|<DIGIT>)* >
- |
- < #LETTER: [ "_","$", "a"-"z", "A"-"Z" ] >
- |
- < #DIGIT: ["0" - "9"] >
-}
-
-/** Start of the grammar */
-
-Object expression() :
-{
- Object exp1 = null;
-}
-{
- exp1=selectorExpression()<EOF>
- {
- return exp1;
- }
-}
-
-Object selectorExpression() :
-{
- Object exp1 = null;
- Object exp2 = null;
-}
-{
- exp1=selectorTerm()
- (
- <OR> exp2=selectorTerm()
- {
- exp1 = new Operator(Operator.OR, exp1, exp2);
- }
- )*
- {
- return exp1;
- }
-}
-
-Object selectorTerm() :
-{
- Object exp1 = null;
- Object exp2 = null;
-}
-{
- exp1=selectorFactor()
- (
- <AND> exp2=selectorFactor()
- {
- exp1 = new Operator(Operator.AND, exp1, exp2);
- }
- )*
- {
- return exp1;
- }
-}
-
-Object selectorFactor() :
-{
- Object exp1 = null;
-}
-{
- exp1=conditionalExpression()
- {
- return exp1;
- }
- | <NOT> exp1=conditionalExpression()
- {
- exp1 = new Operator(Operator.NOT, exp1);
- }
- {
- return exp1;
- }
-}
-
-Object conditionalExpression() :
-{
- Object exp1 = null;
-}
-{
- LOOKAHEAD(3)
- <LPAREN> exp1=selectorExpression() <RPAREN>
- {
- return exp1;
- }
- |
- exp1 = comparisonExpression()
- {
- return exp1;
- }
-}
-
-Object comparisonExpression() :
-{
- int op = -1;
- HashSet set = null;
- Object exp1 = null;
- Object exp2 = null;
- Object exp3 = null;
- Object id = null;
- Token not = null;
-}
-{
- LOOKAHEAD(2147483647)
- exp1=identifier() <IS> [ not=<NOT> ] <NULL>
- {
- int opCode = not == null ? Operator.IS_NULL : Operator.IS_NOT_NULL;
- return new Operator(opCode, exp1);
- }
- |
- LOOKAHEAD(2147483647)
- id=identifier() [ not=<NOT> ] <IN> <LPAREN> { set = new HashSet(); } stringList(set) <RPAREN>
- {
- if (not == null)
- return new Operator(Operator.IN, id, set);
- else
- return new Operator(Operator.NOT_IN, id, set);
- return exp1;
- }
- |
- LOOKAHEAD(2147483647)
- id=identifier() [ not=<NOT> ] <LIKE> exp1=patternExpression(id)
- {
- if (not != null)
- exp1 = new Operator(Operator.NOT, exp1);
- return exp1;
- }
- |
- LOOKAHEAD(2147483647)
- exp1=stringExpression()
- (
- <EQ>{ op = Operator.EQUAL;}
- | <NE>{ op = Operator.DIFFERENT;}
- ) exp2=stringExpression()
- {
- return new Operator(op, exp1, exp2);
- }
- |
- LOOKAHEAD(2147483647)
- exp1=booleanExpression()
- (
- <EQ>{ op = Operator.EQUAL;}
- | <NE>{ op = Operator.DIFFERENT;}
- ) exp2=booleanExpression()
- {
- return new Operator(op, exp1, exp2);
- }
- |
- LOOKAHEAD(2147483647)
- exp1=arithExpression()
- (
- <EQ>{ op = Operator.EQUAL;}
- | <NE>{ op = Operator.DIFFERENT;}
- | <GT>{ op = Operator.GT;}
- | <GE>{ op = Operator.GE;}
- | <LT>{ op = Operator.LT;}
- | <LE>{ op = Operator.LE;}
- ) exp2=arithExpression()
- {
- return new Operator(op, exp1, exp2);
- }
- |
- LOOKAHEAD(2147483647)
- exp1=arithExpression() [ not=<NOT> ] <BETWEEN> exp2=arithExpression() <AND> exp3=arithExpression()
- {
- exp1 = new Operator(Operator.BETWEEN, exp1, exp2, exp3);
- if (not != null)
- exp1 = new Operator(Operator.NOT, exp1);
- return exp1;
- }
- | exp1=booleanExpression()
- {
- return exp1;
- }
-}
-
-void stringList(HashSet set) :
-{
-}
-{
- stringToken(set) ( <COMMA> stringToken(set))*
-}
-
-void stringToken(HashSet set) :
-{
- Token t = null;
-}
-{
- [ t=<STRING> ]
- {
- if (t != null)
- set.add(stripQuotes(t.image));
- }
-}
-
-Object patternExpression(Object exp1) :
-{
- Object exp2 = null;
- Token esc = null;
- Object escChar = null;
-}
-{
- exp2=stringLiteral() [ esc=<ESCAPE> escChar=stringLiteral() ]
- {
- Operator op = null;
- if (esc == null)
- op = new Operator(Operator.LIKE, exp1, exp2);
- else
- op = new Operator(Operator.LIKE_ESCAPE, exp1, exp2, escChar);
- return op;
- }
-}
-
-Object arithExpression() :
-{
- Object exp1 = null;
- Object exp2 = null;
-}
-{
- exp1=arithTerm()
- (
- <PLUS> exp2=arithTerm()
- {
- exp1 = new Operator(Operator.ADD, exp1, exp2);
- }
- | <MINUS> exp2=arithTerm()
- {
- exp1 = new Operator(Operator.SUB, exp1, exp2);
- }
- )*
- {
- return exp1;
- }
-}
-
-Object arithTerm() :
-{
- Object exp1 = null;
- Object exp2 = null;
-}
-{
- exp1=arithFactor()
- (
- <MULT> exp2=arithFactor()
- {
- exp1 = new Operator(Operator.MUL, exp1, exp2);
- }
- | <DIV> exp2=arithFactor()
- {
- exp1 = new Operator(Operator.DIV, exp1, exp2);
- }
- )*
- {
- return exp1;
- }
-}
-
-Object arithFactor() :
-{
- Object exp1 = null;
- boolean negate = false;
-}
-{
- [<PLUS>|<MINUS>{ negate = true; }] exp1=numericExpression()
- {
- if (negate)
- exp1 = new Operator(Operator.NEG, exp1);
- return exp1;
- }
-}
-
-Object booleanExpression() :
-{
- Object exp1 = null;
-}
-{
- (
- exp1=identifier()
- | exp1=booleanLiteral()
- )
- {
- return exp1;
- }
-}
-
-Object booleanLiteral() :
-{
- boolean isTrue = true;
-}
-{
- (<TRUE>|<FALSE>{ isTrue = false; })
- {
- if (isTrue)
- return Boolean.TRUE;
- else
- return Boolean.FALSE;
- }
-}
-
-Object stringExpression() :
-{
- Object exp1 = null;
-}
-{
- (
- exp1=identifier()
- | exp1=stringLiteral()
- )
- {
- return exp1;
- }
-}
-
-Object stringLiteral() :
-{
- Token string = null;
-}
-{
- string=<STRING>
- {
- return stripQuotes(string.image);
- }
-}
-
-Object numericExpression() :
-{
- Object exp1 = null;
-}
-{
- (
- exp1 = numericLiteral()
- | (<LPAREN> exp1=arithExpression() <RPAREN>)
- | exp1 = identifier()
- )
- {
- return exp1;
- }
-}
-Object numericLiteral() :
-{
- Token literal = null;
-}
-{
- literal=<FLOATING_POINT_LITERAL>
- {
- return new Double(literal.image);
- }
- |
- literal=<INTEGER_LITERAL>
- {
- String number = literal.image;
-
- // long suffix
- if (number.endsWith(LOFFER_L) || number.endsWith(UPPER_L))
- {
- // chop off the suffix
- return new Long(number.substring(0, number.length() - 1));
- }
-
- // hex
- if (number.startsWith(OX) || number.startsWith(Ox))
- {
- // handle literals from 0x8000000000000000L to 0xffffffffffffffffL:
- // remove sign bit, parse as positive, then calculate the negative
- // value with the sign bit
- if(number.length() == 18)
- {
- byte first = Byte.decode(number.substring(0, 3)).byteValue();
- if (first >= 8)
- {
- number = Ox + (first - 8) + number.substring(3);
- return new Long(Long.decode(number).longValue() - Long.MAX_VALUE - 1);
- }
- }
- }
- else if (number.startsWith(ZERRO))
- {
- // octal
- // handle literals
- // from 01000000000000000000000L to 01777777777777777777777L
- // remove sign bit, parse as positive, then calculate the
- // negative value with the sign bit
- if (number.length() == 23)
- {
- if (number.charAt(1) == '1')
- {
- number = ZERRO + number.substring(2);
- return new Long(Long.decode(number).longValue() - Long.MAX_VALUE - 1);
- }
- }
- }
- return Long.decode(number);
- }
-}
-
-Object identifier() :
-{
- Token id = null;
-}
-{
- id=<IDENTIFIER>
- {
- Identifier identifier = (Identifier) identifierMap.get(id.image);
- if (identifier == null)
- {
- identifier = new Identifier(id.image);
- identifierMap.put(id.image, identifier);
- }
- return identifier;
- }
-}
More information about the jboss-cvs-commits
mailing list