use of org.antlr.runtime.ANTLRStringStream in project SQLWindowing by hbutani.
the class ParseUtils method parse.
public static QuerySpec parse(String query) throws WindowingException {
Windowing2Lexer lexer;
CommonTokenStream tokens;
Windowing2Parser parser = null;
CommonTree t;
CommonTreeNodeStream nodes;
QSpecBuilder2 qSpecBldr = null;
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 (WindowingException we) {
throw we;
} catch (Throwable te) {
err = parser.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
throw new WindowingException("Parse Error:" + te.toString(), te);
}
TranslateUtils.unescapeStringLiterals((ASTNode) t);
try {
nodes = new CommonTreeNodeStream(t);
nodes.setTokenStream(tokens);
qSpecBldr = new QSpecBuilder2(nodes);
qSpecBldr.query();
err = qSpecBldr.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
return qSpecBldr.getQuerySpec();
} catch (WindowingException we) {
throw we;
} catch (Throwable te) {
err = qSpecBldr.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
throw new WindowingException("Parse Error:" + te.toString(), te);
}
}
use of org.antlr.runtime.ANTLRStringStream in project nifi by apache.
the class ExpressionCompiler method compileTree.
private Tree compileTree(final String expression) throws AttributeExpressionLanguageParsingException {
try {
final CharStream input = new ANTLRStringStream(expression);
final AttributeExpressionLexer lexer = new AttributeExpressionLexer(input);
final CommonTokenStream lexerTokenStream = new CommonTokenStream(lexer);
final AttributeExpressionParser parser = new AttributeExpressionParser(lexerTokenStream);
final Tree ast = (Tree) parser.query().getTree();
final Tree tree = ast.getChild(0);
// ensure that we are able to build the evaluators, so that we validate syntax
final Evaluator<?> evaluator = buildEvaluator(tree);
verifyMappingEvaluatorReduced(evaluator);
return tree;
} catch (final AttributeExpressionLanguageParsingException e) {
throw e;
} catch (final Exception e) {
throw new AttributeExpressionLanguageParsingException(e);
}
}
use of org.antlr.runtime.ANTLRStringStream in project nifi by apache.
the class HL7Query method createTokenStream.
private static CommonTokenStream createTokenStream(final String expression) throws HL7QueryParsingException {
final CharStream input = new ANTLRStringStream(expression);
final HL7QueryLexer lexer = new HL7QueryLexer(input);
return new CommonTokenStream(lexer);
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.
the class AbstractSmokeTest method testSkipTokensInBetween.
@Test
public void testSkipTokensInBetween() throws Exception {
for (String string : getSmokeTestModels()) {
List<CommonToken> tokenList = Lists.newArrayList();
{
Lexer lexer = lexerProvider.get();
lexer.setCharStream(new ANTLRStringStream(string));
Token token = lexer.nextToken();
while (token != Token.EOF_TOKEN) {
tokenList.add((CommonToken) token);
token = lexer.nextToken();
}
}
for (CommonToken token : tokenList) {
int start = token.getStartIndex();
int length = token.getText().length();
logProgress(token);
processModel(string.substring(0, start) + string.substring(start + length));
}
}
}
use of org.antlr.runtime.ANTLRStringStream in project xtext-eclipse by eclipse.
the class AbstractSmokeTest method testSkipTokensInBetweenWithoutResourceSet.
@Test
public void testSkipTokensInBetweenWithoutResourceSet() throws Exception {
for (String string : getSmokeTestModels()) {
List<CommonToken> tokenList = Lists.newArrayList();
{
Lexer lexer = lexerProvider.get();
lexer.setCharStream(new ANTLRStringStream(string));
Token token = lexer.nextToken();
while (token != Token.EOF_TOKEN) {
tokenList.add((CommonToken) token);
token = lexer.nextToken();
}
}
for (CommonToken token : tokenList) {
int start = token.getStartIndex();
int length = token.getText().length();
logProgress(token);
processModelWithoutResourceSet(string.substring(0, start) + string.substring(start + length));
}
}
}
Aggregations