use of org.antlr.runtime.RecognitionException in project xtext-core by eclipse.
the class Lexer method nextToken.
@Override
public Token nextToken() {
while (true) {
this.state.token = null;
this.state.channel = Token.DEFAULT_CHANNEL;
this.state.tokenStartCharIndex = input.index();
this.state.tokenStartCharPositionInLine = input.getCharPositionInLine();
this.state.tokenStartLine = input.getLine();
this.state.text = null;
if (input.LA(1) == CharStream.EOF) {
return Token.EOF_TOKEN;
}
try {
mTokens();
if (this.state.token == null) {
emit();
} else if (this.state.token == Token.SKIP_TOKEN) {
continue;
}
return this.state.token;
} catch (RecognitionException re) {
reportError(re);
if (re instanceof NoViableAltException || re instanceof FailedPredicateException) {
recover(re);
}
// create token that holds mismatched char
Token t = new CommonToken(input, Token.INVALID_TOKEN_TYPE, Token.HIDDEN_CHANNEL, this.state.tokenStartCharIndex, getCharIndex() - 1);
t.setLine(this.state.tokenStartLine);
t.setCharPositionInLine(this.state.tokenStartCharPositionInLine);
tokenErrorMap.put(t, getErrorMessage(re, this.getTokenNames()));
emit(t);
return this.state.token;
}
}
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DrlExprParser method parse.
/**
* Parse an expression from text
*/
public ConstraintConnectiveDescr parse(final String text) {
ConstraintConnectiveDescr constraint = null;
try {
DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
CommonTokenStream input = new CommonTokenStream(lexer);
RecognizerSharedState state = new RecognizerSharedState();
helper = new ParserHelper(input, state, languageLevel);
DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
parser.setBuildDescr(true);
// setting initial value just in case
parser.setLeftMostExpr(null);
BaseDescr expr = parser.conditionalOrExpression();
if (expr != null && !parser.hasErrors()) {
constraint = ConstraintConnectiveDescr.newAnd();
constraint.addOrMerge(expr);
}
} catch (RecognitionException e) {
helper.reportError(e);
}
return constraint;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser method attribute.
/**
* attribute :=
* salience
* | enabled
* | ( NO-LOOP
* | AUTO-FOCUS
* | LOCK-ON-ACTIVE
* | REFRACT
* | DIRECT
* ) BOOLEAN?
* | ( AGENDA-GROUP
* | ACTIVATION-GROUP
* | RULEFLOW-GROUP
* | DATE-EFFECTIVE
* | DATE-EXPIRES
* | DIALECT
* ) STRING
* | CALENDARS STRING (COMMA STRING)*
* | TIMER ( DECIMAL | chunk_(_) )
* | DURATION ( DECIMAL | chunk_(_) )
*
* The above syntax is not quite how this is parsed, because the soft keyword
* is determined by look-ahead and passed on to one of the x-Attribute methods
* (booleanAttribute, stringAttribute, stringListAttribute, intOrChunkAttribute)
* which will actually gobble the tokens.
*
* @return
*/
public AttributeDescr attribute(AttributeSupportBuilder<?> as) {
AttributeDescr attribute = null;
try {
if (state.backtracking == 0 && input.LA(1) != DRL6Lexer.EOF) {
helper.emit(Location.LOCATION_RULE_HEADER_KEYWORD);
}
if (helper.validateIdentifierKey(DroolsSoftKeywords.SALIENCE)) {
attribute = salience(as);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.ENABLED)) {
attribute = enabled(as);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.NO) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.LOOP)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.NO, "-", DroolsSoftKeywords.LOOP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.AUTO) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.FOCUS)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.AUTO, "-", DroolsSoftKeywords.FOCUS });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.LOCK) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.ON) && helper.validateLT(4, "-") && helper.validateLT(5, DroolsSoftKeywords.ACTIVE)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.LOCK, "-", DroolsSoftKeywords.ON, "-", DroolsSoftKeywords.ACTIVE });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.REFRACT)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.REFRACT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DIRECT)) {
attribute = booleanAttribute(as, new String[] { DroolsSoftKeywords.DIRECT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.AGENDA) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.AGENDA, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.ACTIVATION) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.ACTIVATION, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.RULEFLOW) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.GROUP)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.RULEFLOW, "-", DroolsSoftKeywords.GROUP });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DATE) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.EFFECTIVE)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DATE, "-", DroolsSoftKeywords.EFFECTIVE });
attribute.setType(AttributeDescr.Type.DATE);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DATE) && helper.validateLT(2, "-") && helper.validateLT(3, DroolsSoftKeywords.EXPIRES)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DATE, "-", DroolsSoftKeywords.EXPIRES });
attribute.setType(AttributeDescr.Type.DATE);
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DIALECT)) {
attribute = stringAttribute(as, new String[] { DroolsSoftKeywords.DIALECT });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.CALENDARS)) {
attribute = stringListAttribute(as, new String[] { DroolsSoftKeywords.CALENDARS });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.TIMER)) {
attribute = intOrChunkAttribute(as, new String[] { DroolsSoftKeywords.TIMER });
} else if (helper.validateIdentifierKey(DroolsSoftKeywords.DURATION)) {
attribute = intOrChunkAttribute(as, new String[] { DroolsSoftKeywords.DURATION });
}
if (state.backtracking == 0) {
helper.emit(Location.LOCATION_RULE_HEADER);
}
} catch (RecognitionException re) {
reportError(re);
}
return attribute;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DRL6Parser 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 DRL6Parser method qualifiedIdentifier.
/**
* Matches a qualified identifier
*
* qualifiedIdentifier := ID ( DOT ID )*
*
* @return
* @throws org.antlr.runtime.RecognitionException
*/
public String qualifiedIdentifier() throws RecognitionException {
String qi = "";
try {
Token first = match(input, DRL6Lexer.ID, null, new int[] { DRL6Lexer.DOT }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
Token last = first;
while (input.LA(1) == DRL6Lexer.DOT && input.LA(2) == DRL6Lexer.ID) {
last = match(input, DRL6Lexer.DOT, null, new int[] { DRL6Lexer.ID }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
last = match(input, DRL6Lexer.ID, null, new int[] { DRL6Lexer.DOT }, DroolsEditorType.IDENTIFIER);
if (state.failed)
return qi;
}
qi = input.toString(first, last);
qi = qi.replace(" ", "");
} catch (RecognitionException re) {
reportError(re);
}
return qi;
}
Aggregations