问题
The current TestRig tool of ANTLR4 supports the -gui option to parse the whole input file and display the whole resultant parse tree graphically. Is it possible for us to obtain the parse tree first, modify it and call some APIs to display graphically a subset/subtree of the parse tree.
My input source file is large and the standard parse tree displayed by TestRig is impossible to view. What's more, i want to filter out a lot of irrelevant grammar and focus on verifying those grammar I need to test. But it is difficult to locate a small piece of information from the standard huge parse tree provided by TestRig.
回答1:
You can call RuleContext.inspect on any non-terminal in the parse tree to view just that subset. In addition, the next version of ANTLR includes a Save to PNG button on the tree GUI that saves the entire tree display even if it doesn't fit on the screen all at once.
Edit: The next version also includes an update to allow you to focus on a subtree if the full tree doesn't fit.
来源:https://stackoverflow.com/questions/16294778/antlr4-api-to-display-arbitrary-parsetree