function switchState(e, s, c) {
  return s(c), c(e, s);
}
var smallRE = /[a-z_]/, largeRE = /[A-Z]/, digitRE = /\d/, hexitRE = /[0-9A-Fa-f]/, octitRE = /[0-7]/, idRE = /[a-z_A-Z0-9'\xa1-\uffff]/, symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/, specialRE = /[(),;[\]`{}]/, whiteCharRE = /[ \t\v\f]/;
function normal(f, p) {
  if (f.eatWhile(whiteCharRE)) return null;
  var m = f.next();
  if (specialRE.test(m)) {
    if (m == "{" && f.eat("-")) {
      var h = "comment";
      return f.eat("#") && (h = "meta"), switchState(f, p, ncomment(h, 1));
    }
    return null;
  }
  if (m == "'") return f.eat("\\"), f.next(), f.eat("'") ? "string" : "error";
  if (m == '"') return switchState(f, p, stringLiteral);
  if (largeRE.test(m)) return f.eatWhile(idRE), f.eat(".") ? "qualifier" : "type";
  if (smallRE.test(m)) return f.eatWhile(idRE), "variable";
  if (digitRE.test(m)) {
    if (m == "0") {
      if (f.eat(/[xX]/)) return f.eatWhile(hexitRE), "integer";
      if (f.eat(/[oO]/)) return f.eatWhile(octitRE), "number";
    }
    f.eatWhile(digitRE);
    var h = "number";
    return f.match(/^\.\d+/) && (h = "number"), f.eat(/[eE]/) && (h = "number", f.eat(/[-+]/), f.eatWhile(digitRE)), h;
  }
  return m == "." && f.eat(".") ? "keyword" : symbolRE.test(m) ? m == "-" && f.eat(/-/) && (f.eatWhile(/-/), !f.eat(symbolRE)) ? (f.skipToEnd(), "comment") : (f.eatWhile(symbolRE), "variable") : "error";
}
function ncomment(e, s) {
  return s == 0 ? normal : function(c, l) {
    for (var u = s; !c.eol(); ) {
      var d = c.next();
      if (d == "{" && c.eat("-")) ++u;
      else if (d == "-" && c.eat("}") && (--u, u == 0)) return l(normal), e;
    }
    return l(ncomment(e, u)), e;
  };
}
function stringLiteral(e, s) {
  for (; !e.eol(); ) {
    var c = e.next();
    if (c == '"') return s(normal), "string";
    if (c == "\\") {
      if (e.eol() || e.eat(whiteCharRE)) return s(stringGap), "string";
      e.eat("&") || e.next();
    }
  }
  return s(normal), "error";
}
function stringGap(s, c) {
  return s.eat("\\") ? switchState(s, c, stringLiteral) : (s.next(), c(normal), "error");
}
var wellKnownWords = (function() {
  var e = {};
  function s(s2) {
    return function() {
      for (var c = 0; c < arguments.length; c++) e[arguments[c]] = s2;
    };
  }
  return s("keyword")("case", "class", "data", "default", "deriving", "do", "else", "foreign", "if", "import", "in", "infix", "infixl", "infixr", "instance", "let", "module", "newtype", "of", "then", "type", "where", "_"), s("keyword")("..", ":", "::", "=", "\\", "<-", "->", "@", "~", "=>"), s("builtin")("!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<*", "<=", "<$>", "<*>", "=<<", "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "*>", "**"), s("builtin")("Applicative", "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq", "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT", "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left", "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read", "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS", "String", "True"), s("builtin")("abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf", "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling", "compare", "concat", "concatMap", "const", "cos", "cosh", "curry", "cycle", "decodeFloat", "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", "fromEnum", "fromInteger", "fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents", "getLine", "head", "id", "init", "interact", "ioError", "isDenormalized", "isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last", "lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map", "mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound", "minimum", "mod", "negate", "not", "notElem", "null", "odd", "or", "otherwise", "pi", "pred", "print", "product", "properFraction", "pure", "putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile", "readIO", "readList", "readLn", "readParen", "reads", "readsPrec", "realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse", "round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq", "sequence", "sequence_", "show", "showChar", "showList", "showParen", "showString", "shows", "showsPrec", "significand", "signum", "sin", "sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum", "tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger", "toRational", "truncate", "uncurry", "undefined", "unlines", "until", "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip", "zip3", "zipWith", "zipWith3"), e;
})();
const haskell = {
  name: "haskell",
  startState: function() {
    return { f: normal };
  },
  copyState: function(e) {
    return { f: e.f };
  },
  token: function(e, s) {
    var c = s.f(e, function(e2) {
      s.f = e2;
    }), l = e.current();
    return wellKnownWords.hasOwnProperty(l) ? wellKnownWords[l] : c;
  },
  languageData: { commentTokens: {
    line: "--",
    block: {
      open: "{-",
      close: "-}"
    }
  } }
};
export {
  haskell as t
};
