From 3a5f3fdaba8ab869ce1430666c09d8b8042e0be6 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Thu, 26 Dec 2024 21:01:48 +0200 Subject: [PATCH] [C#] support class definitions without a body --- C#/C#.sublime-syntax | 74 ++++++++++++++++++------------------ C#/tests/syntax_test_C#12.cs | 40 +++++++++++++++++++ C#/tests/syntax_test_C#8.cs | 6 +-- 3 files changed, 81 insertions(+), 39 deletions(-) create mode 100644 C#/tests/syntax_test_C#12.cs diff --git a/C#/C#.sublime-syntax b/C#/C#.sublime-syntax index c63d597085..65cfb5be35 100644 --- a/C#/C#.sublime-syntax +++ b/C#/C#.sublime-syntax @@ -446,12 +446,7 @@ contexts: - match: \s*(;) captures: 1: punctuation.terminator.statement.cs - pop: true - - maybe_terminator: - - include: terminator - - match: (?=\S) - pop: true + pop: 1 delegate_end: - include: terminator @@ -477,6 +472,7 @@ contexts: class_signature: - meta_scope: meta.class.cs + - include: terminator - match: (?=\S) set: class_body @@ -517,21 +513,24 @@ contexts: data_type_expect_block: - match: \{ scope: punctuation.section.block.begin.cs - push: - - meta_scope: meta.block.cs - - match: \} - scope: punctuation.section.block.end.cs - pop: 2 - - include: attribute - - include: class_declaration - - include: interface_declaration - - include: delegate_declaration - - include: method_declaration - - include: stray_close_bracket + push: data_type_inside_block + - include: terminator - match: \S* scope: invalid.illegal.cs pop: true + data_type_inside_block: + - meta_scope: meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 2 + - include: attribute + - include: class_declaration + - include: interface_declaration + - include: delegate_declaration + - include: method_declaration + - include: stray_close_bracket + data_type_parameter: - match: '<' scope: meta.generic.cs punctuation.definition.generic.begin.cs @@ -555,8 +554,7 @@ contexts: - match: '{{name}}' scope: entity.other.inherited-class.cs push: - - maybe_terminator - - maybe_constructor_parameters + - function_call_begin_paren - include: type type_constraint_common: @@ -800,17 +798,19 @@ contexts: - include: attribute - include: lambdas - - match: (?=[^\s\[]) - set: - - match: '\s*\b(out|ref|this|params|in)\s+' - captures: - 1: storage.modifier.parameter.cs - - match: \s - pop: true - - include: type + - match: (?=[^\s\[;]) + set: method_param_type_modifier - match: (?=\}|\)|>|\]|;) pop: true + method_param_type_modifier: + - match: '\s*\b(out|ref|this|params|in)\s+' + captures: + 1: storage.modifier.parameter.cs + - match: \s + pop: true + - include: type + constructor_prebody: - meta_scope: meta.method.constructor.cs - match: ':' @@ -1572,15 +1572,17 @@ contexts: type_tuple: - match: \( scope: punctuation.section.sequence.begin.cs - set: - - meta_scope: meta.sequence.tuple.cs - - match: \) - scope: punctuation.section.sequence.end.cs - pop: true - - match: ',' - scope: punctuation.separator.sequence.cs - - match: (?=\S) - push: var_declaration_explicit + set: type_tuple_content + + type_tuple_content: + - meta_scope: meta.sequence.tuple.cs + - match: \) + scope: punctuation.section.sequence.end.cs + pop: true + - match: ',' + scope: punctuation.separator.sequence.cs + - match: (?=\S) + push: var_declaration_explicit type_common: - include: namespace_variables diff --git a/C#/tests/syntax_test_C#12.cs b/C#/tests/syntax_test_C#12.cs new file mode 100644 index 0000000000..b23910be4a --- /dev/null +++ b/C#/tests/syntax_test_C#12.cs @@ -0,0 +1,40 @@ +/// SYNTAX TEST "Packages/C#/C#.sublime-syntax" + +public class InvalidException(string _message) : Exception(_message); +///^^^ storage.modifier.access.cs +/// ^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs +/// ^^^^^ keyword.declaration.class.cs +/// ^^^^^^^^^^^^^^^^ entity.name.class.cs +/// ^^^^^^^^^^^^^^^^^ meta.class.constructor.parameters.cs +/// ^ punctuation.section.parameters.begin.cs +/// ^^^^^^ storage.type.cs +/// ^^^^^^^^ variable.parameter.cs +/// ^ punctuation.section.parameters.end.cs +/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs +/// ^ punctuation.separator.type.cs +/// ^^^^^^^^^ entity.other.inherited-class.cs +/// ^^^^^^^^^^ meta.function-call.cs meta.group.cs +/// ^ punctuation.section.group.begin.cs +/// ^^^^^^^^ variable.other.cs +/// ^ punctuation.section.group.end.cs +/// ^ punctuation.terminator.statement.cs +/// ^ - meta.class + +public class NotFoundException(string _message) : Exception(_message); +///^^^ storage.modifier.access.cs +/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs +/// ^^^^^ keyword.declaration.class.cs +/// ^^^^^^^^^^^^^^^^^ entity.name.class.cs +/// ^^^^^^^^^^^^^^^^^ meta.class.constructor.parameters.cs +/// ^ punctuation.section.parameters.begin.cs +/// ^^^^^^ storage.type.cs +/// ^^^^^^^^ variable.parameter.cs +/// ^ punctuation.section.parameters.end.cs +/// ^^^^^^^^^^^^^^^^^^^^^^^ meta.class.cs +/// ^ punctuation.separator.type.cs +/// ^^^^^^^^^ entity.other.inherited-class.cs +/// ^^^^^^^^^^ meta.function-call.cs meta.group.cs +/// ^ punctuation.section.group.begin.cs +/// ^^^^^^^^ variable.other.cs +/// ^ punctuation.section.group.end.cs +/// ^ punctuation.terminator.statement.cs diff --git a/C#/tests/syntax_test_C#8.cs b/C#/tests/syntax_test_C#8.cs index 9b6dc84daf..b8db83b082 100644 --- a/C#/tests/syntax_test_C#8.cs +++ b/C#/tests/syntax_test_C#8.cs @@ -323,7 +323,7 @@ namespace CommonTests.Attributes; [AttributeUsage(AttributeTargets.Method)] public class CustomAutoDataAttribute() : AutoDataAttribute( () => -///^^^^^^ meta.class.constructor.parameters.cs +///^^^^^^^ meta.class.cs meta.function-call.cs meta.group.cs /// ^^^^^ meta.function.anonymous.cs meta.group.cs /// ^ punctuation.section.group.begin.cs /// ^ meta.group.cs punctuation.section.group.end.cs @@ -333,8 +333,8 @@ public class CustomAutoDataAttribute() : AutoDataAttribute( fixture.Customizations.Add(new DateOnlySpecimenBuilder()); return fixture; }); -///^^^ meta.class.constructor.parameters.cs +///^^^ meta.class.cs meta.function-call.cs meta.group.cs /// ^ punctuation.section.block.end.cs -/// ^ punctuation.section.parameters.end.cs +/// ^ punctuation.section.group.end.cs /// ^ meta.class.cs punctuation.terminator.statement.cs