Skip to content

Commit

Permalink
F#: Fixed comment false positive (#2703)
Browse files Browse the repository at this point in the history
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 `(*)`.
  • Loading branch information
RunDevelopment committed Jan 17, 2021
1 parent 1f91868 commit a5d7178
Show file tree
Hide file tree
Showing 4 changed files with 301 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/prism-fsharp.js
@@ -1,7 +1,7 @@
Prism.languages.fsharp = Prism.languages.extend('clike', {
'comment': [
{
pattern: /(^|[^\\])\(\*[\s\S]*?\*\)/,
pattern: /(^|[^\\])\(\*(?!\))[\s\S]*?\*\)/,
lookbehind: true
},
{
Expand Down
2 changes: 1 addition & 1 deletion components/prism-fsharp.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions tests/languages/fsharp/comment_feature.test
Expand Up @@ -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.
Checks for single-line and multi-line comments.
285 changes: 285 additions & 0 deletions 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"]
]

0 comments on commit a5d7178

Please sign in to comment.