F#: Fixed comment false positive (#2703) F# has supports `(*)` to convert an operator into a function. This syntax collides with F# comments and produced false positives for comments. The comment pattern has been adjusted to not match `(*)`.
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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
diff --git a/components/prism-fsharp.js b/components/prism-fsharp.js
index 442e689..4b2ac05 100644
--- a/components/prism-fsharp.js
+++ b/components/prism-fsharp.js
@@ -1,7 +1,7 @@
Prism.languages.fsharp = Prism.languages.extend('clike', {
'comment': [
{
- pattern: /(^|[^\\])\(\*[\s\S]*?\*\)/,
+ pattern: /(^|[^\\])\(\*(?!\))[\s\S]*?\*\)/,
lookbehind: true
},
{
diff --git a/components/prism-fsharp.min.js b/components/prism-fsharp.min.js
index c44f1dd..3153afb 100644
--- a/components/prism-fsharp.min.js
+++ b/components/prism-fsharp.min.js
@@ -1 +1 @@
-Prism.languages.fsharp=Prism.languages.extend("clike",{comment:[{pattern:/(^|[^\\])\(\*[\s\S]*?\*\)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:{pattern:/(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,greedy:!0},"class-name":{pattern:/(\b(?:exception|inherit|interface|new|of|type)\s+|\w\s*:\s*|\s:\??>\s*)[.\w]+\b(?:\s*(?:->|\*)\s*[.\w]+\b)*(?!\s*[:.])/,lookbehind:!0,inside:{operator:/->|\*/,punctuation:/\./}},keyword:/\b(?:let|return|use|yield)(?:!\B|\b)|\b(?:abstract|and|as|assert|base|begin|class|default|delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|for|fun|function|global|if|in|inherit|inline|interface|internal|lazy|match|member|module|mutable|namespace|new|not|null|of|open|or|override|private|public|rec|select|static|struct|then|to|true|try|type|upcast|val|void|when|while|with|asr|land|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|constructor|continue|eager|event|external|fixed|functor|include|method|mixin|object|parallel|process|protected|pure|sealed|tailcall|trait|virtual|volatile)\b/,number:[/\b0x[\da-fA-F]+(?:un|lf|LF)?\b/,/\b0b[01]+(?:y|uy)?\b/,/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[fm]|e[+-]?\d+)?\b/i,/\b\d+(?:[IlLsy]|u[lsy]?|UL)?\b/],operator:/([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/}),Prism.languages.insertBefore("fsharp","keyword",{preprocessor:{pattern:/^[^\r\n\S]*#.*/m,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:else|endif|if|light|line|nowarn)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.insertBefore("fsharp","punctuation",{"computation-expression":{pattern:/[_a-z]\w*(?=\s*\{)/i,alias:"keyword"}}),Prism.languages.insertBefore("fsharp","string",{annotation:{pattern:/\[<.+?>\]/,inside:{punctuation:/^\[<|>\]$/,"class-name":{pattern:/^\w+$|(^|;\s*)[A-Z]\w*(?=\()/,lookbehind:!0},"annotation-content":{pattern:/[\s\S]+/,inside:Prism.languages.fsharp}}}});
\ No newline at end of file
+Prism.languages.fsharp=Prism.languages.extend("clike",{comment:[{pattern:/(^|[^\\])\(\*(?!\))[\s\S]*?\*\)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],string:{pattern:/(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,greedy:!0},"class-name":{pattern:/(\b(?:exception|inherit|interface|new|of|type)\s+|\w\s*:\s*|\s:\??>\s*)[.\w]+\b(?:\s*(?:->|\*)\s*[.\w]+\b)*(?!\s*[:.])/,lookbehind:!0,inside:{operator:/->|\*/,punctuation:/\./}},keyword:/\b(?:let|return|use|yield)(?:!\B|\b)|\b(?:abstract|and|as|assert|base|begin|class|default|delegate|do|done|downcast|downto|elif|else|end|exception|extern|false|finally|for|fun|function|global|if|in|inherit|inline|interface|internal|lazy|match|member|module|mutable|namespace|new|not|null|of|open|or|override|private|public|rec|select|static|struct|then|to|true|try|type|upcast|val|void|when|while|with|asr|land|lor|lsl|lsr|lxor|mod|sig|atomic|break|checked|component|const|constraint|constructor|continue|eager|event|external|fixed|functor|include|method|mixin|object|parallel|process|protected|pure|sealed|tailcall|trait|virtual|volatile)\b/,number:[/\b0x[\da-fA-F]+(?:un|lf|LF)?\b/,/\b0b[01]+(?:y|uy)?\b/,/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[fm]|e[+-]?\d+)?\b/i,/\b\d+(?:[IlLsy]|u[lsy]?|UL)?\b/],operator:/([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/}),Prism.languages.insertBefore("fsharp","keyword",{preprocessor:{pattern:/^[^\r\n\S]*#.*/m,alias:"property",inside:{directive:{pattern:/(\s*#)\b(?:else|endif|if|light|line|nowarn)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.insertBefore("fsharp","punctuation",{"computation-expression":{pattern:/[_a-z]\w*(?=\s*\{)/i,alias:"keyword"}}),Prism.languages.insertBefore("fsharp","string",{annotation:{pattern:/\[<.+?>\]/,inside:{punctuation:/^\[<|>\]$/,"class-name":{pattern:/^\w+$|(^|;\s*)[A-Z]\w*(?=\()/,lookbehind:!0},"annotation-content":{pattern:/[\s\S]+/,inside:Prism.languages.fsharp}}}});
\ No newline at end of file
diff --git a/tests/languages/fsharp/comment_feature.test b/tests/languages/fsharp/comment_feature.test
index ff9170b..4484944 100644
--- a/tests/languages/fsharp/comment_feature.test
+++ b/tests/languages/fsharp/comment_feature.test
@@ -3,14 +3,26 @@
(* foo
bar *)
+// the next one is not a comment
+(*) (*)
+
----------------------------------------------------
[
["comment", "// foobar"],
["comment", "(**)"],
- ["comment", "(* foo\r\nbar *)"]
+ ["comment", "(* foo\r\nbar *)"],
+
+ ["comment", "// the next one is not a comment"],
+
+ ["punctuation", "("],
+ ["operator", "*"],
+ ["punctuation", ")"],
+ ["punctuation", "("],
+ ["operator", "*"],
+ ["punctuation", ")"]
]
----------------------------------------------------
-Checks for single-line and multi-line comments.
\ No newline at end of file
+Checks for single-line and multi-line comments.
diff --git a/tests/languages/fsharp/issue2696.test b/tests/languages/fsharp/issue2696.test
new file mode 100644
index 0000000..1e7d26f
--- /dev/null
+++ b/tests/languages/fsharp/issue2696.test
@@ -0,0 +1,285 @@
+let score category (dice:Die list) =
+ let iDice = dice |> List.map int |> List.sortDescending
+ let diced = iDice |> List.countBy id |> List.sortByDescending snd
+ let countScore cat = dice |> List.filter (fun d -> d=cat) |> List.length |> (*) (int cat)
+ let isStraight = iDice.[0] - iDice.[4] = 4
+
+ match category , List.map snd diced with
+ | Yacht , [5] -> 50
+ | Ones , _ -> countScore Die.One
+ | Twos , _ -> countScore Die.Two
+ | Threes , _ -> countScore Die.Three
+ | Fours , _ -> countScore Die.Four
+ | Fives , _ -> countScore Die.Five
+ | Sixes , _ -> countScore Die.Six
+ | FourOfAKind , [4;1]
+ | FourOfAKind , [5] -> iDice |> List.head |> (*) 4
+ | LittleStraight, [1;1;1;1;1] when isStraight && iDice.[0] = 5 -> 30
+ | BigStraight , [1;1;1;1;1] when isStraight && iDice.[0] = 6 -> 30
+ | FullHouse , [3;2]
+ | Choice , _ -> iDice |> List.sum
+ | _ , _ -> 0
+
+----------------------------------------------------
+
+[
+ ["keyword", "let"],
+ " score category ",
+ ["punctuation", "("],
+ "dice",
+ ["punctuation", ":"],
+ ["class-name", ["Die"]],
+ " list",
+ ["punctuation", ")"],
+ ["operator", "="],
+
+ ["keyword", "let"],
+ " iDice ",
+ ["operator", "="],
+ " dice ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "map int ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "sortDescending\r\n ",
+
+ ["keyword", "let"],
+ " diced ",
+ ["operator", "="],
+ " iDice ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "countBy id ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "sortByDescending snd\r\n ",
+
+ ["keyword", "let"],
+ " countScore cat ",
+ ["operator", "="],
+ " dice ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "filter ",
+ ["punctuation", "("],
+ ["keyword", "fun"],
+ " d ",
+ ["operator", "->"],
+ " d",
+ ["operator", "="],
+ "cat",
+ ["punctuation", ")"],
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "length ",
+ ["operator", "|>"],
+ ["punctuation", "("],
+ ["operator", "*"],
+ ["punctuation", ")"],
+ ["punctuation", "("],
+ "int cat",
+ ["punctuation", ")"],
+
+ ["keyword", "let"],
+ " isStraight ",
+ ["operator", "="],
+ " iDice",
+ ["punctuation", "."],
+ ["punctuation", "["],
+ ["number", "0"],
+ ["punctuation", "]"],
+ ["operator", "-"],
+ " iDice",
+ ["punctuation", "."],
+ ["punctuation", "["],
+ ["number", "4"],
+ ["punctuation", "]"],
+ ["operator", "="],
+ ["number", "4"],
+
+ ["keyword", "match"],
+ " category ",
+ ["punctuation", ","],
+ " List",
+ ["punctuation", "."],
+ "map snd diced ",
+ ["keyword", "with"],
+
+ ["operator", "|"],
+ " Yacht ",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "5"],
+ ["punctuation", "]"],
+ ["operator", "->"],
+ ["number", "50"],
+
+ ["operator", "|"],
+ " Ones ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "One\r\n ",
+
+ ["operator", "|"],
+ " Twos ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "Two\r\n ",
+
+ ["operator", "|"],
+ " Threes ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "Three\r\n ",
+
+ ["operator", "|"],
+ " Fours ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "Four\r\n ",
+
+ ["operator", "|"],
+ " Fives ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "Five\r\n ",
+
+ ["operator", "|"],
+ " Sixes ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " countScore Die",
+ ["punctuation", "."],
+ "Six\r\n ",
+
+ ["operator", "|"],
+ " FourOfAKind ",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "4"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", "]"],
+
+ ["operator", "|"],
+ " FourOfAKind ",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "5"],
+ ["punctuation", "]"],
+ ["operator", "->"],
+ " iDice ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "head ",
+ ["operator", "|>"],
+ ["punctuation", "("],
+ ["operator", "*"],
+ ["punctuation", ")"],
+ ["number", "4"],
+
+ ["operator", "|"],
+ " LittleStraight",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", "]"],
+ ["keyword", "when"],
+ " isStraight ",
+ ["operator", "&&"],
+ " iDice",
+ ["punctuation", "."],
+ ["punctuation", "["],
+ ["number", "0"],
+ ["punctuation", "]"],
+ ["operator", "="],
+ ["number", "5"],
+ ["operator", "->"],
+ ["number", "30"],
+
+ ["operator", "|"],
+ " BigStraight ",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", ";"],
+ ["number", "1"],
+ ["punctuation", "]"],
+ ["keyword", "when"],
+ " isStraight ",
+ ["operator", "&&"],
+ " iDice",
+ ["punctuation", "."],
+ ["punctuation", "["],
+ ["number", "0"],
+ ["punctuation", "]"],
+ ["operator", "="],
+ ["number", "6"],
+ ["operator", "->"],
+ ["number", "30"],
+
+ ["operator", "|"],
+ " FullHouse ",
+ ["punctuation", ","],
+ ["punctuation", "["],
+ ["number", "3"],
+ ["punctuation", ";"],
+ ["number", "2"],
+ ["punctuation", "]"],
+
+ ["operator", "|"],
+ " Choice ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ " iDice ",
+ ["operator", "|>"],
+ " List",
+ ["punctuation", "."],
+ "sum\r\n ",
+
+ ["operator", "|"],
+ " _ ",
+ ["punctuation", ","],
+ " _ ",
+ ["operator", "->"],
+ ["number", "0"]
+]
\ No newline at end of file