是否有用于解析/自动完成领域特定语言的 JavaScript 框架?
我有一个特定领域语言的语法,我需要为该语言创建一个 javascript 代码编辑器。有没有任何工具可以让我生成 a) 一个 javascript 增量解析器 b) javascript 自动完成/自动建议引擎?
谢谢!
I have a grammar for a domain specific language, and I need to create a javascript code editor for that language. Are there any tools that would allow me to generate
a) a javascript incremental parser
b) a javascript auto-complete / auto-suggest engine?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实施内容辅助(自动完成)的示例
使用 Chevrotain Javascript 解析 DSL:
https://github.com/SAP/chevrotain/tree/master/examples/parser/content_assist
Chevrotain 是专门设计用于构建编辑器/IDE 中使用的语言服务工具(作为一部分)的解析器。
一些相关功能包括:
An Example of implementing content assist (auto-complete)
using Chevrotain Javascript Parsing DSL:
https://github.com/SAP/chevrotain/tree/master/examples/parser/content_assist
Chevrotain was designed specifically to build parsers used (as part of) language services tools in Editors/IDEs.
Some of the relevant features are:
您可能需要 jison,一个 js 解析器生成器。就自动完成/自动建议而言......我知道大多数东西是否更多基于单词完成而不是代码完成。但是一旦你运行了一个解析器,我认为这部分并不太困难。
You may want jison, a js parser generator. In terms of auto-complete / auto-suggest...most of the stuff out there I know if more based on word completion rather than code completion. But once you have a parser running I don't think that part is too difficult..
这很难。我自己也在做同样的事情。
一种方法是:
您需要一个解析器,它将为您提供文本的当前可能的 AST 数组,直到当前光标位置之前的标记。
从那里您可以看到下一个标记可以有多种类型(通常只有一种),并根据部分文本完成补全。
如果我的增量解析器能够工作,我会发送一个链接。
祝你好运,如果你找到一个可以做到这一点的包,请告诉我。
克里斯.
This is difficult. I'm doing the same sort of thing myself.
One approach is:
You need is a parser which will give you an array of the currently possible ASTs for the text up until the token before the current cursor position.
From there you can see the next token can be of a number of types (usually just one), and do the completion, based on the partial text.
If I ever get my incremental parser working, I'll send a link.
Good luck, and let me know if you find a package which does this.
Chris.