Skip to content

Commit

Permalink
Codebases such as Qt or GCC use macros to annotate some class/struct/…
Browse files Browse the repository at this point in the history
…union.

This patch teaches the C++ syntax highlighter about such constructs, and fixes issue #3883.
  • Loading branch information
simartin committed Dec 29, 2024
1 parent be1bdd1 commit d30d00f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
11 changes: 11 additions & 0 deletions C++/C++.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,17 @@ contexts:
- match: ({{macro_identifier}})(?=\s+~?{{identifier}})
captures:
1: meta.assumed-macro.c
- match: '({{macro_identifier}})\s*(\()(?=[^\)]+\))'
captures:
1: variable.function.c++
2: meta.group.c++ punctuation.section.group.begin.c++
push:
- meta_scope: meta.function-call.c++
- meta_content_scope: meta.group.c++
- match: '\)'
scope: meta.group.c++ punctuation.section.group.end.c++
pop: true
- include: expressions

data-structures-class-definition:
- meta_scope: meta.class.c++
Expand Down
43 changes: 43 additions & 0 deletions C++/syntax_test_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3138,3 +3138,46 @@ void test4()
{
return;
}

#define GTY0
/* ^^^^ meta.preprocessor.macro.c++ */
#define GTY1(A)
/* ^^^^ entity.name.function.preprocessor */
/* ^^^ meta.preprocessor.macro.parameters */
#define GTY2(A, B)
/* ^^^^ entity.name.function.preprocessor */
/* ^^^^^^ meta.preprocessor.macro.parameters */

struct GTY0 foo {
/*<- keyword.declaration.struct.type.c++ */
/* ^^^^ meta.assumed-macro */
/* ^^^ entity.name.struct.c++ */
};

struct GTY1(42) bar {
/*<- keyword.declaration.struct.type.c++ */
/* ^^^^ meta.function-call.c++ */
/* ^^ constant.numeric.value.c++ */
/* ^^^ entity.name.struct.c++ */
};

struct GTY1("struct") baz {
/*<- keyword.declaration.struct.type.c++ */
/* ^^^^ meta.function-call.c++ */
/* ^^^^^^^^ string */
/* ^^^ entity.name.struct.c++ */
};

struct GTY2("struct enum", 42) bazz {
/*<- keyword.declaration.struct.type.c++ */
/* ^^^^ meta.function-call.c++ */
/* ^^^^^^^^^^^^^ string */
/* ^^ constant.numeric.value.c++ */
/* ^^^^ entity.name.struct.c++ */
};

class GTY2("struct class", 42) bazz {
/*<- keyword.declaration.class.c++ */
/* ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call */
/* ^^^^ entity.name.class.c++ */
};

0 comments on commit d30d00f

Please sign in to comment.