16

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!

franck102
  • 161
  • 1
  • 3

3 Answers3

4

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.
bd82
  • 201
  • 3
  • 3
  • Parsing (even with error recovery) is necessary but hardly sufficient. Parsing frameworks consequently are never really enough to solve the problem. See Life After Parsing: http://www.semanticdesigns.com/Products/DMS/LifeAfterParsing.html – Ira Baxter Jul 13 '16 at 23:34
  • The Parser in the provided example collects the syntactic information and context for farther processing in a **separate step**. The semantic content assist is performed separately from the parsing. Parsing libraries/frameworks are indeed not enough to build language services, for editors/IDEs. I shall edit my post to make it clearer Chevrotain was designed to be **part** of a tool chain for building editors. and is not a complete solution. – bd82 Jul 14 '16 at 00:05
3

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

ysaw
  • 203
  • 1
  • 7
  • 1
    Can you please provide some hint as to how context sensitive word completion can be provided using jison? Like taking an example of SQL: CREATE (ctrl+space) should show *TABLE* and so on. – Narendra Pathai Apr 29 '14 at 08:19
1

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.

fadedbee
  • 42,671
  • 44
  • 178
  • 308