Skip to content

Commit

Permalink
Improvements to C# operator and punctuation (#1532)
Browse files Browse the repository at this point in the history
Solve the issue of [C# breaking ligature fonts with the `=>` operator](#1133 (comment)). `=>` is now an operator.

There are also some other changes.

1. `?` and `:` are now all included by `punctuation`.
    Because `:` cannot be included in `operator` (because it is also used for inheritance)
the `?` shouldn't be an `operator` either.
2.  `??` and `?.` were added to `punctuation`.
    They weren't explicitly supported before.
3. An operator-test was added.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Dec 1, 2018
1 parent 00bfc96 commit 3b1e091
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 11 deletions.
6 changes: 4 additions & 2 deletions components/prism-csharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ Prism.languages.csharp = Prism.languages.extend('clike', {
}
}
],
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i,
'operator': />>=?|<<=?|[-=]>|([-+&|?])\1|~|[-+*/%&|^!=<>]=?/,
'punctuation': /\?\.?|::|[{}[\];(),.:]/
});

Prism.languages.insertBefore('csharp', 'class-name', {
Expand Down Expand Up @@ -76,4 +78,4 @@ Prism.languages.insertBefore('csharp', 'class-name', {
}
});

Prism.languages.dotnet = Prism.languages.csharp;
Prism.languages.dotnet = Prism.languages.csharp;
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.

12 changes: 4 additions & 8 deletions tests/languages/csharp/issue1371.test
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class Works : LandAnimal {
["class-name", ["Container"]],
["punctuation", "("],
"f ",
["operator", "="],
["operator", ">"],
["operator", "=>"],
["punctuation", "{"],
"\r\n f",
["punctuation", "."],
Expand Down Expand Up @@ -82,8 +81,7 @@ class Works : LandAnimal {
["function", "Move"],
["punctuation", "("],
["punctuation", ")"],
["operator", "="],
["operator", ">"],
["operator", "=>"],
["function", "Run"],
["punctuation", "("],
["punctuation", ")"],
Expand All @@ -100,8 +98,7 @@ class Works : LandAnimal {
["function", "Move"],
["punctuation", "("],
["punctuation", ")"],
["operator", "="],
["operator", ">"],
["operator", "=>"],
["function", "Run"],
["punctuation", "("],
["punctuation", ")"],
Expand All @@ -118,8 +115,7 @@ class Works : LandAnimal {
["function", "Move"],
["punctuation", "("],
["punctuation", ")"],
["operator", "="],
["operator", ">"],
["operator", "=>"],
["function", "Run"],
["punctuation", "("],
["punctuation", ")"],
Expand Down
60 changes: 60 additions & 0 deletions tests/languages/csharp/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
+ - * / % -- ++
>> <<
~ & | ^
+= -= *= /= %= >>= <<= &= |= ^=
! && ||
-> =>
= == != < > <= >=
??

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

[
["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],
["operator", "%"],
["operator", "--"],
["operator", "++"],

["operator", ">>"],
["operator", "<<"],

["operator", "~"],
["operator", "&"],
["operator", "|"],
["operator", "^"],

["operator", "+="],
["operator", "-="],
["operator", "*="],
["operator", "/="],
["operator", "%="],
["operator", ">>="],
["operator", "<<="],
["operator", "&="],
["operator", "|="],
["operator", "^="],

["operator", "!"],
["operator", "&&"],
["operator", "||"],

["operator", "->"],
["operator", "=>"],

["operator", "="],
["operator", "=="],
["operator", "!="],
["operator", "<"],
["operator", ">"],
["operator", "<="],
["operator", ">="],

["operator", "??"]
]

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

Checks for all operators.
27 changes: 27 additions & 0 deletions tests/languages/csharp/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
. , ; : ::
? ?.
[ ] { } ( )

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

[
["punctuation", "."],
["punctuation", ","],
["punctuation", ";"],
["punctuation", ":"],
["punctuation", "::"],

["punctuation", "?"],
["punctuation", "?."],

["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", "("],
["punctuation", ")"]
]

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

Checks for punctuation.

0 comments on commit 3b1e091

Please sign in to comment.