Fix issue with selector parser.
(cherry picked from commit 7b207567d9d304facdfa7c1c5d7fa8a81b6fe70e)
This commit is contained in:
Timothy Bish 2016-06-14 12:49:08 -04:00
parent eb9139dddc
commit 8d114f058d
2 changed files with 197 additions and 195 deletions

View File

@ -21,7 +21,7 @@
options { options {
STATIC = false; STATIC = false;
UNICODE_INPUT = true; UNICODE_INPUT = true;
// some performance optimizations // some performance optimizations
ERROR_REPORTING = false; ERROR_REPORTING = false;
} }
@ -59,9 +59,9 @@ import org.apache.activemq.filter.*;
import org.apache.activemq.filter.FunctionCallExpression.invalidFunctionExpressionException; import org.apache.activemq.filter.FunctionCallExpression.invalidFunctionExpressionException;
import org.apache.activemq.util.LRUCache; import org.apache.activemq.util.LRUCache;
/** /**
* JMS Selector Parser generated by JavaCC * JMS Selector Parser generated by JavaCC
* *
* Do not edit this .java file directly - it is autogenerated from SelectorParser.jj * Do not edit this .java file directly - it is autogenerated from SelectorParser.jj
*/ */
public class SelectorParser { public class SelectorParser {
@ -180,8 +180,8 @@ TOKEN [IGNORE_CASE] :
< DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? > < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? >
| < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
| < OCTAL_LITERAL: "0" (["0"-"7"])* > | < OCTAL_LITERAL: "0" (["0"-"7"])* >
| < FLOATING_POINT_LITERAL: | < FLOATING_POINT_LITERAL:
(["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? // matches: 5.5 or 5. or 5.5E10 or 5.E10 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? // matches: 5.5 or 5. or 5.5E10 or 5.E10
| "." (["0"-"9"])+ (<EXPONENT>)? // matches: .5 or .5E10 | "." (["0"-"9"])+ (<EXPONENT>)? // matches: .5 or .5E10
| (["0"-"9"])+ <EXPONENT> // matches: 5E10 | (["0"-"9"])+ <EXPONENT> // matches: 5E10
@ -204,8 +204,8 @@ BooleanExpression JmsSelector() :
} }
{ {
( (
left = orExpression() left = orExpression() <EOF>
) )
{ {
return asBooleanExpression(left); return asBooleanExpression(left);
} }
@ -219,14 +219,14 @@ Expression orExpression() :
} }
{ {
( (
left = andExpression() left = andExpression()
( (
<OR> right = andExpression() <OR> right = andExpression()
{ {
left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right)); left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right));
} }
)* )*
) )
{ {
return left; return left;
} }
@ -241,14 +241,14 @@ Expression andExpression() :
} }
{ {
( (
left = equalityExpression() left = equalityExpression()
( (
<AND> right = equalityExpression() <AND> right = equalityExpression()
{ {
left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right)); left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right));
} }
)* )*
) )
{ {
return left; return left;
} }
@ -261,31 +261,31 @@ Expression equalityExpression() :
} }
{ {
( (
left = comparisonExpression() left = comparisonExpression()
( (
"=" right = comparisonExpression() "=" right = comparisonExpression()
{ {
left = ComparisonExpression.createEqual(left, right); left = ComparisonExpression.createEqual(left, right);
} }
| |
"<>" right = comparisonExpression() "<>" right = comparisonExpression()
{ {
left = ComparisonExpression.createNotEqual(left, right); left = ComparisonExpression.createNotEqual(left, right);
} }
| |
LOOKAHEAD(2) LOOKAHEAD(2)
<IS> <NULL> <IS> <NULL>
{ {
left = ComparisonExpression.createIsNull(left); left = ComparisonExpression.createIsNull(left);
} }
| |
<IS> <NOT> <NULL> <IS> <NOT> <NULL>
{ {
left = ComparisonExpression.createIsNotNull(left); left = ComparisonExpression.createIsNotNull(left);
} }
)* )*
) )
{ {
return left; return left;
} }
@ -298,106 +298,106 @@ Expression comparisonExpression() :
Expression low; Expression low;
Expression high; Expression high;
String t, u; String t, u;
boolean not; boolean not;
ArrayList list; ArrayList list;
} }
{ {
( (
left = addExpression() left = addExpression()
( (
">" right = addExpression() ">" right = addExpression()
{ {
left = ComparisonExpression.createGreaterThan(left, right); left = ComparisonExpression.createGreaterThan(left, right);
} }
| |
">=" right = addExpression() ">=" right = addExpression()
{ {
left = ComparisonExpression.createGreaterThanEqual(left, right); left = ComparisonExpression.createGreaterThanEqual(left, right);
} }
| |
"<" right = addExpression() "<" right = addExpression()
{ {
left = ComparisonExpression.createLessThan(left, right); left = ComparisonExpression.createLessThan(left, right);
} }
| |
"<=" right = addExpression() "<=" right = addExpression()
{ {
left = ComparisonExpression.createLessThanEqual(left, right); left = ComparisonExpression.createLessThanEqual(left, right);
} }
| |
{ {
u=null; u=null;
} }
<LIKE> t = stringLitteral() <LIKE> t = stringLitteral()
[ <ESCAPE> u = stringLitteral() ] [ <ESCAPE> u = stringLitteral() ]
{ {
left = ComparisonExpression.createLike(left, t, u); left = ComparisonExpression.createLike(left, t, u);
} }
| |
LOOKAHEAD(2) LOOKAHEAD(2)
{ {
u=null; u=null;
} }
<NOT> <LIKE> t = stringLitteral() [ <ESCAPE> u = stringLitteral() ] <NOT> <LIKE> t = stringLitteral() [ <ESCAPE> u = stringLitteral() ]
{ {
left = ComparisonExpression.createNotLike(left, t, u); left = ComparisonExpression.createNotLike(left, t, u);
} }
| |
<BETWEEN> low = addExpression() <AND> high = addExpression() <BETWEEN> low = addExpression() <AND> high = addExpression()
{ {
left = ComparisonExpression.createBetween(left, low, high); left = ComparisonExpression.createBetween(left, low, high);
} }
|
LOOKAHEAD(2)
<NOT> <BETWEEN> low = addExpression() <AND> high = addExpression()
{
left = ComparisonExpression.createNotBetween(left, low, high);
}
| |
<IN> LOOKAHEAD(2)
"(" <NOT> <BETWEEN> low = addExpression() <AND> high = addExpression()
t = stringLitteral() {
{ left = ComparisonExpression.createNotBetween(left, low, high);
list = new ArrayList(); }
list.add( t );
}
(
","
t = stringLitteral()
{
list.add( t );
}
)*
")"
{
left = ComparisonExpression.createInFilter(left, list);
}
| |
LOOKAHEAD(2) <IN>
<NOT> <IN> "("
"(" t = stringLitteral()
t = stringLitteral() {
{ list = new ArrayList();
list = new ArrayList(); list.add( t );
list.add( t ); }
} (
( ","
"," t = stringLitteral()
t = stringLitteral() {
{ list.add( t );
list.add( t ); }
}
)*
)* ")"
")" {
{ left = ComparisonExpression.createInFilter(left, list);
left = ComparisonExpression.createNotInFilter(left, list); }
} |
LOOKAHEAD(2)
<NOT> <IN>
"("
t = stringLitteral()
{
list = new ArrayList();
list.add( t );
}
(
","
t = stringLitteral()
{
list.add( t );
}
)*
")"
{
left = ComparisonExpression.createNotInFilter(left, list);
}
)* )*
) )
{ {
return left; return left;
} }
@ -409,21 +409,21 @@ Expression addExpression() :
Expression right; Expression right;
} }
{ {
left = multExpr() left = multExpr()
( (
LOOKAHEAD( ("+"|"-") multExpr()) LOOKAHEAD( ("+"|"-") multExpr())
( (
"+" right = multExpr() "+" right = multExpr()
{ {
left = ArithmeticExpression.createPlus(left, right); left = ArithmeticExpression.createPlus(left, right);
} }
| |
"-" right = multExpr() "-" right = multExpr()
{ {
left = ArithmeticExpression.createMinus(left, right); left = ArithmeticExpression.createMinus(left, right);
} }
) )
)* )*
{ {
return left; return left;
@ -436,23 +436,23 @@ Expression multExpr() :
Expression right; Expression right;
} }
{ {
left = unaryExpr() left = unaryExpr()
( (
"*" right = unaryExpr() "*" right = unaryExpr()
{ {
left = ArithmeticExpression.createMultiply(left, right); left = ArithmeticExpression.createMultiply(left, right);
} }
| |
"/" right = unaryExpr() "/" right = unaryExpr()
{ {
left = ArithmeticExpression.createDivide(left, right); left = ArithmeticExpression.createDivide(left, right);
} }
| |
"%" right = unaryExpr() "%" right = unaryExpr()
{ {
left = ArithmeticExpression.createMod(left, right); left = ArithmeticExpression.createMod(left, right);
} }
)* )*
{ {
return left; return left;
@ -466,34 +466,34 @@ Expression unaryExpr() :
Expression left=null; Expression left=null;
} }
{ {
( (
LOOKAHEAD( "+" unaryExpr() ) LOOKAHEAD( "+" unaryExpr() )
"+" left=unaryExpr() "+" left=unaryExpr()
| |
"-" left=unaryExpr() "-" left=unaryExpr()
{ {
left = UnaryExpression.createNegate(left); left = UnaryExpression.createNegate(left);
} }
| |
<NOT> left=unaryExpr() <NOT> left=unaryExpr()
{ {
left = UnaryExpression.createNOT( asBooleanExpression(left) ); left = UnaryExpression.createNOT( asBooleanExpression(left) );
} }
| |
<XPATH> s=stringLitteral() <XPATH> s=stringLitteral()
{ {
left = UnaryExpression.createXPath( s ); left = UnaryExpression.createXPath( s );
} }
| |
<XQUERY> s=stringLitteral() <XQUERY> s=stringLitteral()
{ {
left = UnaryExpression.createXQuery( s ); left = UnaryExpression.createXQuery( s );
} }
| |
LOOKAHEAD( <ID> "(" ) LOOKAHEAD( <ID> "(" )
left = functionCallExpr() left = functionCallExpr()
| |
left = primaryExpr() left = primaryExpr()
) )
{ {
return left; return left;
@ -519,7 +519,7 @@ Expression functionCallExpr () :
"," ","
arg = unaryExpr() arg = unaryExpr()
{ {
arg_list.add(arg); arg_list.add(arg);
} }
) * ) *
) )
@ -548,7 +548,7 @@ Expression primaryExpr() :
left = variable() left = variable()
| |
"(" left = orExpression() ")" "(" left = orExpression() ")"
) )
{ {
return left; return left;
} }
@ -569,55 +569,55 @@ ConstantExpression literal() :
{ {
left = new ConstantExpression(s); left = new ConstantExpression(s);
} }
) )
| |
( (
t = <DECIMAL_LITERAL> t = <DECIMAL_LITERAL>
{ {
left = ConstantExpression.createFromDecimal(t.image); left = ConstantExpression.createFromDecimal(t.image);
} }
) )
| |
( (
t = <HEX_LITERAL> t = <HEX_LITERAL>
{ {
left = ConstantExpression.createFromHex(t.image); left = ConstantExpression.createFromHex(t.image);
} }
) )
| |
( (
t = <OCTAL_LITERAL> t = <OCTAL_LITERAL>
{ {
left = ConstantExpression.createFromOctal(t.image); left = ConstantExpression.createFromOctal(t.image);
} }
) )
| |
( (
t = <FLOATING_POINT_LITERAL> t = <FLOATING_POINT_LITERAL>
{ {
left = ConstantExpression.createFloat(t.image); left = ConstantExpression.createFloat(t.image);
} }
) )
| |
( (
<TRUE> <TRUE>
{ {
left = ConstantExpression.TRUE; left = ConstantExpression.TRUE;
} }
) )
| |
( (
<FALSE> <FALSE>
{ {
left = ConstantExpression.FALSE; left = ConstantExpression.FALSE;
} }
) )
| |
( (
<NULL> <NULL>
{ {
left = ConstantExpression.NULL; left = ConstantExpression.NULL;
} }
) )
) )
{ {
@ -632,18 +632,18 @@ String stringLitteral() :
boolean first=true; boolean first=true;
} }
{ {
t = <STRING_LITERAL> t = <STRING_LITERAL>
{ {
// Decode the sting value. // Decode the sting value.
String image = t.image; String image = t.image;
for( int i=1; i < image.length()-1; i++ ) { for( int i=1; i < image.length()-1; i++ ) {
char c = image.charAt(i); char c = image.charAt(i);
if( c == '\'' ) if( c == '\'' )
i++; i++;
rc.append(c); rc.append(c);
} }
return rc.toString(); return rc.toString();
} }
} }
PropertyExpression variable() : PropertyExpression variable() :
@ -652,11 +652,11 @@ PropertyExpression variable() :
PropertyExpression left=null; PropertyExpression left=null;
} }
{ {
( (
t = <ID> t = <ID>
{ {
left = new PropertyExpression(t.image); left = new PropertyExpression(t.image);
} }
) )
{ {
return left; return left;

View File

@ -20,14 +20,14 @@ import javax.jms.InvalidSelectorException;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.Message; import javax.jms.Message;
import junit.framework.TestCase;
import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQTextMessage; import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.filter.BooleanExpression; import org.apache.activemq.filter.BooleanExpression;
import org.apache.activemq.filter.MessageEvaluationContext; import org.apache.activemq.filter.MessageEvaluationContext;
import junit.framework.TestCase;
/** /**
* *
*/ */
@ -327,6 +327,8 @@ public class SelectorTest extends TestCase {
assertInvalidSelector(message, "3+5"); assertInvalidSelector(message, "3+5");
assertInvalidSelector(message, "True AND 3+5"); assertInvalidSelector(message, "True AND 3+5");
assertInvalidSelector(message, "=TEST 'test'"); assertInvalidSelector(message, "=TEST 'test'");
assertInvalidSelector(message, "prop1 = prop2 foo AND string = 'Test'");
assertInvalidSelector(message, "a = 1 AMD b = 2");
} }
public void testFunctionSelector() throws Exception { public void testFunctionSelector() throws Exception {