开发者

Are there any javascript frameworks for parsing/auto-completing a domain specific language?

开发者 https://www.devze.com 2023-02-13 12:06 出处:网络
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

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-sugg开发者_如何转开发est engine?

Thanks!


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:

  • Automatic Error Recovery / Fault tolerance because editors and IDEs need to be able to handle 'mostly valid' inputs.
  • Every Grammar rule may be used as the starting rule as an Editor/IDE may only want to implement incremental parsing for performance reasons.


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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号