Skip to content

Commit ea87d35

Browse files
committed
Add more keyword operators
1 parent 4e4e287 commit ea87d35

File tree

2 files changed

+112
-21
lines changed

2 files changed

+112
-21
lines changed

Diff for: syntax/cs.vim

+25-10
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ set cpoptions&vim
2323

2424
syn keyword csType bool byte char decimal double float int long object sbyte short string T uint ulong ushort var void dynamic
2525
syn keyword csType nint nuint " contextual
26-
syn keyword csStorage delegate enum interface namespace struct
26+
syn keyword csStorage enum interface namespace struct
27+
syn match csStorage "\<delegate\>"
2728
syn keyword csRepeat break continue do for foreach goto return while
28-
syn keyword csConditional else if switch
29+
syn keyword csConditional else if
30+
syn match csCondtional "\<switch\>"
2931
syn keyword csLabel case default
3032
syn match csOperatorError display +::+
3133
syn match csGlobal display +global::+
@@ -54,7 +56,7 @@ syn match csStatement "\<fixed\ze\_s*("
5456
syn keyword csStatement lock
5557
syn match csStatement "\<yield\ze\_s\+\%(return\|break\)\>"
5658

57-
syn keyword csUnspecifiedStatement as base in is nameof operator out params ref sizeof stackalloc this using
59+
syn keyword csUnspecifiedStatement as base in is operator out params ref this using
5860
syn keyword csUnsupportedStatement value
5961
syn keyword csUnspecifiedKeyword explicit implicit
6062

@@ -63,10 +65,22 @@ syn match csContextualStatement "\<\%(get\|set\|init\|add\|remove\)\ze\_s*\%([;{
6365
syn match csContextualStatement "\<where\>\ze[^:]\+:"
6466

6567
" Operators
66-
syn keyword csTypeOf typeof nextgroup=csTypeOfOperand,csTypeOfError skipwhite skipempty
67-
syn region csTypeOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
68-
syn match csTypeOfError "[^([:space:]]" contained
68+
syn keyword csKeywordOperator stackalloc
6969
syn match csKeywordOperator "\<\%(checked\|unchecked\)\ze\_s*("
70+
syn match csKeywordOperator "\<delegate\ze\_s*[({]"
71+
syn match csKeywordOperator "\<switch\ze\_s*{"
72+
syn match csKeywordOperator "\<with\ze\_s*{"
73+
74+
syn keyword csKeywordOperator typeof nextgroup=csTypeOfOperand,csMissingParenError skipwhite skipempty
75+
syn region csTypeOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
76+
77+
syn keyword csKeywordOperator sizeof nextgroup=csSizeOfOperand,csMissingParenError skipwhite skipempty
78+
syn region csSizeOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
79+
80+
syn keyword csKeywordOperator nameof nextgroup=csNameOfOperand,csMissingParenError skipwhite skipempty
81+
syn region csNameOfOperand matchgroup=csParens start="(" end=")" contained contains=csType
82+
83+
syn match csMissingParenError "[^([:space:]]" contained
7084

7185
" Punctuation
7286
syn match csBraces "[{}\[\]]" display
@@ -193,7 +207,7 @@ syn region csInterVerbString matchgroup=csQuote start=+$@"+ start=+@$"+ end=+"+
193207
syn region csBracketed matchgroup=csParens start=+(+ end=+)+ extend contained transparent contains=@csAll,csBraced,csBracketed
194208
syn region csBraced matchgroup=csParens start=+{+ end=+}+ extend contained transparent contains=@csAll,csBraced,csBracketed
195209

196-
syn cluster csAll contains=csCharacter,csClassType,@csComment,csContextualStatement,csEndColon,csIsType,csLabel,csLogicSymbols,csNewType,csBoolean,csConstant,@csNumber,csOpSymbols,csOperatorError,csParens,csPreCondit,csRegion,csString,csSummary,csType,csUnicodeNumber,csUnicodeSpecifier,csInterpolatedString,csVerbatimString,csInterVerbString,csUserType,csUserIdentifier,csUserInterface,csUserMethod
210+
syn cluster csAll contains=csCharacter,csClassType,@csComment,csContextualStatement,csEndColon,csIsType,csLabel,csLogicSymbols,csNewType,csBoolean,csConstant,@csNumber,csOpSymbols,csKeywordOperator,csOperatorError,csParens,csPreCondit,csRegion,csString,csSummary,csType,csUnicodeNumber,csUnicodeSpecifier,csInterpolatedString,csVerbatimString,csInterVerbString,csUserType,csUserIdentifier,csUserInterface,csUserMethod
197211

198212
" Keyword identifiers
199213
syn match csIdentifier "@\h\w*"
@@ -216,7 +230,7 @@ hi def link csUnsupportedStatement Statement
216230
hi def link csUnspecifiedKeyword Keyword
217231
hi def link csNew Statement
218232
hi def link csLinq Statement
219-
hi def link csIsAs Keyword
233+
hi def link csIsAs csKeywordOperator
220234
hi def link csAsyncModifier csModifier
221235
hi def link csContextualStatement Statement
222236

@@ -227,9 +241,10 @@ hi def link csBlockComment csComment
227241

228242
hi def link csKeywordOperator Keyword
229243
hi def link csAsyncOperator csKeywordOperator
230-
hi def link csTypeOf csKeywordOperator
231244
hi def link csTypeOfOperand Typedef
232-
hi def link csTypeOfError Error
245+
hi def link csSizeOfOperand Typedef
246+
hi def link csNameOfOperand Typedef
247+
hi def link csMissingParenError Error
233248
hi def link csOpSymbols Operator
234249
hi def link csLogicSymbols Operator
235250
hi def link csOperatorError Error

Diff for: test/operators.vader

+87-11
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,82 @@ Given cs (typeof operator):
7777
typeof(Dictionary<string,List<Image>>)
7878

7979
Execute:
80-
AssertEqual 'csTypeOf', SyntaxAt(1, 1)
81-
AssertEqual 'csParens', SyntaxAt(1, 7)
82-
AssertEqual 'csTypeOfOperand', SyntaxAt(1, 8)
83-
AssertEqual 'csParens', SyntaxAt(1, 38)
80+
AssertEqual 'csKeywordOperator', SyntaxOf('typeof')
81+
AssertEqual 'csParens', SyntaxOf('(')
82+
AssertEqual 'csTypeOfOperand', SyntaxOf('(\zs')
83+
AssertEqual 'csParens', SyntaxOf(')')
8484

8585
Given cs (typeof operator with space before open paren):
8686
typeof (Dictionary<string,List<Image>>)
8787

8888
Execute:
89-
AssertEqual 'csTypeOf', SyntaxAt(1, 1)
90-
AssertEqual 'csParens', SyntaxAt(1, 8)
91-
AssertEqual 'csTypeOfOperand', SyntaxAt(1, 9)
92-
AssertEqual 'csParens', SyntaxAt(1, 39)
89+
AssertEqual 'csKeywordOperator', SyntaxOf('typeof')
90+
AssertEqual 'csParens', SyntaxOf('(')
91+
AssertEqual 'csTypeOfOperand', SyntaxOf('(\zs')
92+
AssertEqual 'csParens', SyntaxOf(')')
9393

9494
Given cs (typeof operator with missing operand parens):
9595
typeof Dictionary<string,List<Image>>
9696

9797
Execute:
98-
AssertEqual 'csTypeOf', SyntaxAt(1, 1)
99-
AssertEqual 'csTypeOfError', SyntaxAt(1, 8)
98+
AssertEqual 'csKeywordOperator', SyntaxOf('typeof')
99+
AssertEqual 'csMissingParenError', SyntaxAt(1, 8)
100+
101+
Given cs (sizeof operator):
102+
sizeof(byte)
103+
104+
Execute:
105+
AssertEqual 'csKeywordOperator', SyntaxOf('sizeof')
106+
AssertEqual 'csParens', SyntaxOf('(')
107+
AssertEqual 'csType', SyntaxOf('(\zs')
108+
AssertEqual 'csParens', SyntaxOf(')')
109+
110+
Given cs (sizeof operator with space before open paren):
111+
sizeof (byte)
112+
113+
Execute:
114+
AssertEqual 'csKeywordOperator', SyntaxOf('sizeof')
115+
AssertEqual 'csParens', SyntaxOf('(')
116+
AssertEqual 'csType', SyntaxOf('(\zs')
117+
AssertEqual 'csParens', SyntaxOf(')')
118+
119+
Given cs (sizeof operator with missing operand parens):
120+
sizeof byte
121+
122+
Execute:
123+
AssertEqual 'csKeywordOperator', SyntaxOf('sizeof')
124+
AssertEqual 'csMissingParenError', SyntaxOf('b\zeyte')
125+
126+
Given cs (nameof operator):
127+
nameof(foobar)
128+
129+
Execute:
130+
AssertEqual 'csKeywordOperator', SyntaxOf('nameof')
131+
AssertEqual 'csParens', SyntaxOf('(')
132+
AssertEqual 'csNameOfOperand', SyntaxOf('(\zs')
133+
AssertEqual 'csParens', SyntaxOf(')')
134+
135+
Given cs (nameof operator with space before open paren):
136+
nameof (foobar)
137+
138+
Execute:
139+
AssertEqual 'csKeywordOperator', SyntaxOf('nameof')
140+
AssertEqual 'csParens', SyntaxOf('(')
141+
AssertEqual 'csNameOfOperand', SyntaxOf('(\zs')
142+
AssertEqual 'csParens', SyntaxOf(')')
143+
144+
Given cs (nameof operator with missing operand parens):
145+
nameof foobar
146+
147+
Execute:
148+
AssertEqual 'csKeywordOperator', SyntaxOf('nameof')
149+
AssertEqual 'csMissingParenError', SyntaxOf('f\zeoobar')
100150

101151
Given cs (await operator):
102152
await foobar();
103153

104154
Execute:
105-
AssertEqual 'csAsyncOperator', SyntaxAt(1, 1)
155+
AssertEqual 'csAsyncOperator', SyntaxOf('await')
106156

107157
Given cs (checked operator):
108158
var foobar = checked(42 + 1);
@@ -116,3 +166,29 @@ Given cs (unchecked operator):
116166
Execute:
117167
AssertEqual 'csKeywordOperator', SyntaxOf('unchecked')
118168

169+
Given cs (stackalloc operator):
170+
Span<byte> foobar = stackalloc byte[42];
171+
172+
Execute:
173+
AssertEqual 'csKeywordOperator', SyntaxOf('stackalloc')
174+
175+
Given cs (switch operator):
176+
var foo = bar switch { _ => 42 };
177+
178+
Execute:
179+
AssertEqual 'csKeywordOperator', SyntaxOf('switch')
180+
181+
Given cs (delegate operator):
182+
Func<byte> foobar = delegate (byte a) { return 42; };
183+
Action foobar = delegate { FortyTwo(); };
184+
185+
Execute:
186+
AssertEqual 'csKeywordOperator', SyntaxOf('delegate', 1)
187+
AssertEqual 'csKeywordOperator', SyntaxOf('delegate', 2)
188+
189+
Given cs (with operator):
190+
var foo = bar with { Baz = 42 };
191+
192+
Execute:
193+
AssertEqual 'csKeywordOperator', SyntaxOf('with')
194+

0 commit comments

Comments
 (0)