dart-syntax-highlight icon indicating copy to clipboard operation
dart-syntax-highlight copied to clipboard

Switch from using "while" to "end" and adjust nested rules accordingly

Open DanTup opened this issue 1 year ago • 0 comments

While investigating https://github.com/dart-lang/dart-syntax-highlight/issues/11 I found a difference in how VS Code and GitHub/linguist handle when in the grammars.

In VS Code, when a when pattern stops matching, any open scopes from nested rules are ended, whereas on GitHub they are not. This means an unterminated triple-backtick block on GitHub can escape out of the surrounding comment.

The discussion in https://github.com/github-linguist/linguist/issues/7015 concluded that VS Code's behaviour is incorrect, and GitHub's behaviour (to just keep processing the nested rules until they end before re-evaluating the while) matches TextMate.

Since this isn't well specified and it's not clear if VS Code will change behaviour to match, this change stops using while in the grammar and adjusts the end rules for the nested code blocks to detect when they are falling out of the comment (instead of assuming everything until the next triple-backticks is code.. which could be the entire file). It also fixes some issues where we didn't handle termination of block comments correctly either.

Before changes:

image

Although that looks worse because the unclosed comment breaks the whole doc. Without that, the rest of the file before the changes looks like this:

image

After changes:

image

DanTup avatar Oct 10 '24 12:10 DanTup