Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#] Support tuples whose commas are not on the same line as the open paren #2838

Merged
merged 2 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 48 additions & 36 deletions C#/C#.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1330,43 +1330,12 @@ contexts:
2: punctuation.separator.cs
3: punctuation.section.brackets.end.cs
4: keyword.operator.pointer.cs
- match: \((?=(?:[^,)(]|\([^\)]*\))*,)
scope: punctuation.section.group.begin.cs
push:
- meta_scope: meta.group.tuple.cs
- match: \)
scope: punctuation.section.group.end.cs
pop: true
- match: ','
scope: punctuation.separator.tuple.cs
- match: ':'
scope: keyword.operator.assignment.cs
- match: _\b
scope: variable.language.deconstruction.discard.cs
- match: (?!{{reserved}})(?={{namespaced_name}}{{type_suffix}}\s+{{name}}\s*[:,])
push: var_declaration_explicit
- match: '({{name}})(<)'
captures:
1: support.type.cs
2: meta.generic.cs punctuation.definition.generic.begin.cs
push:
- meta_content_scope: meta.generic.cs
- match: ','
scope: punctuation.separator.type.cs
- match: '>'
scope: meta.generic.cs punctuation.definition.generic.end.cs
pop: true
- include: type
- include: line_of_code_in_no_semicolon
- match: \(
scope: punctuation.section.group.begin.cs
push:
- meta_scope: meta.group.cs
- match: \)
scope: punctuation.section.group.end.cs
pop: true
- include: lambdas
- include: line_of_code_in_no_semicolon
branch_point: tuple_or_group
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
branch:
- group
- tuple
- match: \{
scope: punctuation.section.block.begin.cs
set:
Expand All @@ -1377,6 +1346,49 @@ contexts:
- match: (?=\}|\)|>|\]|,|{{reserved}})
pop: true

tuple:
- meta_scope: meta.group.tuple.cs
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
- match: \)
scope: punctuation.section.group.end.cs
pop: true
- match: ','
scope: punctuation.separator.tuple.cs
- match: ':'
scope: keyword.operator.assignment.cs
- match: _\b
scope: variable.language.deconstruction.discard.cs
- match: (?!{{reserved}})(?={{namespaced_name}}{{type_suffix}}\s+{{name}}\s*[:,])
push: var_declaration_explicit
- match: '({{name}})(<)'
captures:
1: support.type.cs
2: meta.generic.cs punctuation.definition.generic.begin.cs
push:
deathaxe marked this conversation as resolved.
Show resolved Hide resolved
- meta_content_scope: meta.generic.cs
- match: ','
scope: punctuation.separator.type.cs
- match: (>)\s*(\()
captures:
1: meta.generic.cs punctuation.definition.generic.end.cs
2: meta.function-call.cs meta.group.cs punctuation.section.group.begin.cs
set: [function_call_arguments, arguments]
- match: '>'
scope: meta.generic.cs punctuation.definition.generic.end.cs
pop: true
- include: type
- include: line_of_code_in_no_semicolon
- include: line_of_code_in_no_semicolon

group:
- meta_scope: meta.group.cs
- match: \)
scope: punctuation.section.group.end.cs
pop: true
- match: ','
fail: tuple_or_group
- include: lambdas
- include: line_of_code_in_no_semicolon

attribute_arguments:
- meta_content_scope: meta.annotation.cs meta.group.cs
- match: ''
Expand Down Expand Up @@ -1428,7 +1440,7 @@ contexts:
scope: invalid.illegal.expected-close-paren.cs
pop: true
- include: stray_close_bracket
- match: '(?=\S)'
- match: (?=\S)
push:
- include: lambdas
- include: line_of_code_in_no_semicolon
Expand Down
16 changes: 16 additions & 0 deletions C#/tests/syntax_test_C#7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ public void TupleTest () {
/// ^ punctuation.section.group.end
/// ^ punctuation.terminator.statement

(
/// ^ meta.group.tuple punctuation.section.group.begin
string Alpha,
/// ^^^^^^ storage.type
/// ^^^^^ variable.other
/// ^ punctuation.separator.tuple
string Beta
) namedLetters = ("a", "b");
/// ^ punctuation.section.group.end
/// ^^^^^^^^^^^^ variable.other
/// ^ keyword.operator.assignment
/// ^ punctuation.section.group.begin
/// ^ punctuation.separator.tuple
/// ^ punctuation.section.group.end
/// ^ punctuation.terminator.statement

(SomeType[] Alpha, SomeType<int> Beta) example = (a, b);
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.group.tuple
/// ^ punctuation.section.group.begin
Expand Down