Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textmate grammar highlighting doesn't match GitHub/Linguist when "end" is never matched #189940

Open
DanTup opened this issue Aug 8, 2023 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug grammar Syntax highlighting grammar
Milestone

Comments

@DanTup
Copy link
Contributor

DanTup commented Aug 8, 2023

This was reported at dart-lang/dart-syntax-highlight#11 (comment). Dart highlighting on GitHub doesn't handle unterminated triple-backticks as expected. VS Code does handle it as expected.

However, while debugging this, I've become less certain that GitHub is wrong, and feel like VS Code might be.

Here's a trimmed down version of the grammar that shows the problem. It defines triple-slash comments, and supports triple-backtick code blocks inside:

It renders like this:

image

It the triple backticks are unclosed, it looks reasonable:

image

However, it's not clear why the variable.other.source.dart scope was exited, because the "end" condition was never found. On GitHub, this does not happen and the rest of the document is consumed (note the first void here is red, but the second one is not because the variable context eats the rest of the document):

image

I can't find anything in the spec for textmate grammars to explain VS Code's behaviour. The most information I've found on it is here:

https://macromates.com/manual/en/language_grammars

The other type of match is the one used by the second rule (lines 9-17). Here two regular expressions are given using the begin and end keys. [...] If there is no match for the end pattern, the end of the document is used.

https://www.apeth.com/nonblog/stories/textmatebundle.html

With begin/end, if the end pattern is not found, the overall match does not fail: rather, once the begin pattern is matched, the overall match runs to the end pattern or to the end of the document, whichever comes first.

While VS Code's behaviour is convenient for me (because I'm not sure how to handle these unclosed triple-backticks if it behaved like GitHub), it doesn't seem correct, and it's more inconvenient if VS Code and GitHub disagree on what the behaviour should be because it makes it more difficult to author a grammar.

@aiday-mar
Copy link
Contributor

Hey @hediet, not sure if this is for you?

@hediet hediet added the grammar Syntax highlighting grammar label Aug 10, 2023
@hediet hediet added this to the September 2023 milestone Aug 10, 2023
@hediet hediet modified the milestones: September 2023, Backlog Sep 25, 2023
@hediet hediet added the bug Issue identified by VS Code Team member as probable bug label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug grammar Syntax highlighting grammar
Projects
None yet
Development

No branches or pull requests

4 participants