var keywords = {
  term: true,
  method: true,
  accu: true,
  rule: true,
  then: true,
  is: true,
  and: true,
  or: true,
  if: true,
  default: true
}, start_blocks = {
  var_input: true,
  var_output: true,
  fuzzify: true,
  defuzzify: true,
  function_block: true,
  ruleblock: true
}, end_blocks = {
  end_ruleblock: true,
  end_defuzzify: true,
  end_function_block: true,
  end_fuzzify: true,
  end_var: true
}, atoms = {
  true: true,
  false: true,
  nan: true,
  real: true,
  min: true,
  max: true,
  cog: true,
  cogs: true
}, isOperatorChar = /[+\-*&^%:=<>!|\/]/;
function tokenBase(o, c) {
  var l = o.next();
  if (/[\d\.]/.test(l)) return l == "." ? o.match(/^[0-9]+([eE][\-+]?[0-9]+)?/) : l == "0" ? o.match(/^[xX][0-9a-fA-F]+/) || o.match(/^0[0-7]+/) : o.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/), "number";
  if (l == "/" || l == "(") {
    if (o.eat("*")) return c.tokenize = tokenComment, tokenComment(o, c);
    if (o.eat("/")) return o.skipToEnd(), "comment";
  }
  if (isOperatorChar.test(l)) return o.eatWhile(isOperatorChar), "operator";
  o.eatWhile(/[\w\$_\xa1-\uffff]/);
  var u = o.current().toLowerCase();
  return keywords.propertyIsEnumerable(u) || start_blocks.propertyIsEnumerable(u) || end_blocks.propertyIsEnumerable(u) ? "keyword" : atoms.propertyIsEnumerable(u) ? "atom" : "variable";
}
function tokenComment(e, n) {
  for (var r = false, i; i = e.next(); ) {
    if ((i == "/" || i == ")") && r) {
      n.tokenize = tokenBase;
      break;
    }
    r = i == "*";
  }
  return "comment";
}
function Context(e, n, r, i, a) {
  this.indented = e, this.column = n, this.type = r, this.align = i, this.prev = a;
}
function pushContext(e, n, r) {
  return e.context = new Context(e.indented, n, r, null, e.context);
}
function popContext(e) {
  if (e.context.prev) return e.context.type == "end_block" && (e.indented = e.context.indented), e.context = e.context.prev;
}
const fcl = {
  name: "fcl",
  startState: function(e) {
    return {
      tokenize: null,
      context: new Context(-e, 0, "top", false),
      indented: 0,
      startOfLine: true
    };
  },
  token: function(e, i) {
    var a = i.context;
    if (e.sol() && (a.align ?? (a.align = false), i.indented = e.indentation(), i.startOfLine = true), e.eatSpace()) return null;
    var s = (i.tokenize || tokenBase)(e, i);
    if (s == "comment") return s;
    a.align ?? (a.align = true);
    var c = e.current().toLowerCase();
    return start_blocks.propertyIsEnumerable(c) ? pushContext(i, e.column(), "end_block") : end_blocks.propertyIsEnumerable(c) && popContext(i), i.startOfLine = false, s;
  },
  indent: function(e, n, i) {
    if (e.tokenize != tokenBase && e.tokenize != null) return 0;
    var a = e.context, s = end_blocks.propertyIsEnumerable(n);
    return a.align ? a.column + (s ? 0 : 1) : a.indented + (s ? 0 : i.unit);
  },
  languageData: { commentTokens: {
    line: "//",
    block: {
      open: "(*",
      close: "*)"
    }
  } }
};
export {
  fcl
};
