function switchState(e, d, f) {
  return d(f), f(e, d);
}
var lowerRE = /[a-z]/, upperRE = /[A-Z]/, innerRE = /[a-zA-Z0-9_]/, digitRE = /[0-9]/, hexRE = /[0-9A-Fa-f]/, symbolRE = /[-&*+.\\/<>=?^|:]/, specialRE = /[(),[\]{}]/, spacesRE = /[ \v\f]/;
function normal() {
  return function(m, h) {
    if (m.eatWhile(spacesRE)) return null;
    var g = m.next();
    if (specialRE.test(g)) return g === "{" && m.eat("-") ? switchState(m, h, chompMultiComment(1)) : g === "[" && m.match("glsl|") ? switchState(m, h, chompGlsl) : "builtin";
    if (g === "'") return switchState(m, h, chompChar);
    if (g === '"') return m.eat('"') ? m.eat('"') ? switchState(m, h, chompMultiString) : "string" : switchState(m, h, chompSingleString);
    if (upperRE.test(g)) return m.eatWhile(innerRE), "type";
    if (lowerRE.test(g)) {
      var _ = m.pos === 1;
      return m.eatWhile(innerRE), _ ? "def" : "variable";
    }
    if (digitRE.test(g)) {
      if (g === "0") {
        if (m.eat(/[xX]/)) return m.eatWhile(hexRE), "number";
      } else m.eatWhile(digitRE);
      return m.eat(".") && m.eatWhile(digitRE), m.eat(/[eE]/) && (m.eat(/[-+]/), m.eatWhile(digitRE)), "number";
    }
    return symbolRE.test(g) ? g === "-" && m.eat("-") ? (m.skipToEnd(), "comment") : (m.eatWhile(symbolRE), "keyword") : g === "_" ? "keyword" : "error";
  };
}
function chompMultiComment(e) {
  return e == 0 ? normal() : function(d, f) {
    for (; !d.eol(); ) {
      var p = d.next();
      if (p == "{" && d.eat("-")) ++e;
      else if (p == "-" && d.eat("}") && (--e, e === 0)) return f(normal()), "comment";
    }
    return f(chompMultiComment(e)), "comment";
  };
}
function chompMultiString(e, d) {
  for (; !e.eol(); ) if (e.next() === '"' && e.eat('"') && e.eat('"')) return d(normal()), "string";
  return "string";
}
function chompSingleString(e, d) {
  for (; e.skipTo('\\"'); ) e.next(), e.next();
  return e.skipTo('"') ? (e.next(), d(normal()), "string") : (e.skipToEnd(), d(normal()), "error");
}
function chompChar(e, d) {
  for (; e.skipTo("\\'"); ) e.next(), e.next();
  return e.skipTo("'") ? (e.next(), d(normal()), "string") : (e.skipToEnd(), d(normal()), "error");
}
function chompGlsl(e, d) {
  for (; !e.eol(); ) if (e.next() === "|" && e.eat("]")) return d(normal()), "string";
  return "string";
}
var wellKnownWords = {
  case: 1,
  of: 1,
  as: 1,
  if: 1,
  then: 1,
  else: 1,
  let: 1,
  in: 1,
  type: 1,
  alias: 1,
  module: 1,
  where: 1,
  import: 1,
  exposing: 1,
  port: 1
};
const elm = {
  name: "elm",
  startState: function() {
    return { f: normal() };
  },
  copyState: function(e) {
    return { f: e.f };
  },
  token: function(e, d) {
    var f = d.f(e, function(e2) {
      d.f = e2;
    }), p = e.current();
    return wellKnownWords.hasOwnProperty(p) ? "keyword" : f;
  },
  languageData: { commentTokens: { line: "--" } }
};
export {
  elm as t
};
