use of org.drools.drl.ast.descr.AtomicExprDescr in project drools by kiegroup.
the class DRL6Expressions method parExpression.
// $ANTLR end "mapEntry"
// $ANTLR start "parExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:627:1: parExpression returns [BaseDescr result] : LEFT_PAREN expr= expression RIGHT_PAREN ;
public final BaseDescr parExpression() throws RecognitionException {
BaseDescr result = null;
ParserRuleReturnScope expr = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:628:5: ( LEFT_PAREN expr= expression RIGHT_PAREN )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:628:7: LEFT_PAREN expr= expression RIGHT_PAREN
{
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_parExpression3643);
if (state.failed)
return result;
pushFollow(FOLLOW_expression_in_parExpression3647);
expr = expression();
state._fsp--;
if (state.failed)
return result;
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_parExpression3649);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = (expr != null ? ((DRL6Expressions.expression_return) expr).result : null);
if (result instanceof AtomicExprDescr) {
((AtomicExprDescr) result).setExpression("(" + ((AtomicExprDescr) result).getExpression() + ")");
}
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.AtomicExprDescr in project drools by kiegroup.
the class DRL5Expressions method relationalExpression.
// $ANTLR start "relationalExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:354:1: relationalExpression returns [BaseDescr result] : left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )* ;
public final BaseDescr relationalExpression() throws RecognitionException {
relationalExpression_stack.push(new relationalExpression_scope());
BaseDescr result = null;
ParserRuleReturnScope left = null;
BaseDescr right = null;
relationalExpression_stack.peek().lsd = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:357:3: (left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:357:5: left= shiftExpression ( ( operator | LEFT_PAREN )=>right= orRestriction )*
{
pushFollow(FOLLOW_shiftExpression_in_relationalExpression1750);
left = shiftExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) == null) {
result = new AtomicExprDescr((left != null ? input.toString(left.start, left.stop) : null));
} else if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) instanceof AtomicExprDescr) {
if ((left != null ? input.toString(left.start, left.stop) : null).equals(((AtomicExprDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null)).getExpression())) {
result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
} else {
result = new AtomicExprDescr((left != null ? input.toString(left.start, left.stop) : null));
}
} else if ((left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null) instanceof BindingDescr) {
if ((left != null ? input.toString(left.start, left.stop) : null).equals(((BindingDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null)).getExpression())) {
result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
} else {
BindingDescr bind = (BindingDescr) (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
int offset = bind.isUnification() ? 2 : 1;
String fullExpression = (left != null ? input.toString(left.start, left.stop) : null).substring((left != null ? input.toString(left.start, left.stop) : null).indexOf(":") + offset).trim();
result = new BindingDescr(bind.getVariable(), bind.getExpression(), fullExpression, bind.isUnification());
}
} else {
result = (left != null ? ((DRL5Expressions.shiftExpression_return) left).result : null);
}
relationalExpression_stack.peek().lsd = result;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:382:3: ( ( operator | LEFT_PAREN )=>right= orRestriction )*
loop37: while (true) {
int alt37 = 2;
int LA37_0 = input.LA(1);
if ((LA37_0 == ID)) {
int LA37_2 = input.LA(2);
if (((synpred8_DRL5Expressions() && (((helper.validateIdentifierKey(DroolsSoftKeywords.NOT))) || ((helper.isPluggableEvaluator(false))))))) {
alt37 = 1;
}
} else if ((LA37_0 == EQUALS)) {
int LA37_3 = input.LA(2);
if ((synpred8_DRL5Expressions())) {
alt37 = 1;
}
} else if ((LA37_0 == NOT_EQUALS)) {
int LA37_4 = input.LA(2);
if ((synpred8_DRL5Expressions())) {
alt37 = 1;
}
} else if ((LA37_0 == LESS)) {
int LA37_20 = input.LA(2);
if ((synpred8_DRL5Expressions())) {
alt37 = 1;
}
} else if ((LA37_0 == GREATER)) {
int LA37_21 = input.LA(2);
if ((synpred8_DRL5Expressions())) {
alt37 = 1;
}
} else if ((LA37_0 == TILDE) && (synpred8_DRL5Expressions())) {
alt37 = 1;
} else if ((LA37_0 == LESS_EQUALS) && (synpred8_DRL5Expressions())) {
alt37 = 1;
} else if ((LA37_0 == GREATER_EQUALS) && (synpred8_DRL5Expressions())) {
alt37 = 1;
} else if ((LA37_0 == LEFT_PAREN) && (synpred8_DRL5Expressions())) {
alt37 = 1;
}
switch(alt37) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:382:5: ( operator | LEFT_PAREN )=>right= orRestriction
{
pushFollow(FOLLOW_orRestriction_in_relationalExpression1775);
right = orRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = right;
relationalExpression_stack.peek().lsd = result;
}
}
}
break;
default:
break loop37;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
relationalExpression_stack.pop();
}
return result;
}
use of org.drools.drl.ast.descr.AtomicExprDescr in project drools by kiegroup.
the class DRL5Expressions method unaryExpression.
// $ANTLR end "multiplicativeExpression"
// $ANTLR start "unaryExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:466:1: unaryExpression returns [BaseDescr result] : ( PLUS ue= unaryExpression | MINUS ue= unaryExpression | INCR primary | DECR primary |left= unaryExpressionNotPlusMinus );
public final BaseDescr unaryExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr ue = null;
ParserRuleReturnScope left = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:467:5: ( PLUS ue= unaryExpression | MINUS ue= unaryExpression | INCR primary | DECR primary |left= unaryExpressionNotPlusMinus )
int alt49 = 5;
switch(input.LA(1)) {
case PLUS:
{
alt49 = 1;
}
break;
case MINUS:
{
alt49 = 2;
}
break;
case INCR:
{
alt49 = 3;
}
break;
case DECR:
{
alt49 = 4;
}
break;
case BOOL:
case DECIMAL:
case FLOAT:
case HEX:
case ID:
case LEFT_PAREN:
case LEFT_SQUARE:
case LESS:
case NEGATION:
case NULL:
case STAR:
case STRING:
case TILDE:
case TIME_INTERVAL:
{
alt49 = 5;
}
break;
default:
if (state.backtracking > 0) {
state.failed = true;
return result;
}
NoViableAltException nvae = new NoViableAltException("", 49, 0, input);
throw nvae;
}
switch(alt49) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:467:9: PLUS ue= unaryExpression
{
match(input, PLUS, FOLLOW_PLUS_in_unaryExpression2269);
if (state.failed)
return result;
pushFollow(FOLLOW_unaryExpression_in_unaryExpression2273);
ue = unaryExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = ue;
if (result instanceof AtomicExprDescr) {
((AtomicExprDescr) result).setExpression("+" + ((AtomicExprDescr) result).getExpression());
}
}
}
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:474:7: MINUS ue= unaryExpression
{
match(input, MINUS, FOLLOW_MINUS_in_unaryExpression2291);
if (state.failed)
return result;
pushFollow(FOLLOW_unaryExpression_in_unaryExpression2295);
ue = unaryExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = ue;
if (result instanceof AtomicExprDescr) {
((AtomicExprDescr) result).setExpression("-" + ((AtomicExprDescr) result).getExpression());
}
}
}
}
break;
case 3:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:481:9: INCR primary
{
match(input, INCR, FOLLOW_INCR_in_unaryExpression2315);
if (state.failed)
return result;
pushFollow(FOLLOW_primary_in_unaryExpression2317);
primary();
state._fsp--;
if (state.failed)
return result;
}
break;
case 4:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:482:9: DECR primary
{
match(input, DECR, FOLLOW_DECR_in_unaryExpression2327);
if (state.failed)
return result;
pushFollow(FOLLOW_primary_in_unaryExpression2329);
primary();
state._fsp--;
if (state.failed)
return result;
}
break;
case 5:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:483:9: left= unaryExpressionNotPlusMinus
{
pushFollow(FOLLOW_unaryExpressionNotPlusMinus_in_unaryExpression2341);
left = unaryExpressionNotPlusMinus();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = (left != null ? ((DRL5Expressions.unaryExpressionNotPlusMinus_return) left).result : null);
}
}
}
break;
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.AtomicExprDescr in project drools by kiegroup.
the class DRL5Expressions method parExpression.
// $ANTLR end "mapEntry"
// $ANTLR start "parExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:577:1: parExpression returns [BaseDescr result] : LEFT_PAREN expr= expression RIGHT_PAREN ;
public final BaseDescr parExpression() throws RecognitionException {
BaseDescr result = null;
ParserRuleReturnScope expr = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:578:5: ( LEFT_PAREN expr= expression RIGHT_PAREN )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:578:7: LEFT_PAREN expr= expression RIGHT_PAREN
{
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_parExpression3200);
if (state.failed)
return result;
pushFollow(FOLLOW_expression_in_parExpression3204);
expr = expression();
state._fsp--;
if (state.failed)
return result;
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_parExpression3206);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = (expr != null ? ((DRL5Expressions.expression_return) expr).result : null);
if (result instanceof AtomicExprDescr) {
((AtomicExprDescr) result).setExpression("(" + ((AtomicExprDescr) result).getExpression() + ")");
}
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.AtomicExprDescr in project drools by kiegroup.
the class DescrDumperTest method testProcessImplicitConstraints.
@Test
public void testProcessImplicitConstraints() throws Exception {
String expr = "field1#Class!.field2";
String expectedConstraints = "field1 instanceof Class";
String expectedExpr = "((Class)field1).field2";
AtomicExprDescr atomicExpr = new AtomicExprDescr(expr);
ConstraintConnectiveDescr ccd = new ConstraintConnectiveDescr();
String[] constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
assertEquals(expectedConstraints, ccd.getDescrs().get(0).toString());
assertEquals(expectedExpr, constraintsAndExpr[1]);
assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
expr = "field1!.field2#Class.field3";
String expectedConstraints1 = "field1 != null";
String expectedConstraints2 = "field1.field2 instanceof Class";
expectedExpr = "((Class)field1.field2).field3";
atomicExpr = new AtomicExprDescr(expr);
ccd = new ConstraintConnectiveDescr();
constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
assertEquals(expectedConstraints1, ccd.getDescrs().get(0).toString());
assertEquals(expectedConstraints2, ccd.getDescrs().get(1).toString());
assertEquals(expectedExpr, constraintsAndExpr[1]);
assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
expr = "field1#Class.field2!.field3";
expectedConstraints1 = "field1 instanceof Class";
expectedConstraints2 = "((Class)field1).field2 != null";
expectedExpr = "((Class)field1).field2.field3";
atomicExpr = new AtomicExprDescr(expr);
ccd = new ConstraintConnectiveDescr();
constraintsAndExpr = dumper.processImplicitConstraints(expr, atomicExpr, ccd, ccd.getDescrs().indexOf(atomicExpr), null);
assertEquals(expectedConstraints1, ccd.getDescrs().get(0).toString());
assertEquals(expectedConstraints2, ccd.getDescrs().get(1).toString());
assertEquals(expectedExpr, constraintsAndExpr[1]);
assertEquals(expectedExpr, atomicExpr.getRewrittenExpression());
}
Aggregations