function words(e) {
  for (var s = {}, c = e.split(" "), l = 0; l < c.length; ++l) s[c[l]] = true;
  return s;
}
var bodiedOps = words("Assert BackQuote D Defun Deriv For ForEach FromFile FromString Function Integrate InverseTaylor Limit LocalSymbols Macro MacroRule MacroRulePattern NIntegrate Rule RulePattern Subst TD TExplicitSum TSum Taylor Taylor1 Taylor2 Taylor3 ToFile ToStdout ToString TraceRule Until While"), pFloatForm = "(?:(?:\\.\\d+|\\d+\\.\\d*|\\d+)(?:[eE][+-]?\\d+)?)", pIdentifier = "(?:[a-zA-Z\\$'][a-zA-Z0-9\\$']*)", reFloatForm = new RegExp(pFloatForm), reIdentifier = new RegExp(pIdentifier), rePattern = /* @__PURE__ */ RegExp(pIdentifier + "?_" + pIdentifier), reFunctionLike = /* @__PURE__ */ RegExp(pIdentifier + "\\s*\\(");
function tokenBase(e, c) {
  var l = e.next();
  if (l === '"') return c.tokenize = tokenString, c.tokenize(e, c);
  if (l === "/") {
    if (e.eat("*")) return c.tokenize = tokenComment, c.tokenize(e, c);
    if (e.eat("/")) return e.skipToEnd(), "comment";
  }
  e.backUp(1);
  var d = e.match(/^(\w+)\s*\(/, false);
  d !== null && bodiedOps.hasOwnProperty(d[1]) && c.scopes.push("bodied");
  var f = currentScope(c);
  if (f === "bodied" && l === "[" && c.scopes.pop(), (l === "[" || l === "{" || l === "(") && c.scopes.push(l), f = currentScope(c), (f === "[" && l === "]" || f === "{" && l === "}" || f === "(" && l === ")") && c.scopes.pop(), l === ";") for (; f === "bodied"; ) c.scopes.pop(), f = currentScope(c);
  return e.match(/\d+ *#/, true, false) ? "qualifier" : e.match(reFloatForm, true, false) ? "number" : e.match(rePattern, true, false) ? "variableName.special" : e.match(/(?:\[|\]|{|}|\(|\))/, true, false) ? "bracket" : e.match(reFunctionLike, true, false) ? (e.backUp(1), "variableName.function") : e.match(reIdentifier, true, false) ? "variable" : e.match(/(?:\\|\+|\-|\*|\/|,|;|\.|:|@|~|=|>|<|&|\||_|`|'|\^|\?|!|%|#)/, true, false) ? "operator" : "error";
}
function tokenString(e, s) {
  for (var c, l = false, u = false; (c = e.next()) != null; ) {
    if (c === '"' && !u) {
      l = true;
      break;
    }
    u = !u && c === "\\";
  }
  return l && !u && (s.tokenize = tokenBase), "string";
}
function tokenComment(e, s) {
  for (var c, l; (l = e.next()) != null; ) {
    if (c === "*" && l === "/") {
      s.tokenize = tokenBase;
      break;
    }
    c = l;
  }
  return "comment";
}
function currentScope(e) {
  var s = null;
  return e.scopes.length > 0 && (s = e.scopes[e.scopes.length - 1]), s;
}
const yacas = {
  name: "yacas",
  startState: function() {
    return {
      tokenize: tokenBase,
      scopes: []
    };
  },
  token: function(e, s) {
    return e.eatSpace() ? null : s.tokenize(e, s);
  },
  indent: function(e, s, c) {
    if (e.tokenize !== tokenBase && e.tokenize !== null) return null;
    var l = 0;
    return (s === "]" || s === "];" || s === "}" || s === "};" || s === ");") && (l = -1), (e.scopes.length + l) * c.unit;
  },
  languageData: {
    electricInput: /[{}\[\]()\;]/,
    commentTokens: {
      line: "//",
      block: {
        open: "/*",
        close: "*/"
      }
    }
  }
};
export {
  yacas as t
};
