Eclipse 中的 ANTLR 和内容辅助
我在 Eclipse 中有一个项目,其中有一个自定义语言的编辑器。我正在使用 ANTLR 为其生成编译器。我需要的是向编辑器添加内容辅助。
输入是自定义语言的源代码以及用户请求内容辅助的字符的位置。源代码大多数时候都是不完整的,因为用户可以随时请求内容帮助。我需要的是计算对给定位置有效的可能令牌列表。
可以编写自定义代码来进行计算,但该代码必须手动与语法保持同步。我认为解析器正在做类似的事情。它必须能够在给定的上下文中确定什么是可接受的标记。是否有可能“重用”它?无论如何,创建内容辅助的最佳实践是什么?
谢谢, 巴林特
I have a project in Eclipse where I have an editor for a custom language. I am using ANTLR to generate the compiler for it. What I need is to add content assist to the editor.
The input is a source code in the custom language, and the position of the character where the user requested content assist. The source code is most of time incomplete as the user can ask for content assist any time. What I need is to calculate the list of possible tokens that are valid for the given position.
It is possible to write a custom code to do the calculation, but that code would have to be manually kept in sync with the grammar. I figured the parser is doing something similar. It has to be able to determine at a given context what are the acceptable tokens. Is it possible to "reuse" that? What is the best practice in creating content assist anyway?
Thanks,
Balint
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看Xtext。 Xtext 在底层使用 Antlr3 并为基于 Antlr 的语言提供内容帮助。特别查看包 org.eclipse.xtext.ui.editor.contentassist。
您可以考虑使用 Xtext 重新定义语法,这将提供开箱即用的内容帮助。无法重用自定义语言的 Antlr 语法。
Have a look at Xtext. Xtext uses Antlr3 under the hood and provides content assist for the Antlr based languages. Have a look especially into package org.eclipse.xtext.ui.editor.contentassist.
You may consider to redefine your grammar with Xtext, which would provide the content assist out-of-the-box. It is not possible to reuse the Antlr grammar of a custom language.