use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DrlExprParser method parse.
/**
* Parse an expression from text
*/
public ConstraintConnectiveDescr parse(final String text) {
ConstraintConnectiveDescr constraint = null;
try {
DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
CommonTokenStream input = new CommonTokenStream(lexer);
RecognizerSharedState state = new RecognizerSharedState();
helper = new ParserHelper(input, state, languageLevel);
DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
parser.setBuildDescr(true);
// setting initial value just in case
parser.setLeftMostExpr(null);
BaseDescr expr = parser.conditionalOrExpression();
if (expr != null && !parser.hasErrors()) {
constraint = ConstraintConnectiveDescr.newAnd();
constraint.addOrMerge(expr);
}
} catch (RecognitionException e) {
helper.reportError(e);
}
return constraint;
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Expressions method conditionalAndExpression.
// $ANTLR end "conditionalOrExpression"
// $ANTLR start "conditionalAndExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:230:1: conditionalAndExpression returns [BaseDescr result] : left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )* ;
public final BaseDescr conditionalAndExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:231:3: (left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:231:5: left= inclusiveOrExpression ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )*
{
pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression1182);
left = inclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:232:3: ( DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression )*
loop27: while (true) {
int alt27 = 2;
int LA27_0 = input.LA(1);
if ((LA27_0 == DOUBLE_AMPER)) {
alt27 = 1;
}
switch(alt27) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:232:5: DOUBLE_AMPER (args= fullAnnotation[null] )? right= inclusiveOrExpression
{
match(input, DOUBLE_AMPER, FOLLOW_DOUBLE_AMPER_in_conditionalAndExpression1190);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (isNotEOF())
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:234:13: (args= fullAnnotation[null] )?
int alt26 = 2;
int LA26_0 = input.LA(1);
if ((LA26_0 == AT)) {
alt26 = 1;
}
switch(alt26) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:234:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_conditionalAndExpression1213);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression1219);
right = inclusiveOrExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newAnd();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop27;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Expressions method conditionalOrExpression.
// $ANTLR end "annotationArray"
// $ANTLR start "conditionalOrExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:214:1: conditionalOrExpression returns [BaseDescr result] : left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )* ;
public final BaseDescr conditionalOrExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:215:3: (left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:215:5: left= conditionalAndExpression ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )*
{
pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression1110);
left = conditionalAndExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:216:3: ( DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression )*
loop25: while (true) {
int alt25 = 2;
int LA25_0 = input.LA(1);
if ((LA25_0 == DOUBLE_PIPE)) {
alt25 = 1;
}
switch(alt25) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:216:5: DOUBLE_PIPE (args= fullAnnotation[null] )? right= conditionalAndExpression
{
match(input, DOUBLE_PIPE, FOLLOW_DOUBLE_PIPE_in_conditionalOrExpression1119);
if (state.failed)
return result;
if (state.backtracking == 0) {
if (isNotEOF())
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:218:13: (args= fullAnnotation[null] )?
int alt24 = 2;
int LA24_0 = input.LA(1);
if ((LA24_0 == AT)) {
alt24 = 1;
}
switch(alt24) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:218:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_conditionalOrExpression1141);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_conditionalAndExpression_in_conditionalOrExpression1147);
right = conditionalAndExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newOr();
descr.addOrMerge(result);
descr.addOrMerge(right);
if (args != null) {
descr.addAnnotation(args);
}
result = descr;
}
}
}
break;
default:
break loop25;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
use of org.drools.drl.ast.descr.BaseDescr 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.BaseDescr in project drools by kiegroup.
the class DRL5Expressions method exclusiveOrExpression.
// $ANTLR end "inclusiveOrExpression"
// $ANTLR start "exclusiveOrExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:259:1: exclusiveOrExpression returns [BaseDescr result] : left= andExpression ( XOR right= andExpression )* ;
public final BaseDescr exclusiveOrExpression() throws RecognitionException {
BaseDescr result = null;
BaseDescr left = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:260:3: (left= andExpression ( XOR right= andExpression )* )
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:260:5: left= andExpression ( XOR right= andExpression )*
{
pushFollow(FOLLOW_andExpression_in_exclusiveOrExpression1301);
left = andExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:261:3: ( XOR right= andExpression )*
loop29: while (true) {
int alt29 = 2;
int LA29_0 = input.LA(1);
if ((LA29_0 == XOR)) {
alt29 = 1;
}
switch(alt29) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:261:5: XOR right= andExpression
{
match(input, XOR, FOLLOW_XOR_in_exclusiveOrExpression1309);
if (state.failed)
return result;
pushFollow(FOLLOW_andExpression_in_exclusiveOrExpression1313);
right = andExpression();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newXor();
descr.addOrMerge(result);
descr.addOrMerge(right);
result = descr;
}
}
}
break;
default:
break loop29;
}
}
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
return result;
}
Aggregations