Personally, I try to err on the side of graceful highlighting even for invalid code. Flickering is one reason; it would be awful if invalid code always brought forth angry splotches of magenta. Another reason is recontextualization; it’s nice if a code snippet into a temporary buffer is highlighted even if it’s invalid out of context. When I wrote my Oracle syntax, a key design goal was that disconnected snippets should be highlighted properly. Example:
runQuery("select #expr# as foo from #table# where id=:id and active=1", { id: 42 });
As far as the Oracle syntax knows, that’s select as foo from where id= and active=1
. Even though this is invalid, I expect the syntax to handle it. One of the key benefits of the architecture I devised for that syntax is that tokens are optional by default; missing tokens will be skipped and ignored.
In a perfect world, I would expect a linter to catch syntax errors, obviating any such functionality in the syntax. However, quality linters aren’t always available (or used when available) and it’s not unreasonable for the syntax to catch some of the lowest-hanging fruit, like unmatched close parens, invalid escapes, and so forth. However, more sophisticated error handling is often impossible in Sublime’s parser, particularly in complex languages like JavaScript and C.