Skip to content

Commit 9b56156

Browse files
authoredJul 11, 2021
C#: Added 'record', 'init', and 'nullable' keyword (#2991)
1 parent bb93fac commit 9b56156

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed
 

‎components/prism-csharp.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
// keywords which represent a return or variable type
4545
type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
4646
// keywords which are used to declare a type
47-
typeDeclaration: 'class enum interface struct',
47+
typeDeclaration: 'class enum interface record struct',
4848
// contextual keywords
4949
// ("var" and "dynamic" are missing because they are used like types)
50-
contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into join let nameof not notnull on or orderby partial remove select set unmanaged value when where',
50+
contextual: 'add alias and ascending async await by descending from(?=\\s*(?:\\w|$)) get global group into init(?=\\s*;) join let nameof not notnull on or orderby partial remove select set unmanaged value when where',
5151
// all other keywords
5252
other: 'abstract as base break case catch checked const continue default delegate do else event explicit extern finally fixed for foreach goto if implicit in internal is lock namespace new null operator out override params private protected public readonly ref return sealed sizeof stackalloc static switch this throw try typeof unchecked unsafe using virtual volatile while yield'
5353
};
@@ -260,7 +260,7 @@
260260
inside: {
261261
// highlight preprocessor directives as keywords
262262
'directive': {
263-
pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
263+
pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,
264264
lookbehind: true,
265265
alias: 'keyword'
266266
}

‎components/prism-csharp.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/csharp/issue2991.test

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
record TestData
2+
{
3+
public string Name { get; init; }
4+
public void Func()
5+
{
6+
}
7+
}
8+
9+
record TestData(string Name);
10+
11+
----------------------------------------------------
12+
13+
[
14+
["keyword", "record"],
15+
["class-name", ["TestData"]],
16+
17+
["punctuation", "{"],
18+
19+
["keyword", "public"],
20+
["return-type", [
21+
["keyword", "string"]
22+
]],
23+
" Name ",
24+
["punctuation", "{"],
25+
["keyword", "get"],
26+
["punctuation", ";"],
27+
["keyword", "init"],
28+
["punctuation", ";"],
29+
["punctuation", "}"],
30+
31+
["keyword", "public"],
32+
["return-type", [
33+
["keyword", "void"]
34+
]],
35+
["function", "Func"],
36+
["punctuation", "("],
37+
["punctuation", ")"],
38+
["punctuation", "{"],
39+
["punctuation", "}"],
40+
41+
["punctuation", "}"],
42+
43+
["keyword", "record"],
44+
["class-name", ["TestData"]],
45+
["punctuation", "("],
46+
["class-name", [
47+
["keyword", "string"]
48+
]],
49+
" Name",
50+
["punctuation", ")"],
51+
["punctuation", ";"]
52+
]

‎tests/languages/csharp/keyword_feature.test

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ group
4343
if
4444
implicit
4545
in
46+
init;
4647
int;
4748
interface;
4849
internal
@@ -71,6 +72,7 @@ private
7172
protected
7273
public
7374
readonly
75+
record;
7476
ref
7577
remove
7678
return
@@ -154,6 +156,7 @@ yield
154156
["keyword", "if"],
155157
["keyword", "implicit"],
156158
["keyword", "in"],
159+
["keyword", "init"], ["punctuation", ";"],
157160
["keyword", "int"], ["punctuation", ";"],
158161
["keyword", "interface"], ["punctuation", ";"],
159162
["keyword", "internal"],
@@ -182,6 +185,7 @@ yield
182185
["keyword", "protected"],
183186
["keyword", "public"],
184187
["keyword", "readonly"],
188+
["keyword", "record"], ["punctuation", ";"],
185189
["keyword", "ref"],
186190
["keyword", "remove"],
187191
["keyword", "return"],

‎tests/languages/csharp/preprocessor_feature.test

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#endregion
88
#error
99
#line
10+
#nullable
1011
#pragma
1112
#region
1213
#undef
@@ -24,6 +25,7 @@
2425
["preprocessor", ["#", ["directive", "endregion"]]],
2526
["preprocessor", ["#", ["directive", "error"]]],
2627
["preprocessor", ["#", ["directive", "line"]]],
28+
["preprocessor", ["#", ["directive", "nullable"]]],
2729
["preprocessor", ["#", ["directive", "pragma"]]],
2830
["preprocessor", ["#", ["directive", "region"]]],
2931
["preprocessor", ["#", ["directive", "undef"]]],

0 commit comments

Comments
 (0)
Please sign in to comment.