use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method attribute.
/**
* attribute :=
* salience
* | enabled
* | ( NO-LOOP
* | AUTO-FOCUS
* | LOCK-ON-ACTIVE
* | REFRACT
* | DIRECT
* ) BOOLEAN?
* | ( AGENDA-GROUP
* | ACTIVATION-GROUP
* | RULEFLOW-GROUP
* | DATE-EFFECTIVE
* | DATE-EXPIRES
* | DIALECT
* ) STRING
* | CALENDARS STRING (COMMA STRING)*
* | TIMER ( DECIMAL | chunk_(_) )
* | DURATION ( DECIMAL | chunk_(_) )
*
* The above syntax is not quite how this is parsed, because the soft keyword
* is determined by look-ahead and passed on to one of the x-Attribute methods
* (booleanAttribute, stringAttribute, stringListAttribute, intOrChunkAttribute)
* which will actually gobble the tokens.
*
* @return
*/
public AttributeDescr attribute(AttributeSupportBuilder<?> as) {
AttributeDescr attribute = null;
try {
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_RULE_HEADER_KEYWORD);
}
if (helper.validateIdentifierKey(DroolsSoftKeywords.SALIENCE)) {
attribute = salience(as);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.ENABLED)) {
attribute = enabled(as);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.NO) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.LOOP)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.NO, "-", DroolsSoftKeywords.LOOP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.AUTO) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.FOCUS)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.AUTO, "-", DroolsSoftKeywords.FOCUS });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.LOCK) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.ON) && helper.validateLT(4, "-") && helper.validateLT(5, DroolsSoftKeywords.ACTIVE)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.LOCK, "-", DroolsSoftKeywords.ON, "-", DroolsSoftKeywords.ACTIVE });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.REFRACT)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.REFRACT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DIRECT)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.DIRECT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.AGENDA) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.AGENDA, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.ACTIVATION) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.ACTIVATION, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.RULEFLOW) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.RULEFLOW, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DATE) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.EFFECTIVE)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DATE, "-", DroolsSoftKeywords.EFFECTIVE });
attribute.setType(AttributeDescr.Type.DATE);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DATE) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.EXPIRES)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DATE, "-", DroolsSoftKeywords.EXPIRES });
attribute.setType(AttributeDescr.Type.DATE);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DIALECT)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DIALECT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.CALENDARS)) {
attribute = stringListAttribute(as, new String[] { DroolsSoftKeywords.CALENDARS });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.TIMER)) {
attribute = intOrChunkAttribute(as, new String[] { DroolsSoftKeywords.TIMER });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DURATION)) {
attribute = intOrChunkAttribute(as, new String[] { DroolsSoftKeywords.DURATION });
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_RULE_HEADER);
}
} catch (RecognitionException re) {
reportError(re);
}
return attribute;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method annotation.
/* ------------------------------------------------------------------------------------------------
* ANNOTATION
* ------------------------------------------------------------------------------------------------ */
/**
* annotation := fullAnnotation | AT ID chunk_(_)?
*/
void annotation(AnnotatedDescrBuilder<?> adb) {
AnnotationDescrBuilder<?> annotation = null;
try {
if (speculateFullAnnotation()) {
boolean buildState = exprParser.isBuildDescr();
exprParser.setBuildDescr(true);
exprParser.fullAnnotation(adb);
exprParser.setBuildDescr(buildState);
} else {
// '@'
Token at = match(input, DRL6Lexer.AT, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
// identifier
String fqn = qualifiedIdentifier();
if (state.failed)
return;
if (state.backtracking == 0) {
annotation = adb.newAnnotation(fqn);
helper.setStart(annotation, at);
}
try {
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
String value = chunk(DRL6Lexer.LEFT_PAREN, DRL6Lexer.RIGHT_PAREN, -1).trim();
if (state.failed)
return;
if (state.backtracking == 0) {
annotation.value(value);
}
}
} finally {
if (state.backtracking == 0) {
helper.setEnd(annotation);
}
}
}
} catch (RecognitionException re) {
reportError(re);
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method qualifiedIdentifier.
/**
* Matches a qualified identifier
*
* qualifiedIdentifier := ID ( DOT ID )*
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public String qualifiedIdentifier() throws RecognitionException {
String qi = "";
try {
Token first = match(input, DRL6Lexer.ID, null, new int[] { DRL6Lexer.DOT }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
Token last = first;
while (input.LA(1) == DRL6Lexer.DOT && input.LA(2) == DRL6Lexer.ID) {
last = match(input, DRL6Lexer.DOT, null, new int[] { DRL6Lexer.ID }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
last = match(input, DRL6Lexer.ID, null, new int[] { DRL6Lexer.DOT }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
}
qi = input.toString(first, last);
qi = qi.replace(" ", "");
} catch (RecognitionException re) {
reportError(re);
}
return qi;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method typeArguments.
/**
* Matches type arguments
*
* typeArguments := LESS typeArgument (COMMA typeArgument)* GREATER
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public String typeArguments() throws RecognitionException {
String typeArguments = "";
try {
int first = input.index();
Token token = match(input, DRL6Lexer.LESS, null, new int[] { DRL6Lexer.QUESTION, DRL6Lexer.ID }, DroolsEditorType.SYMBOL);
if (state.failed)
return typeArguments;
typeArgument();
if (state.failed)
return typeArguments;
while (input.LA(1) == DRL6Lexer.COMMA) {
token = match(input, DRL6Lexer.COMMA, null, new int[] { DRL6Lexer.QUESTION, DRL6Lexer.ID }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return typeArguments;
typeArgument();
if (state.failed)
return typeArguments;
}
token = match(input, DRL6Lexer.GREATER, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return typeArguments;
typeArguments = input.toString(first, token.getTokenIndex());
} catch (RecognitionException re) {
reportError(re);
}
return typeArguments;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method rule.
/* ------------------------------------------------------------------------------------------------
* RULE STATEMENT
* ------------------------------------------------------------------------------------------------ */
/**
* rule := RULE stringId (EXTENDS stringId)? annotation* attributes? lhs? rhs END
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public RuleDescr rule(PackageDescrBuilder pkg) throws RecognitionException {
RuleDescrBuilder rule = null;
try {
rule = helper.start(pkg, RuleDescrBuilder.class, null);
// 'rule'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.RULE, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN) || helper.validateIdentifierKey(DroolsSoftKeywords.THEN) || helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
failMissingTokenException();
// in case it is backtracking
return null;
}
String name = stringId();
if (state.failed)
return null;
if (state.backtracking == 0) {
rule.name(name);
helper.setParaphrasesValue(DroolsParaphraseTypes.RULE, "\"" + name + "\"");
helper.emit(Location.LOCATION_RULE_HEADER);
}
if (helper.validateIdentifierKey(DroolsSoftKeywords.EXTENDS)) {
// 'extends'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.EXTENDS, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
String parent = stringId();
if (state.backtracking == 0)
rule.extendsRule(parent);
if (state.failed)
return null;
}
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_RULE_HEADER);
}
while (input.LA(1) == DRL6Lexer.AT) {
// annotation*
annotation(rule);
if (state.failed)
return null;
}
attributes(rule);
if (helper.validateIdentifierKey(DroolsSoftKeywords.WHEN)) {
lhs(rule);
} else {
// creates an empty LHS
rule.lhs();
}
rhs(rule);
match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(RuleDescrBuilder.class, rule);
}
return (rule != null) ? rule.getDescr() : null;
}
Aggregations