Skip to content

Commit b35772b

Browse files
authored
[C#] Add support for C#9 function pointers (#4376)
Fixes #3131 This commit adds `funcptr_...` contexts, implementing C#9 function pointers. see: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/function-pointers
1 parent 463760e commit b35772b

File tree

2 files changed

+432
-11
lines changed

2 files changed

+432
-11
lines changed

C#/C#.sublime-syntax

Lines changed: 86 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,18 @@ contexts:
471471
pop: true
472472

473473
delegate_declaration:
474-
- match: \b(delegate)\b\s+
474+
# delegate function pointer declaration
475+
- match: \b(delegate)\s*(\*)
476+
captures:
477+
1: storage.type.delegate.cs
478+
2: keyword.operator.pointer.cs
479+
push:
480+
- variables_declaration
481+
- funcptr_type_meta
482+
- funcptr_parameter_list
483+
- funcptr_type_modifier
484+
# delegate function declaration
485+
- match: \b(delegate)\s+
475486
captures:
476487
1: storage.type.delegate.cs
477488
push: delegate_type
@@ -611,9 +622,7 @@ contexts:
611622
data_type_parameter:
612623
- match: '<'
613624
scope: meta.generic.cs punctuation.definition.generic.begin.cs
614-
push:
615-
- meta_content_scope: meta.generic.cs
616-
- include: type_parameter
625+
push: type_parameter
617626
- match: (?=\S)
618627
pop: true
619628

@@ -1271,7 +1280,8 @@ contexts:
12711280
pop: true
12721281

12731282
keywords:
1274-
- match: '\b(this|base)\s*(\[)'
1283+
- include: funcptr_types
1284+
- match: \b(this|base)\s*(\[)
12751285
captures:
12761286
1: variable.language.cs
12771287
2: meta.brackets.cs punctuation.section.brackets.begin.cs
@@ -1698,6 +1708,71 @@ contexts:
16981708
pop: true
16991709
- include: line_of_code_in
17001710

1711+
funcptr_types:
1712+
# https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/function-pointers
1713+
- match: (delegate)\s*(\*)
1714+
captures:
1715+
1: storage.type.delegate.cs
1716+
2: keyword.operator.pointer.cs
1717+
push:
1718+
- funcptr_type_meta
1719+
- funcptr_parameter_list
1720+
- funcptr_type_modifier
1721+
1722+
funcptr_type_meta:
1723+
- meta_include_prototype: false
1724+
- meta_scope: meta.type.funcptr.cs
1725+
- match: ''
1726+
pop: true
1727+
1728+
funcptr_type_modifier:
1729+
- match: \s*(managed)\b
1730+
scope: storage.modifier.delegate.cs
1731+
pop: 1
1732+
- match: \s*(unmanaged)\b
1733+
scope: storage.modifier.delegate.cs
1734+
set: funcptr_type_calling_convention
1735+
- match: (?=[^\n])
1736+
pop: true
1737+
1738+
funcptr_type_calling_convention:
1739+
- match: \s*(\[)
1740+
captures:
1741+
1: meta.brackets.cs punctuation.section.brackets.begin.cs
1742+
set: inside_funcptr_type_calling_convention
1743+
- match: (?=[^\n])
1744+
pop: true
1745+
1746+
inside_funcptr_type_calling_convention:
1747+
- meta_content_scope: meta.brackets.cs
1748+
- match: \]
1749+
scope: meta.brackets.cs punctuation.section.brackets.end.cs
1750+
pop: true
1751+
- match: ','
1752+
scope: punctuation.separator.type.cs
1753+
- match: (?:Cdecl|Stdcall|Thiscall|Fastcall)\b
1754+
scope: storage.modifier.funcptr.cs
1755+
- include: type
1756+
1757+
funcptr_parameter_list:
1758+
- match: \s*(<)
1759+
captures:
1760+
1: meta.generic.cs punctuation.definition.generic.begin.cs
1761+
set: inside_funcptr_parameter_list
1762+
- match: (?=[^\n])
1763+
pop: true
1764+
1765+
inside_funcptr_parameter_list:
1766+
- meta_content_scope: meta.generic.cs
1767+
- match: '>'
1768+
scope: meta.generic.cs punctuation.definition.generic.end.cs
1769+
pop: true
1770+
- match: ','
1771+
scope: punctuation.separator.type.cs
1772+
- match: (?:in|out|ref|readonly)\b
1773+
scope: storage.modifier.cs
1774+
- include: type
1775+
17011776
type:
17021777
- include: type_common
17031778
- match: (?=\()
@@ -1720,7 +1795,8 @@ contexts:
17201795

17211796
type_common:
17221797
- include: namespace_variables
1723-
- match: '(class|struct|enum)'
1798+
- include: funcptr_types
1799+
- match: (?:class|struct|enum)\b
17241800
scope: storage.type.other.cs
17251801
- match: 'new\s*\(\s*\)'
17261802
scope: keyword.operator.new.cs
@@ -1750,8 +1826,6 @@ contexts:
17501826
pop: true
17511827

17521828
type_arg_param_common:
1753-
- match: ','
1754-
scope: punctuation.separator.type.cs
17551829
- match: '(>){{type_suffix_capture}}'
17561830
captures:
17571831
1: meta.generic.cs punctuation.definition.generic.end.cs
@@ -1762,18 +1836,19 @@ contexts:
17621836
6: punctuation.section.brackets.end.cs
17631837
7: keyword.operator.pointer.cs
17641838
pop: true
1839+
- match: ','
1840+
scope: punctuation.separator.type.cs
17651841
- include: type
17661842

17671843
type_argument:
17681844
- meta_content_scope: meta.generic.cs
17691845
- include: type_arg_param_common
17701846

17711847
type_parameter:
1772-
- match: '(in|out)\b'
1848+
- meta_content_scope: meta.generic.cs
1849+
- match: (?:in|out)\b
17731850
scope: storage.modifier.cs
17741851
- include: type_arg_param_common
1775-
- match: '{{name}}'
1776-
scope: support.type.cs
17771852

17781853
type_no_space:
17791854
- include: type

0 commit comments

Comments
 (0)