function buildRegexp(e, l) {
  l || (l = {});
  for (var u = l.prefix === void 0 ? "^" : l.prefix, d = l.suffix === void 0 ? "\\b" : l.suffix, f = 0; f < e.length; f++) e[f] instanceof RegExp ? e[f] = e[f].source : e[f] = e[f].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
  return RegExp(u + "(" + e.join("|") + ")" + d, "i");
}
var notCharacterOrDash = "(?=[^A-Za-z\\d\\-_]|$)", varNames = /[\w\-:]/, grammar = {
  keyword: buildRegexp([
    /begin|break|catch|continue|data|default|do|dynamicparam/,
    /else|elseif|end|exit|filter|finally|for|foreach|from|function|if|in/,
    /param|process|return|switch|throw|trap|try|until|where|while/
  ], { suffix: notCharacterOrDash }),
  number: /^((0x[\da-f]+)|((\d+\.\d+|\d\.|\.\d+|\d+)(e[\+\-]?\d+)?))[ld]?([kmgtp]b)?/i,
  operator: buildRegexp([buildRegexp([
    "f",
    /b?not/,
    /[ic]?split/,
    "join",
    /is(not)?/,
    "as",
    /[ic]?(eq|ne|[gl][te])/,
    /[ic]?(not)?(like|match|contains)/,
    /[ic]?replace/,
    /b?(and|or|xor)/
  ], { prefix: "-" }), /[+\-*\/%]=|\+\+|--|\.\.|[+\-*&^%:=!|\/]|<(?!#)|(?!#)>/], { suffix: "" }),
  builtin: buildRegexp([
    /[A-Z]:|%|\?/i,
    buildRegexp([
      /Add-(Computer|Content|History|Member|PSSnapin|Type)/,
      /Checkpoint-Computer/,
      /Clear-(Content|EventLog|History|Host|Item(Property)?|Variable)/,
      /Compare-Object/,
      /Complete-Transaction/,
      /Connect-PSSession/,
      /ConvertFrom-(Csv|Json|SecureString|StringData)/,
      /Convert-Path/,
      /ConvertTo-(Csv|Html|Json|SecureString|Xml)/,
      /Copy-Item(Property)?/,
      /Debug-Process/,
      /Disable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,
      /Disconnect-PSSession/,
      /Enable-(ComputerRestore|PSBreakpoint|PSRemoting|PSSessionConfiguration)/,
      /(Enter|Exit)-PSSession/,
      /Export-(Alias|Clixml|Console|Counter|Csv|FormatData|ModuleMember|PSSession)/,
      /ForEach-Object/,
      /Format-(Custom|List|Table|Wide)/,
      /* @__PURE__ */ RegExp("Get-(Acl|Alias|AuthenticodeSignature|ChildItem|Command|ComputerRestorePoint|Content|ControlPanelItem|Counter|Credential|Culture|Date|Event|EventLog|EventSubscriber|ExecutionPolicy|FormatData|Help|History|Host|HotFix|Item|ItemProperty|Job|Location|Member|Module|PfxCertificate|Process|PSBreakpoint|PSCallStack|PSDrive|PSProvider|PSSession|PSSessionConfiguration|PSSnapin|Random|Service|TraceSource|Transaction|TypeData|UICulture|Unique|Variable|Verb|WinEvent|WmiObject)"),
      /Group-Object/,
      /Import-(Alias|Clixml|Counter|Csv|LocalizedData|Module|PSSession)/,
      /ImportSystemModules/,
      /Invoke-(Command|Expression|History|Item|RestMethod|WebRequest|WmiMethod)/,
      /Join-Path/,
      /Limit-EventLog/,
      /Measure-(Command|Object)/,
      /Move-Item(Property)?/,
      /* @__PURE__ */ RegExp("New-(Alias|Event|EventLog|Item(Property)?|Module|ModuleManifest|Object|PSDrive|PSSession|PSSessionConfigurationFile|PSSessionOption|PSTransportOption|Service|TimeSpan|Variable|WebServiceProxy|WinEvent)"),
      /Out-(Default|File|GridView|Host|Null|Printer|String)/,
      /Pause/,
      /(Pop|Push)-Location/,
      /Read-Host/,
      /Receive-(Job|PSSession)/,
      /Register-(EngineEvent|ObjectEvent|PSSessionConfiguration|WmiEvent)/,
      /Remove-(Computer|Event|EventLog|Item(Property)?|Job|Module|PSBreakpoint|PSDrive|PSSession|PSSnapin|TypeData|Variable|WmiObject)/,
      /Rename-(Computer|Item(Property)?)/,
      /Reset-ComputerMachinePassword/,
      /Resolve-Path/,
      /Restart-(Computer|Service)/,
      /Restore-Computer/,
      /Resume-(Job|Service)/,
      /Save-Help/,
      /Select-(Object|String|Xml)/,
      /Send-MailMessage/,
      /* @__PURE__ */ RegExp("Set-(Acl|Alias|AuthenticodeSignature|Content|Date|ExecutionPolicy|Item(Property)?|Location|PSBreakpoint|PSDebug|PSSessionConfiguration|Service|StrictMode|TraceSource|Variable|WmiInstance)"),
      /Show-(Command|ControlPanelItem|EventLog)/,
      /Sort-Object/,
      /Split-Path/,
      /Start-(Job|Process|Service|Sleep|Transaction|Transcript)/,
      /Stop-(Computer|Job|Process|Service|Transcript)/,
      /Suspend-(Job|Service)/,
      /TabExpansion2/,
      /Tee-Object/,
      /Test-(ComputerSecureChannel|Connection|ModuleManifest|Path|PSSessionConfigurationFile)/,
      /Trace-Command/,
      /Unblock-File/,
      /Undo-Transaction/,
      /Unregister-(Event|PSSessionConfiguration)/,
      /Update-(FormatData|Help|List|TypeData)/,
      /Use-Transaction/,
      /Wait-(Event|Job|Process)/,
      /Where-Object/,
      /Write-(Debug|Error|EventLog|Host|Output|Progress|Verbose|Warning)/,
      /cd|help|mkdir|more|oss|prompt/,
      /ac|asnp|cat|cd|chdir|clc|clear|clhy|cli|clp|cls|clv|cnsn|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|dnsn|ebp/,
      /echo|epal|epcsv|epsn|erase|etsn|exsn|fc|fl|foreach|ft|fw|gal|gbp|gc|gci|gcm|gcs|gdr|ghy|gi|gjb|gl|gm|gmo|gp|gps/,
      /group|gsn|gsnp|gsv|gu|gv|gwmi|h|history|icm|iex|ihy|ii|ipal|ipcsv|ipmo|ipsn|irm|ise|iwmi|iwr|kill|lp|ls|man|md/,
      /measure|mi|mount|move|mp|mv|nal|ndr|ni|nmo|npssc|nsn|nv|ogv|oh|popd|ps|pushd|pwd|r|rbp|rcjb|rcsn|rd|rdr|ren|ri/,
      /rjb|rm|rmdir|rmo|rni|rnp|rp|rsn|rsnp|rujb|rv|rvpa|rwmi|sajb|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls/,
      /sort|sp|spjb|spps|spsv|start|sujb|sv|swmi|tee|trcm|type|where|wjb|write/
    ], {
      prefix: "",
      suffix: ""
    }),
    buildRegexp([
      /[$?^_]|Args|ConfirmPreference|ConsoleFileName|DebugPreference|Error|ErrorActionPreference|ErrorView|ExecutionContext/,
      /FormatEnumerationLimit|Home|Host|Input|MaximumAliasCount|MaximumDriveCount|MaximumErrorCount|MaximumFunctionCount/,
      /MaximumHistoryCount|MaximumVariableCount|MyInvocation|NestedPromptLevel|OutputEncoding|Pid|Profile|ProgressPreference/,
      /PSBoundParameters|PSCommandPath|PSCulture|PSDefaultParameterValues|PSEmailServer|PSHome|PSScriptRoot|PSSessionApplicationName/,
      /PSSessionConfigurationName|PSSessionOption|PSUICulture|PSVersionTable|Pwd|ShellId|StackTrace|VerbosePreference/,
      /WarningPreference|WhatIfPreference/,
      /Event|EventArgs|EventSubscriber|Sender/,
      /Matches|Ofs|ForEach|LastExitCode|PSCmdlet|PSItem|PSSenderInfo|This/,
      /true|false|null/
    ], {
      prefix: "\\$",
      suffix: ""
    })
  ], { suffix: notCharacterOrDash }),
  punctuation: /[\[\]{},;`\\\.]|@[({]/,
  variable: /^[A-Za-z\_][A-Za-z\-\_\d]*\b/
};
function tokenBase(e, l) {
  var f = l.returnStack[l.returnStack.length - 1];
  if (f && f.shouldReturnFrom(l)) return l.tokenize = f.tokenize, l.returnStack.pop(), l.tokenize(e, l);
  if (e.eatSpace()) return null;
  if (e.eat("(")) return l.bracketNesting += 1, "punctuation";
  if (e.eat(")")) return --l.bracketNesting, "punctuation";
  for (var p in grammar) if (e.match(grammar[p])) return p;
  var m = e.next();
  if (m === "'") return tokenSingleQuoteString(e, l);
  if (m === "$") return tokenVariable(e, l);
  if (m === '"') return tokenDoubleQuoteString(e, l);
  if (m === "<" && e.eat("#")) return l.tokenize = tokenComment, tokenComment(e, l);
  if (m === "#") return e.skipToEnd(), "comment";
  if (m === "@") {
    var h = e.eat(/["']/);
    if (h && e.eol()) return l.tokenize = tokenMultiString, l.startQuote = h[0], tokenMultiString(e, l);
    if (e.eol()) return "error";
    if (e.peek().match(/[({]/)) return "punctuation";
    if (e.peek().match(varNames)) return tokenVariable(e, l);
  }
  return "error";
}
function tokenSingleQuoteString(e, l) {
  for (var u; (u = e.peek()) != null; ) if (e.next(), u === "'" && !e.eat("'")) return l.tokenize = tokenBase, "string";
  return "error";
}
function tokenDoubleQuoteString(e, l) {
  for (var u; (u = e.peek()) != null; ) {
    if (u === "$") return l.tokenize = tokenStringInterpolation, "string";
    if (e.next(), u === "`") {
      e.next();
      continue;
    }
    if (u === '"' && !e.eat('"')) return l.tokenize = tokenBase, "string";
  }
  return "error";
}
function tokenStringInterpolation(e, l) {
  return tokenInterpolation(e, l, tokenDoubleQuoteString);
}
function tokenMultiStringReturn(e, l) {
  return l.tokenize = tokenMultiString, l.startQuote = '"', tokenMultiString(e, l);
}
function tokenHereStringInterpolation(e, l) {
  return tokenInterpolation(e, l, tokenMultiStringReturn);
}
function tokenInterpolation(e, l, u) {
  if (e.match("$(")) {
    var d = l.bracketNesting;
    return l.returnStack.push({
      shouldReturnFrom: function(e2) {
        return e2.bracketNesting === d;
      },
      tokenize: u
    }), l.tokenize = tokenBase, l.bracketNesting += 1, "punctuation";
  } else return e.next(), l.returnStack.push({
    shouldReturnFrom: function() {
      return true;
    },
    tokenize: u
  }), l.tokenize = tokenVariable, l.tokenize(e, l);
}
function tokenComment(e, l) {
  for (var u = false, d; (d = e.next()) != null; ) {
    if (u && d == ">") {
      l.tokenize = tokenBase;
      break;
    }
    u = d === "#";
  }
  return "comment";
}
function tokenVariable(e, l) {
  var d = e.peek();
  return e.eat("{") ? (l.tokenize = tokenVariableWithBraces, tokenVariableWithBraces(e, l)) : d != null && d.match(varNames) ? (e.eatWhile(varNames), l.tokenize = tokenBase, "variable") : (l.tokenize = tokenBase, "error");
}
function tokenVariableWithBraces(e, l) {
  for (var u; (u = e.next()) != null; ) if (u === "}") {
    l.tokenize = tokenBase;
    break;
  }
  return "variable";
}
function tokenMultiString(e, l) {
  var u = l.startQuote;
  if (e.sol() && e.match(/* @__PURE__ */ RegExp(u + "@"))) l.tokenize = tokenBase;
  else if (u === '"') for (; !e.eol(); ) {
    var d = e.peek();
    if (d === "$") return l.tokenize = tokenHereStringInterpolation, "string";
    e.next(), d === "`" && e.next();
  }
  else e.skipToEnd();
  return "string";
}
const powerShell = {
  name: "powershell",
  startState: function() {
    return {
      returnStack: [],
      bracketNesting: 0,
      tokenize: tokenBase
    };
  },
  token: function(e, l) {
    return l.tokenize(e, l);
  },
  languageData: { commentTokens: {
    line: "#",
    block: {
      open: "<#",
      close: "#>"
    }
  } }
};
export {
  powerShell as t
};
