function mkVerilog(e) {
  var t = e.statementIndentUnit, n = e.dontAlignCalls, r = e.noIndentKeywords || [], i = e.multiLineStrings, a = e.hooks || {};
  function o(e2) {
    for (var t2 = {}, n2 = e2.split(" "), r2 = 0; r2 < n2.length; ++r2) t2[n2[r2]] = true;
    return t2;
  }
  var s = o("accept_on alias always always_comb always_ff always_latch and assert assign assume automatic before begin bind bins binsof bit break buf bufif0 bufif1 byte case casex casez cell chandle checker class clocking cmos config const constraint context continue cover covergroup coverpoint cross deassign default defparam design disable dist do edge else end endcase endchecker endclass endclocking endconfig endfunction endgenerate endgroup endinterface endmodule endpackage endprimitive endprogram endproperty endspecify endsequence endtable endtask enum event eventually expect export extends extern final first_match for force foreach forever fork forkjoin function generate genvar global highz0 highz1 if iff ifnone ignore_bins illegal_bins implements implies import incdir include initial inout input inside instance int integer interconnect interface intersect join join_any join_none large let liblist library local localparam logic longint macromodule matches medium modport module nand negedge nettype new nexttime nmos nor noshowcancelled not notif0 notif1 null or output package packed parameter pmos posedge primitive priority program property protected pull0 pull1 pulldown pullup pulsestyle_ondetect pulsestyle_onevent pure rand randc randcase randsequence rcmos real realtime ref reg reject_on release repeat restrict return rnmos rpmos rtran rtranif0 rtranif1 s_always s_eventually s_nexttime s_until s_until_with scalared sequence shortint shortreal showcancelled signed small soft solve specify specparam static string strong strong0 strong1 struct super supply0 supply1 sync_accept_on sync_reject_on table tagged task this throughout time timeprecision timeunit tran tranif0 tranif1 tri tri0 tri1 triand trior trireg type typedef union unique unique0 unsigned until until_with untyped use uwire var vectored virtual void wait wait_order wand weak weak0 weak1 while wildcard wire with within wor xnor xor"), c = /[\+\-\*\/!~&|^%=?:]/, l = /[\[\]{}()]/, u = /\d[0-9_]*/, d = /\d*\s*'s?d\s*\d[0-9_]*/i, f = /\d*\s*'s?b\s*[xz01][xz01_]*/i, p = /\d*\s*'s?o\s*[xz0-7][xz0-7_]*/i, m = /\d*\s*'s?h\s*[0-9a-fxz?][0-9a-fxz?_]*/i, h = /(\d[\d_]*(\.\d[\d_]*)?E-?[\d_]+)|(\d[\d_]*\.\d[\d_]*)/i, g = /^((\w+)|[)}\]])/, _ = /[)}\]]/, v, y, b = o("case checker class clocking config function generate interface module package primitive program property specify sequence table task"), x = {};
  for (var S in b) x[S] = "end" + S;
  for (var C in x.begin = "end", x.casex = "endcase", x.casez = "endcase", x.do = "while", x.fork = "join;join_any;join_none", x.covergroup = "endgroup", r) {
    var S = r[C];
    x[S] && (x[S] = void 0);
  }
  var w = o("always always_comb always_ff always_latch assert assign assume else export for foreach forever if import initial repeat while");
  function T(e2, t2) {
    var n2 = e2.peek(), r2;
    if (a[n2] && (r2 = a[n2](e2, t2)) != 0 || a.tokenBase && (r2 = a.tokenBase(e2, t2)) != 0) return r2;
    if (/[,;:\.]/.test(n2)) return v = e2.next(), null;
    if (l.test(n2)) return v = e2.next(), "bracket";
    if (n2 == "`") return e2.next(), e2.eatWhile(/[\w\$_]/) ? "def" : null;
    if (n2 == "$") return e2.next(), e2.eatWhile(/[\w\$_]/) ? "meta" : null;
    if (n2 == "#") return e2.next(), e2.eatWhile(/[\d_.]/), "def";
    if (n2 == '"') return e2.next(), t2.tokenize = E(n2), t2.tokenize(e2, t2);
    if (n2 == "/") {
      if (e2.next(), e2.eat("*")) return t2.tokenize = D, D(e2, t2);
      if (e2.eat("/")) return e2.skipToEnd(), "comment";
      e2.backUp(1);
    }
    if (e2.match(h) || e2.match(d) || e2.match(f) || e2.match(p) || e2.match(m) || e2.match(u) || e2.match(h)) return "number";
    if (e2.eatWhile(c)) return "meta";
    if (e2.eatWhile(/[\w\$_]/)) {
      var i2 = e2.current();
      return s[i2] ? (x[i2] && (v = "newblock"), w[i2] && (v = "newstatement"), y = i2, "keyword") : "variable";
    }
    return e2.next(), null;
  }
  function E(e2) {
    return function(t2, n2) {
      for (var r2 = false, a2, o2 = false; (a2 = t2.next()) != null; ) {
        if (a2 == e2 && !r2) {
          o2 = true;
          break;
        }
        r2 = !r2 && a2 == "\\";
      }
      return (o2 || !(r2 || i)) && (n2.tokenize = T), "string";
    };
  }
  function D(e2, t2) {
    for (var n2 = false, r2; r2 = e2.next(); ) {
      if (r2 == "/" && n2) {
        t2.tokenize = T;
        break;
      }
      n2 = r2 == "*";
    }
    return "comment";
  }
  function O(e2, t2, n2, r2, i2) {
    this.indented = e2, this.column = t2, this.type = n2, this.align = r2, this.prev = i2;
  }
  function k(e2, t2, n2) {
    var r2 = e2.indented;
    return e2.context = new O(r2, t2, n2, null, e2.context);
  }
  function A(e2) {
    var t2 = e2.context.type;
    return (t2 == ")" || t2 == "]" || t2 == "}") && (e2.indented = e2.context.indented), e2.context = e2.context.prev;
  }
  function j(e2, t2) {
    if (e2 == t2) return true;
    var n2 = t2.split(";");
    for (var r2 in n2) if (e2 == n2[r2]) return true;
    return false;
  }
  function M() {
    var e2 = [];
    for (var t2 in x) if (x[t2]) {
      var n2 = x[t2].split(";");
      for (var r2 in n2) e2.push(n2[r2]);
    }
    return /* @__PURE__ */ RegExp("[{}()\\[\\]]|(" + e2.join("|") + ")$");
  }
  return {
    name: "verilog",
    startState: function(e2) {
      var t2 = {
        tokenize: null,
        context: new O(-e2, 0, "top", false),
        indented: 0,
        startOfLine: true
      };
      return a.startState && a.startState(t2), t2;
    },
    token: function(e2, t2) {
      var n2 = t2.context;
      if (e2.sol() && (n2.align ?? (n2.align = false), t2.indented = e2.indentation(), t2.startOfLine = true), a.token) {
        var r2 = a.token(e2, t2);
        if (r2 !== void 0) return r2;
      }
      if (e2.eatSpace()) return null;
      v = null, y = null;
      var r2 = (t2.tokenize || T)(e2, t2);
      if (r2 == "comment" || r2 == "meta" || r2 == "variable") return r2;
      if (n2.align ?? (n2.align = true), v == n2.type) A(t2);
      else if (v == ";" && n2.type == "statement" || n2.type && j(y, n2.type)) for (n2 = A(t2); n2 && n2.type == "statement"; ) n2 = A(t2);
      else if (v == "{") k(t2, e2.column(), "}");
      else if (v == "[") k(t2, e2.column(), "]");
      else if (v == "(") k(t2, e2.column(), ")");
      else if (n2 && n2.type == "endcase" && v == ":") k(t2, e2.column(), "statement");
      else if (v == "newstatement") k(t2, e2.column(), "statement");
      else if (v == "newblock" && !(y == "function" && n2 && (n2.type == "statement" || n2.type == "endgroup")) && !(y == "task" && n2 && n2.type == "statement")) {
        var i2 = x[y];
        k(t2, e2.column(), i2);
      }
      return t2.startOfLine = false, r2;
    },
    indent: function(e2, r2, i2) {
      if (e2.tokenize != T && e2.tokenize != null) return null;
      if (a.indent) {
        var o2 = a.indent(e2);
        if (o2 >= 0) return o2;
      }
      var s2 = e2.context, c2 = r2 && r2.charAt(0);
      s2.type == "statement" && c2 == "}" && (s2 = s2.prev);
      var l2 = false, u2 = r2.match(g);
      return u2 && (l2 = j(u2[0], s2.type)), s2.type == "statement" ? s2.indented + (c2 == "{" ? 0 : t || i2.unit) : _.test(s2.type) && s2.align && !n ? s2.column + (l2 ? 0 : 1) : s2.type == ")" && !l2 ? s2.indented + (t || i2.unit) : s2.indented + (l2 ? 0 : i2.unit);
    },
    languageData: {
      indentOnInput: M(),
      commentTokens: {
        line: "//",
        block: {
          open: "/*",
          close: "*/"
        }
      }
    }
  };
}
const verilog = mkVerilog({});
var tlvIdentifierStyle = {
  "|": "link",
  ">": "property",
  $: "variable",
  $$: "variable",
  "?$": "qualifier",
  "?*": "qualifier",
  "-": "contentSeparator",
  "/": "property",
  "/-": "property",
  "@": "variableName.special",
  "@-": "variableName.special",
  "@++": "variableName.special",
  "@+=": "variableName.special",
  "@+=-": "variableName.special",
  "@--": "variableName.special",
  "@-=": "variableName.special",
  "%+": "tag",
  "%-": "tag",
  "%": "tag",
  ">>": "tag",
  "<<": "tag",
  "<>": "tag",
  "#": "tag",
  "^": "attribute",
  "^^": "attribute",
  "^!": "attribute",
  "*": "variable",
  "**": "variable",
  "\\": "keyword",
  '"': "comment"
}, tlvScopePrefixChars = {
  "/": "beh-hier",
  ">": "beh-hier",
  "-": "phys-hier",
  "|": "pipe",
  "?": "when",
  "@": "stage",
  "\\": "keyword"
}, tlvIndentUnit = 3, tlvTrackStatements = false, tlvIdentMatch = /^([~!@#\$%\^&\*-\+=\?\/\\\|'"<>]+)([\d\w_]*)/, tlvLineIndentationMatch = /^[! ] */, tlvCommentMatch = /^\/[\/\*]/;
mkVerilog({ hooks: {
  electricInput: false,
  token: function(e, t) {
    var l = void 0, u;
    if (e.sol() && !t.tlvInBlockComment) {
      e.peek() == "\\" && (l = "def", e.skipToEnd(), e.string.match(/\\SV/) ? t.tlvCodeActive = false : e.string.match(/\\TLV/) && (t.tlvCodeActive = true)), t.tlvCodeActive && e.pos == 0 && t.indented == 0 && (u = e.match(tlvLineIndentationMatch, false)) && (t.indented = u[0].length);
      var d = t.indented, f = d / tlvIndentUnit;
      if (f <= t.tlvIndentationStyle.length) {
        var p = e.string.length == d, m = f * tlvIndentUnit;
        if (m < e.string.length) {
          var h = e.string.slice(m), g = h[0];
          tlvScopePrefixChars[g] && (u = h.match(tlvIdentMatch)) && tlvIdentifierStyle[u[1]] && (d += tlvIndentUnit, g == "\\" && m > 0 || (t.tlvIndentationStyle[f] = tlvScopePrefixChars[g], tlvTrackStatements && (t.statementComment = false), f++));
        }
        if (!p) for (; t.tlvIndentationStyle.length > f; ) t.tlvIndentationStyle.pop();
      }
      t.tlvNextIndent = d;
    }
    if (t.tlvCodeActive) {
      var _ = false;
      tlvTrackStatements && (_ = e.peek() != " " && l === void 0 && !t.tlvInBlockComment && e.column() == t.tlvIndentationStyle.length * tlvIndentUnit, _ && (t.statementComment && (_ = false), t.statementComment = e.match(tlvCommentMatch, false)));
      var u;
      if (l === void 0) if (t.tlvInBlockComment) e.match(/^.*?\*\//) ? (t.tlvInBlockComment = false, tlvTrackStatements && !e.eol() && (t.statementComment = false)) : e.skipToEnd(), l = "comment";
      else if ((u = e.match(tlvCommentMatch)) && !t.tlvInBlockComment) u[0] == "//" ? e.skipToEnd() : t.tlvInBlockComment = true, l = "comment";
      else if (u = e.match(tlvIdentMatch)) {
        var v = u[1], y = u[2];
        tlvIdentifierStyle.hasOwnProperty(v) && (y.length > 0 || e.eol()) ? l = tlvIdentifierStyle[v] : e.backUp(e.current().length - 1);
      } else e.match(/^\t+/) ? l = "invalid" : e.match(/^[\[\]{}\(\);\:]+/) ? l = "meta" : (u = e.match(/^[mM]4([\+_])?[\w\d_]*/)) ? l = u[1] == "+" ? "keyword.special" : "keyword" : e.match(/^ +/) ? e.eol() && (l = "error") : e.match(/^[\w\d_]+/) ? l = "number" : e.next();
    } else e.match(/^[mM]4([\w\d_]*)/) && (l = "keyword");
    return l;
  },
  indent: function(e) {
    return e.tlvCodeActive == 1 ? e.tlvNextIndent : -1;
  },
  startState: function(e) {
    e.tlvIndentationStyle = [], e.tlvCodeActive = true, e.tlvNextIndent = -1, e.tlvInBlockComment = false, tlvTrackStatements && (e.statementComment = false);
  }
} });
export {
  verilog as t
};
