var words = {};
function define(a, o) {
  for (var s = 0; s < o.length; s++) words[o[s]] = a;
}
var commonAtoms = ["true", "false"], commonKeywords = [
  "if",
  "then",
  "do",
  "else",
  "elif",
  "while",
  "until",
  "for",
  "in",
  "esac",
  "fi",
  "fin",
  "fil",
  "done",
  "exit",
  "set",
  "unset",
  "export",
  "function"
], commonCommands = /* @__PURE__ */ "ab.awk.bash.beep.cat.cc.cd.chown.chmod.chroot.clear.cp.curl.cut.diff.echo.find.gawk.gcc.get.git.grep.hg.kill.killall.ln.ls.make.mkdir.openssl.mv.nc.nl.node.npm.ping.ps.restart.rm.rmdir.sed.service.sh.shopt.shred.source.sort.sleep.ssh.start.stop.su.sudo.svn.tee.telnet.top.touch.vi.vim.wall.wc.wget.who.write.yes.zsh".split(".");
define("atom", commonAtoms), define("keyword", commonKeywords), define("builtin", commonCommands);
function tokenBase(a, o) {
  if (a.eatSpace()) return null;
  var s = a.sol(), c = a.next();
  if (c === "\\") return a.next(), null;
  if (c === "'" || c === '"' || c === "`") return o.tokens.unshift(tokenString(c, c === "`" ? "quote" : "string")), tokenize(a, o);
  if (c === "#") return s && a.eat("!") ? (a.skipToEnd(), "meta") : (a.skipToEnd(), "comment");
  if (c === "$") return o.tokens.unshift(tokenDollar), tokenize(a, o);
  if (c === "+" || c === "=") return "operator";
  if (c === "-") return a.eat("-"), a.eatWhile(/\w/), "attribute";
  if (c == "<") {
    if (a.match("<<")) return "operator";
    var l = a.match(/^<-?\s*(?:['"]([^'"]*)['"]|([^'"\s]*))/);
    if (l) return o.tokens.unshift(tokenHeredoc(l[1] || l[2])), "string.special";
  }
  if (/\d/.test(c) && (a.eatWhile(/\d/), a.eol() || !/\w/.test(a.peek()))) return "number";
  a.eatWhile(/[\w-]/);
  var u = a.current();
  return a.peek() === "=" && /\w+/.test(u) ? "def" : words.hasOwnProperty(u) ? words[u] : null;
}
function tokenString(e, a) {
  var o = e == "(" ? ")" : e == "{" ? "}" : e;
  return function(s, c) {
    for (var l, d = false; (l = s.next()) != null; ) {
      if (l === o && !d) {
        c.tokens.shift();
        break;
      } else if (l === "$" && !d && e !== "'" && s.peek() != o) {
        d = true, s.backUp(1), c.tokens.unshift(tokenDollar);
        break;
      } else if (!d && e !== o && l === e) return c.tokens.unshift(tokenString(e, a)), tokenize(s, c);
      else if (!d && /['"]/.test(l) && !/['"]/.test(e)) {
        c.tokens.unshift(tokenStringStart(l, "string")), s.backUp(1);
        break;
      }
      d = !d && l === "\\";
    }
    return a;
  };
}
function tokenStringStart(e, a) {
  return function(o, s) {
    return s.tokens[0] = tokenString(e, a), o.next(), tokenize(o, s);
  };
}
var tokenDollar = function(e, a) {
  a.tokens.length > 1 && e.eat("$");
  var o = e.next();
  return /['"({]/.test(o) ? (a.tokens[0] = tokenString(o, o == "(" ? "quote" : o == "{" ? "def" : "string"), tokenize(e, a)) : (/\d/.test(o) || e.eatWhile(/\w/), a.tokens.shift(), "def");
};
function tokenHeredoc(e) {
  return function(a, o) {
    return a.sol() && a.string == e && o.tokens.shift(), a.skipToEnd(), "string.special";
  };
}
function tokenize(e, a) {
  return (a.tokens[0] || tokenBase)(e, a);
}
const shell = {
  name: "shell",
  startState: function() {
    return { tokens: [] };
  },
  token: function(e, a) {
    return tokenize(e, a);
  },
  languageData: {
    autocomplete: commonAtoms.concat(commonKeywords, commonCommands),
    closeBrackets: { brackets: [
      "(",
      "[",
      "{",
      "'",
      '"',
      "`"
    ] },
    commentTokens: { line: "#" }
  }
};
export {
  shell as t
};
