use of org.antlr.runtime.CommonTokenStream in project jabref by JabRef.
the class VM method charStream2CommonTree.
private static CommonTree charStream2CommonTree(CharStream bst) throws RecognitionException {
BstLexer lex = new BstLexer(bst);
CommonTokenStream tokens = new CommonTokenStream(lex);
BstParser parser = new BstParser(tokens);
BstParser.program_return r = parser.program();
return (CommonTree) r.getTree();
}
use of org.antlr.runtime.CommonTokenStream in project drill by apache.
the class TestBuilder method parsePath.
// modified code from SchemaPath.De class. This should be used sparingly and only in tests if absolutely needed.
public static SchemaPath parsePath(String path) {
try {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(path));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
ExprParser.parse_return ret = parser.parse();
if (ret.e instanceof SchemaPath) {
return (SchemaPath) ret.e;
} else {
throw new IllegalStateException("Schema path is not a valid format.");
}
} catch (RecognitionException e) {
throw new RuntimeException(e);
}
}
use of org.antlr.runtime.CommonTokenStream in project drill by apache.
the class TreeTest method parseExpression.
private LogicalExpression parseExpression(String expr) throws RecognitionException, IOException {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
CommonTokenStream tokens = new CommonTokenStream(lexer);
// tokens.fill();
// for(Token t : (List<Token>) tokens.getTokens()){
// System.out.println(t + "" + t.getType());
// }
// tokens.rewind();
ExprParser parser = new ExprParser(tokens);
parse_return ret = parser.parse();
return ret.e;
}
use of org.antlr.runtime.CommonTokenStream in project SQLWindowing by hbutani.
the class WindowingShell method checkQuery.
public void checkQuery(String query) throws WindowingException {
Windowing2Lexer lexer;
CommonTokenStream tokens;
Windowing2Parser parser = null;
@SuppressWarnings("unused") CommonTree t;
// CommonTreeNodeStream nodes;
String err;
try {
lexer = new Windowing2Lexer(new ANTLRStringStream(query));
tokens = new CommonTokenStream(lexer);
parser = new Windowing2Parser(tokens);
parser.setTreeAdaptor(TranslateUtils.adaptor);
t = (CommonTree) parser.query().getTree();
err = parser.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
} catch (Throwable te) {
err = parser.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
throw new WindowingException("Parse Error:" + te.toString(), te);
}
}
use of org.antlr.runtime.CommonTokenStream 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;
}
Aggregations