Skip to content

Commit

Permalink
C# improvements (#1444)
Browse files Browse the repository at this point in the history
A complete rewrite of the C# language to support almost every feature of C# 8.0.
  • Loading branch information
RunDevelopment authored Mar 24, 2020
1 parent 43efde2 commit 42b1546
Show file tree
Hide file tree
Showing 24 changed files with 1,934 additions and 177 deletions.
394 changes: 336 additions & 58 deletions components/prism-csharp.js

Large diffs are not rendered by default.

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.

258 changes: 258 additions & 0 deletions tests/languages/csharp/attribute_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
[Foo]
[Foo(1, 2)]
[Foo(1, 2, Name = "bar")]
[Foo, Bar]
[Foo("()"), Bar("[]"), Baz]

[return: MaybeNull]
[assembly: InternalsVisibleTo("Tests")]

[assembly: Foo]
[module: Foo]
[field: Foo]
[event: Foo]
[method: Foo]
[param: Foo]
[property: Foo]
[return: Foo]
[type: Foo]

// not attributes

var a = d
[Foo];
var b = new Foo<int>?[Count];
var c = new (int, int)[Count];

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

[
["punctuation", "["],
["attribute", [
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["class-name", [
"Foo"
]],
["attribute-arguments", [
["punctuation", "("],
["number", "1"],
["punctuation", ","],
["number", "2"],
["punctuation", ")"]
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["class-name", [
"Foo"
]],
["attribute-arguments", [
["punctuation", "("],
["number", "1"],
["punctuation", ","],
["number", "2"],
["punctuation", ","],
" Name ",
["operator", "="],
["string", "\"bar\""],
["punctuation", ")"]
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["class-name", [
"Foo"
]],
["punctuation", ","],
["class-name", [
"Bar"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["class-name", [
"Foo"
]],
["attribute-arguments", [
["punctuation", "("],
["string", "\"()\""],
["punctuation", ")"]
]],
["punctuation", ","],
["class-name", [
"Bar"
]],
["attribute-arguments", [
["punctuation", "("],
["string", "\"[]\""],
["punctuation", ")"]
]],
["punctuation", ","],
["class-name", [
"Baz"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "return"],
["punctuation", ":"],
["class-name", [
"MaybeNull"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "assembly"],
["punctuation", ":"],
["class-name", [
"InternalsVisibleTo"
]],
["attribute-arguments", [
["punctuation", "("],
["string", "\"Tests\""],
["punctuation", ")"]
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "assembly"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "module"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "field"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "event"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "method"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "param"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "property"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "return"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["punctuation", "["],
["attribute", [
["target", "type"],
["punctuation", ":"],
["class-name", [
"Foo"
]]
]],
["punctuation", "]"],
["comment", "// not attributes"],
["class-name", [
["keyword", "var"]
]],
" a ",
["operator", "="],
" d\n",
["punctuation", "["],
"Foo",
["punctuation", "]"],
["punctuation", ";"],
["class-name", [
["keyword", "var"]
]],
" b ",
["operator", "="],
["keyword", "new"],
["constructor-invocation", [
"Foo",
["punctuation", "<"],
["keyword", "int"],
["punctuation", ">"],
["punctuation", "?"]
]],
["punctuation", "["],
"Count",
["punctuation", "]"],
["punctuation", ";"],
["class-name", [
["keyword", "var"]
]],
" c ",
["operator", "="],
["keyword", "new"],
["constructor-invocation", [
["punctuation", "("],
["keyword", "int"],
["punctuation", ","],
["keyword", "int"],
["punctuation", ")"]
]],
["punctuation", "["],
"Count",
["punctuation", "]"],
["punctuation", ";"]
]

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

Checks for class names of attributes.
110 changes: 110 additions & 0 deletions tests/languages/csharp/class-name-declaration_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
class Foo
interface BarBaz
struct Foo
enum Foo
class Foo<A, B>
interface Bar<out T>

// not variables
public static RGBColor FromRainbow(Rainbow colorBand) =>
colorBand switch
{
Rainbow.Red => new RGBColor(0xFF, 0x00, 0x00),
_ => throw new ArgumentException(message: "invalid enum value", paramName: nameof(colorBand)),
};

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

[
["keyword", "class"],
["class-name", ["Foo"]],

["keyword", "interface"],
["class-name", ["BarBaz"]],

["keyword", "struct"],
["class-name", ["Foo"]],

["keyword", "enum"],
["class-name", ["Foo"]],

["keyword", "class"],
["class-name", [
"Foo",
["punctuation", "<"],
"A",
["punctuation", ","],
" B",
["punctuation", ">"]
]],

["keyword", "interface"],
["class-name", [
"Bar",
["punctuation", "<"],
["keyword", "out"],
" T",
["punctuation", ">"]
]],

["comment", "// not variables"],

["keyword", "public"],
["keyword", "static"],
["return-type", [
"RGBColor"
]],
["function", "FromRainbow"],
["punctuation", "("],
["class-name", [
"Rainbow"
]],
" colorBand",
["punctuation", ")"],
["operator", "=>"],
"\n\tcolorBand ",
["keyword", "switch"],
["punctuation", "{"],
"\n\t\tRainbow",
["punctuation", "."],
"Red ",
["operator", "=>"],
["keyword", "new"],
["constructor-invocation", [
"RGBColor"
]],
["punctuation", "("],
["number", "0xFF"],
["punctuation", ","],
["number", "0x00"],
["punctuation", ","],
["number", "0x00"],
["punctuation", ")"],
["punctuation", ","],
"\n\t\t_ ",
["operator", "=>"],
["keyword", "throw"],
["keyword", "new"],
["constructor-invocation", [
"ArgumentException"
]],
["punctuation", "("],
["named-parameter", "message"],
["punctuation", ":"],
["string", "\"invalid enum value\""],
["punctuation", ","],
["named-parameter", "paramName"],
["punctuation", ":"],
["keyword", "nameof"],
["punctuation", "("],
"colorBand",
["punctuation", ")"],
["punctuation", ")"],
["punctuation", ","],
["punctuation", "}"],
["punctuation", ";"]
]

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

Checks for class names at the class declaration.
Loading

0 comments on commit 42b1546

Please sign in to comment.