3 ms·
I believe CodeMirror does something like this. It uses restartable parsers (or it used to) to make parsing fast while editing. I experimented editing code usin
by ioquatix 12y ago
I believe CodeMirror does something like this. It uses restartable parsers (or it used to) to make parsing fast while editing.
I experimented editing code using jQuery.Syntax. I used the match tree it generated to figure out where to restart parsing and it was pretty fast, it would only re-evaluate the current line in most cases.
- cben 12y agoCodeMirror still uses the restartable parsers. But they produce a flat sequence of styles, not a hierarchical AST. E.g. `foo bar* baz` in markdown becomes <span class="cm-em">foo </span><span class="cm-strong cm-em">bar</span><span class="cm-em"> baz*</span>. Also, most parsers reuse a small set of style names (that are covered by themes) without much regard to semantic appropriateness. E.g. markdown lists cycle through 'variable-2', 'variable-3', 'keyword'.