F#: Chars can only contain one character (#1570) This PR fixes #1480.
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
diff --git a/components/prism-fsharp.js b/components/prism-fsharp.js
index 3e701e0..375ab8c 100644
--- a/components/prism-fsharp.js
+++ b/components/prism-fsharp.js
@@ -11,7 +11,7 @@ Prism.languages.fsharp = Prism.languages.extend('clike', {
],
'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/,
'string': {
- pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1)B?/,
+ pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\.)'B?/,
greedy: true
},
'number': [
diff --git a/components/prism-fsharp.min.js b/components/prism-fsharp.min.js
index 85403b8..3579777 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}],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/,string:{pattern:/(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|("|')(?:\\[\s\S]|(?!\1)[^\\])*\1)B?/,greedy:!0},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/]}),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"}}}});
\ No newline at end of file
+Prism.languages.fsharp=Prism.languages.extend("clike",{comment:[{pattern:/(^|[^\\])\(\*[\s\S]*?\*\)/,lookbehind:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0}],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/,string:{pattern:/(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?|'(?:[^\\']|\\.)'B?/,greedy:!0},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/]}),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"}}}});
\ No newline at end of file
diff --git a/tests/languages/fsharp/issue1480.test b/tests/languages/fsharp/issue1480.test
new file mode 100644
index 0000000..f46fce2
--- /dev/null
+++ b/tests/languages/fsharp/issue1480.test
@@ -0,0 +1,37 @@
+let foo' = failWith "foo"
+
+let bar' = failWith "bar"
+
+let map (f: 'a -> 'b) (xs: 'a list): 'b list = failWith "not implemented"
+
+----------------------------------------------------
+
+[
+ ["keyword", "let"], " foo' ", ["operator", "="], " failWith ", ["string", "\"foo\""],
+ ["keyword", "let"], " bar' ", ["operator", "="], " failWith ", ["string", "\"bar\""],
+
+ ["keyword", "let"],
+ " map ",
+ ["punctuation", "("],
+ "f",
+ ["punctuation", ":"],
+ " 'a ",
+ ["operator", "-"],
+ ["operator", ">"],
+ " 'b",
+ ["punctuation", ")"],
+ ["punctuation", "("],
+ "xs",
+ ["punctuation", ":"],
+ " 'a list",
+ ["punctuation", ")"],
+ ["punctuation", ":"],
+ " 'b list ",
+ ["operator", "="],
+ " failWith ",
+ ["string", "\"not implemented\""]
+]
+
+----------------------------------------------------
+
+Checks for apostrophes in names. See #1480.
\ No newline at end of file
diff --git a/tests/languages/fsharp/string_feature.test b/tests/languages/fsharp/string_feature.test
index 89412ac..3c984a8 100644
--- a/tests/languages/fsharp/string_feature.test
+++ b/tests/languages/fsharp/string_feature.test
@@ -15,6 +15,7 @@ bar"""
"""foo"""B
'a'
+'a'B
'\''
'\\'
@@ -36,6 +37,7 @@ bar"""
["string", "\"\"\"foo\"\"\"B"],
["string", "'a'"],
+ ["string", "'a'B"],
["string", "'\\''"],
["string", "'\\\\'"]
]