jeff-hykin / better-cpp-syntax

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

Unterminated [[ in preprocessor-disabled section breaks highlighting for rest of file #569

Open HighCommander4 opened 3 years ago

HighCommander4 commented 3 years ago

The code with a problem is:

int func1(int);  // highlighted correctly

#ifdef FOO
[[
#endif

int func2(int);  // not highlighted

Lines after the preprocessor-disabled section do not get highlightings.

Inspecting the scopes, it looks like they get entity.other.attribute.int.cpp. I guess that's related to the fact that [[ opens an attribute.

(Originally reported at https://github.com/clangd/clangd/issues/882.)

RedCMD commented 1 year ago

could possibly add #endif etc to [[? idk how badly it would intersect with other stuff and obviously would need to add all the extra #endif checks to it (?=^((?:((?:\\s*+\\/\\*(?:[^\\*]++|\\*+(?!\\/))*+\\*\\/\\s*+)+)|(?:\\s++)|(?<=\\W)|(?=\\W)|^|(?:\\n?$)|(?:\\A)|(?:\\Z)))(#)(?:(?:\\s)+)?((?<!\\w)(?:endif|else|elif)(?!\\w)))

image image

https://github.com/jeff-hykin/better-cpp-syntax/blob/b159c5efc8bd3248b07420713babf597e4dab363/autogenerated/cpp.tmLanguage.json#L1056-L1099 image

jeff-hykin commented 1 year ago

For the program to run correctly under all cases, there needs to be a closing ]] somewhere. e.g. if FOO is defined, the syntax of the C++ is broken.