use of org.drools.compiler.lang.descr.RelationalExprDescr in project drools by kiegroup.
the class DRL5Expressions method singleRestriction.
// $ANTLR end "andRestriction"
// $ANTLR start "singleRestriction"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:421:1: singleRestriction returns [BaseDescr result] : (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN );
public final BaseDescr singleRestriction() throws RecognitionException {
BaseDescr result = null;
ParserRuleReturnScope op = null;
java.util.List<String> sa = null;
ParserRuleReturnScope value = null;
BaseDescr or = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:422:3: (op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression ) | LEFT_PAREN or= orRestriction RIGHT_PAREN )
int alt44 = 2;
int LA44_0 = input.LA(1);
if ((LA44_0 == EQUALS || (LA44_0 >= GREATER && LA44_0 <= GREATER_EQUALS) || (LA44_0 >= LESS && LA44_0 <= LESS_EQUALS) || LA44_0 == NOT_EQUALS || LA44_0 == TILDE)) {
alt44 = 1;
} else if ((LA44_0 == ID) && ((((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) || ((helper.isPluggableEvaluator(false)))))) {
alt44 = 1;
} else if ((LA44_0 == LEFT_PAREN)) {
alt44 = 2;
} else {
if (state.backtracking > 0) {
state.failed = true;
return result;
}
NoViableAltException nvae = new NoViableAltException("", 44, 0, input);
throw nvae;
}
switch(alt44) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:422:6: op= operator ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
{
pushFollow(FOLLOW_operator_in_singleRestriction1963);
op = operator();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:424:6: ( ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression |value= shiftExpression )
int alt43 = 2;
int LA43_0 = input.LA(1);
if ((LA43_0 == LEFT_SQUARE)) {
int LA43_1 = input.LA(2);
if ((synpred11_DRL5Expressions())) {
alt43 = 1;
} else if ((true)) {
alt43 = 2;
}
} else if ((LA43_0 == BOOL || (LA43_0 >= DECIMAL && LA43_0 <= DECR) || LA43_0 == FLOAT || LA43_0 == HEX || (LA43_0 >= ID && LA43_0 <= INCR) || LA43_0 == LEFT_PAREN || LA43_0 == LESS || LA43_0 == MINUS || LA43_0 == NEGATION || LA43_0 == NULL || LA43_0 == PLUS || (LA43_0 >= STAR && LA43_0 <= TIME_INTERVAL))) {
alt43 = 2;
} else {
if (state.backtracking > 0) {
state.failed = true;
return result;
}
NoViableAltException nvae = new NoViableAltException("", 43, 0, input);
throw nvae;
}
switch(alt43) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:424:8: ( squareArguments shiftExpression )=>sa= squareArguments value= shiftExpression
{
pushFollow(FOLLOW_squareArguments_in_singleRestriction1992);
sa = squareArguments();
state._fsp--;
if (state.failed)
return result;
pushFollow(FOLLOW_shiftExpression_in_singleRestriction1996);
value = shiftExpression();
state._fsp--;
if (state.failed)
return result;
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:425:10: value= shiftExpression
{
pushFollow(FOLLOW_shiftExpression_in_singleRestriction2009);
value = shiftExpression();
state._fsp--;
if (state.failed)
return result;
}
break;
}
if (state.backtracking == 0) {
if (buildDescr) {
BaseDescr descr = ((value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) != null && ((!((value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) instanceof AtomicExprDescr)) || ((value != null ? input.toString(value.start, value.stop) : null).equals(((AtomicExprDescr) (value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null)).getExpression())))) ? (value != null ? ((DRL5Expressions.shiftExpression_return) value).result : null) : new AtomicExprDescr((value != null ? input.toString(value.start, value.stop) : null));
result = new RelationalExprDescr((op != null ? ((DRL5Expressions.operator_return) op).opr : null), (op != null ? ((DRL5Expressions.operator_return) op).negated : false), sa, relationalExpression_stack.peek().lsd, descr);
if (relationalExpression_stack.peek().lsd instanceof BindingDescr) {
relationalExpression_stack.peek().lsd = new AtomicExprDescr(((BindingDescr) relationalExpression_stack.peek().lsd).getExpression());
}
}
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
}
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:440:6: LEFT_PAREN or= orRestriction RIGHT_PAREN
{
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_singleRestriction2034);
if (state.failed)
return result;
pushFollow(FOLLOW_orRestriction_in_singleRestriction2038);
or = orRestriction();
state._fsp--;
if (state.failed)
return result;
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_singleRestriction2040);
if (state.failed)
return result;
if (state.backtracking == 0) {
result = or;
}
}
break;
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.compiler.lang.descr.RelationalExprDescr in project drools by kiegroup.
the class DRLExprParserTest method testDeepBinding.
@Test
public void testDeepBinding() throws Exception {
String source = "($a : a > $b : b[10].prop || 10 != 20) && $x : someMethod(10) == 20";
ConstraintConnectiveDescr result = parser.parse(source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals(ConnectiveType.AND, result.getConnective());
assertEquals(2, result.getDescrs().size());
ConstraintConnectiveDescr or = (ConstraintConnectiveDescr) result.getDescrs().get(0);
assertEquals(ConnectiveType.OR, or.getConnective());
assertEquals(2, or.getDescrs().size());
RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get(0);
assertEquals(">", expr.getOperator());
BindingDescr leftBind = (BindingDescr) expr.getLeft();
BindingDescr rightBind = (BindingDescr) expr.getRight();
assertEquals("$a", leftBind.getVariable());
assertEquals("a", leftBind.getExpression());
assertEquals("$b", rightBind.getVariable());
assertEquals("b[10].prop", rightBind.getExpression());
expr = (RelationalExprDescr) or.getDescrs().get(1);
assertEquals("!=", expr.getOperator());
AtomicExprDescr leftExpr = (AtomicExprDescr) expr.getLeft();
AtomicExprDescr rightExpr = (AtomicExprDescr) expr.getRight();
assertEquals("10", leftExpr.getExpression());
assertEquals("20", rightExpr.getExpression());
expr = (RelationalExprDescr) result.getDescrs().get(1);
assertEquals("==", expr.getOperator());
leftBind = (BindingDescr) expr.getLeft();
rightExpr = (AtomicExprDescr) expr.getRight();
assertEquals("$x", leftBind.getVariable());
assertEquals("someMethod(10)", leftBind.getExpression());
assertEquals("20", rightExpr.getExpression());
}
use of org.drools.compiler.lang.descr.RelationalExprDescr in project drools by kiegroup.
the class DRLExprParserTest method testConnective2.
@Test
public void testConnective2() throws Exception {
String source = "(a > b || 10 != 20) && someMethod(10) == 20";
ConstraintConnectiveDescr result = parser.parse(source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals(ConnectiveType.AND, result.getConnective());
assertEquals(2, result.getDescrs().size());
ConstraintConnectiveDescr or = (ConstraintConnectiveDescr) result.getDescrs().get(0);
assertEquals(ConnectiveType.OR, or.getConnective());
assertEquals(2, or.getDescrs().size());
RelationalExprDescr expr = (RelationalExprDescr) or.getDescrs().get(0);
assertEquals(">", expr.getOperator());
AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
assertEquals("a", left.getExpression());
assertEquals("b", right.getExpression());
expr = (RelationalExprDescr) or.getDescrs().get(1);
assertEquals("!=", expr.getOperator());
left = (AtomicExprDescr) expr.getLeft();
right = (AtomicExprDescr) expr.getRight();
assertEquals("10", left.getExpression());
assertEquals("20", right.getExpression());
expr = (RelationalExprDescr) result.getDescrs().get(1);
assertEquals("==", expr.getOperator());
left = (AtomicExprDescr) expr.getLeft();
right = (AtomicExprDescr) expr.getRight();
assertEquals("someMethod(10)", left.getExpression());
assertEquals("20", right.getExpression());
}
use of org.drools.compiler.lang.descr.RelationalExprDescr in project drools by kiegroup.
the class DRLExprParserTest method testSimpleExpression.
@Test
public void testSimpleExpression() throws Exception {
String source = "a > b";
ConstraintConnectiveDescr result = parser.parse(source);
assertFalse(parser.getErrors().toString(), parser.hasErrors());
assertEquals(ConnectiveType.AND, result.getConnective());
assertEquals(1, result.getDescrs().size());
RelationalExprDescr expr = (RelationalExprDescr) result.getDescrs().get(0);
assertEquals(">", expr.getOperator());
AtomicExprDescr left = (AtomicExprDescr) expr.getLeft();
AtomicExprDescr right = (AtomicExprDescr) expr.getRight();
assertEquals("a", left.getExpression());
assertEquals("b", right.getExpression());
}
Aggregations