function wordObj(e) {
  for (var s = {}, c = 0, l = e.length; c < l; ++c) s[e[c]] = true;
  return s;
}
var keywordList = /* @__PURE__ */ "alias.and.BEGIN.begin.break.case.class.def.defined?.do.else.elsif.END.end.ensure.false.for.if.in.module.next.not.or.redo.rescue.retry.return.self.super.then.true.undef.unless.until.when.while.yield.nil.raise.throw.catch.fail.loop.callcc.caller.lambda.proc.public.protected.private.require.load.require_relative.extend.autoload.__END__.__FILE__.__LINE__.__dir__".split("."), keywords = wordObj(keywordList), indentWords = wordObj([
  "def",
  "class",
  "case",
  "for",
  "while",
  "until",
  "module",
  "catch",
  "loop",
  "proc",
  "begin"
]), dedentWords = wordObj(["end", "until"]), opening = {
  "[": "]",
  "{": "}",
  "(": ")"
}, closing = {
  "]": "[",
  "}": "{",
  ")": "("
}, curPunc;
function chain(e, s, c) {
  return c.tokenize.push(e), e(s, c);
}
function tokenBase(e, s) {
  if (e.sol() && e.match("=begin") && e.eol()) return s.tokenize.push(readBlockComment), "comment";
  if (e.eatSpace()) return null;
  var c = e.next(), l;
  if (c == "`" || c == "'" || c == '"') return chain(readQuoted(c, "string", c == '"' || c == "`"), e, s);
  if (c == "/") return regexpAhead(e) ? chain(readQuoted(c, "string.special", true), e, s) : "operator";
  if (c == "%") {
    var u = "string", f = true;
    e.eat("s") ? u = "atom" : e.eat(/[WQ]/) ? u = "string" : e.eat(/[r]/) ? u = "string.special" : e.eat(/[wxq]/) && (u = "string", f = false);
    var h = e.eat(/[^\w\s=]/);
    return h ? (opening.propertyIsEnumerable(h) && (h = opening[h]), chain(readQuoted(h, u, f, true), e, s)) : "operator";
  } else if (c == "#") return e.skipToEnd(), "comment";
  else if (c == "<" && (l = e.match(/^<([-~])[\`\"\']?([a-zA-Z_?]\w*)[\`\"\']?(?:;|$)/))) return chain(readHereDoc(l[2], l[1]), e, s);
  else if (c == "0") return e.eat("x") ? e.eatWhile(/[\da-fA-F]/) : e.eat("b") ? e.eatWhile(/[01]/) : e.eatWhile(/[0-7]/), "number";
  else if (/\d/.test(c)) return e.match(/^[\d_]*(?:\.[\d_]+)?(?:[eE][+\-]?[\d_]+)?/), "number";
  else if (c == "?") {
    for (; e.match(/^\\[CM]-/); ) ;
    return e.eat("\\") ? e.eatWhile(/\w/) : e.next(), "string";
  } else if (c == ":") return e.eat("'") ? chain(readQuoted("'", "atom", false), e, s) : e.eat('"') ? chain(readQuoted('"', "atom", true), e, s) : e.eat(/[\<\>]/) ? (e.eat(/[\<\>]/), "atom") : e.eat(/[\+\-\*\/\&\|\:\!]/) ? "atom" : e.eat(/[a-zA-Z$@_\xa1-\uffff]/) ? (e.eatWhile(/[\w$\xa1-\uffff]/), e.eat(/[\?\!\=]/), "atom") : "operator";
  else if (c == "@" && e.match(/^@?[a-zA-Z_\xa1-\uffff]/)) return e.eat("@"), e.eatWhile(/[\w\xa1-\uffff]/), "propertyName";
  else if (c == "$") return e.eat(/[a-zA-Z_]/) ? e.eatWhile(/[\w]/) : e.eat(/\d/) ? e.eat(/\d/) : e.next(), "variableName.special";
  else if (/[a-zA-Z_\xa1-\uffff]/.test(c)) return e.eatWhile(/[\w\xa1-\uffff]/), e.eat(/[\?\!]/), e.eat(":") ? "atom" : "variable";
  else if (c == "|" && (s.varList || s.lastTok == "{" || s.lastTok == "do")) return curPunc = "|", null;
  else if (/[\(\)\[\]{}\\;]/.test(c)) return curPunc = c, null;
  else if (c == "-" && e.eat(">")) return "operator";
  else if (/[=+\-\/*:\.^%<>~|]/.test(c)) {
    var g = e.eatWhile(/[=+\-\/*:\.^%<>~|]/);
    return c == "." && !g && (curPunc = "."), "operator";
  } else return null;
}
function regexpAhead(e) {
  for (var s = e.pos, c = 0, l, u = false, d = false; (l = e.next()) != null; ) if (d) d = false;
  else {
    if ("[{(".indexOf(l) > -1) c++;
    else if ("]})".indexOf(l) > -1) {
      if (c--, c < 0) break;
    } else if (l == "/" && c == 0) {
      u = true;
      break;
    }
    d = l == "\\";
  }
  return e.backUp(e.pos - s), u;
}
function tokenBaseUntilBrace(e) {
  return e || (e = 1), function(s, c) {
    if (s.peek() == "}") {
      if (e == 1) return c.tokenize.pop(), c.tokenize[c.tokenize.length - 1](s, c);
      c.tokenize[c.tokenize.length - 1] = tokenBaseUntilBrace(e - 1);
    } else s.peek() == "{" && (c.tokenize[c.tokenize.length - 1] = tokenBaseUntilBrace(e + 1));
    return tokenBase(s, c);
  };
}
function tokenBaseOnce() {
  var e = false;
  return function(s, c) {
    return e ? (c.tokenize.pop(), c.tokenize[c.tokenize.length - 1](s, c)) : (e = true, tokenBase(s, c));
  };
}
function readQuoted(e, s, c, l) {
  return function(u, d) {
    var f = false, p;
    for (d.context.type === "read-quoted-paused" && (d.context = d.context.prev, u.eat("}")); (p = u.next()) != null; ) {
      if (p == e && (l || !f)) {
        d.tokenize.pop();
        break;
      }
      if (c && p == "#" && !f) {
        if (u.eat("{")) {
          e == "}" && (d.context = {
            prev: d.context,
            type: "read-quoted-paused"
          }), d.tokenize.push(tokenBaseUntilBrace());
          break;
        } else if (/[@\$]/.test(u.peek())) {
          d.tokenize.push(tokenBaseOnce());
          break;
        }
      }
      f = !f && p == "\\";
    }
    return s;
  };
}
function readHereDoc(e, s) {
  return function(c, l) {
    return s && c.eatSpace(), c.match(e) ? l.tokenize.pop() : c.skipToEnd(), "string";
  };
}
function readBlockComment(e, s) {
  return e.sol() && e.match("=end") && e.eol() && s.tokenize.pop(), e.skipToEnd(), "comment";
}
const ruby = {
  name: "ruby",
  startState: function(e) {
    return {
      tokenize: [tokenBase],
      indented: 0,
      context: {
        type: "top",
        indented: -e
      },
      continuedLine: false,
      lastTok: null,
      varList: false
    };
  },
  token: function(e, s) {
    curPunc = null, e.sol() && (s.indented = e.indentation());
    var d = s.tokenize[s.tokenize.length - 1](e, s), f, m = curPunc;
    if (d == "variable") {
      var h = e.current();
      d = s.lastTok == "." ? "property" : keywords.propertyIsEnumerable(e.current()) ? "keyword" : /^[A-Z]/.test(h) ? "tag" : s.lastTok == "def" || s.lastTok == "class" || s.varList ? "def" : "variable", d == "keyword" && (m = h, indentWords.propertyIsEnumerable(h) ? f = "indent" : dedentWords.propertyIsEnumerable(h) ? f = "dedent" : ((h == "if" || h == "unless") && e.column() == e.indentation() || h == "do" && s.context.indented < s.indented) && (f = "indent"));
    }
    return (curPunc || d && d != "comment") && (s.lastTok = m), curPunc == "|" && (s.varList = !s.varList), f == "indent" || /[\(\[\{]/.test(curPunc) ? s.context = {
      prev: s.context,
      type: curPunc || d,
      indented: s.indented
    } : (f == "dedent" || /[\)\]\}]/.test(curPunc)) && s.context.prev && (s.context = s.context.prev), e.eol() && (s.continuedLine = curPunc == "\\" || d == "operator"), d;
  },
  indent: function(e, s, c) {
    if (e.tokenize[e.tokenize.length - 1] != tokenBase) return null;
    var l = s && s.charAt(0), u = e.context, d = u.type == closing[l] || u.type == "keyword" && /^(?:end|until|else|elsif|when|rescue)\b/.test(s);
    return u.indented + (d ? 0 : c.unit) + (e.continuedLine ? c.unit : 0);
  },
  languageData: {
    indentOnInput: /^\s*(?:end|rescue|elsif|else|\})$/,
    commentTokens: { line: "#" },
    autocomplete: keywordList
  }
};
export {
  ruby as t
};
