use of org.antlr.v4.runtime.CommonTokenStream in project siddhi by wso2.
the class SiddhiCompiler method parsePartition.
public static Partition parsePartition(String partition) throws SiddhiParserException {
CharStream input = CharStreams.fromString(partition);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.partition_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (Partition) eval.visit(tree);
}
use of org.antlr.v4.runtime.CommonTokenStream in project siddhi by wso2.
the class SiddhiCompiler method parseExpression.
public static Expression parseExpression(String expression) {
CharStream input = CharStreams.fromString(expression);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.expression();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (Expression) eval.visit(tree);
}
use of org.antlr.v4.runtime.CommonTokenStream in project jaybird by FirebirdSQL.
the class TestGrammar method createParser.
// TODO Add more testcases for grammar
protected JaybirdSqlParser createParser(String testString) {
CharStream stream = CharStreams.fromString(testString);
JaybirdSqlLexer lexer = new JaybirdSqlLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
return new JaybirdSqlParser(tokenStream);
}
use of org.antlr.v4.runtime.CommonTokenStream in project alliance by codice.
the class BqsConverter method convertBQSToDDF.
public Filter convertBQSToDDF(String query) {
query = query.trim();
LOGGER.debug("Original Query: {}", query);
ANTLRInputStream inputStream = new ANTLRInputStream(query);
// transforms characters into tokens
BqsLexer lex = new BqsLexer(inputStream);
// a token stream
CommonTokenStream tokens = new CommonTokenStream(lex);
// transforms tokens into parse trees
BqsParser parser = new BqsParser(tokens);
BqsTreeWalkerListener bqsListener = new BqsTreeWalkerListener(filterBuilder);
ParseTree tree = parser.query();
ParseTreeWalker.DEFAULT.walk(bqsListener, tree);
Filter filter = bqsListener.getFilter();
if (filter != null && StringUtils.isNotBlank(filter.toString())) {
LOGGER.debug("Parsed Query: {}", filter);
} else {
filter = filterBuilder.attribute(Metacard.ANY_TEXT).is().text("*");
LOGGER.debug("After parsing filter, didn't have any query parameters. Defaulting to everything search: {}", filter);
}
return filter;
}
use of org.antlr.v4.runtime.CommonTokenStream in project components by Talend.
the class SoqlQuery method init.
/**
* init method parses input <code>queryString</code> and stores is as tree.
* Should be invoked right after
* {@link org.talend.components.salesforce.soql.SoqlQuery#getInstance()} method
*
* @param queryString SOQL query
*/
public void init(String queryString) {
ANTLRInputStream is = new ANTLRInputStream(queryString);
SoqlLexer lexer = new SoqlLexer(is);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SoqlParser parser = new SoqlParser(tokenStream);
queryTree = parser.query();
fieldDescriptions = new ArrayList<>();
FieldRetrieverListener listener = new FieldRetrieverListener();
ParseTreeWalker.DEFAULT.walk(listener, queryTree);
}
Aggregations