use of org.antlr.runtime.ANTLRReaderStream in project freud by LMAX-Exchange.
the class JavaSourceJdomParser method parseJavaSourceToDocument.
private static Document parseJavaSourceToDocument(final Reader javaSourceReader) throws RecognitionException, IOException {
JavaParser parser = new JavaParser(new CommonTokenStream(new JavaLexer(new ANTLRReaderStream(javaSourceReader))));
final JdomTreeAdaptor treeAdaptor = new JdomTreeAdaptor(JAVA_SOURCE_ROOT_ELEMENT_NAME, JAVA_SOURCE_TOKEN_TYPES);
parser.setTreeAdaptor(treeAdaptor);
parser.compilationUnit();
return treeAdaptor.getDocument();
}
use of org.antlr.runtime.ANTLRReaderStream in project freud by LMAX-Exchange.
the class CssJdomParser method parseCssToDocument.
private static Document parseCssToDocument(final Reader reader) throws RecognitionException, IOException {
CssParser parser = new CssParser(new CommonTokenStream(new CssLexer(new ANTLRReaderStream(reader))));
final JdomTreeAdaptor treeAdaptor = new JdomTreeAdaptor(CSS_ROOT_ELEMENT_NAME, CSS_TOKEN_TYPES);
parser.setTreeAdaptor(treeAdaptor);
parser.stylesheet();
return treeAdaptor.getDocument();
}
use of org.antlr.runtime.ANTLRReaderStream 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.ANTLRReaderStream 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();
}
Aggregations