Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/haskell/haskell.js
1293 views
CodeMirror.defineMode("haskell", function(_config, modeConfig) {12function switchState(source, setState, f) {3setState(f);4return f(source, setState);5}67// These should all be Unicode extended, as per the Haskell 2010 report8var smallRE = /[a-z_]/;9var largeRE = /[A-Z]/;10var digitRE = /\d/;11var hexitRE = /[0-9A-Fa-f]/;12var octitRE = /[0-7]/;13var idRE = /[a-z_A-Z0-9']/;14var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;15var specialRE = /[(),;[\]`{}]/;16var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer1718function normal(source, setState) {19if (source.eatWhile(whiteCharRE)) {20return null;21}2223var ch = source.next();24if (specialRE.test(ch)) {25if (ch == '{' && source.eat('-')) {26var t = "comment";27if (source.eat('#')) {28t = "meta";29}30return switchState(source, setState, ncomment(t, 1));31}32return null;33}3435if (ch == '\'') {36if (source.eat('\\')) {37source.next(); // should handle other escapes here38}39else {40source.next();41}42if (source.eat('\'')) {43return "string";44}45return "error";46}4748if (ch == '"') {49return switchState(source, setState, stringLiteral);50}5152if (largeRE.test(ch)) {53source.eatWhile(idRE);54if (source.eat('.')) {55return "qualifier";56}57return "variable-2";58}5960if (smallRE.test(ch)) {61source.eatWhile(idRE);62return "variable";63}6465if (digitRE.test(ch)) {66if (ch == '0') {67if (source.eat(/[xX]/)) {68source.eatWhile(hexitRE); // should require at least 169return "integer";70}71if (source.eat(/[oO]/)) {72source.eatWhile(octitRE); // should require at least 173return "number";74}75}76source.eatWhile(digitRE);77var t = "number";78if (source.match(/^\.\d+/)) {79t = "number";80}81if (source.eat(/[eE]/)) {82t = "number";83source.eat(/[-+]/);84source.eatWhile(digitRE); // should require at least 185}86return t;87}8889if (ch == "." && source.eat("."))90return "keyword";9192if (symbolRE.test(ch)) {93if (ch == '-' && source.eat(/-/)) {94source.eatWhile(/-/);95if (!source.eat(symbolRE)) {96source.skipToEnd();97return "comment";98}99}100var t = "variable";101if (ch == ':') {102t = "variable-2";103}104source.eatWhile(symbolRE);105return t;106}107108return "error";109}110111function ncomment(type, nest) {112if (nest == 0) {113return normal;114}115return function(source, setState) {116var currNest = nest;117while (!source.eol()) {118var ch = source.next();119if (ch == '{' && source.eat('-')) {120++currNest;121}122else if (ch == '-' && source.eat('}')) {123--currNest;124if (currNest == 0) {125setState(normal);126return type;127}128}129}130setState(ncomment(type, currNest));131return type;132};133}134135function stringLiteral(source, setState) {136while (!source.eol()) {137var ch = source.next();138if (ch == '"') {139setState(normal);140return "string";141}142if (ch == '\\') {143if (source.eol() || source.eat(whiteCharRE)) {144setState(stringGap);145return "string";146}147if (source.eat('&')) {148}149else {150source.next(); // should handle other escapes here151}152}153}154setState(normal);155return "error";156}157158function stringGap(source, setState) {159if (source.eat('\\')) {160return switchState(source, setState, stringLiteral);161}162source.next();163setState(normal);164return "error";165}166167168var wellKnownWords = (function() {169var wkw = {};170function setType(t) {171return function () {172for (var i = 0; i < arguments.length; i++)173wkw[arguments[i]] = t;174};175}176177setType("keyword")(178"case", "class", "data", "default", "deriving", "do", "else", "foreign",179"if", "import", "in", "infix", "infixl", "infixr", "instance", "let",180"module", "newtype", "of", "then", "type", "where", "_");181182setType("keyword")(183"\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");184185setType("builtin")(186"!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",187"==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");188189setType("builtin")(190"Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",191"False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",192"IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",193"Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",194"ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",195"String", "True");196197setType("builtin")(198"abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",199"asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",200"compare", "concat", "concatMap", "const", "cos", "cosh", "curry",201"cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",202"elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",203"enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",204"flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",205"foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",206"fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",207"getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",208"isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",209"lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",210"mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",211"minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",212"otherwise", "pi", "pred", "print", "product", "properFraction",213"putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",214"readIO", "readList", "readLn", "readParen", "reads", "readsPrec",215"realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",216"round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",217"sequence", "sequence_", "show", "showChar", "showList", "showParen",218"showString", "shows", "showsPrec", "significand", "signum", "sin",219"sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",220"tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",221"toRational", "truncate", "uncurry", "undefined", "unlines", "until",222"unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",223"zip3", "zipWith", "zipWith3");224225var override = modeConfig.overrideKeywords;226if (override) for (var word in override) if (override.hasOwnProperty(word))227wkw[word] = override[word];228229return wkw;230})();231232233234return {235startState: function () { return { f: normal }; },236copyState: function (s) { return { f: s.f }; },237238token: function(stream, state) {239var t = state.f(stream, function(s) { state.f = s; });240var w = stream.current();241return wellKnownWords.hasOwnProperty(w) ? wellKnownWords[w] : t;242},243244blockCommentStart: "{-",245blockCommentEnd: "-}",246lineComment: "--"247};248249});250251CodeMirror.defineMIME("text/x-haskell", "haskell");252253254