use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL6StrictParser method lhsParen.
/**
* lhsParen := LEFT_PAREN lhsOr RIGHT_PAREN
*
* @param ce
* @return
* @throws org.antlr.runtime.RecognitionException
*/
private BaseDescr lhsParen(CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
BaseDescr descr = lhsOr(ce, allowOr);
if (state.failed)
return null;
match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
return descr;
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Parser method fromAccumulate.
/**
* fromAccumulate := ACCUMULATE LEFT_PAREN lhsAnd COMMA
* ( INIT chunk_(_) COMMA ACTION chunk_(_) COMMA
* ( REVERSE chunk_(_) COMMA)? RESULT chunk_(_)
* | accumulateFunction
* ) RIGHT_PAREN
*
* @param pattern
* @throws RecognitionException
*/
private void fromAccumulate(PatternDescrBuilder<?> pattern) throws RecognitionException {
AccumulateDescrBuilder<?> accumulate = helper.start(pattern, AccumulateDescrBuilder.class, null);
try {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
}
match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
CEDescrBuilder<?, AndDescr> source = accumulate.source();
try {
helper.start(source, CEDescrBuilder.class, null);
lhsAnd(source, false);
if (state.failed)
return;
if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
root.getDescrs().clear();
for (int i = 0; i < descrs.length; i++) {
root.addOrMerge(descrs[i]);
}
}
} finally {
helper.end(CEDescrBuilder.class, source);
}
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
if (helper.validateIdentifierKey(DroolsSoftKeywords.INIT)) {
// custom code, inline accumulate
// initBlock
match(input, DRL5Lexer.ID, DroolsSoftKeywords.INIT, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_INIT);
}
String init = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, Location.LOCATION_LHS_FROM_ACCUMULATE_INIT_INSIDE);
if (state.failed)
return;
if (state.backtracking == 0)
accumulate.init(init);
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
// actionBlock
match(input, DRL5Lexer.ID, DroolsSoftKeywords.ACTION, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION);
}
String action = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, Location.LOCATION_LHS_FROM_ACCUMULATE_ACTION_INSIDE);
if (state.failed)
return;
if (state.backtracking == 0)
accumulate.action(action);
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
// reverseBlock
if (helper.validateIdentifierKey(DroolsSoftKeywords.REVERSE)) {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.REVERSE, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE);
}
String reverse = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, Location.LOCATION_LHS_FROM_ACCUMULATE_REVERSE_INSIDE);
if (state.failed)
return;
if (state.backtracking == 0)
accumulate.reverse(reverse);
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
}
// resultBlock
match(input, DRL5Lexer.ID, DroolsSoftKeywords.RESULT, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT);
}
String result = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, Location.LOCATION_LHS_FROM_ACCUMULATE_RESULT_INSIDE);
if (state.failed)
return;
if (state.backtracking == 0)
accumulate.result(result);
} else {
// accumulate functions
accumulateFunction(accumulate, false, null);
if (state.failed)
return;
}
match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
} finally {
helper.end(AccumulateDescrBuilder.class, accumulate);
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
}
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Parser method lhsAccumulate.
/**
* lhsAccumulate := ACCUMULATE LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
* accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
* (SEMICOLON constraints)?
* RIGHT_PAREN SEMICOLON?
*
* @param ce
* @return
* @throws RecognitionException
*/
private BaseDescr lhsAccumulate(PatternContainerDescrBuilder<?, ?> ce) throws RecognitionException {
PatternDescrBuilder<?> pattern = null;
BaseDescr result = null;
pattern = helper.start((DescrBuilder<?, ?>) ce, PatternDescrBuilder.class, null);
if (pattern != null) {
result = pattern.getDescr();
}
try {
if (state.backtracking == 0) {
pattern.type("Object[]");
pattern.isQuery(false);
// might have to add the implicit bindings as well
}
AccumulateDescrBuilder<?> accumulate = helper.start(pattern, AccumulateDescrBuilder.class, null);
try {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
}
match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
CEDescrBuilder<?, AndDescr> source = accumulate.source();
try {
helper.start(source, CEDescrBuilder.class, null);
lhsAnd(source, false);
if (state.failed)
return null;
if (source.getDescr() != null && source.getDescr() instanceof ConditionalElementDescr) {
ConditionalElementDescr root = (ConditionalElementDescr) source.getDescr();
BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
root.getDescrs().clear();
for (int i = 0; i < descrs.length; i++) {
root.addOrMerge(descrs[i]);
}
}
} finally {
helper.end(CEDescrBuilder.class, source);
}
if (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} else if (input.LA(-1) != DRL5Lexer.SEMICOLON) {
// lhsUnary will consume an optional SEMICOLON, so we need to check if it was consumed already
// or if we must fail consuming it now
match(input, DRL5Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
}
// accumulate functions
accumulateFunctionBinding(accumulate);
if (state.failed)
return null;
while (input.LA(1) == DRL5Lexer.COMMA) {
match(input, DRL5Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
accumulateFunctionBinding(accumulate);
if (state.failed)
return null;
}
if (input.LA(1) == DRL5Lexer.SEMICOLON) {
match(input, DRL5Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
constraints(pattern);
}
match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
helper.end(AccumulateDescrBuilder.class, accumulate);
if (state.backtracking == 0 && input.LA(1) != DRL5Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
}
} finally {
helper.end(PatternDescrBuilder.class, pattern);
}
if (input.LA(1) == DRL5Lexer.SEMICOLON) {
match(input, DRL5Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
}
return result;
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Parser method lhsExpression.
/**
* lhsExpression := lhsOr*
*
* @param lhs
* @throws RecognitionException
*/
private void lhsExpression(CEDescrBuilder<?, AndDescr> lhs) throws RecognitionException {
helper.start(lhs, CEDescrBuilder.class, null);
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
try {
while (input.LA(1) != DRL5Lexer.EOF && !helper.validateIdentifierKey(DroolsSoftKeywords.THEN) && !helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
lhsOr(lhs, true);
if (lhs.getDescr() != null && lhs.getDescr() instanceof ConditionalElementDescr) {
ConditionalElementDescr root = (ConditionalElementDescr) lhs.getDescr();
BaseDescr[] descrs = root.getDescrs().toArray(new BaseDescr[root.getDescrs().size()]);
root.getDescrs().clear();
for (int i = 0; i < descrs.length; i++) {
root.addOrMerge(descrs[i]);
}
}
if (state.failed)
return;
}
} finally {
helper.end(CEDescrBuilder.class, lhs);
}
}
use of org.drools.drl.ast.descr.BaseDescr in project drools by kiegroup.
the class DRL5Expressions method castExpression.
// $ANTLR end "unaryExpressionNotPlusMinus"
// $ANTLR start "castExpression"
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:520:1: castExpression : ( ( LEFT_PAREN primitiveType )=> LEFT_PAREN primitiveType RIGHT_PAREN expr= unaryExpression | ( LEFT_PAREN type )=> LEFT_PAREN type RIGHT_PAREN unaryExpressionNotPlusMinus );
public final void castExpression() throws RecognitionException {
BaseDescr expr = null;
try {
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:521:5: ( ( LEFT_PAREN primitiveType )=> LEFT_PAREN primitiveType RIGHT_PAREN expr= unaryExpression | ( LEFT_PAREN type )=> LEFT_PAREN type RIGHT_PAREN unaryExpressionNotPlusMinus )
int alt54 = 2;
int LA54_0 = input.LA(1);
if ((LA54_0 == LEFT_PAREN)) {
int LA54_1 = input.LA(2);
if ((synpred17_DRL5Expressions())) {
alt54 = 1;
} else if ((synpred18_DRL5Expressions())) {
alt54 = 2;
} else {
if (state.backtracking > 0) {
state.failed = true;
return;
}
int nvaeMark = input.mark();
try {
input.consume();
NoViableAltException nvae = new NoViableAltException("", 54, 1, input);
throw nvae;
} finally {
input.rewind(nvaeMark);
}
}
} else {
if (state.backtracking > 0) {
state.failed = true;
return;
}
NoViableAltException nvae = new NoViableAltException("", 54, 0, input);
throw nvae;
}
switch(alt54) {
case 1:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:521:8: ( LEFT_PAREN primitiveType )=> LEFT_PAREN primitiveType RIGHT_PAREN expr= unaryExpression
{
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_castExpression2593);
if (state.failed)
return;
pushFollow(FOLLOW_primitiveType_in_castExpression2595);
primitiveType();
state._fsp--;
if (state.failed)
return;
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_castExpression2597);
if (state.failed)
return;
pushFollow(FOLLOW_unaryExpression_in_castExpression2601);
expr = unaryExpression();
state._fsp--;
if (state.failed)
return;
}
break;
case 2:
// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:522:8: ( LEFT_PAREN type )=> LEFT_PAREN type RIGHT_PAREN unaryExpressionNotPlusMinus
{
match(input, LEFT_PAREN, FOLLOW_LEFT_PAREN_in_castExpression2618);
if (state.failed)
return;
pushFollow(FOLLOW_type_in_castExpression2620);
type();
state._fsp--;
if (state.failed)
return;
match(input, RIGHT_PAREN, FOLLOW_RIGHT_PAREN_in_castExpression2622);
if (state.failed)
return;
pushFollow(FOLLOW_unaryExpressionNotPlusMinus_in_castExpression2624);
unaryExpressionNotPlusMinus();
state._fsp--;
if (state.failed)
return;
}
break;
}
} catch (RecognitionException re) {
throw re;
} finally {
// do for sure before leaving
}
}
Aggregations