Fix issue with selector parser.
This commit is contained in:
Timothy Bish 2016-06-14 12:49:08 -04:00
parent a953f11d0e
commit 7b207567d9
2 changed files with 197 additions and 195 deletions

View File

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

View File

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