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

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

问题描述

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 显示任意解析树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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