Ejemplo n.º 1
0
    def parse(self, input, trace=False):
        lexer = self.lexerClass(input)
        tokenStream = antlr4.CommonTokenStream(lexer)
        parser = self.parserClass(tokenStream)
        parser.setTrace(True if trace else False)
        meth = getattr(parser, self.startSymbol)
        self._syntaxErrors = parser._syntaxErrors
        tree = meth()
        listener = amllib.Listener()
        walker = antlr4.ParseTreeWalker()
        walker.walk(listener, tree)

        #pprint(tree.toStringTree())
        """
        JavaLexer lexer = new JavaLexer(input);
        CommonTokenStream tokens = new CommonTokenStream(lexer);
        JavaParser parser = new JavaParser(tokens);

        ParseTree tree = parser.compilationUnit(); // parse
        ParseTreeWalker walker = new ParseTreeWalker(); // create standard walker
        ExtractInterfaceListener extractor = new ExtractInterfaceListener(parser);
        walker.walk(extractor, tree); // initiate walk of tree with listener
        """

        return tree
Ejemplo n.º 2
0
 def parse(self, input):
     lexer = self.lexerClass(input)
     tokenStream = antlr4.CommonTokenStream(lexer)
     parser = self.parserClass(tokenStream)
     meth = getattr(parser, self.startSymbol)
     self._syntaxErrors = parser._syntaxErrors
     tree = meth()
     listener = amllib.Listener()
     walker = antlr4.ParseTreeWalker()
     walker.walk(listener, tree)
     return tree