Does anyone have any resources about syntax highli...
# thinking-together
e
Does anyone have any resources about syntax highlighting? I’m looking to answer questions such as: How do you decide which terms to highlight? How to use color to help readability?
1
c
I implemented a basic syntax highlighting in my editor. It just matches based on a list of tokens. Each of the below gets a different color • keywords (e.g. 'typedef', 'int') • identifiers (e.g. 'vector', 'floor') • numbers • comments • quoted strings Additionally, I do rainbow brackets, which I think is probably the biggest bang for the buck; it makes it much easier to resolve the 'too many/too few brackets' problem in most languages. Colors are based on themes, so that 'Keyword' will be different in Light vs Dark theme, for example. I consider my system crude at best, but it works well enough. Better introspection of the language using a language server would help matters.... Implementation of this stuff gets quite tricky if you want it to be fast and handle combinations of states, such as highlighting text while working with the syntax coloring. Really, you need a layer system to prioritize the coloring of each character based on the background, syntax color, additional effects, etc. Tokens: https://github.com/Rezonality/zep/blob/master/src/syntax_providers.cpp Implementation: https://github.com/Rezonality/zep/blob/master/src/syntax.cpp Rainbow Brackets: https://github.com/Rezonality/zep/blob/master/src/syntax_rainbow_brackets.cpp
👍 2