use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class DRL5Parser method lhsOr.
/**
* lhsOr := LEFT_PAREN OR lhsAnd+ RIGHT_PAREN
* | lhsAnd (OR lhsAnd)*
*
* @param ce
* @param allowOr
* @throws RecognitionException
*/
private BaseDescr lhsOr(final CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
BaseDescr result = null;
if (allowOr && input.LA(1) == DRL5Lexer.LEFT_PAREN && helper.validateLT(2, DroolsSoftKeywords.OR)) {
// prefixed OR
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
while (input.LA(1) == DRL5Lexer.AT) {
// annotation*
annotation(or);
if (state.failed)
return null;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
while (input.LA(1) != DRL5Lexer.RIGHT_PAREN) {
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
match(input, DRL5Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
} else {
// infix OR
// create an OR anyway, as if it is not an OR we remove it later
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
lhsAnd(or, allowOr);
if (state.failed)
return null;
if (allowOr && (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL5Lexer.DOUBLE_PIPE)) {
while (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL5Lexer.DOUBLE_PIPE) {
if (input.LA(1) == DRL5Lexer.DOUBLE_PIPE) {
match(input, DRL5Lexer.DOUBLE_PIPE, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
}
if (state.failed)
return null;
while (input.LA(1) == DRL5Lexer.AT) {
// annotation*
annotation(or);
if (state.failed)
return null;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
} else if (allowOr) {
if (state.backtracking == 0) {
// if no OR present, then remove it and add children to parent
((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(or.getDescr());
for (BaseDescr base : or.getDescr().getDescrs()) {
((ConditionalElementDescr) ce.getDescr()).addDescr(base);
}
result = ce.getDescr();
}
}
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
}
return result;
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class DRL6StrictParser method lhsOr.
/**
* lhsOr := LEFT_PAREN OR lhsAnd+ RIGHT_PAREN
* | lhsAnd (OR lhsAnd)*
*
* @param ce
* @param allowOr
* @throws org.antlr.runtime.RecognitionException
*/
private BaseDescr lhsOr(final CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
BaseDescr result = null;
if (allowOr && input.LA(1) == DRL6Lexer.LEFT_PAREN && helper.validateLT(2, DroolsSoftKeywords.OR)) {
// prefixed OR
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
while (input.LA(1) != DRL6Lexer.RIGHT_PAREN) {
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
} else {
// infix OR
// create an OR anyway, as if it is not an OR we remove it later
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
lhsAnd(or, allowOr);
if (state.failed)
return null;
if (allowOr && (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL6Lexer.DOUBLE_PIPE)) {
while (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL6Lexer.DOUBLE_PIPE) {
if (input.LA(1) == DRL6Lexer.DOUBLE_PIPE) {
match(input, DRL6Lexer.DOUBLE_PIPE, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
}
if (state.failed)
return null;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
} else if (allowOr) {
if (state.backtracking == 0) {
// if no OR present, then remove it and add children to parent
((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(or.getDescr());
for (BaseDescr base : or.getDescr().getDescrs()) {
((ConditionalElementDescr) ce.getDescr()).addDescr(base);
}
result = ce.getDescr();
}
}
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
}
return result;
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class DRL6StrictParser method lhsPatternBind.
/**
* lhsPatternBind := label?
* ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
* | lhsPattern )
*
* @param ce
* @return
* @throws org.antlr.runtime.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) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.COLON && !helper.validateCEKeyword(1)) {
label = label(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
} else if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.UNIFY && !helper.validateCEKeyword(1)) {
label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
isUnification = true;
}
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
try {
match(input, DRL6Lexer.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, DRL6Lexer.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, DRL6Lexer.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.OrDescr in project drools by kiegroup.
the class DRL6Parser method lhsOr.
/**
* lhsOr := LEFT_PAREN OR lhsAnd+ RIGHT_PAREN
* | lhsAnd (OR lhsAnd)*
*
* @param ce
* @param allowOr
* @throws org.antlr.runtime.RecognitionException
*/
private BaseDescr lhsOr(final CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
BaseDescr result = null;
if (allowOr && input.LA(1) == DRL6Lexer.LEFT_PAREN && helper.validateLT(2, DroolsSoftKeywords.OR)) {
// prefixed OR
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
while (input.LA(1) == DRL6Lexer.AT) {
// annotation*
annotation(or);
if (state.failed)
return null;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
while (input.LA(1) != DRL6Lexer.RIGHT_PAREN) {
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
} else {
// infix OR
// create an OR anyway, as if it is not an OR we remove it later
CEDescrBuilder<?, OrDescr> or = null;
if (state.backtracking == 0) {
or = ce.or();
result = or.getDescr();
helper.start(or, CEDescrBuilder.class, null);
}
try {
lhsAnd(or, allowOr);
if (state.failed)
return null;
if (allowOr && (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL6Lexer.DOUBLE_PIPE)) {
while (helper.validateIdentifierKey(DroolsSoftKeywords.OR) || input.LA(1) == DRL6Lexer.DOUBLE_PIPE) {
if (input.LA(1) == DRL6Lexer.DOUBLE_PIPE) {
match(input, DRL6Lexer.DOUBLE_PIPE, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.OR, null, DroolsEditorType.KEYWORD);
}
if (state.failed)
return null;
while (input.LA(1) == DRL6Lexer.AT) {
// annotation*
annotation(or);
if (state.failed)
return null;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
lhsAnd(or, allowOr);
if (state.failed)
return null;
}
} else if (allowOr) {
if (state.backtracking == 0) {
// if no OR present, then remove it and add children to parent
((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(or.getDescr());
for (BaseDescr base : or.getDescr().getDescrs()) {
((ConditionalElementDescr) ce.getDescr()).addDescr(base);
}
result = ce.getDescr();
}
}
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, or);
}
}
}
return result;
}
use of org.drools.drl.ast.descr.OrDescr in project drools by kiegroup.
the class DRL6Parser method lhsPatternBind.
/**
* lhsPatternBind := label?
* ( LEFT_PAREN lhsPattern (OR lhsPattern)* RIGHT_PAREN
* | lhsPattern )
*
* @param ce
* @return
* @throws org.antlr.runtime.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) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.COLON && !helper.validateCEKeyword(1)) {
label = label(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
} else if (input.LA(1) == DRL6Lexer.ID && input.LA(2) == DRL6Lexer.UNIFY && !helper.validateCEKeyword(1)) {
label = unif(DroolsEditorType.IDENTIFIER_PATTERN);
if (state.failed)
return null;
isUnification = true;
}
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
try {
match(input, DRL6Lexer.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, DRL6Lexer.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, DRL6Lexer.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;
}
Aggregations