Commit f96b083a43ed60641fa1263f35c32bc9960bd1e2

Michael Schmidt 2018-09-23T15:20:05

F#: Chars can only contain one character (#1570) This PR fixes #1480.

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", "'\\\\'"]
 ]