use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL6Expressions method andRestriction.
// $ANTLR end "orRestriction"
// $ANTLR start "andRestriction"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:419:1: andRestriction returns [BaseDescr result] : left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* ;
public final BaseDescr andRestriction() throws RecognitionException {
BaseDescr result = null;
Token lop = null;
BaseDescr left = null;
AnnotationDescr args = null;
BaseDescr right = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:420:3: (left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )* )
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:420:5: left= singleRestriction ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
{
pushFollow(FOLLOW_singleRestriction_in_andRestriction1963);
left = singleRestriction();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = left;
}
}
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:3: ( ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction )*
loop42: while (true) {
int alt42 = 2;
int LA42_0 = input.LA(1);
if ((LA42_0 == DOUBLE_AMPER)) {
int LA42_9 = input.LA(2);
if ((synpred11_DRL6Expressions())) {
alt42 = 1;
}
}
switch(alt42) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:421:5: ( DOUBLE_AMPER ( fullAnnotation[null] )? operator )=>lop= DOUBLE_AMPER (args= fullAnnotation[null] )? right= singleRestriction
{
lop = (Token) match(input, DOUBLE_AMPER, FOLLOW_DOUBLE_AMPER_in_andRestriction1983);
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/DRL6Expressions.g:423:13: (args= fullAnnotation[null] )?
int alt41 = 2;
int LA41_0 = input.LA(1);
if ((LA41_0 == AT)) {
alt41 = 1;
}
switch(alt41) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:423:13: args= fullAnnotation[null]
{
pushFollow(FOLLOW_fullAnnotation_in_andRestriction2004);
args = fullAnnotation(null);
state._fsp--;
if (state.failed)
return result;
}
break;
}
pushFollow(FOLLOW_singleRestriction_in_andRestriction2009);
right = singleRestriction();
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 loop42;
}
}
}
} 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 DRL6Expressions method unaryExpression.
// $ANTLR end "multiplicativeExpression"
// $ANTLR start "unaryExpression"
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:480: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/DRL6Expressions.g:481: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 DIV:
case DOT:
case FLOAT:
case HEX:
case ID:
case LEFT_PAREN:
case LEFT_SQUARE:
case LESS:
case NEGATION:
case NULL:
case QUESTION_DIV:
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/DRL6Expressions.g:481:9: PLUS ue= unaryExpression
{
match(input, PLUS, FOLLOW_PLUS_in_unaryExpression2351);
if (state.failed)
return result;
pushFollow(FOLLOW_unaryExpression_in_unaryExpression2355);
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/DRL6Expressions.g:488:7: MINUS ue= unaryExpression
{
match(input, MINUS, FOLLOW_MINUS_in_unaryExpression2373);
if (state.failed)
return result;
pushFollow(FOLLOW_unaryExpression_in_unaryExpression2377);
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/DRL6Expressions.g:495:9: INCR primary
{
match(input, INCR, FOLLOW_INCR_in_unaryExpression2397);
if (state.failed)
return result;
pushFollow(FOLLOW_primary_in_unaryExpression2399);
primary();
state._fsp--;
if (state.failed)
return result;
}
break;
case 4:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:496:9: DECR primary
{
match(input, DECR, FOLLOW_DECR_in_unaryExpression2409);
if (state.failed)
return result;
pushFollow(FOLLOW_primary_in_unaryExpression2411);
primary();
state._fsp--;
if (state.failed)
return result;
}
break;
case 5:
// src/main/resources/org/drools/compiler/lang/DRL6Expressions.g:497:9: left= unaryExpressionNotPlusMinus
{
pushFollow(FOLLOW_unaryExpressionNotPlusMinus_in_unaryExpression2423);
left = unaryExpressionNotPlusMinus();
state._fsp--;
if (state.failed)
return result;
if (state.backtracking == 0) {
if (buildDescr) {
result = (left != null ? ((DRL6Expressions.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.BaseDescr 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.BaseDescr in project drools by kiegroup.
the class DRL5Parser method lhsPatternBind.
/**
* lhsPatternBind := label?
* ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
* | lhsPattern )
*
* @param ce
* @return
* @throws RecognitionException
*/
@SuppressWarnings("unchecked")
private BaseDescr lhsPatternBind(PatternContainerDescrBuilder<?, ?> ce, final boolean allowOr) throws RecognitionException {
PatternDescrBuilder<?> pattern = null;
CEDescrBuilder<?, OrDescr> or = null;
BaseDescr result = null;
Token first = input.LT(1);
pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
if (pattern != null) {
result = pattern.getDescr();
}
String label = null;
boolean isUnification = false;
if (input.LA(1) == DRL5Lexer.ID && input.LA(2) == DRL5Lexer.COLON && !helper.validateCEKeyword(1)) {
label = label(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
} else if (input.LA(1) == DRL5Lexer.ID && input.LA(2) == DRL5Lexer.UNIFY && !helper.validateCEKeyword(1)) {
label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
isUnification = true;
}
if (input.LA(1) == DRL5Lexer.LEFT_PAREN) {
try {
match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
if (helper.validateCEKeyword(1)) {
failMismatchedTokenException();
// in case it is backtracking
return null;
}
lhsPattern(pattern, label, isUnification);
if (state.failed)
return null;
if (allowOr && helper.validateIdentifierKey(DroolsSoftKeywords.OR) && ce instanceof CEDescrBuilder) {
if (state.backtracking == 0) {
// this is necessary because of the crappy bind with multi-pattern OR syntax
or = ((CEDescrBuilder<DescrBuilder<?, ?>, OrDescr>) ce).or();
result = or.getDescr();
helper.end(PatternDescrBuilder.class, pattern);
helper.start(or, CEDescrBuilder.class, null);
// adjust real or starting token:
helper.setStart(or, first);
// remove original pattern from the parent CE child list:
((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(pattern.getDescr());
// add pattern to the OR instead
or.getDescr().addDescr(pattern.getDescr());
}
while (helper.validateIdentifierKey(DroolsSoftKeywords.OR)) {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
pattern = helper.start(or, PatternDescrBuilder.class, null);
// new pattern, same binding
lhsPattern(pattern, label, isUnification);
if (state.failed)
return null;
helper.end(PatternDescrBuilder.class, pattern);
}
}
match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
if (or != null) {
helper.end(CEDescrBuilder.class, or);
} else {
helper.end(PatternDescrBuilder.class, pattern);
}
}
} else {
try {
lhsPattern(pattern, label, isUnification);
if (state.failed)
return null;
} finally {
helper.end(PatternDescrBuilder.class, pattern);
}
}
return result;
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL6StrictParser method constraint.
/**
* constraint := nestedConstraint | conditionalOrExpression
* @param pattern
* @throws org.antlr.runtime.RecognitionException
*/
private void constraint(PatternDescrBuilder<?> pattern, boolean positional, String prefix) throws RecognitionException {
if (speculateNestedConstraint()) {
nestedConstraint(pattern, prefix);
return;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_START);
}
int first = input.index();
// resetting
exprParser.getHelper().setHasOperator(false);
try {
exprParser.conditionalOrExpression();
} finally {
if (state.backtracking == 0) {
if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
} else if (input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_END);
} else if (!lastTokenWasWhiteSpace()) {
int location = getCurrentLocation();
if (location == Location.LOCATION_LHS_INSIDE_CONDITION_END) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_ARGUMENT);
} else if (input.get(input.index()).getType() != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_START);
}
} else if (getCurrentLocation() == Location.LOCATION_LHS_INSIDE_CONDITION_START && !exprParser.getHelper().getHasOperator() && lastTokenWasWhiteSpace() && input.LA(1) == DRL6Lexer.EOF && input.LA(-1) == DRL6Lexer.ID) {
helper.emit(Location.LOCATION_LHS_INSIDE_CONDITION_OPERATOR);
}
}
}
if (state.failed)
return;
if (state.backtracking == 0 && input.index() > first) {
// expression consumed something
int last = input.LT(-1).getTokenIndex();
String expr = toExpression(prefix, first, last);
pattern.constraint(expr, positional);
BaseDescr constrDescr = pattern.getDescr().getDescrs().get(pattern.getDescr().getDescrs().size() - 1);
constrDescr.setLocation(input.get(first).getLine(), input.get(first).getCharPositionInLine());
constrDescr.setEndLocation(input.get(last).getLine(), input.get(last).getCharPositionInLine());
constrDescr.setStartCharacter(((CommonToken) input.get(first)).getStartIndex());
constrDescr.setEndCharacter(((CommonToken) input.get(last)).getStopIndex());
}
}
Aggregations