Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is fairly easy to build Javascript editor with code completion from PEG grammar. I would describe how to do it with <code>PEG.js</code>. You need to extend your grammar with some lax parsing rules that allow to provide suggestions when previous statements are broken. These lax rules need to be handled conditionally or you will need two separate grammars - one for parsing source and second for code completion. You can maintain one grammar by using Javascript predicates (available in <code>PEG.js</code>). It looks like <code>&amp;{return laxParsing}</code> and it causes that whole rule to be processed when <code>laxParsing</code> flag is <code>true</code>. You can switch between lax and strict parsing easily by setting parser's internal flag.</p> <p>To provide suggestions to user easily you must modify slightly generated <code>PEG.js</code> parser (version 0.5) to receive in the parsing error structure position (beside the column and line) and list of expectations (beside the error message). You can copy prepared fragment from <a href="https://gist.github.com/1281239" rel="nofollow">https://gist.github.com/1281239</a>.</p> <p>When you have parser then you can attach it in editor on for example CTRL+SPACE keypress. When these are pressed in text source you need to put a special unparseable sign in place of cursor (to cause a parsing error) and launch parser in lax mode. Then you receive an error with list of suggestions.</p> <p>Some of suggestions are not only syntax but also they define references (e.g. entities, variables). You can trigger searching these when a particular expectation is found (e.g. <code>VariableName</code>). You can provide the list by parsing the same source in a different lax parsing mode (filtering only variable names).</p> <p>For a working example and source to this approach you can check on <a href="https://github.com/mstefaniuk/Concrete-Freetext" rel="nofollow">https://github.com/mstefaniuk/Concrete-Freetext</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload