Commit 8a77383bffa9b37d934fa5a6bb3fd7f61f0b8df1

Bastian Holst 2014-07-13T20:49:37

Add language definition for Haskell

diff --git a/components.js b/components.js
index 0c3321b..0afb821 100644
--- a/components.js
+++ b/components.js
@@ -152,6 +152,10 @@ var components = {
 			"require": "java",
 			"owner": "jozic"
 		},
+		"haskell": {
+			"title": "Haskell"
+			"owner": "bholst"
+		},
 		"swift": {
 			"title": "Swift",
 			"require": "clike",
diff --git a/components/prism-haskell.js b/components/prism-haskell.js
new file mode 100644
index 0000000..fd82036
--- /dev/null
+++ b/components/prism-haskell.js
@@ -0,0 +1,26 @@
+Prism.languages.haskell= {
+	'comment': {
+		pattern: /(^|[^-!#$%*+=\?&@|~.:<>^\\]|&amp;|&gt;|&lt;)(--([^-!#$%*+=\?&@|~.:<>^\\]|&amp;|&gt;|&lt;).*(\r?\n|$)|{-[\w\W]*?-})/gm,
+		lookbehind: true
+	},
+	'string': /("|')(\\?.)*?\1/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
+		// statement. This is because we want to highlight those exactly like
+		// we do for the names in the program.
+		pattern: /(\n|^)\s*(import)\s+(qualified\s+)?(([A-Z][_a-zA-Z0-9']*)(\.[A-Z][_a-zA-Z0-9']*)*)(\s+(as)\s+(([A-Z][_a-zA-Z0-9']*)(\.[A-Z][_a-zA-Z0-9']*)*))?(\s+hiding\b)?/gm,
+		inside: {
+			'keyword': /\b(import|qualified|as|hiding)\b/g
+		}
+	},
+	// These are builtin variables only. Constructors are highlighted later as a constant.
+	'builtin': /\b(abs|acos|acosh|all|and|any|appendFile|approxRational|asTypeOf|asin|asinh|atan|atan2|atanh|basicIORun|break|catch|ceiling|chr|compare|concat|concatMap|const|cos|cosh|curry|cycle|decodeFloat|denominator|digitToInt|div|divMod|drop|dropWhile|either|elem|encodeFloat|enumFrom|enumFromThen|enumFromThenTo|enumFromTo|error|even|exp|exponent|fail|filter|flip|floatDigits|floatRadix|floatRange|floor|fmap|foldl|foldl1|foldr|foldr1|fromDouble|fromEnum|fromInt|fromInteger|fromIntegral|fromRational|fst|gcd|getChar|getContents|getLine|group|head|id|inRange|index|init|intToDigit|interact|ioError|isAlpha|isAlphaNum|isAscii|isControl|isDenormalized|isDigit|isHexDigit|isIEEE|isInfinite|isLower|isNaN|isNegativeZero|isOctDigit|isPrint|isSpace|isUpper|iterate|last|lcm|length|lex|lexDigits|lexLitChar|lines|log|logBase|lookup|map|mapM|mapM_|max|maxBound|maximum|maybe|min|minBound|minimum|mod|negate|not|notElem|null|numerator|odd|or|ord|otherwise|pack|pi|pred|primExitWith|print|product|properFraction|putChar|putStr|putStrLn|quot|quotRem|range|rangeSize|read|readDec|readFile|readFloat|readHex|readIO|readInt|readList|readLitChar|readLn|readOct|readParen|readSigned|reads|readsPrec|realToFrac|recip|rem|repeat|replicate|return|reverse|round|scaleFloat|scanl|scanl1|scanr|scanr1|seq|sequence|sequence_|show|showChar|showInt|showList|showLitChar|showParen|showSigned|showString|shows|showsPrec|significand|signum|sin|sinh|snd|sort|span|splitAt|sqrt|subtract|succ|sum|tail|take|takeWhile|tan|tanh|threadToIOResult|toEnum|toInt|toInteger|toLower|toRational|toUpper|truncate|uncurry|undefined|unlines|until|unwords|unzip|unzip3|userError|words|writeFile|zip|zip3|zipWith|zipWith3)\b/g,
+	// In Haskell, nearly everything is a variable, do not highlight these.
+	// 'variable': /\b[_a-z][_a-zA-Z0-9']*\b/,
+	'operator' : /(&amp;|&lt;|&gt;|[-!#$%*+=\?&@|~.:<>^\\])+|(`[_a-zA-Z0-9']+`)/g,
+	'constant': /\b[A-Z][_a-zA-Z0-9']*\b/g,
+	'number' : /\b-?\d*(\.?\d+)\b/g,
+	'ignore' : /&(lt|gt|amp);/gi,
+	'punctuation' : /[{}[\];(),.:]/g
+};
diff --git a/components/prism-haskell.min.js b/components/prism-haskell.min.js
new file mode 100644
index 0000000..f6800b3
--- /dev/null
+++ b/components/prism-haskell.min.js
@@ -0,0 +1 @@
+Prism.languages.haskell={'comment':{pattern:/(^|[^-!#$%*+=\?&@|~.:<>^\\]|&amp;|&gt;|&lt;)(--([^-!#$%*+=\?&@|~.:<>^\\]|&amp;|&gt;|&lt;).*(\r?\n|$)|{-[\w\W]*?-})/gm,lookbehind:true},'string':/("|')(\\?.)*?\1/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':{pattern:/(\n|^)\s*(import)\s+(qualified\s+)?(([A-Z][_a-zA-Z0-9']*)(\.[A-Z][_a-zA-Z0-9']*)*)(\s+(as)\s+(([A-Z][_a-zA-Z0-9']*)(\.[A-Z][_a-zA-Z0-9']*)*))?(\s+hiding\b)?/gm,inside:{'keyword':/\b(import|qualified|as|hiding)\b/g}},'builtin':/\b(abs|acos|acosh|all|and|any|appendFile|approxRational|asTypeOf|asin|asinh|atan|atan2|atanh|basicIORun|break|catch|ceiling|chr|compare|concat|concatMap|const|cos|cosh|curry|cycle|decodeFloat|denominator|digitToInt|div|divMod|drop|dropWhile|either|elem|encodeFloat|enumFrom|enumFromThen|enumFromThenTo|enumFromTo|error|even|exp|exponent|fail|filter|flip|floatDigits|floatRadix|floatRange|floor|fmap|foldl|foldl1|foldr|foldr1|fromDouble|fromEnum|fromInt|fromInteger|fromIntegral|fromRational|fst|gcd|getChar|getContents|getLine|group|head|id|inRange|index|init|intToDigit|interact|ioError|isAlpha|isAlphaNum|isAscii|isControl|isDenormalized|isDigit|isHexDigit|isIEEE|isInfinite|isLower|isNaN|isNegativeZero|isOctDigit|isPrint|isSpace|isUpper|iterate|last|lcm|length|lex|lexDigits|lexLitChar|lines|log|logBase|lookup|map|mapM|mapM_|max|maxBound|maximum|maybe|min|minBound|minimum|mod|negate|not|notElem|null|numerator|odd|or|ord|otherwise|pack|pi|pred|primExitWith|print|product|properFraction|putChar|putStr|putStrLn|quot|quotRem|range|rangeSize|read|readDec|readFile|readFloat|readHex|readIO|readInt|readList|readLitChar|readLn|readOct|readParen|readSigned|reads|readsPrec|realToFrac|recip|rem|repeat|replicate|return|reverse|round|scaleFloat|scanl|scanl1|scanr|scanr1|seq|sequence|sequence_|show|showChar|showInt|showList|showLitChar|showParen|showSigned|showString|shows|showsPrec|significand|signum|sin|sinh|snd|sort|span|splitAt|sqrt|subtract|succ|sum|tail|take|takeWhile|tan|tanh|threadToIOResult|toEnum|toInt|toInteger|toLower|toRational|toUpper|truncate|uncurry|undefined|unlines|until|unwords|unzip|unzip3|userError|words|writeFile|zip|zip3|zipWith|zipWith3)\b/g,'operator':/(&amp;|&lt;|&gt;|[-!#$%*+=\?&@|~.:<>^\\])+|(`[_a-zA-Z0-9']+`)/g,'constant':/\b[A-Z][_a-zA-Z0-9']*\b/g,'number':/\b-?\d*(\.?\d+)\b/g,'ignore':/&(lt|gt|amp);/gi,'punctuation':/[{}[\];(),.:]/g};