Skip to content
Open
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
97 changes: 86 additions & 11 deletions C#/C#.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,18 @@ contexts:
pop: true

delegate_declaration:
- match: \b(delegate)\b\s+
# delegate function pointer declaration
- match: \b(delegate)\s*(\*)
captures:
1: storage.type.delegate.cs
2: keyword.operator.pointer.cs
push:
- variables_declaration
- funcptr_type_meta
- funcptr_parameter_list
- funcptr_type_modifier
# delegate function declaration
- match: \b(delegate)\s+
captures:
1: storage.type.delegate.cs
push: delegate_type
Expand Down Expand Up @@ -599,9 +610,7 @@ contexts:
data_type_parameter:
- match: '<'
scope: meta.generic.cs punctuation.definition.generic.begin.cs
push:
- meta_content_scope: meta.generic.cs
- include: type_parameter
push: type_parameter
- match: (?=\S)
pop: true

Expand Down Expand Up @@ -1237,7 +1246,8 @@ contexts:
pop: true

keywords:
- match: '\b(this|base)\s*(\[)'
- include: funcptr_types
- match: \b(this|base)\s*(\[)
captures:
1: variable.language.cs
2: meta.brackets.cs punctuation.section.brackets.begin.cs
Expand Down Expand Up @@ -1664,6 +1674,71 @@ contexts:
pop: true
- include: line_of_code_in

funcptr_types:
# https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/function-pointers
- match: (delegate)\s*(\*)
captures:
1: storage.type.delegate.cs
2: keyword.operator.pointer.cs
push:
- funcptr_type_meta
- funcptr_parameter_list
- funcptr_type_modifier

funcptr_type_meta:
- meta_include_prototype: false
- meta_scope: meta.type.funcptr.cs
- match: ''
pop: true

funcptr_type_modifier:
- match: \s*(managed)\b
scope: storage.modifier.delegate.cs
pop: 1
- match: \s*(unmanaged)\b
scope: storage.modifier.delegate.cs
set: funcptr_type_calling_convention
- match: (?=[^\n])
pop: true

funcptr_type_calling_convention:
- match: \s*(\[)
captures:
1: meta.brackets.cs punctuation.section.brackets.begin.cs
set: inside_funcptr_type_calling_convention
- match: (?=[^\n])
pop: true

inside_funcptr_type_calling_convention:
- meta_content_scope: meta.brackets.cs
- match: \]
scope: meta.brackets.cs punctuation.section.brackets.end.cs
pop: true
- match: ','
scope: punctuation.separator.type.cs
- match: (?:Cdecl|Stdcall|Thiscall|Fastcall)\b
scope: storage.modifier.funcptr.cs
- include: type

funcptr_parameter_list:
- match: \s*(<)
captures:
1: meta.generic.cs punctuation.definition.generic.begin.cs
set: inside_funcptr_parameter_list
- match: (?=[^\n])
pop: true

inside_funcptr_parameter_list:
- meta_content_scope: meta.generic.cs
- match: '>'
scope: meta.generic.cs punctuation.definition.generic.end.cs
pop: true
- match: ','
scope: punctuation.separator.type.cs
- match: (?:in|out|ref|readonly)\b
scope: storage.modifier.cs
- include: type

type:
- include: type_common
- match: (?=\()
Expand All @@ -1686,7 +1761,8 @@ contexts:

type_common:
- include: namespace_variables
- match: '(class|struct|enum)'
- include: funcptr_types
- match: (?:class|struct|enum)\b
scope: storage.type.other.cs
- match: 'new\s*\(\s*\)'
scope: keyword.operator.new.cs
Expand Down Expand Up @@ -1716,8 +1792,6 @@ contexts:
pop: true

type_arg_param_common:
- match: ','
scope: punctuation.separator.type.cs
- match: '(>){{type_suffix_capture}}'
captures:
1: meta.generic.cs punctuation.definition.generic.end.cs
Expand All @@ -1728,18 +1802,19 @@ contexts:
6: punctuation.section.brackets.end.cs
7: keyword.operator.pointer.cs
pop: true
- match: ','
scope: punctuation.separator.type.cs
- include: type

type_argument:
- meta_content_scope: meta.generic.cs
- include: type_arg_param_common

type_parameter:
- match: '(in|out)\b'
- meta_content_scope: meta.generic.cs
- match: (?:in|out)\b
scope: storage.modifier.cs
- include: type_arg_param_common
- match: '{{name}}'
scope: support.type.cs

type_no_space:
- include: type
Expand Down
Loading