function words(e) {
  for (var l = {}, u = e.split(" "), d = 0; d < u.length; ++d) l[u[d]] = true;
  return l;
}
function metaHook(e, l) {
  return l.startOfLine ? (e.skipToEnd(), "meta") : false;
}
var keyword = words("abs acos allnodes ascii asin asstring atan atan2 ave case choose choosen choosesets clustersize combine correlation cos cosh count covariance cron dataset dedup define denormalize distribute distributed distribution ebcdic enth error evaluate event eventextra eventname exists exp failcode failmessage fetch fromunicode getisvalid global graph group hash hash32 hash64 hashcrc hashmd5 having if index intformat isvalid iterate join keyunicode length library limit ln local log loop map matched matchlength matchposition matchtext matchunicode max merge mergejoin min nolocal nonempty normalize parse pipe power preload process project pull random range rank ranked realformat recordof regexfind regexreplace regroup rejected rollup round roundup row rowdiff sample set sin sinh sizeof soapcall sort sorted sqrt stepped stored sum table tan tanh thisnode topn tounicode transfer trim truncate typeof ungroup unicodeorder variance which workunit xmldecode xmlencode xmltext xmlunicode"), variable = words("apply assert build buildindex evaluate fail keydiff keypatch loadxml nothor notify output parallel sequential soapcall wait"), variable_2 = words("__compressed__ all and any as atmost before beginc++ best between case const counter csv descend encrypt end endc++ endmacro except exclusive expire export extend false few first flat from full function group header heading hole ifblock import in interface joined keep keyed last left limit load local locale lookup macro many maxcount maxlength min skew module named nocase noroot noscan nosort not of only opt or outer overwrite packed partition penalty physicallength pipe quote record relationship repeat return right scan self separator service shared skew skip sql store terminator thor threshold token transform trim true type unicodeorder unsorted validate virtual whole wild within xml xpath"), variable_3 = words("ascii big_endian boolean data decimal ebcdic integer pattern qstring real record rule set of string token udecimal unicode unsigned varstring varunicode"), builtin = words("checkpoint deprecated failcode failmessage failure global independent onwarning persist priority recovery stored success wait when"), blockKeywords = words("catch class do else finally for if switch try while"), atoms = words("true false null"), hooks = { "#": metaHook }, isOperatorChar = /[+\-*&%=<>!?|\/]/, curPunc;
function tokenBase(e, l) {
  var m = e.next();
  if (hooks[m]) {
    var h = hooks[m](e, l);
    if (h !== false) return h;
  }
  if (m == '"' || m == "'") return l.tokenize = tokenString(m), l.tokenize(e, l);
  if (/[\[\]{}\(\),;\:\.]/.test(m)) return curPunc = m, null;
  if (/\d/.test(m)) return e.eatWhile(/[\w\.]/), "number";
  if (m == "/") {
    if (e.eat("*")) return l.tokenize = tokenComment, tokenComment(e, l);
    if (e.eat("/")) return e.skipToEnd(), "comment";
  }
  if (isOperatorChar.test(m)) return e.eatWhile(isOperatorChar), "operator";
  e.eatWhile(/[\w\$_]/);
  var g = e.current().toLowerCase();
  if (keyword.propertyIsEnumerable(g)) return blockKeywords.propertyIsEnumerable(g) && (curPunc = "newstatement"), "keyword";
  if (variable.propertyIsEnumerable(g)) return blockKeywords.propertyIsEnumerable(g) && (curPunc = "newstatement"), "variable";
  if (variable_2.propertyIsEnumerable(g)) return blockKeywords.propertyIsEnumerable(g) && (curPunc = "newstatement"), "modifier";
  if (variable_3.propertyIsEnumerable(g)) return blockKeywords.propertyIsEnumerable(g) && (curPunc = "newstatement"), "type";
  if (builtin.propertyIsEnumerable(g)) return blockKeywords.propertyIsEnumerable(g) && (curPunc = "newstatement"), "builtin";
  for (var _ = g.length - 1; _ >= 0 && (!isNaN(g[_]) || g[_] == "_"); ) --_;
  if (_ > 0) {
    var v = g.substr(0, _ + 1);
    if (variable_3.propertyIsEnumerable(v)) return blockKeywords.propertyIsEnumerable(v) && (curPunc = "newstatement"), "type";
  }
  return atoms.propertyIsEnumerable(g) ? "atom" : null;
}
function tokenString(e) {
  return function(l, u) {
    for (var d = false, f, p = false; (f = l.next()) != null; ) {
      if (f == e && !d) {
        p = true;
        break;
      }
      d = !d && f == "\\";
    }
    return (p || !d) && (u.tokenize = tokenBase), "string";
  };
}
function tokenComment(e, l) {
  for (var u = false, d; d = e.next(); ) {
    if (d == "/" && u) {
      l.tokenize = tokenBase;
      break;
    }
    u = d == "*";
  }
  return "comment";
}
function Context(e, l, u, d, f) {
  this.indented = e, this.column = l, this.type = u, this.align = d, this.prev = f;
}
function pushContext(e, l, u) {
  return e.context = new Context(e.indented, l, u, null, e.context);
}
function popContext(e) {
  var l = e.context.type;
  return (l == ")" || l == "]" || l == "}") && (e.indented = e.context.indented), e.context = e.context.prev;
}
const ecl = {
  name: "ecl",
  startState: function(e) {
    return {
      tokenize: null,
      context: new Context(-e, 0, "top", false),
      indented: 0,
      startOfLine: true
    };
  },
  token: function(e, l) {
    var u = l.context;
    if (e.sol() && (u.align ?? (u.align = false), l.indented = e.indentation(), l.startOfLine = true), e.eatSpace()) return null;
    curPunc = null;
    var d = (l.tokenize || tokenBase)(e, l);
    if (d == "comment" || d == "meta") return d;
    if (u.align ?? (u.align = true), (curPunc == ";" || curPunc == ":") && u.type == "statement") popContext(l);
    else if (curPunc == "{") pushContext(l, e.column(), "}");
    else if (curPunc == "[") pushContext(l, e.column(), "]");
    else if (curPunc == "(") pushContext(l, e.column(), ")");
    else if (curPunc == "}") {
      for (; u.type == "statement"; ) u = popContext(l);
      for (u.type == "}" && (u = popContext(l)); u.type == "statement"; ) u = popContext(l);
    } else curPunc == u.type ? popContext(l) : (u.type == "}" || u.type == "top" || u.type == "statement" && curPunc == "newstatement") && pushContext(l, e.column(), "statement");
    return l.startOfLine = false, d;
  },
  indent: function(e, l, u) {
    if (e.tokenize != tokenBase && e.tokenize != null) return 0;
    var d = e.context, f = l && l.charAt(0);
    d.type == "statement" && f == "}" && (d = d.prev);
    var p = f == d.type;
    return d.type == "statement" ? d.indented + (f == "{" ? 0 : u.unit) : d.align ? d.column + (p ? 0 : 1) : d.indented + (p ? 0 : u.unit);
  },
  languageData: { indentOnInput: /^\s*[{}]$/ }
};
export {
  ecl as t
};
