use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method function.
/* ------------------------------------------------------------------------------------------------
* FUNCTION STATEMENT
* ------------------------------------------------------------------------------------------------ */
/**
* function := FUNCTION type? ID parameters(typed) chunk_{_}
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public FunctionDescr function(PackageDescrBuilder pkg) throws RecognitionException {
FunctionDescrBuilder function = null;
try {
function = helper.start(pkg, FunctionDescrBuilder.class, null);
// 'function'
match(input, DRL6Lexer.ID, DroolsSoftKeywords.FUNCTION, null, DroolsEditorType.KEYWORD);
if (state.failed)
return null;
if (input.LA(1) != DRL6Lexer.ID || input.LA(2) != DRL6Lexer.LEFT_PAREN) {
// type
String type = type();
if (state.failed)
return null;
if (state.backtracking == 0)
function.returnType(type);
}
// name
Token id = match(input, DRL6Lexer.ID, null, null, DroolsEditorType.IDENTIFIER);
if (state.failed)
return null;
if (state.backtracking == 0) {
function.name(id.getText());
helper.setParaphrasesValue(DroolsParaphraseTypes.FUNCTION, "\"" + id.getText() + "\"");
}
// arguments
parameters(function, true);
if (state.failed)
return null;
// body
String body = chunk(DRL6Lexer.LEFT_CURLY, DRL6Lexer.RIGHT_CURLY, -1);
if (state.failed)
return null;
if (state.backtracking == 0)
function.body(body);
} catch (RecognitionException re) {
reportError(re);
} finally {
helper.end(FunctionDescrBuilder.class, function);
}
return (function != null) ? function.getDescr() : null;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method enumDeclaration.
/*
* typeDeclaration := [ENUM] qualifiedIdentifier
* annotation*
* enumerative+
* field*
* END
*
* @return
* @throws RecognitionException
*/
public EnumDeclarationDescr enumDeclaration(DeclareDescrBuilder ddb) throws RecognitionException {
EnumDeclarationDescrBuilder declare = null;
try {
declare = helper.start(ddb, EnumDeclarationDescrBuilder.class, null);
// 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.AT) {
// annotation*
annotation(declare);
if (state.failed)
return null;
}
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;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser 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;
}
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;
}
Aggregations