UNPKG

4.04 kBJavaScriptView Raw
1Prism.languages.haskell = {
2 'comment': {
3 pattern: /(^|[^-!#$%*+=?&@|~.:<>^\\\/])(?:--(?:(?=.)[^-!#$%*+=?&@|~.:<>^\\\/].*|$)|\{-[\s\S]*?-\})/m,
4 lookbehind: true
5 },
6 'char': {
7 pattern: /'(?:[^\\']|\\(?:[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]+))'/,
8 alias: 'string'
9 },
10 'string': {
11 pattern: /"(?:[^\\"]|\\(?:\S|\s+\\))*"/,
12 greedy: true
13 },
14 'keyword': /\b(?:case|class|data|deriving|do|else|if|in|infixl|infixr|instance|let|module|newtype|of|primitive|then|type|where)\b/,
15 'import-statement': {
16 // The imported or hidden names are not included in this import
17 // statement. This is because we want to highlight those exactly like
18 // we do for the names in the program.
19 pattern: /(^[\t ]*)import\s+(?:qualified\s+)?(?:[A-Z][\w']*)(?:\.[A-Z][\w']*)*(?:\s+as\s+(?:[A-Z][\w']*)(?:\.[A-Z][\w']*)*)?(?:\s+hiding\b)?/m,
20 lookbehind: true,
21 inside: {
22 'keyword': /\b(?:import|qualified|as|hiding)\b/,
23 'punctuation': /\./
24 }
25 },
26 // These are builtin variables only. Constructors are highlighted later as a constant.
27 '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/,
28 // decimal integers and floating point numbers | octal integers | hexadecimal integers
29 'number': /\b(?:\d+(?:\.\d+)?(?:e[+-]?\d+)?|0o[0-7]+|0x[0-9a-f]+)\b/i,
30 'operator': [
31 {
32 // infix operator
33 pattern: /`(?:[A-Z][\w']*\.)*[_a-z][\w']*`/,
34 greedy: true
35 },
36 {
37 // function composition
38 pattern: /(\s)\.(?=\s)/,
39 lookbehind: true
40 },
41 // Most of this is needed because of the meaning of a single '.'.
42 // If it stands alone freely, it is the function composition.
43 // It may also be a separator between a module name and an identifier => no
44 // operator. If it comes together with other special characters it is an
45 // operator too.
46 //
47 // This regex means: /[-!#$%*+=?&@|~.:<>^\\\/]+/ without /\./.
48 /[-!#$%*+=?&@|~:<>^\\\/][-!#$%*+=?&@|~.:<>^\\\/]*|\.[-!#$%*+=?&@|~.:<>^\\\/]+/,
49 ],
50 // In Haskell, nearly everything is a variable, do not highlight these.
51 'hvariable': {
52 pattern: /\b(?:[A-Z][\w']*\.)*[_a-z][\w']*/,
53 inside: {
54 'punctuation': /\./
55 }
56 },
57 'constant': {
58 pattern: /\b(?:[A-Z][\w']*\.)*[A-Z][\w']*/,
59 inside: {
60 'punctuation': /\./
61 }
62 },
63 'punctuation': /[{}[\];(),.:]/
64};
65
66Prism.languages.hs = Prism.languages.haskell;