Syntax Highlighting generation with antlr? #272
-
So this extension is for syntax highlighting for antlr grammar files. But how would I use antlr grammars for syntax highlighting of other languages or maybe any language? There once seem to be an attempt with uni-vscode but all articles I found was for writing extensions for individual languages. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The answer heavily depends on the IDE for which syntax highlighting is to be implemented. In fact each IDE has its own rules. VS Code for example uses a declarative approach in the standard highlighter (Monarch) that is driven by a JSON file with regex patterns. So, ANTLR or any of its grammars aren't involved at all there. But there's also semantic highlighting on top of syntax highlighting, which can make use of an ANTLR based lexer (to know the token types). But still this is not something that can be done in a generic way, unless all lexer would return the same token types (which might be possible for some standard types like strings, comments and identifiers), but usually a language has some specialities that would not be taken into account, if semantic highlight would just use a generic lexer. |
Beta Was this translation helpful? Give feedback.
The answer heavily depends on the IDE for which syntax highlighting is to be implemented. In fact each IDE has its own rules. VS Code for example uses a declarative approach in the standard highlighter (Monarch) that is driven by a JSON file with regex patterns. So, ANTLR or any of its grammars aren't involved at all there.
But there's also semantic highlighting on top of syntax highlighting, which can make use of an ANTLR based lexer (to know the token types). But still this is not something that can be done in a generic way, unless all lexer would return the same token types (which might be possible for some standard types like strings, comments and identifiers), but usually a language …