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