diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index ead8a51376..ea153317da 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -20,9 +20,9 @@ file_extensions: first_line_match: '-\*- C\+\+ -\*-' scope: source.c++ variables: - identifier: '\b[[:alpha:]_][[:alnum:]_]*\b' + identifier: \b[[:alpha:]_][[:alnum:]_]*\b # upper and lowercase + macro_identifier: \b[[:upper:]_][[:upper:][:digit:]_]{2,}\b # only uppercase, at least 3 chars path_lookahead: '(?:::\s*)?(?:{{identifier}}\s*::\s*)*(?:template\s+)?{{identifier}}' - macro_identifier: '\b[[:upper:]_][[:upper:][:digit:]_]+\b' operator_method_name: '\boperator\s*(?:[-+*/%^&|~!=<>]|[-+*/%^&|=!<>]=|<<=?|>>=?|&&|\|\||\+\+|--|,|->\*?|\(\)|\[\]|""\s*{{identifier}})' casts: 'const_cast|dynamic_cast|reinterpret_cast|static_cast' operator_keywords: 'and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq|noexcept' @@ -1447,7 +1447,7 @@ contexts: preprocessor-data-structures: - include: preprocessor-rule-enabled-data-structures - include: preprocessor-rule-disabled-data-structures - - include: scope:source.c#preprocessor-practical-workarounds + - include: preprocessor-practical-workarounds preprocessor-rule-disabled-data-structures: - match: ^\s*((#if)\s+(0))\b @@ -1899,6 +1899,23 @@ contexts: scope: punctuation.section.block.end.c++ - include: expressions + preprocessor-practical-workarounds: + - include: preprocessor-convention-ignore-uppercase-ident-lines + - include: scope:source.c#preprocessor-convention-ignore-uppercase-calls-without-semicolon + + preprocessor-convention-ignore-uppercase-ident-lines: + - match: ^(\s*{{macro_identifier}})+\s*$ + scope: meta.assumed-macro.c++ + push: + # It's possible that we are dealing with a function return type on its own line, and the + # name of the function is on the subsequent line. + - match: '(?={{path_lookahead}}({{generic_lookahead}}({{path_lookahead}})?)\s*\()' + set: [function-definition-params, global-function-identifier-generic] + - match: '(?={{path_lookahead}}\s*\()' + set: [function-definition-params, global-function-identifier] + - match: ^ + pop: true + preprocessor-other: - match: ^\s*(#\s*(?:if|ifdef|ifndef|elif|else|line|pragma|undef))\b captures: @@ -1946,4 +1963,4 @@ contexts: - match: '>' scope: punctuation.definition.string.end.c++ pop: true - - include: scope:source.c#preprocessor-practical-workarounds + - include: preprocessor-practical-workarounds diff --git a/C++/C.sublime-syntax b/C++/C.sublime-syntax index 89b6255f55..cabd206f82 100644 --- a/C++/C.sublime-syntax +++ b/C++/C.sublime-syntax @@ -1119,6 +1119,16 @@ contexts: preprocessor-convention-ignore-uppercase-ident-lines: - match: ^(\s*{{macro_identifier}})+\s*$ scope: meta.assumed-macro.c + push: + # It's possible that we are dealing with a function return type on its own line, and the + # name of the function is on the subsequent line. + - match: \s*({{identifier}})(?=\s*\() + captures: + 1: meta.function.c entity.name.function.c + set: function-definition-params + - match: ^ + pop: true + preprocessor-convention-ignore-uppercase-calls-without-semicolon: - match: ^\s*({{macro_identifier}})\s*(\()(?=[^)]*\)\s*$) diff --git a/C++/syntax_test_c.c b/C++/syntax_test_c.c index 76c45181d1..86b9db13c7 100644 --- a/C++/syntax_test_c.c +++ b/C++/syntax_test_c.c @@ -111,6 +111,50 @@ bool still_C_code_here = true; /* <- storage.type */ /* ^ constant.language */ +FOOBAR +hello() { + /* <- meta.function entity.name.function */ + return 0; +} + +EFIAPI +UserStructCompare ( + /* <- meta.function entity.name.function */ + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + const USER_STRUCT *CmpStruct1; + /* <- meta.block storage.modifier */ + + CmpStruct1 = UserStruct1; + return KeyCompare (&CmpStruct1->Key, UserStruct2); + /* <- meta.block keyword.control */ + /* ^ meta.block meta.function-call variable.function */ +} + +LIB_RESULT +foo() +/* <- meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +LIB_RESULT bar() +/* ^ meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +THIS_IS_REALLY_JUST_A_MACRO_AND_NOT_A_RETURN_TYPE +/* <- meta.assumed-macro */ + +int main() { +/* <- storage.type */ + /* ^ meta.function entity.name.function */ + return 0; +} + #if 0 #ifdef moo /* <- - keyword.control */ diff --git a/C++/syntax_test_cpp.cpp b/C++/syntax_test_cpp.cpp index 2b2b932c31..463e0c1c40 100644 --- a/C++/syntax_test_cpp.cpp +++ b/C++/syntax_test_cpp.cpp @@ -58,6 +58,57 @@ int g(int x = 5 \ /* <- keyword.control.import.define */ /* ^ entity.name.constant */ +FOOBAR +hello() { + /* <- meta.function entity.name.function */ + return 0; +} + +EFIAPI +UserStructCompare ( + /* <- meta.function entity.name.function */ + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + const USER_STRUCT *CmpStruct1; + /* <- meta.block storage.modifier */ + + CmpStruct1 = UserStruct1; + return KeyCompare (&CmpStruct1->Key, UserStruct2); + /* <- meta.block keyword.control */ + /* ^ meta.block meta.function-call variable.function */ +} + +LIB_RESULT +foo() +/* <- meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +LIB_RESULT bar() +/* ^ meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +THIS_IS_REALLY_JUST_A_MACRO_AND_NOT_A_RETURN_TYPE +/* <- meta.assumed-macro */ + +int main() { +/* <- storage.type */ + /* ^ meta.function entity.name.function */ + return 0; +} + +// This is a method/function with the return type on a separate line and so should not be a +// constructor. +FOOLIB_RESULT +some_namespace::some_function(int a_parameter, double another_parameter) { + /* <- meta.function entity.name.function - entity.name.function.constructor */ + return FOOLIB_SUCCESS; +} #pragma foo(bar, \ "baz", \ diff --git a/Objective-C/Objective-C++.sublime-syntax b/Objective-C/Objective-C++.sublime-syntax index bf784541f8..448a3a62b2 100644 --- a/Objective-C/Objective-C++.sublime-syntax +++ b/Objective-C/Objective-C++.sublime-syntax @@ -8,9 +8,9 @@ file_extensions: - h scope: source.objc++ variables: - identifier: '\b[[:alpha:]_][[:alnum:]_]*\b' + identifier: \b[[:alpha:]_][[:alnum:]_]*\b # upper and lowercase + macro_identifier: \b[[:upper:]_][[:upper:][:digit:]_]{2,}\b # only uppercase, at least 3 chars path_lookahead: '(?:::\s*)?(?:{{identifier}}\s*::\s*)*(?:template\s+)?{{identifier}}' - macro_identifier: '\b[[:upper:]_][[:upper:][:digit:]_]+\b' operator_method_name: '\boperator\s*(?:[-+*/%ˆ&|~!=<>]|[-+*/%^&|=!<>]=|<<=?|>>=?|&&|\|\||\+\+|--|,|->\*?|\(\)|\[\]|""\s*{{identifier}})' casts: 'const_cast|dynamic_cast|reinterpret_cast|static_cast' operator_keywords: 'and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq|noexcept' @@ -1518,7 +1518,7 @@ contexts: preprocessor-data-structures: - include: preprocessor-rule-enabled-data-structures - include: preprocessor-rule-disabled-data-structures - - include: scope:source.c#preprocessor-practical-workarounds + - include: scope:source.c++#preprocessor-practical-workarounds preprocessor-rule-disabled-data-structures: - match: ^\s*((#if)\s+(0))\b @@ -2007,7 +2007,7 @@ contexts: push: - meta_scope: meta.preprocessor.import.objc++ - include: preprocessor-other-include-common - - include: scope:source.c#preprocessor-practical-workarounds + - include: scope:source.c++#preprocessor-practical-workarounds preprocessor-other-include-common: - include: scope:source.c#preprocessor-line-continuation diff --git a/Objective-C/syntax_test_objc++.mm b/Objective-C/syntax_test_objc++.mm index 27d6036ae6..91f4e99fe8 100644 --- a/Objective-C/syntax_test_objc++.mm +++ b/Objective-C/syntax_test_objc++.mm @@ -58,6 +58,57 @@ int g(int x = 5 \ /* <- keyword.control.import.define */ /* ^ entity.name.constant */ +FOOBAR +hello() { + /* <- meta.function entity.name.function */ + return 0; +} + +EFIAPI +UserStructCompare ( + /* <- meta.function entity.name.function */ + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + const USER_STRUCT *CmpStruct1; + /* <- meta.block storage.modifier */ + + CmpStruct1 = UserStruct1; + return KeyCompare (&CmpStruct1->Key, UserStruct2); + /* <- meta.block keyword.control */ + /* ^ meta.block meta.function-call variable.function */ +} + +LIB_RESULT +foo() +/* <- meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +LIB_RESULT bar() +/* ^ meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +THIS_IS_REALLY_JUST_A_MACRO_AND_NOT_A_RETURN_TYPE +/* <- meta.assumed-macro */ + +int main() { +/* <- storage.type */ + /* ^ meta.function entity.name.function */ + return 0; +} + +// This is a method/function with the return type on a separate line and so should not be a +// constructor. +FOOLIB_RESULT +some_namespace::some_function(int a_parameter, double another_parameter) { + /* <- meta.function entity.name.function - entity.name.function.constructor */ + return FOOLIB_SUCCESS; +} #pragma foo(bar, \ "baz", \ diff --git a/Objective-C/syntax_test_objc.m b/Objective-C/syntax_test_objc.m index ca0bae63c0..4a5b877709 100644 --- a/Objective-C/syntax_test_objc.m +++ b/Objective-C/syntax_test_objc.m @@ -111,6 +111,50 @@ int f(int x, \ /* <- storage.type */ /* ^ constant.language */ +FOOBAR +hello() { + /* <- meta.function entity.name.function */ + return 0; +} + +EFIAPI +UserStructCompare ( + /* <- meta.function entity.name.function */ + IN CONST VOID *UserStruct1, + IN CONST VOID *UserStruct2 + ) +{ + const USER_STRUCT *CmpStruct1; + /* <- meta.block storage.modifier */ + + CmpStruct1 = UserStruct1; + return KeyCompare (&CmpStruct1->Key, UserStruct2); + /* <- meta.block keyword.control */ + /* ^ meta.block meta.function-call variable.function */ +} + +LIB_RESULT +foo() +/* <- meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +LIB_RESULT bar() +/* ^ meta.function entity.name.function */ +{ + return LIB_SUCCESS; +} + +THIS_IS_REALLY_JUST_A_MACRO_AND_NOT_A_RETURN_TYPE +/* <- meta.assumed-macro */ + +int main() { +/* <- storage.type */ + /* ^ meta.function entity.name.function */ + return 0; +} + #if 0 #ifdef moo /* <- - keyword.control */