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

C define highlighting can be wrong with C++ grammar but not in C grammar #404

Open alexr00 opened 5 years ago

alexr00 commented 5 years ago

From @jaudiger in https://github.com/microsoft/vscode/issues/82848

Steps to Reproduce:

  1. Use the following code inside a test.c(uses C grammar) file and a test.h(uses C++ grammar) file:
#define A 1
#define B 2

#define E (A | B)
  1. The file test.h(using the C++ grammar) contains a wrong highlighting define for E: A is not of the same color as B.

image

Does this issue occur when C/C++ extension is disabled?: Yes

rianquinn commented 5 years ago

I can confirm this issue with mine as well. Might be related to the issue I just posted.

image

matter123 commented 5 years ago

This is caused by the grammar treating any #define foo (/* snip */) as a macro function even when it contains invalid characters.

It should be easy enough to restrict a macro function definition to:

Standard reference: http://eel.is/c++draft/gram.cpp

sean-mcmanus commented 4 years ago

A user reported another repro with

#define ITEM_MASK 0x00000001U /**< Documentation
                                   that goes onto the next line */

It seems like that's the same issue as this? Only repros with C++ and not C.