Skip to content

Commit

Permalink
C#: Added 'record', 'init', and 'nullable' keyword (#2991)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Jul 11, 2021
1 parent bb93fac commit 9b56156
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
6 changes: 3 additions & 3 deletions components/prism-csharp.js
Expand Up @@ -44,10 +44,10 @@
// keywords which represent a return or variable type
type: 'bool byte char decimal double dynamic float int long object sbyte short string uint ulong ushort var void',
// keywords which are used to declare a type
typeDeclaration: 'class enum interface struct',
typeDeclaration: 'class enum interface record struct',
// contextual keywords
// ("var" and "dynamic" are missing because they are used like types)
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',
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',
// all other keywords
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'
};
Expand Down Expand Up @@ -260,7 +260,7 @@
inside: {
// highlight preprocessor directives as keywords
'directive': {
pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
pattern: /(#)\b(?:define|elif|else|endif|endregion|error|if|line|nullable|pragma|region|undef|warning)\b/,
lookbehind: true,
alias: 'keyword'
}
Expand Down
2 changes: 1 addition & 1 deletion components/prism-csharp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions tests/languages/csharp/issue2991.test
@@ -0,0 +1,52 @@
record TestData
{
public string Name { get; init; }
public void Func()
{
}
}

record TestData(string Name);

----------------------------------------------------

[
["keyword", "record"],
["class-name", ["TestData"]],

["punctuation", "{"],

["keyword", "public"],
["return-type", [
["keyword", "string"]
]],
" Name ",
["punctuation", "{"],
["keyword", "get"],
["punctuation", ";"],
["keyword", "init"],
["punctuation", ";"],
["punctuation", "}"],

["keyword", "public"],
["return-type", [
["keyword", "void"]
]],
["function", "Func"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["punctuation", "}"],

["keyword", "record"],
["class-name", ["TestData"]],
["punctuation", "("],
["class-name", [
["keyword", "string"]
]],
" Name",
["punctuation", ")"],
["punctuation", ";"]
]
4 changes: 4 additions & 0 deletions tests/languages/csharp/keyword_feature.test
Expand Up @@ -43,6 +43,7 @@ group
if
implicit
in
init;
int;
interface;
internal
Expand Down Expand Up @@ -71,6 +72,7 @@ private
protected
public
readonly
record;
ref
remove
return
Expand Down Expand Up @@ -154,6 +156,7 @@ yield
["keyword", "if"],
["keyword", "implicit"],
["keyword", "in"],
["keyword", "init"], ["punctuation", ";"],
["keyword", "int"], ["punctuation", ";"],
["keyword", "interface"], ["punctuation", ";"],
["keyword", "internal"],
Expand Down Expand Up @@ -182,6 +185,7 @@ yield
["keyword", "protected"],
["keyword", "public"],
["keyword", "readonly"],
["keyword", "record"], ["punctuation", ";"],
["keyword", "ref"],
["keyword", "remove"],
["keyword", "return"],
Expand Down
2 changes: 2 additions & 0 deletions tests/languages/csharp/preprocessor_feature.test
Expand Up @@ -7,6 +7,7 @@
#endregion
#error
#line
#nullable
#pragma
#region
#undef
Expand All @@ -24,6 +25,7 @@
["preprocessor", ["#", ["directive", "endregion"]]],
["preprocessor", ["#", ["directive", "error"]]],
["preprocessor", ["#", ["directive", "line"]]],
["preprocessor", ["#", ["directive", "nullable"]]],
["preprocessor", ["#", ["directive", "pragma"]]],
["preprocessor", ["#", ["directive", "region"]]],
["preprocessor", ["#", ["directive", "undef"]]],
Expand Down

0 comments on commit 9b56156

Please sign in to comment.