ANTLR4 API显示任意ParseTree [英] ANTLR4 API to Display Arbitrary ParseTree

查看:555
本文介绍了ANTLR4 API显示任意ParseTree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前ANTLR4的TestRig工具支持-gui选项来解析整个输入文件并以图形方式显示整个结果解析树.我们是否有可能首先获取解析树,对其进行修改并调用一些API以图形方式显示解析树的子集/子树.

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.

我的输入源文件很大,无法查看TestRig显示的标准解析树.更重要的是,我想过滤掉许多不相关的语法,并专注于验证我需要测试的那些语法.但是很难从TestRig提供的标准巨大解析树中找到一小部分信息.

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.

推荐答案

您可以调用 RuleContext.inspect 放在分析树中的任何非终端上,以仅查看该子集.此外,ANTLR的下一个版本在树形GUI上包含一个保存到PNG"按钮,即使一次不完全显示在屏幕上,该按钮也可以保存整个树形显示.

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.

下一版本还包括一个更新,如果整个树都不适合,则可以使您专注于子树.

The next version also includes an update to allow you to focus on a subtree if the full tree doesn't fit.

这篇关于ANTLR4 API显示任意ParseTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆