use of org.antlr.runtime.CommonTokenStream in project drill by axbaretto.
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 drill by axbaretto.
the class SchemaPath method parseFromString.
/**
* Parses input string using the same rules which are used for the field in the query.
* If a string contains dot outside back-ticks, or there are no backticks in the string,
* will be created {@link SchemaPath} with the {@link NameSegment}
* which contains one else {@link NameSegment}, etc.
* If a string contains [] then {@link ArraySegment} will be created.
*
* @param expr input string to be parsed
* @return {@link SchemaPath} instance
*/
public static SchemaPath parseFromString(String expr) {
if (expr == null || expr.isEmpty()) {
return null;
}
try {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
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 vespa by vespa-engine.
the class Predicate method fromString.
public static Predicate fromString(String str) {
ANTLRStringStream input = new ANTLRStringStream(str);
PredicateLexer lexer = new PredicateLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PredicateParser parser = new PredicateParser(tokens);
try {
return parser.predicate();
} catch (RecognitionException e) {
throw new IllegalArgumentException(e);
}
}
use of org.antlr.runtime.CommonTokenStream in project cuba by cuba-platform.
the class Parser method createParser.
private static JPA2Parser createParser(String input) {
if (input.contains("~"))
throw new IllegalArgumentException("Input string cannot contain \"~\"");
CharStream cs = new AntlrNoCaseStringStream(input);
JPA2Lexer lexer = new JPA2Lexer(cs);
TokenStream tstream = new CommonTokenStream(lexer);
return new JPA2Parser(tstream);
}
use of org.antlr.runtime.CommonTokenStream in project cuba by cuba-platform.
the class Jpa2GrammarTest method testTypeField.
@Test
public void testTypeField() throws Exception {
String query = "where e.model.type = :component$filter.model_type89015";
CharStream cs = new AntlrNoCaseStringStream(query);
JPA2Lexer lexer = new JPA2Lexer(cs);
TokenStream tstream = new CommonTokenStream(lexer);
JPA2Parser jpa2Parser = new JPA2Parser(tstream);
JPA2Parser.where_clause_return aReturn = jpa2Parser.where_clause();
Assertions.assertTrue(isValid((CommonTree) aReturn.getTree()));
}
Aggregations