use of org.antlr.runtime.RecognitionException in project Palladio-Editors-Sirius by PalladioSimulator.
the class PCMServices method validExpression.
/**
* Parses an stochastic expression to determine whether it is valid.
*
* @param the
* expressionString
* @return the validity
*/
private boolean validExpression(final String expressionString) {
final MyPCMStoExLexer lexer = new MyPCMStoExLexer(new ANTLRStringStream(expressionString));
final MyPCMStoExParser parser = new MyPCMStoExParser(new CommonTokenStream(lexer));
try {
parser.expression();
} catch (final RecognitionException e1) {
return false;
}
if (lexer.hasErrors() || parser.hasErrors()) {
return false;
}
return true;
}
use of org.antlr.runtime.RecognitionException in project hive by apache.
the class ParseDriver method parseTriggerExpression.
public ASTNode parseTriggerExpression(String command) throws ParseException {
HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
HiveParser parser = new HiveParser(tokens);
parser.setTreeAdaptor(adaptor);
HiveParser_ResourcePlanParser.triggerExpressionStandalone_return r = null;
try {
r = parser.gResourcePlanParser.triggerExpressionStandalone();
} catch (RecognitionException e) {
e.printStackTrace();
throw new ParseException(parser.errors);
}
if (lexer.getErrors().size() != 0) {
throw new ParseException(lexer.getErrors());
} else if (parser.errors.size() != 0) {
throw new ParseException(parser.errors);
}
return r.getTree();
}
use of org.antlr.runtime.RecognitionException in project hive by apache.
the class ParseDriver method parse.
/**
* Parses a command, optionally assigning the parser's token stream to the
* given context.
*
* @param command
* command to parse
*
* @param ctx
* context with which to associate this parser's token stream, or
* null if either no context is available or the context already has
* an existing stream
*
* @return parsed AST
*/
public ASTNode parse(String command, Context ctx, String viewFullyQualifiedName) throws ParseException {
if (LOG.isDebugEnabled()) {
LOG.debug("Parsing command: " + command);
}
HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
if (ctx != null) {
if (viewFullyQualifiedName == null) {
// Top level query
ctx.setTokenRewriteStream(tokens);
} else {
// It is a view
ctx.addViewTokenRewriteStream(viewFullyQualifiedName, tokens);
}
lexer.setHiveConf(ctx.getConf());
}
HiveParser parser = new HiveParser(tokens);
if (ctx != null) {
parser.setHiveConf(ctx.getConf());
}
parser.setTreeAdaptor(adaptor);
HiveParser.statement_return r = null;
try {
r = parser.statement();
} catch (RecognitionException e) {
e.printStackTrace();
throw new ParseException(parser.errors);
}
if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
LOG.debug("Parse Completed");
} else if (lexer.getErrors().size() != 0) {
throw new ParseException(lexer.getErrors());
} else {
throw new ParseException(parser.errors);
}
ASTNode tree = (ASTNode) r.getTree();
tree.setUnknownTokenBoundaries();
return tree;
}
use of org.antlr.runtime.RecognitionException in project hive by apache.
the class PartFilterExprUtil method getFilterParser.
public static FilterParser getFilterParser(String filter) throws MetaException {
FilterLexer lexer = new FilterLexer(new ANTLRNoCaseStringStream(filter));
CommonTokenStream tokens = new CommonTokenStream(lexer);
FilterParser parser = new FilterParser(tokens);
try {
parser.filter();
} catch (RecognitionException re) {
throw new MetaException("Error parsing partition filter; lexer error: " + lexer.errorMsg + "; exception " + re);
}
if (lexer.errorMsg != null) {
throw new MetaException("Error parsing partition filter : " + lexer.errorMsg);
}
return parser;
}
use of org.antlr.runtime.RecognitionException in project xtext-core by eclipse.
the class AbstractInternalAntlrParser method recoverFromMismatchedToken.
@Override
protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) throws RecognitionException {
RecognitionException e = null;
// if next token is what we are looking for then "delete" this token
if (mismatchIsUnwantedToken(input, ttype)) {
e = new UnwantedTokenException(ttype, input);
/*
System.err.println("recoverFromMismatchedToken deleting "+
((TokenStream)input).LT(1)+
" since "+((TokenStream)input).LT(2)+" is what we want");
*/
beginResync();
// simply delete extra token
input.consume();
endResync();
// report after consuming so AW sees the token in the exception
reportError(e);
// we want to return the token we're actually matching
Object matchedSymbol = getCurrentInputSymbol(input);
// move past ttype token as if all were ok
input.consume();
return matchedSymbol;
}
// can't recover with single token deletion, try insertion
if (mismatchIsMissingToken(input, follow)) {
Object inserted = getMissingSymbol(input, e, ttype, follow);
e = new MissingTokenException(ttype, input, inserted);
// report after inserting so AW sees the token in the exception
reportError(e);
return null;
// throw e;
}
// even that didn't work; must throw the exception
e = new MismatchedTokenException(ttype, input);
throw e;
}
Aggregations