I get simple antlr3 grammar MicroXpath and build lexer and parser for Python.
Then I wrote a simple test code:
import antlr3 from XPathLexer import XPathLexer from XPathParser import XPathParser def print_level_order(tree, indent): print('{0}{1}'.format(' '*indent, tree.text, tree.getType())) for child in tree.getChildren(): print_level_order(child, indent+1) input = 'descendant::name[class/name[test="x"]="File"]' char_stream = antlr3.ANTLRStringStream(input) lexer = XPathLexer(char_stream) tokens = antlr3.CommonTokenStream(lexer) parser = XPathParser(tokens) tree = parser.xPath().tree print_level_order(tree, 0) Result:
None descendant : name [ class / name [ test = "x" ] = "File" ] Where the tree? This is a linear list! What am I doing wrong? Or using ANTLR can not build a tree?