function words(e) {
  for (var C = {}, w = e.split(" "), T = 0; T < w.length; ++T) C[w[T]] = true;
  return C;
}
var parserConfig = {
  name: "ttcn",
  keywords: words("activate address alive all alt altstep and and4b any break case component const continue control deactivate display do else encode enumerated except exception execute extends extension external for from function goto group if import in infinity inout interleave label language length log match message mixed mod modifies module modulepar mtc noblock not not4b nowait of on optional or or4b out override param pattern port procedure record recursive rem repeat return runs select self sender set signature system template testcase to type union value valueof var variant while with xor xor4b"),
  builtin: words("bit2hex bit2int bit2oct bit2str char2int char2oct encvalue decomp decvalue float2int float2str hex2bit hex2int hex2oct hex2str int2bit int2char int2float int2hex int2oct int2str int2unichar isbound ischosen ispresent isvalue lengthof log2str oct2bit oct2char oct2hex oct2int oct2str regexp replace rnd sizeof str2bit str2float str2hex str2int str2oct substr unichar2int unichar2char enum2int"),
  types: words("anytype bitstring boolean char charstring default float hexstring integer objid octetstring universal verdicttype timer"),
  timerOps: words("read running start stop timeout"),
  portOps: words("call catch check clear getcall getreply halt raise receive reply send trigger"),
  configOps: words("create connect disconnect done kill killed map unmap"),
  verdictOps: words("getverdict setverdict"),
  sutOps: words("action"),
  functionOps: words("apply derefers refers"),
  verdictConsts: words("error fail inconc none pass"),
  booleanConsts: words("true false"),
  otherConsts: words("null NULL omit"),
  visibilityModifiers: words("private public friend"),
  templateMatch: words("complement ifpresent subset superset permutation"),
  multiLineStrings: true
}, wordList = [];
function add(e) {
  if (e) for (var C in e) e.hasOwnProperty(C) && wordList.push(C);
}
add(parserConfig.keywords), add(parserConfig.builtin), add(parserConfig.timerOps), add(parserConfig.portOps);
var keywords = parserConfig.keywords || {}, builtin = parserConfig.builtin || {}, timerOps = parserConfig.timerOps || {}, portOps = parserConfig.portOps || {}, configOps = parserConfig.configOps || {}, verdictOps = parserConfig.verdictOps || {}, sutOps = parserConfig.sutOps || {}, functionOps = parserConfig.functionOps || {}, verdictConsts = parserConfig.verdictConsts || {}, booleanConsts = parserConfig.booleanConsts || {}, otherConsts = parserConfig.otherConsts || {}, types = parserConfig.types || {}, visibilityModifiers = parserConfig.visibilityModifiers || {}, templateMatch = parserConfig.templateMatch || {}, multiLineStrings = parserConfig.multiLineStrings, indentStatements = parserConfig.indentStatements !== false, isOperatorChar = /[+\-*&@=<>!\/]/, curPunc;
function tokenBase(e, C) {
  var w = e.next();
  if (w == '"' || w == "'") return C.tokenize = tokenString(w), C.tokenize(e, C);
  if (/[\[\]{}\(\),;\\:\?\.]/.test(w)) return curPunc = w, "punctuation";
  if (w == "#") return e.skipToEnd(), "atom";
  if (w == "%") return e.eatWhile(/\b/), "atom";
  if (/\d/.test(w)) return e.eatWhile(/[\w\.]/), "number";
  if (w == "/") {
    if (e.eat("*")) return C.tokenize = tokenComment, tokenComment(e, C);
    if (e.eat("/")) return e.skipToEnd(), "comment";
  }
  if (isOperatorChar.test(w)) return w == "@" && (e.match("try") || e.match("catch") || e.match("lazy")) ? "keyword" : (e.eatWhile(isOperatorChar), "operator");
  e.eatWhile(/[\w\$_\xa1-\uffff]/);
  var T = e.current();
  return keywords.propertyIsEnumerable(T) ? "keyword" : builtin.propertyIsEnumerable(T) ? "builtin" : timerOps.propertyIsEnumerable(T) || configOps.propertyIsEnumerable(T) || verdictOps.propertyIsEnumerable(T) || portOps.propertyIsEnumerable(T) || sutOps.propertyIsEnumerable(T) || functionOps.propertyIsEnumerable(T) ? "def" : verdictConsts.propertyIsEnumerable(T) || booleanConsts.propertyIsEnumerable(T) || otherConsts.propertyIsEnumerable(T) ? "string" : types.propertyIsEnumerable(T) ? "typeName.standard" : visibilityModifiers.propertyIsEnumerable(T) ? "modifier" : templateMatch.propertyIsEnumerable(T) ? "atom" : "variable";
}
function tokenString(e) {
  return function(C, w) {
    for (var T = false, E, D = false; (E = C.next()) != null; ) {
      if (E == e && !T) {
        var O = C.peek();
        O && (O = O.toLowerCase(), (O == "b" || O == "h" || O == "o") && C.next()), D = true;
        break;
      }
      T = !T && E == "\\";
    }
    return (D || !(T || multiLineStrings)) && (w.tokenize = null), "string";
  };
}
function tokenComment(e, C) {
  for (var w = false, T; T = e.next(); ) {
    if (T == "/" && w) {
      C.tokenize = null;
      break;
    }
    w = T == "*";
  }
  return "comment";
}
function Context(e, C, w, T, E) {
  this.indented = e, this.column = C, this.type = w, this.align = T, this.prev = E;
}
function pushContext(e, C, w) {
  var T = e.indented;
  return e.context && e.context.type == "statement" && (T = e.context.indented), e.context = new Context(T, C, w, null, e.context);
}
function popContext(e) {
  var C = e.context.type;
  return (C == ")" || C == "]" || C == "}") && (e.indented = e.context.indented), e.context = e.context.prev;
}
const ttcn = {
  name: "ttcn",
  startState: function() {
    return {
      tokenize: null,
      context: new Context(0, 0, "top", false),
      indented: 0,
      startOfLine: true
    };
  },
  token: function(e, C) {
    var w = C.context;
    if (e.sol() && (w.align ?? (w.align = false), C.indented = e.indentation(), C.startOfLine = true), e.eatSpace()) return null;
    curPunc = null;
    var T = (C.tokenize || tokenBase)(e, C);
    if (T == "comment") return T;
    if (w.align ?? (w.align = true), (curPunc == ";" || curPunc == ":" || curPunc == ",") && w.type == "statement") popContext(C);
    else if (curPunc == "{") pushContext(C, e.column(), "}");
    else if (curPunc == "[") pushContext(C, e.column(), "]");
    else if (curPunc == "(") pushContext(C, e.column(), ")");
    else if (curPunc == "}") {
      for (; w.type == "statement"; ) w = popContext(C);
      for (w.type == "}" && (w = popContext(C)); w.type == "statement"; ) w = popContext(C);
    } else curPunc == w.type ? popContext(C) : indentStatements && ((w.type == "}" || w.type == "top") && curPunc != ";" || w.type == "statement" && curPunc == "newstatement") && pushContext(C, e.column(), "statement");
    return C.startOfLine = false, T;
  },
  languageData: {
    indentOnInput: /^\s*[{}]$/,
    commentTokens: {
      line: "//",
      block: {
        open: "/*",
        close: "*/"
      }
    },
    autocomplete: wordList
  }
};
export {
  ttcn as t
};
