use of org.drools.drl.ast.dsl.AttributeDescrBuilder in project drools by kiegroup.
the class DRL6Parser 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) {
if (attribute != null) {
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.drl.ast.dsl.AttributeDescrBuilder 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) {
if (attribute != null) {
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) {
if (attribute != null) {
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.drl.ast.dsl.AttributeDescrBuilder in project drools by kiegroup.
the class DRL6StrictParser method booleanAttribute.
/**
* booleanAttribute := attributeKey (BOOLEAN)?
* @param key
* @throws org.antlr.runtime.RecognitionException
*/
private AttributeDescr booleanAttribute(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());
}
String value = "true";
if (input.LA(1) == DRL6Lexer.BOOL) {
Token bool = match(input, DRL6Lexer.BOOL, null, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
value = bool.getText();
}
if (state.backtracking == 0) {
if (attribute != null) {
attribute.value(value);
attribute.type(AttributeDescr.Type.BOOLEAN);
}
}
} finally {
if (attribute != null) {
helper.end(AttributeDescrBuilder.class, attribute);
}
}
return attribute != null ? attribute.getDescr() : null;
}
use of org.drools.drl.ast.dsl.AttributeDescrBuilder in project drools by kiegroup.
the class DRL5Parser method stringAttribute.
/**
* stringAttribute := attributeKey STRING
* @param key
* @throws 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, DRL5Lexer.MINUS, k, null, // part of the keyword
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} else {
match(input, DRL5Lexer.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, DRL5Lexer.STRING, null, null, DroolsEditorType.STRING_CONST);
if (state.failed)
return null;
if (state.backtracking == 0) {
if (attribute != null) {
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.drl.ast.dsl.AttributeDescrBuilder in project drools by kiegroup.
the class DRL5Parser method intOrChunkAttribute.
/**
* intOrChunkAttribute := attributeKey ( DECIMAL | chunk_(_) )
* @param key
* @throws 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, DRL5Lexer.MINUS, k, null, // part of the keyword
DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} else {
match(input, DRL5Lexer.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) == DRL5Lexer.LEFT_PAREN) {
String value = chunk(DRL5Lexer.LEFT_PAREN, DRL5Lexer.RIGHT_PAREN, -1);
if (state.failed)
return null;
if (state.backtracking == 0) {
if (attribute != null) {
attribute.value(safeStripDelimiters(value, "(", ")"));
attribute.type(AttributeDescr.Type.EXPRESSION);
}
}
} else {
String value = "";
if (input.LA(1) == DRL5Lexer.PLUS) {
Token sign = match(input, DRL5Lexer.PLUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
} else if (input.LA(1) == DRL5Lexer.MINUS) {
Token sign = match(input, DRL5Lexer.MINUS, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += sign.getText();
}
Token nbr = match(input, DRL5Lexer.DECIMAL, null, null, DroolsEditorType.NUMERIC_CONST);
if (state.failed)
return null;
value += nbr.getText();
if (state.backtracking == 0) {
if (attribute != null) {
attribute.value(value);
attribute.type(AttributeDescr.Type.NUMBER);
}
}
}
} finally {
if (attribute != null) {
helper.end(AttributeDescrBuilder.class, attribute);
}
}
return attribute != null ? attribute.getDescr() : null;
}
Aggregations