Are there any good CSS grammars out there for antlr4? I know there are some grammars for antlr3, but it turns out CSS is not trivial to parse without "lexer modes", which were added in v4. Why?
Consider the following CSS selectors:
.hello.world { /* ... */ }
.hello .world { /* ... */ }
In most grammars, whitespace is simply ignored. But if you ignore whitespace, it becomes impossible to distinguish between the two selectors above at the parser level.
Then again, if you don't ignore whitespace, the grammar becomes pretty noisy with WS? or WS* patterns everywhere, since whitespace is mostly meaningless unless it occurs within a selector.
Which is where modes from antlr4 come in, because with support for lexer modes you can define new rules for the lexer whenever you enter different contexts (i.e. don't ignore whitespace within the "selector" context).
That said, I'll accept any grammar for antlr3 as well so long as it handles whitespaces properly, as that's the version we're using now anyway ;-)