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