0
votes

I'm working on CSS editor and I need to highlight selectors.

This is parser rule in ANTLR

selectors
: selector (COMMA selector)*
;

selector
: simple_selector_sequence (combinator? simple_selector_sequence)*
;

and so on... As you can see selectors rule contains antother rules so I cannot simply colorize one type of token.

I belive the best way is to set one type to every token in selectors rule. And then colorize only tokens with this type. But i don't know how to do this.

1

1 Answers

0
votes

typical syntax highlighters work just on the token types. If you need grammatical structure to indicate color, then you need to operate on the parse tree. Look for the subtree root with name selector. All tokens underneath should be highlighted in your special color then.