From 22d5e97dfb4fb5151f07cd697e791999e1721ec7 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 04:47:06 -0600 Subject: [PATCH 1/7] Add concept support --- C++/C++.sublime-syntax | 43 +++++++++++++++++++++++++++++++++++++++-- C++/syntax_test_cpp.cpp | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 524e5ff129..7391032cb3 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -61,7 +61,7 @@ variables: control_keywords: 'break|case|catch|continue|default|do|else|for|goto|if|_Pragma|switch|throw|try|while|{{coroutine_keywords}}' memory_operators: 'new|delete' basic_types: 'asm|__asm__|auto|bool|_Bool|char|_Complex|double|float|_Imaginary|int|long|short|signed|unsigned|void' - before_tag: 'struct|union|enum\s+class|enum\s+struct|enum|class' + before_tag: 'struct|union|enum\s+class|enum\s+struct|enum|class|concept' declspec: '__declspec\(\s*\w+(?:\([^)]+\))?\s*\)' storage_classes: 'static|export|extern|friend|explicit|virtual|register|thread_local' type_qualifier: 'const|mutable|typename|volatile' @@ -745,7 +745,10 @@ contexts: - meta_content_scope: meta.template.c++ - match: '>' scope: meta.template.c++ punctuation.definition.generic.end.c++ - pop: true + set: + - include: constraint-requires + - match: (?=\S) + pop: true - match: \.{3} scope: keyword.operator.variadic.c++ - match: \b(typename|{{before_tag}})\b @@ -759,6 +762,26 @@ contexts: scope: keyword.declaration.c++ - include: template-common + requires: + - match: \brequires\b + scope: keyword.operator.word.c++ + push: function-definition-params + + constraint: + - match: (?=;) + pop: true + - include: requires + - include: expressions-minus-generic-type-function-call + + constraint-requires: + - match: '\brequires\b' + scope: storage.modifier.c++ + set: + - meta_scope: meta.constraint.c++ + - match: (?=\{|{{identifier}}\s*{{identifier}}\() + pop: true + - include: constraint + generic-type: - match: '(?=(?!template){{path_lookahead}}\s*{{generic_lookahead}}\s*(\(|\{))' push: @@ -1248,6 +1271,7 @@ contexts: scope: punctuation.separator.c++ set: function-definition-trailing-return - include: function-specifiers + - include: constraint-requires - match: '=' scope: keyword.operator.assignment.c++ - match: '&' @@ -1268,6 +1292,7 @@ contexts: - match: '(?=\{)' set: function-definition-body - include: function-specifiers + - include: constraint-requires - include: function-trailing-return-type function-definition-body: @@ -1303,6 +1328,9 @@ contexts: - match: '\bunion\b' scope: keyword.declaration.union.type.c++ set: data-structures-union-definition + - match: '\bconcept\b' + scope: keyword.declaration.concept.c++ + set: data-structures-concept-definition - match: '(?=\S)' pop: true @@ -1463,6 +1491,17 @@ contexts: - match: '(?=;)' pop: true + data-structures-concept-definition: + - meta_content_scope: meta.concept.c++ + - include: data-structures-definition-common-begin + - match: '({{identifier}})\s+(=)' + captures: + 1: entity.name.concept.c++ + 2: keyword.operator.assignment.c++ + set: + - meta_content_scope: meta.concept.c++ meta.constraint.c++ + - include: constraint + data-structures-definition-common-begin: - include: comments - match: '(?=\b(?:{{before_tag}}|{{control_keywords}})\b)' diff --git a/C++/syntax_test_cpp.cpp b/C++/syntax_test_cpp.cpp index d0552e9c91..77cf487fd2 100644 --- a/C++/syntax_test_cpp.cpp +++ b/C++/syntax_test_cpp.cpp @@ -3139,6 +3139,46 @@ void test4() return; } +///////////////////////////////////////////// +// Concepts +///////////////////////////////////////////// + +template +/* <- meta.template.c++ keyword.declaration.template.c++ */ +concept has_foo = requires(T t) { +/* <- meta.concept.c++ keyword.declaration.concept.c++ */ +/* ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.concept.c++ */ +/* ^^^^^^^ meta.concept.c++ entity.name.concept.c++ */ +/* ^^^^^^^^^^^^^^^ meta.concept.c++ meta.constraint.c++ */ +/* ^^^^^ meta.function.parameters.c++ */ +/* ^ meta.block meta.function.c++ */ + t.foo(); +/* ^^^^^^^^ meta.concept.c++ meta.constraint.c++ meta.block.c++ meta.function.c++ */ +} && std::move_constructible; +/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.concept.c++ meta.constraint.c++ */ + +template +/* <- meta.template.c++ keyword.declaration.template.c++ */ +void foo() requires std::same_as +/* <- storage.type.c */ +/* ^^^^ meta.function.c++ entity.name.function.c++ */ +/* ^^^^^^^^ meta.function.c++ meta.constraint.c++ storage.modifier.c++ */ +/* ^^^^^^^^^^^^^^^^^^^^^ meta.function.c++ meta.constraint.c++ */ +{ + return; +} + +template requires std::same_as +/* <- meta.template.c++ keyword.declaration.template.c++ */ +/* ^^^^^^^^ meta.constraint.c++ storage.modifier.c++ */ +/* ^^^^^^^^^^^^^^^^^^^^^ meta.constraint.c++ */ +void bar() +/* <- storage.type.c */ +/* ^^^^ meta.function.c++ entity.name.function.c++ */ +{ + return; +} + #define GTY0 /* ^^^^ meta.preprocessor.macro.c++ */ #define GTY1(A) From ee6830c1bd935f1282a20dfd797bb89478f90000 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 04:56:53 -0600 Subject: [PATCH 2/7] Fix bug when using requires for a data type rather than function --- C++/C++.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 7391032cb3..80926aa41d 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -778,7 +778,7 @@ contexts: scope: storage.modifier.c++ set: - meta_scope: meta.constraint.c++ - - match: (?=\{|{{identifier}}\s*{{identifier}}\() + - match: (?=\{|{{identifier}}\s*{{identifier}}\(|{{before_tag}}) pop: true - include: constraint From 41e8db5f3fb9e5c6c3437b83af1ac190906a258c Mon Sep 17 00:00:00 2001 From: camila <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 05:52:06 -0600 Subject: [PATCH 3/7] Cover concept keyword with meta.concept Co-authored-by: deathaxe --- C++/C++.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 80926aa41d..a9388c9b8a 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -1329,7 +1329,7 @@ contexts: scope: keyword.declaration.union.type.c++ set: data-structures-union-definition - match: '\bconcept\b' - scope: keyword.declaration.concept.c++ + scope: meta.concept.c++ keyword.declaration.concept.c++ set: data-structures-concept-definition - match: '(?=\S)' pop: true From b58a74c2ba1dc5a6700728e939d64cb5dfe97152 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 06:17:07 -0600 Subject: [PATCH 4/7] Fix meta.function scope being inaccessible --- C++/C++.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index a9388c9b8a..58f3ad4ae5 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -776,7 +776,7 @@ contexts: constraint-requires: - match: '\brequires\b' scope: storage.modifier.c++ - set: + push: - meta_scope: meta.constraint.c++ - match: (?=\{|{{identifier}}\s*{{identifier}}\(|{{before_tag}}) pop: true From ed2beb46363dd8aa909e7cd3d2fe8b4930d66925 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 06:27:16 -0600 Subject: [PATCH 5/7] Make constraints work on methods --- C++/C++.sublime-syntax | 1 + 1 file changed, 1 insertion(+) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 58f3ad4ae5..79b7b94a41 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -1764,6 +1764,7 @@ contexts: scope: punctuation.separator.c++ set: method-definition-trailing-return - include: function-specifiers + - include: constraint-requires - match: '=' scope: keyword.operator.assignment.c++ - match: '&' From f12a7dc75d3480f80fb3724a5c2ae65475b86577 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 06:35:42 -0600 Subject: [PATCH 6/7] Add : as a constraint terminator for constructors --- C++/C++.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C++/C++.sublime-syntax b/C++/C++.sublime-syntax index 79b7b94a41..81ed81d942 100644 --- a/C++/C++.sublime-syntax +++ b/C++/C++.sublime-syntax @@ -778,7 +778,7 @@ contexts: scope: storage.modifier.c++ push: - meta_scope: meta.constraint.c++ - - match: (?=\{|{{identifier}}\s*{{identifier}}\(|{{before_tag}}) + - match: (?=\{|{{identifier}}\s*{{identifier}}\(|{{before_tag}}|:) pop: true - include: constraint From 88e57c8277e1d689a7cbf1c15ab915e48c95ac27 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Sat, 1 Feb 2025 12:51:03 -0600 Subject: [PATCH 7/7] Fix syntax test --- C++/syntax_test_cpp.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/C++/syntax_test_cpp.cpp b/C++/syntax_test_cpp.cpp index 77cf487fd2..8a6ee23d42 100644 --- a/C++/syntax_test_cpp.cpp +++ b/C++/syntax_test_cpp.cpp @@ -3151,9 +3151,9 @@ concept has_foo = requires(T t) { /* ^^^^^^^ meta.concept.c++ entity.name.concept.c++ */ /* ^^^^^^^^^^^^^^^ meta.concept.c++ meta.constraint.c++ */ /* ^^^^^ meta.function.parameters.c++ */ -/* ^ meta.block meta.function.c++ */ +/* ^ meta.function.c++ meta.block.c++ */ t.foo(); -/* ^^^^^^^^ meta.concept.c++ meta.constraint.c++ meta.block.c++ meta.function.c++ */ +/* ^^^^^^^^ meta.concept.c++ meta.constraint.c++ meta.function.c++ meta.block.c++ */ } && std::move_constructible; /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.concept.c++ meta.constraint.c++ */ @@ -3161,8 +3161,8 @@ template /* <- meta.template.c++ keyword.declaration.template.c++ */ void foo() requires std::same_as /* <- storage.type.c */ -/* ^^^^ meta.function.c++ entity.name.function.c++ */ -/* ^^^^^^^^ meta.function.c++ meta.constraint.c++ storage.modifier.c++ */ +/* ^^^ meta.function.c++ entity.name.function.c++ */ +/* ^^^^^^^^ meta.function.c++ meta.constraint.c++ storage.modifier.c++ */ /* ^^^^^^^^^^^^^^^^^^^^^ meta.function.c++ meta.constraint.c++ */ { return; @@ -3174,7 +3174,7 @@ template requires std::same_as /* ^^^^^^^^^^^^^^^^^^^^^ meta.constraint.c++ */ void bar() /* <- storage.type.c */ -/* ^^^^ meta.function.c++ entity.name.function.c++ */ +/* ^^^ meta.function.c++ entity.name.function.c++ */ { return; }