Greetings. Thanks for your great work on codemirrors (I used previous version).
I need implement an editor supporting custom template langauge. It’s an in-house templating solution (don’t ask, not my decision). Examples of the strings are Mama mila ramu {what} and {Who} got {where} on {when}.
I want to have syntax highlighting, autocompletion of the variables (sets are dynamic, will change depending on context in which editor is used) and linting of the variables usage (check variable usage against list of known ones).
I can get autocompletion wihout introduction of own grammar (it’s in the source code). But for the advanced features I need AST. For those I’ve created grammar and tests (using your repo with langauge example). I get tests (they fail and success properly). But when I introduce language to the editor, I’m not getting any ast-related highlighting. Also I don’t get proper AST (I see only 1 node at all times) when I do myLangyage.parser.parse.
Please help with following questions:
What’s wrong with my grammar, and/or approach? Are there better ways to get things I want done?
True. This was missing. I got some highlight working after adding this extension and “playing” with highlight definitions.
Yes. I was confused that I did not see layout changes inside the editor and did not see ast in the result of parser.parse call. But in both cases my assumptions were wrong: editor’s DOM updates only under some circumstances (not every style definition will make it happen), and ast needs special walker to see it.
For now my blockers are resolved. I’ll get back in case I’ll need help for variable name validation and linting. I’ll keep the repo for historical reasons for those who will want to do the same.
I managed to achieve listed goals. I keep the repository GitHub - podgorniy/atl: atl in read-only mode for those who will have same set of goals and for historical reasons. In total it contians
Custom template language grammar with tests.
Highlighting of the variable usage.
Highlighting of the invalid variables (compares agains a list of available ones).
Autocompletion of the variables based on the list of provided ones.
Highlighting of the syntax errors according to grammar.
Class-wrapper around Codemirror@6, and demo of its usage.
PS. You might want to export Severity type so people like could construct linting suggestion objects without issues. I had to use any to overcome the issue, link to the code I’m talking about atl/src/main.ts at main · podgorniy/atl · GitHub