use of org.drools.compiler.lang.api.DescrBuilder in project drools by kiegroup.
the class DRL6Parser method intOrChunkAttribute.
/**
* intOrChunkAttribute := attributeKey ( DECIMAL | chunk_(_) )
* @param key
* @throws org.antlr.runtime.RecognitionException
*/
private AttributeDescr intOrChunkAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
AttributeDescrBuilder<?> attribute = null;
try {
StringBuilder builder = new StringBuilder();
for (String k : key) {
if ("-".equals(k)) {
match(input, DRL6Lexer.MINUS, k, null, // part of the keyword
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} else {
match(input, DRL6Lexer.ID, k, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
}
builder.append(k);
}
if (state.backtracking == 0) {
attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
}
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
String value = chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
if (state.failed)
return null;
if (state.backtracking == 0) {
attribute.value(safeStripDelimiters(value, "(", ")"));
attribute.type(AttributeDescr.Type.EXPRESSION);
}
} else {
String value = "";
if (input.LA(1) == DRL6Lexer.PLUS) {
Token sign = match(input, DRL6Lexer.PLUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
} else if (input.LA(1) == DRL6Lexer.MINUS) {
Token sign = match(input, DRL6Lexer.MINUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
}
Token nbr = match(input, DRL6Lexer.DECIMAL, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += nbr.getText();
if (state.backtracking == 0) {
attribute.value(value);
attribute.type(AttributeDescr.Type.NUMBER);
}
}
} finally {
if (attribute != null) {
helper.end(AttributeDescrBuilder.class, attribute);
}
}
return attribute != null ? attribute.getDescr() : null;
}
use of org.drools.compiler.lang.api.DescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method lhsAccumulate.
/**
* lhsAccumulate := (ACCUMULATE|ACC) LEFT_PAREN lhsAnd (COMMA|SEMICOLON)
* accumulateFunctionBinding (COMMA accumulateFunctionBinding)*
* (SEMICOLON constraints)?
* RIGHT_PAREN SEMICOLON?
*
* @param ce
* @return
* @throws org.antlr.runtime.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 {
if (helper.validateIdentifierKey(DroolsSoftKeywords.ACCUMULATE)) {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACCUMULATE, null, DroolsEditorType.KEYWORD);
} else {
// might be using the short mnemonic
match(input, DRL6Lexer.ID, DroolsSoftKeywords.ACC, null, DroolsEditorType.KEYWORD);
}
if (state.failed)
return null;
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_FROM_ACCUMULATE);
}
match(input, DRL6Lexer.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) == DRL6Lexer.COMMA) {
match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} else if (input.LA(-1) != DRL6Lexer.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, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
}
// accumulate functions
accumulateFunctionBinding(accumulate);
if (state.failed)
return null;
while (input.LA(1) == DRL6Lexer.COMMA) {
match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
accumulateFunctionBinding(accumulate);
if (state.failed)
return null;
}
if (input.LA(1) == DRL6Lexer.SEMICOLON) {
match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
constraints(pattern);
}
match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
helper.end(AccumulateDescrBuilder.class, accumulate);
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
}
} finally {
helper.end(PatternDescrBuilder.class, pattern);
}
if (input.LA(1) == DRL6Lexer.SEMICOLON) {
match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
}
return result;
}
use of org.drools.compiler.lang.api.DescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method stringAttribute.
/**
* stringAttribute := attributeKey STRING
* @param key
* @throws org.antlr.runtime.RecognitionException
*/
private AttributeDescr stringAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
AttributeDescrBuilder<?> attribute = null;
try {
StringBuilder builder = new StringBuilder();
for (String k : key) {
if ("-".equals(k)) {
match(input, DRL6Lexer.MINUS, k, null, // part of the keyword
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} else {
match(input, DRL6Lexer.ID, k, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
}
builder.append(k);
}
if (state.backtracking == 0) {
attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
}
Token value = match(input, DRL6Lexer.STRING, null, null, DroolsEditorType.STRING_CONST);
if (state.failed)
return null;
if (state.backtracking == 0) {
attribute.value(StringUtils.unescapeJava(safeStripStringDelimiters(value.getText())));
attribute.type(AttributeDescr.Type.STRING);
}
} finally {
if (attribute != null) {
helper.end(AttributeDescrBuilder.class, attribute);
}
}
return attribute != null ? attribute.getDescr() : null;
}
use of org.drools.compiler.lang.api.DescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method namedConsequence.
/**
* namedConsequence := DO LEFT_SQUARE ID RIGHT_SQUARE BREAK?
*/
private BaseDescr namedConsequence(CEDescrBuilder<?, ?> ce, NamedConsequenceDescrBuilder<?> namedConsequence) throws RecognitionException {
if (namedConsequence == null) {
namedConsequence = helper.start((DescrBuilder<?, ?>) ce, NamedConsequenceDescrBuilder.class, null);
}
try {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.DO, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
match(input, DRL6Lexer.LEFT_SQUARE, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
Token label = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
namedConsequence.name(label.getText());
match(input, DRL6Lexer.RIGHT_SQUARE, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return null;
} finally {
helper.end(NamedConsequenceDescrBuilder.class, namedConsequence);
}
return namedConsequence.getDescr();
}
use of org.drools.compiler.lang.api.DescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method intOrChunkAttribute.
/**
* intOrChunkAttribute := attributeKey ( DECIMAL | chunk_(_) )
* @param key
* @throws org.antlr.runtime.RecognitionException
*/
private AttributeDescr intOrChunkAttribute(AttributeSupportBuilder<?> as, String[] key) throws RecognitionException {
AttributeDescrBuilder<?> attribute = null;
try {
StringBuilder builder = new StringBuilder();
for (String k : key) {
if ("-".equals(k)) {
match(input, DRL6Lexer.MINUS, k, null, // part of the keyword
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} else {
match(input, DRL6Lexer.ID, k, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
}
builder.append(k);
}
if (state.backtracking == 0) {
attribute = helper.start((DescrBuilder<?, ?>) as, AttributeDescrBuilder.class, builder.toString());
}
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
String value = chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1);
if (state.failed)
return null;
if (state.backtracking == 0) {
attribute.value(safeStripDelimiters(value, "(", ")"));
attribute.type(AttributeDescr.Type.EXPRESSION);
}
} else {
String value = "";
if (input.LA(1) == DRL6Lexer.PLUS) {
Token sign = match(input, DRL6Lexer.PLUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
} else if (input.LA(1) == DRL6Lexer.MINUS) {
Token sign = match(input, DRL6Lexer.MINUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
}
Token nbr = match(input, DRL6Lexer.DECIMAL, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += nbr.getText();
if (state.backtracking == 0) {
attribute.value(value);
attribute.type(AttributeDescr.Type.NUMBER);
}
}
} finally {
if (attribute != null) {
helper.end(AttributeDescrBuilder.class, attribute);
}
}
return attribute != null ? attribute.getDescr() : null;
}
Aggregations