Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding keyword 'record' 'init' 'nullable' (new syntax of C# 8, 9) #2991

Merged
merged 4 commits into from Jul 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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