use of org.antlr.runtime.ANTLRStringStream in project SQLWindowing by hbutani.
the class ParseUtils method parseSelect.
public static SelectSpec parseSelect(String selectExprStr) throws WindowingException {
Windowing2Lexer lexer;
CommonTokenStream tokens;
Windowing2Parser parser = null;
CommonTree t;
CommonTreeNodeStream nodes;
QSpecBuilder2 qSpecBldr = null;
String err;
try {
lexer = new Windowing2Lexer(new ANTLRStringStream(selectExprStr));
tokens = new CommonTokenStream(lexer);
parser = new Windowing2Parser(tokens);
parser.setTreeAdaptor(TranslateUtils.adaptor);
t = (CommonTree) parser.select().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);
SelectSpec selectSpec = qSpecBldr.select();
err = qSpecBldr.getWindowingParseErrors();
if (err != null) {
throw new WindowingException(err);
}
return selectSpec;
} 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 binnavi by google.
the class DebuggerMemoryExpressionParser method parse.
/**
* Parses a single memory expression string.
*
* @param memoryExpression The memory expression string to parse.
*
* @return The parsed memory expression tree.
*
* @throws RecognitionException Thrown if parsing failed.
*/
public static MemoryExpressionElement parse(final String memoryExpression) throws RecognitionException {
final CharStream charStream = new ANTLRStringStream(memoryExpression);
final MemoryExpressionLexer lexer = new MemoryExpressionLexer(charStream);
final CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
final MemoryExpressionParser parser = new MemoryExpressionParser(tokens) {
@Override
public void recover(final IntStream input, final RecognitionException exception) {
// Nothing to do
}
@Override
public Object recoverFromMismatchedToken(final IntStream input, final int ttype, final org.antlr.runtime.BitSet follow) throws RecognitionException {
throw new MismatchedTokenException(ttype, input);
}
@Override
public void reportError(final RecognitionException exception) {
// Nothing to do
}
};
parser.setTreeAdaptor(adaptor);
final MemoryExpressionParser.prog_return parserResult = parser.prog();
final CommonTree ast = (CommonTree) parserResult.getTree();
return convert(ast);
}
use of org.antlr.runtime.ANTLRStringStream in project dex2jar by pxb1988.
the class Jasmin2JarCmd method assemble1.
private void assemble1(Path file, Path output) throws IOException {
try (BufferedReader bufferedReader = Files.newBufferedReader(file, Charset.forName(encoding))) {
ANTLRStringStream is = new ANTLRReaderStream(bufferedReader);
is.name = file.toString();
JasminLexer lexer = new JasminLexer(is);
CommonTokenStream ts = new CommonTokenStream(lexer);
JasminParser parser = new JasminParser(ts);
parser.rebuildLine = autogenLines;
ClassWriter cw = new ClassWriter(noComputeMax ? 0 : ClassWriter.COMPUTE_MAXS);
ClassNode cn = parser.parse();
if (cn.version == 0) {
cn.version = versions[classVersion];
}
if (dump) {
new JasminDumper(new PrintWriter(new OutputStreamWriter(System.out, StandardCharsets.UTF_8), true)).dump(cn);
}
cn.accept(cw);
Path clzFile = output.resolve(cn.name.replace('.', '/') + ".class");
createParentDirectories(clzFile);
Files.write(clzFile, cw.toByteArray());
} catch (RecognitionException e) {
System.err.println("Fail to assemble " + file);
e.printStackTrace();
}
}
use of org.antlr.runtime.ANTLRStringStream in project dex2jar by pxb1988.
the class Jasmins method parse.
public static ClassNode parse(String fileName, Reader bufferedReader) throws IOException, RecognitionException {
ANTLRStringStream is = new ANTLRReaderStream(bufferedReader);
is.name = fileName;
JasminLexer lexer = new JasminLexer(is);
CommonTokenStream ts = new CommonTokenStream(lexer);
JasminParser parser = new JasminParser(ts);
return parser.parse();
}
use of org.antlr.runtime.ANTLRStringStream in project rsense by m2ym.
the class AnnotationHelper method parseAnnotation.
public static TypeAnnotation parseAnnotation(String annot, int lineno) {
if (annot.startsWith("#%")) {
ANTLRStringStream in = new ANTLRStringStream(annot.substring(2));
in.setLine(lineno);
TypeAnnotationLexer lex = new TypeAnnotationLexer(in);
CommonTokenStream tokens = new CommonTokenStream(lex);
TypeAnnotationParser parser = new TypeAnnotationParser(tokens);
try {
return parser.type();
} catch (RecognitionException e) {
}
}
return null;
}
Aggregations