C#: More generic class-name highlighting. Fix #1365
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
diff --git a/components/prism-csharp.js b/components/prism-csharp.js
index d804ade..84a36e6 100644
--- a/components/prism-csharp.js
+++ b/components/prism-csharp.js
@@ -13,7 +13,17 @@ Prism.languages.csharp = Prism.languages.extend('clike', {
'number': /\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i
});
-Prism.languages.insertBefore('csharp', 'keyword', {
+if (Prism.util.type(Prism.languages.csharp['class-name']) !== 'Array') {
+ Prism.languages.csharp['class-name'] = [Prism.languages.csharp['class-name']];
+}
+Prism.languages.csharp['class-name'].push({
+ pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?!\()/,
+ inside: {
+ punctuation: /\./
+ }
+});
+
+Prism.languages.insertBefore('csharp', 'class-name', {
'generic-method': {
pattern: /[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,
alias: 'function',
diff --git a/components/prism-csharp.min.js b/components/prism-csharp.min.js
index 02a664e..00f441b 100644
--- a/components/prism-csharp.min.js
+++ b/components/prism-csharp.min.js
@@ -1 +1 @@
-Prism.languages.csharp=Prism.languages.extend("clike",{keyword:/\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,string:[{pattern:/@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,greedy:!0},{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,greedy:!0}],number:/\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i}),Prism.languages.insertBefore("csharp","keyword",{"generic-method":{pattern:/[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,alias:"function",inside:{keyword:Prism.languages.csharp.keyword,punctuation:/[<>(),.:]/}},preprocessor:{pattern:/(^\s*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.dotnet=Prism.languages.csharp;
\ No newline at end of file
+Prism.languages.csharp=Prism.languages.extend("clike",{keyword:/\b(?:abstract|add|alias|as|ascending|async|await|base|bool|break|byte|case|catch|char|checked|class|const|continue|decimal|default|delegate|descending|do|double|dynamic|else|enum|event|explicit|extern|false|finally|fixed|float|for|foreach|from|get|global|goto|group|if|implicit|in|int|interface|internal|into|is|join|let|lock|long|namespace|new|null|object|operator|orderby|out|override|params|partial|private|protected|public|readonly|ref|remove|return|sbyte|sealed|select|set|short|sizeof|stackalloc|static|string|struct|switch|this|throw|true|try|typeof|uint|ulong|unchecked|unsafe|ushort|using|value|var|virtual|void|volatile|where|while|yield)\b/,string:[{pattern:/@("|')(?:\1\1|\\[\s\S]|(?!\1)[^\\])*\1/,greedy:!0},{pattern:/("|')(?:\\.|(?!\1)[^\\\r\n])*?\1/,greedy:!0}],number:/\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)f?/i}),"Array"!==Prism.util.type(Prism.languages.csharp["class-name"])&&(Prism.languages.csharp["class-name"]=[Prism.languages.csharp["class-name"]]),Prism.languages.csharp["class-name"].push({pattern:/\b[A-Z]\w*(?:\.\w+)*\b(?!\()/,inside:{punctuation:/\./}}),Prism.languages.insertBefore("csharp","class-name",{"generic-method":{pattern:/[a-z0-9_]+\s*<[^>\r\n]+?>\s*(?=\()/i,alias:"function",inside:{keyword:Prism.languages.csharp.keyword,punctuation:/[<>(),.:]/}},preprocessor:{pattern:/(^\s*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.dotnet=Prism.languages.csharp;
\ No newline at end of file
diff --git a/tests/languages/csharp+aspnet/directive_feature.test b/tests/languages/csharp+aspnet/directive_feature.test
index f19c2a8..7e5ff3a 100644
--- a/tests/languages/csharp+aspnet/directive_feature.test
+++ b/tests/languages/csharp+aspnet/directive_feature.test
@@ -10,59 +10,65 @@
[
["directive tag", [
["directive tag", "<%:"],
- " Page",
- ["punctuation", "."],
- "Title ",
+ ["class-name", [
+ "Page",
+ ["punctuation", "."],
+ "Title"
+ ]],
["directive tag", "%>"]
]],
["directive tag", [
- ["directive tag", "<%#:"],
- "Item",
- ["punctuation", "."],
- "ProductID",
- ["directive tag", "%>"]
- ]],
+ ["directive tag", "<%#:"],
+ ["class-name", [
+ "Item",
+ ["punctuation", "."],
+ "ProductID"
+ ]],
+ ["directive tag", "%>"]
+ ]],
- ["tag", [
- ["tag", [
- ["punctuation", "<"],
- "a"
- ]],
- ["attr-name", [
- "href"
- ]],
- ["attr-value", [
- ["punctuation", "="],
- ["punctuation", "\""],
- "ProductDetails.aspx?productID=",
- ["directive tag", [
- ["directive tag", "<%#:"],
- "Item",
- ["punctuation", "."],
- "ProductID",
- ["directive tag", "%>"]
- ]],
- ["punctuation", "\""]
- ]],
- ["punctuation", ">"]
- ]],
+ ["tag", [
+ ["tag", [
+ ["punctuation", "<"],
+ "a"
+ ]],
+ ["attr-name", [
+ "href"
+ ]],
+ ["attr-value", [
+ ["punctuation", "="],
+ ["punctuation", "\""],
+ "ProductDetails.aspx?productID=",
+ ["directive tag", [
+ ["directive tag", "<%#:"],
+ ["class-name", [
+ "Item",
+ ["punctuation", "."],
+ "ProductID"
+ ]],
+ ["directive tag", "%>"]
+ ]],
+ ["punctuation", "\""]
+ ]],
+ ["punctuation", ">"]
+ ]],
- ["directive tag", [
- ["directive tag", "<%"],
- ["keyword", "if"],
- ["punctuation", "("],
- "foo",
- ["punctuation", ")"],
- ["punctuation", "{"],
- ["directive tag", "%>"]
- ]],
- "\r\n\tfoobar\r\n",
- ["directive tag", [
- ["directive tag", "<%"],
- ["punctuation", "}"],
- ["directive tag", "%>"]
- ]]
+ ["directive tag", [
+ ["directive tag", "<%"],
+ ["keyword", "if"],
+ ["punctuation", "("],
+ "foo",
+ ["punctuation", ")"],
+ ["punctuation", "{"],
+ ["directive tag", "%>"]
+ ]],
+ "\r\n\tfoobar\r\n",
+ ["directive tag", [
+ ["directive tag", "<%"],
+ ["punctuation", "}"],
+ ["directive tag", "%>"]
+ ]]
]
----------------------------------------------------
diff --git a/tests/languages/csharp/class-name_feature.test b/tests/languages/csharp/class-name_feature.test
new file mode 100644
index 0000000..1f8bfa1
--- /dev/null
+++ b/tests/languages/csharp/class-name_feature.test
@@ -0,0 +1,21 @@
+class Foo
+interface BarBaz
+Foo.Barbaz
+
+----------------------------------------------------
+
+[
+ ["keyword", "class"],
+ ["class-name", ["Foo"]],
+ ["keyword", "interface"],
+ ["class-name", ["BarBaz"]],
+ ["class-name", [
+ "Foo",
+ ["punctuation", "."],
+ "Barbaz"
+ ]]
+]
+
+----------------------------------------------------
+
+Checks for class names.
\ No newline at end of file
diff --git a/tests/languages/csharp/issue1365.test b/tests/languages/csharp/issue1365.test
new file mode 100644
index 0000000..6aaf3c7
--- /dev/null
+++ b/tests/languages/csharp/issue1365.test
@@ -0,0 +1,39 @@
+interface ILogger {
+ void Init(SomeClass file);
+ void LogInfo(string message);
+}
+public class SomeClass : BaseClass {}
+
+----------------------------------------------------
+
+[
+ ["keyword", "interface"],
+ ["class-name", ["ILogger"]],
+ ["punctuation", "{"],
+ ["keyword", "void"],
+ ["function", "Init"],
+ ["punctuation", "("],
+ ["class-name", ["SomeClass"]],
+ " file",
+ ["punctuation", ")"],
+ ["punctuation", ";"],
+ ["keyword", "void"],
+ ["function", "LogInfo"],
+ ["punctuation", "("],
+ ["keyword", "string"],
+ " message",
+ ["punctuation", ")"],
+ ["punctuation", ";"],
+ ["punctuation", "}"],
+ ["keyword", "public"],
+ ["keyword", "class"],
+ ["class-name", ["SomeClass"]],
+ ["punctuation", ":"],
+ ["class-name", ["BaseClass"]],
+ ["punctuation", "{"],
+ ["punctuation", "}"]
+]
+
+----------------------------------------------------
+
+Checks for class names. See #1365
\ No newline at end of file