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;
}
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;
}
Aggregations