use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.
the class CEDescrBuilderImpl method exists.
/**
* {@inheritDoc}
*/
public CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists() {
CEDescrBuilder<CEDescrBuilder<P, T>, ExistsDescr> exists = new CEDescrBuilderImpl<CEDescrBuilder<P, T>, ExistsDescr>(this, new ExistsDescr());
((ConditionalElementDescr) descr).addDescr(exists.getDescr());
return exists;
}
use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.
the class CEDescrBuilderImpl method or.
/**
* {@inheritDoc}
*/
public CEDescrBuilder<CEDescrBuilder<P, T>, OrDescr> or() {
OrDescr orDescr = new OrDescr();
((ConditionalElementDescr) descr).addDescr(orDescr);
return new CEDescrBuilderImpl<CEDescrBuilder<P, T>, OrDescr>(this, orDescr);
}
use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.
the class PatternHandler method end.
public Object end(final String uri, final String localName, final ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final PatternDescr patternDescr = (PatternDescr) parser.getCurrent();
final Object parent = parser.getParent();
if (parent instanceof PatternDestinationDescr) {
final PatternDestinationDescr parentDescr = (PatternDestinationDescr) parent;
parentDescr.setInputPattern(patternDescr);
} else {
final ConditionalElementDescr parentDescr = (ConditionalElementDescr) parent;
parentDescr.addDescr(patternDescr);
}
return patternDescr;
}
use of org.drools.drl.ast.descr.ConditionalElementDescr in project drools by kiegroup.
the class DRL5Parser method lhsAnd.
/**
* lhsAnd := LEFT_PAREN AND lhsUnary+ RIGHT_PAREN
* | lhsUnary (AND lhsUnary)*
*
* @param ce
* @throws RecognitionException
*/
private BaseDescr lhsAnd(final CEDescrBuilder<?, ?> ce, boolean allowOr) throws RecognitionException {
BaseDescr result = null;
if (input.LA(1) == DRL5Lexer.LEFT_PAREN && helper.validateLT(2, DroolsSoftKeywords.AND)) {
// prefixed AND
CEDescrBuilder<?, AndDescr> and = null;
if (state.backtracking == 0) {
and = ce.and();
result = ce.getDescr();
helper.start(and, CEDescrBuilder.class, null);
}
try {
match(input, DRL5Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
match(input, DRL5Lexer.ID, DroolsSoftKeywords.AND, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
while (input.LA(1) == DRL5Lexer.AT) {
// annotation*
annotation(and);
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) {
lhsUnary(and, 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, and);
}
}
} else {
// infix AND
// create an AND anyway, since if it is not an AND we remove it later
CEDescrBuilder<?, AndDescr> and = null;
if (state.backtracking == 0) {
and = ce.and();
result = and.getDescr();
helper.start(and, CEDescrBuilder.class, null);
}
try {
lhsUnary(and, allowOr);
if (state.failed)
return null;
if (helper.validateIdentifierKey(DroolsSoftKeywords.AND) || input.LA(1) == DRL5Lexer.DOUBLE_AMPER) {
while (helper.validateIdentifierKey(DroolsSoftKeywords.AND) || input.LA(1) == DRL5Lexer.DOUBLE_AMPER) {
if (input.LA(1) == DRL5Lexer.DOUBLE_AMPER) {
match(input, DRL5Lexer.DOUBLE_AMPER, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL5Lexer.ID, DroolsSoftKeywords.AND, null, DroolsEditorType.KEYWORD);
}
if (state.failed)
return null;
while (input.LA(1) == DRL5Lexer.AT) {
// annotation*
annotation(and);
if (state.failed)
return null;
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION_AND_OR);
}
lhsUnary(and, allowOr);
if (state.failed)
return null;
}
} else {
if (state.backtracking == 0 && and.getDescr().getDescrs().size() < 2) {
// if no AND present, then remove it and add children to parent
((ConditionalElementDescr) ce.getDescr()).getDescrs().remove(and.getDescr());
for (BaseDescr base : and.getDescr().getDescrs()) {
((ConditionalElementDescr) ce.getDescr()).addDescr(base);
}
result = ce.getDescr();
}
}
} finally {
if (state.backtracking == 0) {
helper.end(CEDescrBuilder.class, and);
}
}
}
return result;
}
use of org.drools.drl.ast.descr.ConditionalElementDescr 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;
}
Aggregations