jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
155 stars 30 forks source link

Raw strings fail if the last line of the sting includes a comment. #632

Open a-stewart opened 1 year ago

a-stewart commented 1 year ago

Checklist

The code with a problem is:

R"sql(SELECT * FROM foo  -- comment)sql";

It looks like (Default Light+):

image

It should look like:

The comment should end at the end of the string.

image
jeff-hykin commented 1 year ago

This is going to be hard to fix in a generic way.

When the string starts it completely hands control over to the SQL highlighter. And then the SQL highlighter says "everything after the -- is a comment" before giving control back to the C++ highlighter. @ matter123 and I made a tool to help with this called "textmate-bailout", which is where we download a grammar (in this case the SQL grammar), then use the tool to inject code into every single pattern of the grammar (like the comment pattern) so that, instead of their original parsing, those patterns will "bailout" and immediately halt they see something like ".

Its as hacky as it sounds, and we would have to bundle an entire modified SQL grammar inside of the C++ grammar, but its possible. I probably won't be working on that anytime soon though