ANTLR的AST树更新
我使用 ANTLR 工具生成的 Lexer 和 Parser 类(针对 C#)。假设我已经解析了一些代码并得到了它的 AST 树。如果我的部分初始代码已更改并且我只想更新树的相应部分怎么办?有一个通用的方法可以做到这一点吗? 例如,在某些函数体内插入了一行代码。我只想重建表示该函数的树的部分并更新后续函数标记的位置
I use Lexer and Parser classes generated by ANTLR tool (targeting C#). Assume I have parsed some code and got an AST tree for it. What if part of my initial code has changed and I want to update just the corresponding parts of the tree? Is there a common way to do that?
For example a line of code was inserted inside some functions body. And I want to rebuild just the part of the tree representing this function and update positions of subsequent functions tokens
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一些项目可以实现您可能想要完成的任务。
但不知道ANTLR是否支持这个。
您可以查看:http://en.wikipedia.org/wiki/Incremental_compiler
语法突出显示仅建议,我建议对语法中的不同标记使用正则表达式。 (如果您仅更新正在处理的行,则不应出现任何性能问题。)
There are a few projects out there which do what you might want to accomplish.
But I don't know if ANTLR supports this.
You might take a look at: http://en.wikipedia.org/wiki/Incremental_compiler
For syntax highlighting propose only, I suggest using regular expression for the different token in your syntax. (If you update just the line you're working on you should not get any performance problems.)