From f96b083a43ed60641fa1263f35c32bc9960bd1e2 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Sun, 23 Sep 2018 15:20:05 +0200 Subject: [PATCH] F#: Chars can only contain one character (#1570) This PR fixes #1480. --- components/prism-fsharp.js | 2 +- components/prism-fsharp.min.js | 2 +- tests/languages/fsharp/issue1480.test | 37 ++++++++++++++++++++++ tests/languages/fsharp/string_feature.test | 2 ++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 tests/languages/fsharp/issue1480.test diff --git a/components/prism-fsharp.js b/components/prism-fsharp.js index 3e701e0dc1..375ab8cc15 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 85403b8e7a..3579777708 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 0000000000..f46fce23df --- /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 89412ac072..3c984a8c65 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", "'\\\\'"] ]