diff --git a/C#/C#.sublime-syntax b/C#/C#.sublime-syntax index 2017d88667..51f6df494f 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 @@ -554,11 +553,31 @@ contexts: - include: type_constraint_common - match: '{{name}}' scope: entity.other.inherited-class.cs - push: - - maybe_terminator - - maybe_constructor_parameters + push: inherited_class_arguments - include: type + inherited_class_arguments: + - match: (?=\() + push: [inside_inherited_class_arguments, arguments, inherited_class_arguments-begin] + - match: (?=\S) + pop: true + + inherited_class_arguments-begin: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + pop: true + + inside_inherited_class_arguments: + - clear_scopes: 1 + - meta_include_prototype: false + - meta_scope: meta.class.constructor.arguments.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: true + - match: '' + pop: true + type_constraint_common: - match: (?=\{) pop: true @@ -800,17 +819,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: ':' @@ -1577,15 +1598,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..c48ffe6f63 --- /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.class.constructor.arguments.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.class.constructor.arguments.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..fea5193075 100644 --- a/C#/tests/syntax_test_C#8.cs +++ b/C#/tests/syntax_test_C#8.cs @@ -323,18 +323,18 @@ namespace CommonTests.Attributes; [AttributeUsage(AttributeTargets.Method)] public class CustomAutoDataAttribute() : AutoDataAttribute( () => -///^^^^^^ meta.class.constructor.parameters.cs +///^^^^^^^ meta.class.constructor.arguments.cs meta.group.cs /// ^^^^^ meta.function.anonymous.cs meta.group.cs /// ^ punctuation.section.group.begin.cs -/// ^ meta.group.cs punctuation.section.group.end.cs +/// ^ punctuation.section.group.end.cs /// ^^ keyword.declaration.function.arrow.cs { var fixture = new Fixture(); fixture.Customizations.Add(new DateOnlySpecimenBuilder()); return fixture; }); -///^^^ meta.class.constructor.parameters.cs +///^^^ meta.class.constructor.arguments.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