Commit b58cd7227fec6c7ce312d87d24919ec109a0b7fd

Michael Schmidt 2021-12-06T22:42:55

F#: Added `char` token (#3271)

diff --git a/components/prism-fsharp.js b/components/prism-fsharp.js
index 3c670aa..0dcb147 100644
--- a/components/prism-fsharp.js
+++ b/components/prism-fsharp.js
@@ -2,15 +2,17 @@ Prism.languages.fsharp = Prism.languages.extend('clike', {
 	'comment': [
 		{
 			pattern: /(^|[^\\])\(\*(?!\))[\s\S]*?\*\)/,
-			lookbehind: true
+			lookbehind: true,
+			greedy: true
 		},
 		{
 			pattern: /(^|[^\\:])\/\/.*/,
-			lookbehind: true
+			lookbehind: true,
+			greedy: true
 		}
 	],
 	'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?/,
+		pattern: /(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")B?/,
 		greedy: true
 	},
 	'class-name': {
@@ -53,6 +55,7 @@ Prism.languages.insertBefore('fsharp', 'punctuation', {
 Prism.languages.insertBefore('fsharp', 'string', {
 	'annotation': {
 		pattern: /\[<.+?>\]/,
+		greedy: true,
 		inside: {
 			'punctuation': /^\[<|>\]$/,
 			'class-name': {
@@ -64,5 +67,9 @@ Prism.languages.insertBefore('fsharp', 'string', {
 				inside: Prism.languages.fsharp
 			}
 		}
+	},
+	'char': {
+		pattern: /'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,
+		greedy: true
 	}
 });
diff --git a/components/prism-fsharp.min.js b/components/prism-fsharp.min.js
index 99f0b6f..73fa5e2 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|asr|assert|atomic|base|begin|break|checked|class|component|const|constraint|constructor|continue|default|delegate|do|done|downcast|downto|eager|elif|else|end|event|exception|extern|external|false|finally|fixed|for|fun|function|functor|global|if|in|include|inherit|inline|interface|internal|land|lazy|lor|lsl|lsr|lxor|match|member|method|mixin|mod|module|mutable|namespace|new|not|null|object|of|open|or|override|parallel|private|process|protected|public|pure|rec|sealed|select|sig|static|struct|tailcall|then|to|trait|true|try|type|upcast|val|virtual|void|volatile|when|while|with)\b/,number:[/\b0x[\da-fA-F]+(?:LF|lf|un)?\b/,/\b0b[01]+(?:uy|y)?\b/,/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[fm]|e[+-]?\d+)?\b/i,/\b\d+(?:[IlLsy]|UL|u[lsy]?)?\b/],operator:/([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/}),Prism.languages.insertBefore("fsharp","keyword",{preprocessor:{pattern:/(^[\t ]*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(^#)\b(?:else|endif|if|light|line|nowarn)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.insertBefore("fsharp","punctuation",{"computation-expression":{pattern:/\b[_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,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(?:"""[\s\S]*?"""|@"(?:""|[^"])*"|"(?:\\[\s\S]|[^\\"])*")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|asr|assert|atomic|base|begin|break|checked|class|component|const|constraint|constructor|continue|default|delegate|do|done|downcast|downto|eager|elif|else|end|event|exception|extern|external|false|finally|fixed|for|fun|function|functor|global|if|in|include|inherit|inline|interface|internal|land|lazy|lor|lsl|lsr|lxor|match|member|method|mixin|mod|module|mutable|namespace|new|not|null|object|of|open|or|override|parallel|private|process|protected|public|pure|rec|sealed|select|sig|static|struct|tailcall|then|to|trait|true|try|type|upcast|val|virtual|void|volatile|when|while|with)\b/,number:[/\b0x[\da-fA-F]+(?:LF|lf|un)?\b/,/\b0b[01]+(?:uy|y)?\b/,/(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:[fm]|e[+-]?\d+)?\b/i,/\b\d+(?:[IlLsy]|UL|u[lsy]?)?\b/],operator:/([<>~&^])\1\1|([*.:<>&])\2|<-|->|[!=:]=|<?\|{1,3}>?|\??(?:<=|>=|<>|[-+*/%=<>])\??|[!?^&]|~[+~-]|:>|:\?>?/}),Prism.languages.insertBefore("fsharp","keyword",{preprocessor:{pattern:/(^[\t ]*)#.*/m,lookbehind:!0,alias:"property",inside:{directive:{pattern:/(^#)\b(?:else|endif|if|light|line|nowarn)\b/,lookbehind:!0,alias:"keyword"}}}}),Prism.languages.insertBefore("fsharp","punctuation",{"computation-expression":{pattern:/\b[_a-z]\w*(?=\s*\{)/i,alias:"keyword"}}),Prism.languages.insertBefore("fsharp","string",{annotation:{pattern:/\[<.+?>\]/,greedy:!0,inside:{punctuation:/^\[<|>\]$/,"class-name":{pattern:/^\w+$|(^|;\s*)[A-Z]\w*(?=\()/,lookbehind:!0},"annotation-content":{pattern:/[\s\S]+/,inside:Prism.languages.fsharp}}},char:{pattern:/'(?:[^\\']|\\(?:.|\d{3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}|U[a-fA-F\d]{8}))'B?/,greedy:!0}});
\ No newline at end of file
diff --git a/tests/languages/fsharp/char_feature.test b/tests/languages/fsharp/char_feature.test
new file mode 100644
index 0000000..2648a9f
--- /dev/null
+++ b/tests/languages/fsharp/char_feature.test
@@ -0,0 +1,21 @@
+'a'
+'a'B
+'\''
+'\\'
+'\231'
+'\x41'
+'\u0041'
+'\U0001F47D'
+
+----------------------------------------------------
+
+[
+	["char", "'a'"],
+	["char", "'a'B"],
+	["char", "'\\''"],
+	["char", "'\\\\'"],
+	["char", "'\\231'"],
+	["char", "'\\x41'"],
+	["char", "'\\u0041'"],
+	["char", "'\\U0001F47D'"]
+]
diff --git a/tests/languages/fsharp/string_feature.test b/tests/languages/fsharp/string_feature.test
index c6310d8..a281856 100644
--- a/tests/languages/fsharp/string_feature.test
+++ b/tests/languages/fsharp/string_feature.test
@@ -14,15 +14,6 @@ bar"
 bar"""
 """foo"""B
 
-'a'
-'a'B
-'\''
-'\\'
-'\231'
-'\x41'
-'\u0041'
-'\U0001F47D'
-
 ----------------------------------------------------
 
 [
@@ -38,18 +29,9 @@ bar"""
 
 	["string", "\"\"\"\"\"\""],
 	["string", "\"\"\"fo\"\"o\"\r\nbar\"\"\""],
-	["string", "\"\"\"foo\"\"\"B"],
-
-	["string", "'a'"],
-	["string", "'a'B"],
-	["string", "'\\''"],
-	["string", "'\\\\'"],
-	["string", "'\\231'"],
-	["string", "'\\x41'"],
-	["string", "'\\u0041'"],
-	["string", "'\\U0001F47D'"]
+	["string", "\"\"\"foo\"\"\"B"]
 ]
 
 ----------------------------------------------------
 
-Checks for normal strings, verbatim strings, triple-quoted strings and character literals.
+Checks for normal strings, verbatim strings, and triple-quoted strings.