Search in sources :

Example 1 with ANTLRReaderStream

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();
}
Also used : JavaParser(org.freud.analysed.javasource.parser.JavaParser) CommonTokenStream(org.antlr.runtime.CommonTokenStream) JdomTreeAdaptor(org.freud.core.parser.JdomTreeAdaptor) JavaLexer(org.freud.analysed.javasource.parser.JavaLexer) ANTLRReaderStream(org.antlr.runtime.ANTLRReaderStream)

Example 2 with ANTLRReaderStream

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();
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) JdomTreeAdaptor(org.freud.core.parser.JdomTreeAdaptor) ANTLRReaderStream(org.antlr.runtime.ANTLRReaderStream) CssParser(org.freud.analysed.css.parser.CssParser) CssLexer(org.freud.analysed.css.parser.CssLexer)

Example 3 with ANTLRReaderStream

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();
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ClassNode(org.objectweb.asm.tree.ClassNode) ClassWriter(org.objectweb.asm.ClassWriter) ANTLRReaderStream(org.antlr.runtime.ANTLRReaderStream) RecognitionException(org.antlr.runtime.RecognitionException)

Example 4 with ANTLRReaderStream

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();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ANTLRReaderStream(org.antlr.runtime.ANTLRReaderStream)

Aggregations

ANTLRReaderStream (org.antlr.runtime.ANTLRReaderStream)4 CommonTokenStream (org.antlr.runtime.CommonTokenStream)4 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)2 JdomTreeAdaptor (org.freud.core.parser.JdomTreeAdaptor)2 RecognitionException (org.antlr.runtime.RecognitionException)1 CssLexer (org.freud.analysed.css.parser.CssLexer)1 CssParser (org.freud.analysed.css.parser.CssParser)1 JavaLexer (org.freud.analysed.javasource.parser.JavaLexer)1 JavaParser (org.freud.analysed.javasource.parser.JavaParser)1 ClassWriter (org.objectweb.asm.ClassWriter)1 ClassNode (org.objectweb.asm.tree.ClassNode)1