Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions C++/C++.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,9 @@ contexts:
pop: true
- include: angle-brackets
- include: types
# Allow a macro call
- match: '({{identifier}})\s*(\()(?=[^\)]+\))'
# Allow a macro call. The lookahead permits up to two levels of nested
# parentheses in the macro arguments (e.g. `FOO(a = (b))`).
- match: '({{identifier}})\s*(\()(?=(?:[^()]|\((?:[^()]|\([^()]*\))*\))+\))'
captures:
1: variable.function.c++
2: meta.group.c++ punctuation.section.group.begin.c++
Expand Down Expand Up @@ -1340,7 +1341,7 @@ contexts:
- match: ({{macro_identifier}})(?=\s+~?{{identifier}})
captures:
1: meta.assumed-macro.c
- match: '({{macro_identifier}})\s*(\()(?=[^\)]+\))'
- match: '({{macro_identifier}})\s*(\()(?=(?:[^()]|\((?:[^()]|\([^()]*\))*\))+\))'
captures:
1: variable.function.c++
2: meta.group.c++ punctuation.section.group.begin.c++
Expand Down
11 changes: 8 additions & 3 deletions C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,9 @@ contexts:
pop: true
- match: '(?=\s)'
set: global-maybe-function
# Allow a macro call
- match: '({{identifier}})\s*(\()(?=[^\)]+\))'
# Allow a macro call. The lookahead permits up to two levels of nested
# parentheses in the macro arguments (e.g. `FOO(a = (b))`).
- match: '({{identifier}})\s*(\()(?=(?:[^()]|\((?:[^()]|\([^()]*\))*\))+\))'
captures:
1: variable.function.c
2: meta.group.c punctuation.section.group.begin.c
Expand Down Expand Up @@ -1433,7 +1434,11 @@ contexts:


preprocessor-convention-ignore-uppercase-calls-without-semicolon:
- match: ^\s*({{macro_identifier}})\s*(\()(?=[^)]*\)\s*$)
# The lookahead permits up to two levels of nested parentheses in the
# macro arguments (e.g. Unreal Engine's `USTRUCT(meta = (Abstract))`),
# so that macros which are the sole content of a line are still
# recognised when their arguments contain grouped expressions.
- match: ^\s*({{macro_identifier}})\s*(\()(?=(?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)\s*$)
captures:
1: variable.function.assumed-macro.c
2: punctuation.section.group.begin.c
Expand Down
20 changes: 20 additions & 0 deletions C++/tests/syntax_test_parentheses_in_macro_arguments.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SYNTAX TEST "Packages/C++/C++.sublime-syntax"

// Test: macros with nested parentheses (e.g. Unreal Engine USTRUCT)
// should not break highlighting of subsequent struct members.

struct MyPlainStruct
{
public:
// <- storage.modifier.c++
};

USTRUCT(meta = (Abstract))
// <- meta.assumed-macro.c variable.function.assumed-macro.c
struct MyUStruct
// <- keyword.declaration.struct.type.c++
// ^ meta.struct.c++ entity.name.struct.c++
{
public:
// <- storage.modifier.c++
};