Skip to content

Commit

Permalink
QPID-8674 - [Broker-J] Jms Selector Parsing - multiple AND's (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakirily authored Jan 10, 2025
1 parent 65e6524 commit 3223e43
Show file tree
Hide file tree
Showing 3 changed files with 865 additions and 593 deletions.
273 changes: 119 additions & 154 deletions broker-core/src/main/grammar/SelectorParser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public class SelectorParser<E>
}
throw new ParseException("Expression will not result in a boolean value: " + value);
}


}

PARSER_END(SelectorParser)
Expand Down Expand Up @@ -202,37 +200,31 @@ Expression orExpression() :
Expression right;
}
{
left = andExpression()
(
left = andExpression()
(
<OR> right = andExpression()
{
left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right));
}
)*
)
<OR> right = andExpression()
{
left = LogicExpression.createOR(asBooleanExpression(left), asBooleanExpression(right));
}
)*
{
return left;
}

}


Expression andExpression() :
{
Expression left;
Expression right;
}
{
left = equalityExpression()
(
left = equalityExpression()
(
<AND> right = equalityExpression()
{
left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right));
}
)*
)
<AND> right = equalityExpression()
{
left = LogicExpression.createAND(asBooleanExpression(left), asBooleanExpression(right));
}
)*
{
return left;
}
Expand All @@ -244,32 +236,28 @@ Expression equalityExpression() :
Expression right;
}
{
left = comparisonExpression()
(
left = comparisonExpression()
(

"=" right = comparisonExpression()
{
left = ComparisonExpression.createEqual(left, right);
}
|
"<>" right = comparisonExpression()
{
left = ComparisonExpression.createNotEqual(left, right);
}
|
LOOKAHEAD(2)
<IS> <NULL>
{
left = ComparisonExpression.createIsNull(left);
}
|
<IS> <NOT> <NULL>
{
left = ComparisonExpression.createIsNotNull(left);
}
)*
)
LOOKAHEAD(2) "=" right = comparisonExpression()
{
left = ComparisonExpression.createEqual(left, right);
}
|
"<>" right = comparisonExpression()
{
left = ComparisonExpression.createNotEqual(left, right);
}
|
LOOKAHEAD(2) <IS> <NULL>
{
left = ComparisonExpression.createIsNull(left);
}
|
<IS> <NOT> <NULL>
{
left = ComparisonExpression.createIsNotNull(left);
}
)*
{
return left;
}
Expand All @@ -286,102 +274,83 @@ Expression comparisonExpression() :
ArrayList list;
}
{
left = addExpression()
(
left = addExpression()
(

">" right = addExpression()
{
left = ComparisonExpression.createGreaterThan(left, right);
}
|
">=" right = addExpression()
{
left = ComparisonExpression.createGreaterThanEqual(left, right);
}
|
"<" right = addExpression()
{
left = ComparisonExpression.createLessThan(left, right);
}
|
"<=" right = addExpression()
{
left = ComparisonExpression.createLessThanEqual(left, right);
}
|
{
u=null;
}
<LIKE> t = stringLiteral()
[ <ESCAPE> u = stringLiteral() ]
{
left = ComparisonExpression.createLike(left, t, u);
}
|
LOOKAHEAD(2)
{
u=null;
}
<NOT> <LIKE> t = stringLiteral() [ <ESCAPE> u = stringLiteral() ]
{
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);
}
|
<IN>
"("
t = stringLiteral()
{
list = new ArrayList();
list.add( t );
}
(
","
t = stringLiteral()
{
list.add( t );
}

)*
")"
{
left = ComparisonExpression.createInFilter(left, list, false );
}
|
LOOKAHEAD(2)
<NOT> <IN>
"("
t = stringLiteral()
{
list = new ArrayList();
list.add( t );
}
(
","
t = stringLiteral()
{
list.add( t );
}

)*
")"
{
left = ComparisonExpression.createNotInFilter(left, list, false);
}

)*
)
LOOKAHEAD(2) ">" right = addExpression()
{
left = ComparisonExpression.createGreaterThan(left, right);
}
|
">=" right = addExpression()
{
left = ComparisonExpression.createGreaterThanEqual(left, right);
}
|
"<" right = addExpression()
{
left = ComparisonExpression.createLessThan(left, right);
}
|
"<=" right = addExpression()
{
left = ComparisonExpression.createLessThanEqual(left, right);
}
|
{
u=null;
}
<LIKE> t = stringLiteral() [ <ESCAPE> u = stringLiteral() ]
{
left = ComparisonExpression.createLike(left, t, u);
}
|
LOOKAHEAD(2)
{
u=null;
}
<NOT> <LIKE> t = stringLiteral() [ <ESCAPE> u = stringLiteral() ]
{
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);
}
|
<IN> "(" t = stringLiteral()
{
list = new ArrayList();
list.add( t );
}
( "," t = stringLiteral()
{
list.add( t );
}
)* ")"
{
left = ComparisonExpression.createInFilter(left, list, false );
}
|
LOOKAHEAD(2) <NOT> <IN> "(" t = stringLiteral()
{
list = new ArrayList();
list.add( t );
}
( "," t = stringLiteral()
{
list.add( t );
}
)* ")"
{
left = ComparisonExpression.createNotInFilter(left, list, false);
}
)*
{
return left;
}
Expand All @@ -407,7 +376,6 @@ Expression addExpression() :
left = ArithmeticExpression.createMinus(left, right);
}
)

)*
{
return left;
Expand All @@ -422,7 +390,7 @@ Expression multExpr() :
{
left = unaryExpr()
(
"*" right = unaryExpr()
LOOKAHEAD(2) "*" right = unaryExpr()
{
left = ArithmeticExpression.createMultiply(left, right);
}
Expand All @@ -436,30 +404,32 @@ Expression multExpr() :
{
left = ArithmeticExpression.createMod(left, right);
}

)*
{
return left;
}
}


Expression unaryExpr() :
{
String s=null;
Expression left=null;
}
{
(
LOOKAHEAD( "+" unaryExpr() )
"+" left=unaryExpr()
LOOKAHEAD("+" unaryExpr()) "+" left = unaryExpr()
|
"-" left=unaryExpr()
"-" left = unaryExpr()
{
left = UnaryExpression.createNegate(left);
}
|
<NOT> left=orExpression()
LOOKAHEAD(<NOT> equalityExpression()) <NOT> left = equalityExpression()
{
left = UnaryExpression.createNOT( asBooleanExpression(left) );
}
|
LOOKAHEAD(<NOT> unaryExpr()) <NOT> left = unaryExpr()
{
left = UnaryExpression.createNOT( asBooleanExpression(left) );
}
Expand All @@ -469,7 +439,6 @@ Expression unaryExpr() :
{
return left;
}

}

Expression primaryExpr() :
Expand All @@ -482,15 +451,13 @@ Expression primaryExpr() :
|
left = variable()
|
"(" left = orExpression() ")"
LOOKAHEAD(2) "(" left = orExpression() ")"
)
{
return left;
}
}



ConstantExpression literal() :
{
Token t;
Expand Down Expand Up @@ -610,8 +577,6 @@ PropertyExpression variable() :
}
return _factory.createPropertyExpression(rc.toString());
}


)
{
return left;
Expand Down
Loading

0 comments on commit 3223e43

Please sign in to comment.