use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method namedConsequence.
/**
* namedConsequence := THEN LEFT_SQUARE ID RIGHT_SQUARE chunk
* @param rule
*/
public void namedConsequence(RuleDescrBuilder rule) {
try {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.THEN, null, DroolsEditorType.KEYWORD);
match(input, DRL6Lexer.LEFT_SQUARE, null, null, DroolsEditorType.SYMBOL);
Token label = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.SYMBOL);
int first = input.index();
match(input, DRL6Lexer.RIGHT_SQUARE, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
String name = label.getText();
String chunk = getConsequenceCode(first);
// remove the closing squqre bracket "]" and any subsequent spaces and line breaks
// keep indentation of 1st non-blank line
chunk = chunk.replaceFirst("^\\]\\s*\\r?\\n?", "");
rule.namedRhs(name, chunk);
} catch (RecognitionException re) {
reportError(re);
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method declare.
/* ------------------------------------------------------------------------------------------------
* DECLARE STATEMENT
* ------------------------------------------------------------------------------------------------ */
/**
* declare := DECLARE
* | (ENTRY-POINT) => entryPointDeclaration
* | (WINDOW) => windowDeclaration
* | (TRAIT) => typeDeclaration (trait)
* | (ENUM) => enumDeclaration
* | typeDeclaration (class)
* END
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public BaseDescr declare(PackageDescrBuilder pkg) throws RecognitionException {
BaseDescr declaration = null;
try {
DeclareDescrBuilder declare = helper.start(pkg, DeclareDescrBuilder.class, null);
// 'declare'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.DECLARE, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (helper.validateIdentifierKey(DroolsSoftKeywords.ENTRY)) {
// entry point declaration
declaration = entryPointDeclaration(declare);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.WINDOW)) {
// window declaration
declaration = windowDeclaration(declare);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.TRAIT)) {
// trait type declaration
// 'trait'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.TRAIT, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
declaration = typeDeclaration(declare, true);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.ENUM)) {
match(input, DRL6Lexer.ID, DroolsSoftKeywords.ENUM, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
declaration = enumDeclaration(declare);
} else {
// class type declaration
declaration = typeDeclaration(declare, false);
}
} catch (RecognitionException re) {
reportError(re);
}
return declaration;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser 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 DRL6StrictParser method field.
/**
* field := annotation* label fieldType (EQUALS_ASSIGN conditionalExpression)? SEMICOLON?
*/
private void field(AbstractClassTypeDeclarationBuilder declare) {
annotations();
FieldDescrBuilder field = null;
String fname = null;
try {
fname = label(DroolsEditorType.IDENTIFIER);
if (state.failed)
return;
} catch (RecognitionException re) {
reportError(re);
}
try {
field = helper.start(declare, FieldDescrBuilder.class, fname);
setAnnotationsOn(field);
// type
String type = type();
if (state.failed)
return;
if (state.backtracking == 0)
field.type(type);
if (input.LA(1) == DRL6Lexer.EQUALS_ASSIGN) {
// EQUALS_ASSIGN
match(input, DRL6Lexer.EQUALS_ASSIGN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
int first = input.index();
exprParser.conditionalExpression();
if (state.failed)
return;
if (state.backtracking == 0 && input.index() > first) {
// expression consumed something
String value = input.toString(first, input.LT(-1).getTokenIndex());
field.initialValue(value);
}
}
if (input.LA(1) == DRL6Lexer.SEMICOLON) {
match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(FieldDescrBuilder.class, field);
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method enumDeclaration.
/*
* typeDeclaration := annotation* [ENUM] qualifiedIdentifier
* enumerative+
* field*
* END
*
* @return
* @throws RecognitionException
*/
public EnumDeclarationDescr enumDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
EnumDeclarationDescrBuilder declare = null;
try {
declare = helper.start(ddb, EnumDeclarationDescrBuilder.class, null);
setAnnotationsOn(declare);
// type may be qualified when adding metadata
String type = qualifiedIdentifier();
if (state.failed)
return null;
if (state.backtracking == 0)
declare.name(type);
while (input.LA(1) == DRL6Lexer.ID) {
int next = input.LA(2);
if (next == DRL6Lexer.LEFT_PAREN || next == DRL6Lexer.COMMA || next == DRL6Lexer.SEMICOLON) {
enumerative(declare);
if (state.failed)
return null;
}
if (input.LA(1) == DRL6Lexer.COMMA) {
match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
} else {
match(input, DRL6Lexer.SEMICOLON, null, null, DroolsEditorType.SYMBOL);
break;
}
}
// boolean qualified = type.indexOf( '.' ) >= 0;
while (// ! qualified &&
input.LA(1) == DRL6Lexer.ID && !helper.validateIdentifierKey(DroolsSoftKeywords.END)) {
// field*
field(declare);
if (state.failed)
return null;
}
match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(TypeDeclarationDescrBuilder.class, declare);
}
return (declare != null) ? declare.getDescr() : null;
}
Aggregations