use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method enumerative.
/**
* enumerative := ID ( LEFT_PAREN expression (COMMA expression)* RIGHT_PAREN )?
*/
private void enumerative(EnumDeclarationDescrBuilder declare) {
EnumLiteralDescrBuilder literal = null;
String lit = null;
try {
Token enumLit = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
lit = enumLit.getText();
if (state.failed)
return;
} catch (RecognitionException re) {
reportError(re);
}
try {
literal = helper.start(declare, EnumLiteralDescrBuilder.class, lit);
if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
match(input, DRL6Lexer.LEFT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
boolean more;
do {
int first = input.index();
exprParser.conditionalExpression();
if (state.failed)
return;
if (state.backtracking == 0 && input.index() > first) {
// expression consumed something
String arg = input.toString(first, input.LT(-1).getTokenIndex());
literal.constructorArg(arg);
}
more = input.LA(1) == DRL6Lexer.COMMA;
if (more) {
match(input, DRL6Lexer.COMMA, null, null, DroolsEditorType.SYMBOL);
}
} while (more);
match(input, DRL6Lexer.RIGHT_PAREN, null, null, DroolsEditorType.SYMBOL);
if (state.failed)
return;
}
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(FieldDescrBuilder.class, literal);
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method entryPointDeclaration.
/**
* entryPointDeclaration := annotation* ENTRY-POINT stringId END
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public EntryPointDeclarationDescr entryPointDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
EntryPointDeclarationDescrBuilder declare = null;
try {
declare = helper.start(ddb, EntryPointDeclarationDescrBuilder.class, null);
setAnnotationsOn(declare);
match(input, DRL6Lexer.ID, DroolsSoftKeywords.ENTRY, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
match(input, DRL6Lexer.MINUS, null, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
match(input, DRL6Lexer.ID, DroolsSoftKeywords.POINT, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
String ep = stringId();
if (state.failed)
return null;
if (state.backtracking == 0) {
declare.entryPointId(ep);
}
match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(EntryPointDeclarationDescrBuilder.class, declare);
}
return (declare != null) ? declare.getDescr() : null;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method defaultConsequence.
/**
* defaultConsequence := THEN chunk
* @param rule
*/
public void defaultConsequence(RuleDescrBuilder rule) {
try {
int first = input.index();
Token t = match(input, DRL6Lexer.ID, DroolsSoftKeywords.THEN, null, DroolsEditorType.KEYWORD);
if (state.failed)
return;
if (state.backtracking == 0) {
rule.getDescr().setConsequenceLocation(t.getLine(), t.getCharPositionInLine());
helper.emit(Location.LOCATION_RHS);
}
String chunk = getConsequenceCode(first);
// remove the "then" keyword and any subsequent spaces and line breaks
// keep indentation of 1st non-blank line
chunk = chunk.replaceFirst("^then\\s*\\r?\\n?", "");
rule.rhs(chunk);
} catch (RecognitionException re) {
reportError(re);
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method query.
/* ------------------------------------------------------------------------------------------------
* QUERY STATEMENT
* ------------------------------------------------------------------------------------------------ */
/**
* query := annotation* QUERY stringId parameters? lhsExpression END
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public RuleDescr query(PackageDescrBuilder pkg) throws RecognitionException {
QueryDescrBuilder query = null;
try {
query = helper.start(pkg, QueryDescrBuilder.class, null);
setAnnotationsOn(query);
// 'query'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.QUERY, 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.backtracking == 0)
query.name(name);
if (state.failed)
return null;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_RULE_HEADER);
}
if (speculateParameters(true)) {
// parameters
parameters(query, true);
if (state.failed)
return null;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
} else if (speculateParameters(false)) {
// parameters
parameters(query, false);
if (state.failed)
return null;
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
}
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_LHS_BEGIN_OF_CONDITION);
}
if (input.LA(1) != DRL6Lexer.EOF) {
lhsExpression(query != null ? query.lhs() : null);
}
match(input, DRL6Lexer.ID, DroolsSoftKeywords.END, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
helper.emit(Location.LOCATION_RHS);
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(QueryDescrBuilder.class, query);
}
return (query != null) ? query.getDescr() : null;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6StrictParser method globalStatement.
/* ------------------------------------------------------------------------------------------------
* GLOBAL STATEMENT
* ------------------------------------------------------------------------------------------------ */
/**
* globalStatement := GLOBAL type ID
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public GlobalDescr globalStatement(PackageDescrBuilder pkg) throws RecognitionException {
GlobalDescrBuilder global = null;
try {
global = helper.start(pkg, GlobalDescrBuilder.class, null);
// 'global'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.GLOBAL, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
// type
String type = type();
if (state.backtracking == 0)
global.type(type);
if (state.failed)
return null;
// identifier
Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER_TYPE);
if (state.failed)
return null;
if (state.backtracking == 0) {
global.identifier(id.getText());
helper.setParaphrasesValue(DroolsParaphraseTypes.GLOBAL, id.getText());
}
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(GlobalDescrBuilder.class, global);
}
return (global != null) ? global.getDescr() : null;
}
Aggregations