better-cpp-syntax icon indicating copy to clipboard operation
better-cpp-syntax copied to clipboard

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

Open alexr00 opened this issue 6 years ago • 3 comments

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

  • VSCode Version: 1.39.2
  • OS Version: Windows 10 (64 bits) + ArchLinux WSL

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

alexr00 avatar Oct 21 '19 09:10 alexr00

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

image

rianquinn avatar Oct 21 '19 11:10 rianquinn

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:

  • identifiers
  • spaces
  • comments
  • commas
  • ... as the last item

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

matter123 avatar Oct 21 '19 16:10 matter123

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.

sean-mcmanus avatar May 08 '20 19:05 sean-mcmanus