function words(e) {
  for (var d = {}, f = e.split(" "), p = 0; p < f.length; ++p) d[f[p]] = true;
  return d;
}
var keywords = words("algorithm and annotation assert block break class connect connector constant constrainedby der discrete each else elseif elsewhen encapsulated end enumeration equation expandable extends external false final flow for function if import impure in initial inner input loop model not operator or outer output package parameter partial protected public pure record redeclare replaceable return stream then true type when while within"), builtin = words("abs acos actualStream asin atan atan2 cardinality ceil cos cosh delay div edge exp floor getInstanceName homotopy inStream integer log log10 mod pre reinit rem semiLinear sign sin sinh spatialDistribution sqrt tan tanh"), atoms = words("Real Boolean Integer String"), completions = [].concat(Object.keys(keywords), Object.keys(builtin), Object.keys(atoms)), isSingleOperatorChar = /[;=\(:\),{}.*<>+\-\/^\[\]]/, isDoubleOperatorChar = /(:=|<=|>=|==|<>|\.\+|\.\-|\.\*|\.\/|\.\^)/, isDigit = /[0-9]/, isNonDigit = /[_a-zA-Z]/;
function tokenLineComment(e, d) {
  return e.skipToEnd(), d.tokenize = null, "comment";
}
function tokenBlockComment(e, d) {
  for (var f = false, p; p = e.next(); ) {
    if (f && p == "/") {
      d.tokenize = null;
      break;
    }
    f = p == "*";
  }
  return "comment";
}
function tokenString(e, d) {
  for (var f = false, p; (p = e.next()) != null; ) {
    if (p == '"' && !f) {
      d.tokenize = null, d.sol = false;
      break;
    }
    f = !f && p == "\\";
  }
  return "string";
}
function tokenIdent(e, m) {
  for (e.eatWhile(isDigit); e.eat(isDigit) || e.eat(isNonDigit); ) ;
  var h = e.current();
  return m.sol && (h == "package" || h == "model" || h == "when" || h == "connector") ? m.level++ : m.sol && h == "end" && m.level > 0 && m.level--, m.tokenize = null, m.sol = false, keywords.propertyIsEnumerable(h) ? "keyword" : builtin.propertyIsEnumerable(h) ? "builtin" : atoms.propertyIsEnumerable(h) ? "atom" : "variable";
}
function tokenQIdent(e, d) {
  for (; e.eat(/[^']/); ) ;
  return d.tokenize = null, d.sol = false, e.eat("'") ? "variable" : "error";
}
function tokenUnsignedNumber(e, d) {
  return e.eatWhile(isDigit), e.eat(".") && e.eatWhile(isDigit), (e.eat("e") || e.eat("E")) && (e.eat("-") || e.eat("+"), e.eatWhile(isDigit)), d.tokenize = null, d.sol = false, "number";
}
const modelica = {
  name: "modelica",
  startState: function() {
    return {
      tokenize: null,
      level: 0,
      sol: true
    };
  },
  token: function(e, d) {
    if (d.tokenize != null) return d.tokenize(e, d);
    if (e.sol() && (d.sol = true), e.eatSpace()) return d.tokenize = null, null;
    var f = e.next();
    if (f == "/" && e.eat("/")) d.tokenize = tokenLineComment;
    else if (f == "/" && e.eat("*")) d.tokenize = tokenBlockComment;
    else if (isDoubleOperatorChar.test(f + e.peek())) return e.next(), d.tokenize = null, "operator";
    else if (isSingleOperatorChar.test(f)) return d.tokenize = null, "operator";
    else if (isNonDigit.test(f)) d.tokenize = tokenIdent;
    else if (f == "'" && e.peek() && e.peek() != "'") d.tokenize = tokenQIdent;
    else if (f == '"') d.tokenize = tokenString;
    else if (isDigit.test(f)) d.tokenize = tokenUnsignedNumber;
    else return d.tokenize = null, "error";
    return d.tokenize(e, d);
  },
  indent: function(e, d, f) {
    if (e.tokenize != null) return null;
    var p = e.level;
    return /(algorithm)/.test(d) && p--, /(equation)/.test(d) && p--, /(initial algorithm)/.test(d) && p--, /(initial equation)/.test(d) && p--, /(end)/.test(d) && p--, p > 0 ? f.unit * p : 0;
  },
  languageData: {
    commentTokens: {
      line: "//",
      block: {
        open: "/*",
        close: "*/"
      }
    },
    autocomplete: completions
  }
};
export {
  modelica as t
};
