From ed81867382f9e1e10399365116530a3bfb295834 Mon Sep 17 00:00:00 2001 From: James Buren Date: Sun, 10 Nov 2024 20:14:54 -0600 Subject: [PATCH] [C] Make function parameter names optional Function parameter names are now optional in C and C++. Previously the syntax highlighting rules would assume that the last identifier found in a parameter was the parameter name but this was making it impossible to properly highlight parameters without a parameter name. The only solution I could find was to include the specific types and modifiers before the more general match for the parameter name. With this, the types and modifiers are no longer mistaken for a parameter name. --- C++/C++.sublime-syntax | 4 ++-- C++/C.sublime-syntax | 4 ++-- C++/syntax_test_c.c | 17 +++++++++++++++++ C++/syntax_test_cpp.cpp | 17 +++++++++++++++++ Objective-C/Objective-C++.sublime-syntax | 4 ++-- Objective-C/Objective-C.sublime-syntax | 4 ++-- Objective-C/syntax_test_objc++.mm | 17 +++++++++++++++++ Objective-C/syntax_test_objc.m | 17 +++++++++++++++++ 8 files changed, 76 insertions(+), 8 deletions(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 0040b19645..fa46e950cf 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -1223,8 +1223,8 @@ contexts: - match : \) scope: punctuation.section.group.end.c++ set: function-definition-continue - - match: '\bvoid\b' - scope: storage.type.c++ + - include: modifiers + - include: types - match: '{{identifier}}(?=\s*(\[|,|\)|=))' scope: variable.parameter.c++ - match: '=' diff --git a/C++/C.sublime-syntax b/C++/C.sublime-syntax index 7100604955..51e893888c 100644 --- a/C++/C.sublime-syntax +++ b/C++/C.sublime-syntax @@ -613,8 +613,8 @@ contexts: - match : \) scope: punctuation.section.group.end.c set: function-definition-continue - - match: '\bvoid\b' - scope: storage.type.c + - include: modifiers + - include: types - match: '{{identifier}}(?=\s*(\[|,|\)))' scope: variable.parameter.c - include: expressions diff --git a/C++/syntax_test_c.c b/C++/syntax_test_c.c index 5e35312076..a419c38071 100644 --- a/C++/syntax_test_c.c +++ b/C++/syntax_test_c.c @@ -834,6 +834,23 @@ struct UI_MenuBoxData // Test preprocessor branching and C blocks ///////////////////////////////////////////// +int bar(int, int const *, int const * const); +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ +/* ^ punctuation.section.group.begin */ +/* ^ punctuation.section.group.end */ +/* ^ punctuation.terminator */ +/* ^^^ storage.type */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^^^^^ storage.modifier */ + int foo(int val, float val2[]) /* ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ /* ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ diff --git a/C++/syntax_test_cpp.cpp b/C++/syntax_test_cpp.cpp index 2b7226b044..fa3815f5b2 100644 --- a/C++/syntax_test_cpp.cpp +++ b/C++/syntax_test_cpp.cpp @@ -2547,6 +2547,23 @@ MyEnum MACRO1 // Test preprocessor branching and C blocks ///////////////////////////////////////////// +int bar(int, int const *, int const * const); +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ +/* ^ punctuation.section.group.begin */ +/* ^ punctuation.section.group.end */ +/* ^ punctuation.terminator */ +/* ^^^ storage.type */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^^^^^ storage.modifier */ + int foo(int val, float val2[], bool val3 = false) /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ diff --git a/Objective-C/Objective-C++.sublime-syntax b/Objective-C/Objective-C++.sublime-syntax index d8e02eb5a1..a072f4eebc 100644 --- a/Objective-C/Objective-C++.sublime-syntax +++ b/Objective-C/Objective-C++.sublime-syntax @@ -1113,8 +1113,8 @@ contexts: - match : \) scope: punctuation.section.group.end.objc++ set: function-definition-continue - - match: '\bvoid\b' - scope: storage.type.objc++ + - include: modifiers + - include: types - match: '{{identifier}}(?=\s*(\[|,|\)|=))' scope: variable.parameter.objc++ - match: '=' diff --git a/Objective-C/Objective-C.sublime-syntax b/Objective-C/Objective-C.sublime-syntax index 9dc6574028..eab06e4af6 100644 --- a/Objective-C/Objective-C.sublime-syntax +++ b/Objective-C/Objective-C.sublime-syntax @@ -619,8 +619,8 @@ contexts: - match : \) scope: punctuation.section.group.end.objc set: function-definition-continue - - match: '\bvoid\b' - scope: storage.type.objc + - include: modifiers + - include: types - match: '{{identifier}}(?=\s*(\[|,|\)))' scope: variable.parameter.objc - include: expressions diff --git a/Objective-C/syntax_test_objc++.mm b/Objective-C/syntax_test_objc++.mm index ef45656ede..2075fe4c07 100644 --- a/Objective-C/syntax_test_objc++.mm +++ b/Objective-C/syntax_test_objc++.mm @@ -2501,6 +2501,23 @@ T operator()(int a) { // Test preprocessor branching and C blocks ///////////////////////////////////////////// +int bar(int, int const *, int const * const); +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ +/* ^ punctuation.section.group.begin */ +/* ^ punctuation.section.group.end */ +/* ^ punctuation.terminator */ +/* ^^^ storage.type */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^^^^^ storage.modifier */ + int foo(int val, float val2[], bool val3 = false) /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ diff --git a/Objective-C/syntax_test_objc.m b/Objective-C/syntax_test_objc.m index df8e6b839e..9ba2514aed 100644 --- a/Objective-C/syntax_test_objc.m +++ b/Objective-C/syntax_test_objc.m @@ -533,6 +533,23 @@ int main(void) // Test preprocessor branching and C blocks ///////////////////////////////////////////// +int bar(int, int const *, int const * const); +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ +/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */ +/* ^ punctuation.section.group.begin */ +/* ^ punctuation.section.group.end */ +/* ^ punctuation.terminator */ +/* ^^^ storage.type */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^ punctuation.separator */ +/* ^^^ storage.type */ +/* ^^^^^ storage.modifier */ +/* ^ keyword.operator */ +/* ^^^^^ storage.modifier */ + int foo(int val, float val2[]) /* ^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function */ /* ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters meta.group */