-
Hi, I'm working on a DSL that uses indentation to delimit block structure, like Python or Haskell. Is that something Langium can cope with? I see you are using Chevrotain under the hood - my current implementation is also in Chevrotain, and makes use of the pattern matching callbacks in the lexer. I've been putting off writing a VS Code editing mode, and if I understand right, Langium could make that a lot easier. My understanding was that VC Code syntax highlighting is driven not by a full parser but by a bunch of regexes, like in the old TextMate modes. Is that something Langium can derive from the grammar? Seems difficult! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Hi @tslocke, you're getting into uncharted waters here, as we haven't tried that out yet, but as long as it's possible in Chevrotain, it should be possible in Langium as well. By default, Langium will create relatively simple
vscode syntax highlighting is twofold: For one we can simply let vscode do syntactical highlighting, which is provided based on TextMate grammars. Additionally, the language server protocol also offers semantic highlighting, which enables far more fine-grained control over your highlighting.
We actually already generate TextMate grammars from Langium grammars, see the textmate-generator.ts. It suffices for a lot of use cases, but isn't recommended for production use of more complicated languages, as these probably require a bit fine tuning. It does these kinds of highlighting all by itself:
All the TextMate grammars for our example languages are generated using the provided generator. Semantic highlighting can be implemented using the AbstractSemanticTokenProvider and allows to perform highlighting based on AST info. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the advice. Yes I already have it working in chevrotain based on that example. I think I'm firmly in the realm of "more complicated languages" in terms of generating a useful textmate grammar. |
Beta Was this translation helpful? Give feedback.
The IndentationAwareTokenBuilder has been released in v3.2.0, and there is now a recipe explaining how to use it.