Commit 6e26a58b9db175e2ef931ea4fce794a88673d533

Bastian Holst 2014-08-12T21:35:01

Correct haskell support for strings and characters This commit adds correct support for Haskell characters and strings. To me, having only one type of token for characters and strings makes no sense in Haskell as they can be distinguished easily. Characters start with a single quote and strings start with a double quote. Furthermore, characters can only contain —guess what— one character whereas strings can caintain multiple or none of them. String can also have gaps.

diff --git a/components/prism-haskell.js b/components/prism-haskell.js
index ad460c9..7f97163 100644
--- a/components/prism-haskell.js
+++ b/components/prism-haskell.js
@@ -3,7 +3,8 @@ Prism.languages.haskell= {
 		pattern: /(^|[^-!#$%*+=\?&@|~.:<>^\\])(--[^-!#$%*+=\?&@|~.:<>^\\].*(\r?\n|$)|{-[\w\W]*?-})/gm,
 		lookbehind: true
 	},
-	'string': /("|')(\\?.)*?\1/g,
+	'char': /'([^\\"]|\\([abfnrtv\\"'&]|\^[A-Z@[\]\^_]|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|\d+|o[0-7]+|x[0-9a-fA-F]+))'/g,
+	'string': /"([^\\"]|\\([abfnrtv\\"'&]|\^[A-Z@[\]\^_]|NUL|SOH|STX|ETX|EOT|ENQ|ACK|BEL|BS|HT|LF|VT|FF|CR|SO|SI|DLE|DC1|DC2|DC3|DC4|NAK|SYN|ETB|CAN|EM|SUB|ESC|FS|GS|RS|US|SP|DEL|\d+|o[0-7]+|x[0-9a-fA-F]+)|\\\s+\\)*"/g,
 	'keyword' : /\b(case|class|data|deriving|do|else|if|in|infixl|infixr|instance|let|module|newtype|of|primitive|then|type|where)\b/g,
 	'import_statement' : {
 		// The imported or hidden names are not included in this import
diff --git a/themes/prism-coy.css b/themes/prism-coy.css
index 5992337..f9b7472 100644
--- a/themes/prism-coy.css
+++ b/themes/prism-coy.css
@@ -130,6 +130,7 @@ pre[class*="language-"]:after {
 .token.selector,
 .token.attr-name,
 .token.string,
+.token.char,
 .token.function,
 .token.builtin {
   color: #2f9c0a;
diff --git a/themes/prism-dark.css b/themes/prism-dark.css
index 32fa6ff..93b8ac4 100644
--- a/themes/prism-dark.css
+++ b/themes/prism-dark.css
@@ -82,6 +82,7 @@ pre[class*="language-"] {
 .token.selector,
 .token.attr-name,
 .token.string,
+.token.char,
 .token.builtin {
 	color: hsl(75, 70%, 60%);
 }
diff --git a/themes/prism-funky.css b/themes/prism-funky.css
index 946eac2..32003cd 100644
--- a/themes/prism-funky.css
+++ b/themes/prism-funky.css
@@ -72,6 +72,7 @@ code[class*="language-"] {
 .token.selector,
 .token.attr-name,
 .token.string,
+.token.char,
 .token.builtin {
 	color: yellow;
 }
diff --git a/themes/prism-okaidia.css b/themes/prism-okaidia.css
index 37d9b35..0382bd2 100644
--- a/themes/prism-okaidia.css
+++ b/themes/prism-okaidia.css
@@ -74,6 +74,7 @@ pre[class*="language-"] {
 .token.selector,
 .token.attr-name,
 .token.string,
+.token.char,
 .token.builtin {
 	color: #a6e22e;
 }
diff --git a/themes/prism-tomorrow.css b/themes/prism-tomorrow.css
index c8b5db4..a4ce55b 100644
--- a/themes/prism-tomorrow.css
+++ b/themes/prism-tomorrow.css
@@ -89,6 +89,7 @@ pre[class*="language-"] {
 }
 
 .token.string,
+.token.char,
 .token.attr-value,
 .token.regex,
 .token.variable {
diff --git a/themes/prism-twilight.css b/themes/prism-twilight.css
index f774413..a4cf44a 100644
--- a/themes/prism-twilight.css
+++ b/themes/prism-twilight.css
@@ -98,6 +98,7 @@ code[class*="language-"]::selection, code[class*="language-"] ::selection {
 .token.attr-name,
 .token.attr-value,
 .token.string,
+.token.char,
 .token.operator,
 .token.entity,
 .token.url,
diff --git a/themes/prism.css b/themes/prism.css
index 588bd35..b547599 100644
--- a/themes/prism.css
+++ b/themes/prism.css
@@ -90,6 +90,7 @@ pre[class*="language-"] {
 .token.selector,
 .token.attr-name,
 .token.string,
+.token.char,
 .token.builtin {
 	color: #690;
 }