import{c as g,e as Cr}from"./vscode-jsonrpc-CNa_m3dn.js";import{d as be,E as Lr,L as $r,a as Ct,b as Ir,c as Jt,e as Lt}from"./chevrotain-DpHeT9wh.js";import{R as Mr,B as _r}from"./@chevrotain-B6EChqeP.js";import{L as Or}from"./chevrotain-allstar-DNgMC3_z.js";import{P as y,R as N}from"./vscode-languageserver-types-NoPvPymt.js";import{T as Br}from"./vscode-languageserver-textdocument-CKBVUiR3.js";import{U as V,a as M}from"./vscode-uri-BBKMTmn0.js";function x(n){return typeof n=="object"&&n!==null&&typeof n.$type=="string"}function T(n){return typeof n=="object"&&n!==null&&typeof n.$refText=="string"}function Fr(n){return typeof n=="object"&&n!==null&&typeof n.name=="string"&&typeof n.type=="string"&&typeof n.path=="string"}function Me(n){return typeof n=="object"&&n!==null&&x(n.container)&&T(n.reference)&&typeof n.message=="string"}class Gr{constructor(){this.subtypes={},this.allSubtypes={}}isInstance(e,t){return x(e)&&this.isSubtype(e.$type,t)}isSubtype(e,t){if(e===t)return!0;let r=this.subtypes[e];r||(r=this.subtypes[e]={});const s=r[t];if(s!==void 0)return s;{const i=this.computeIsSubtype(e,t);return r[t]=i,i}}getAllSubTypes(e){const t=this.allSubtypes[e];if(t)return t;{const r=this.getAllTypes(),s=[];for(const i of r)this.isSubtype(i,e)&&s.push(i);return this.allSubtypes[e]=s,s}}}function ke(n){return typeof n=="object"&&n!==null&&Array.isArray(n.content)}function qt(n){return typeof n=="object"&&n!==null&&typeof n.tokenType=="object"}function Qt(n){return ke(n)&&typeof n.fullText=="string"}class v{constructor(e,t){this.startFn=e,this.nextFn=t}iterator(){const e={state:this.startFn(),next:()=>this.nextFn(e.state),[Symbol.iterator]:()=>e};return e}[Symbol.iterator](){return this.iterator()}isEmpty(){return!!this.iterator().next().done}count(){const e=this.iterator();let t=0,r=e.next();for(;!r.done;)t++,r=e.next();return t}toArray(){const e=[],t=this.iterator();let r;do r=t.next(),r.value!==void 0&&e.push(r.value);while(!r.done);return e}toSet(){return new Set(this)}toMap(e,t){const r=this.map(s=>[e?e(s):s,t?t(s):s]);return new Map(r)}toString(){return this.join()}concat(e){return new v(()=>({first:this.startFn(),firstDone:!1,iterator:e[Symbol.iterator]()}),t=>{let r;if(!t.firstDone){do if(r=this.nextFn(t.first),!r.done)return r;while(!r.done);t.firstDone=!0}do if(r=t.iterator.next(),!r.done)return r;while(!r.done);return S})}join(e=","){const t=this.iterator();let r="",s,i=!1;do s=t.next(),s.done||(i&&(r+=e),r+=Ur(s.value)),i=!0;while(!s.done);return r}indexOf(e,t=0){const r=this.iterator();let s=0,i=r.next();for(;!i.done;){if(s>=t&&i.value===e)return s;i=r.next(),s++}return-1}every(e){const t=this.iterator();let r=t.next();for(;!r.done;){if(!e(r.value))return!1;r=t.next()}return!0}some(e){const t=this.iterator();let r=t.next();for(;!r.done;){if(e(r.value))return!0;r=t.next()}return!1}forEach(e){const t=this.iterator();let r=0,s=t.next();for(;!s.done;)e(s.value,r),s=t.next(),r++}map(e){return new v(this.startFn,t=>{const{done:r,value:s}=this.nextFn(t);return r?S:{done:!1,value:e(s)}})}filter(e){return new v(this.startFn,t=>{let r;do if(r=this.nextFn(t),!r.done&&e(r.value))return r;while(!r.done);return S})}nonNullable(){return this.filter(e=>e!=null)}reduce(e,t){const r=this.iterator();let s=t,i=r.next();for(;!i.done;)s===void 0?s=i.value:s=e(s,i.value),i=r.next();return s}reduceRight(e,t){return this.recursiveReduce(this.iterator(),e,t)}recursiveReduce(e,t,r){const s=e.next();if(s.done)return r;const i=this.recursiveReduce(e,t,r);return i===void 0?s.value:t(i,s.value)}find(e){const t=this.iterator();let r=t.next();for(;!r.done;){if(e(r.value))return r.value;r=t.next()}}findIndex(e){const t=this.iterator();let r=0,s=t.next();for(;!s.done;){if(e(s.value))return r;s=t.next(),r++}return-1}includes(e){const t=this.iterator();let r=t.next();for(;!r.done;){if(r.value===e)return!0;r=t.next()}return!1}flatMap(e){return new v(()=>({this:this.startFn()}),t=>{do{if(t.iterator){const i=t.iterator.next();if(i.done)t.iterator=void 0;else return i}const{done:r,value:s}=this.nextFn(t.this);if(!r){const i=e(s);if(Be(i))t.iterator=i[Symbol.iterator]();else return{done:!1,value:i}}}while(t.iterator);return S})}flat(e){if(e===void 0&&(e=1),e<=0)return this;const t=e>1?this.flat(e-1):this;return new v(()=>({this:t.startFn()}),r=>{do{if(r.iterator){const a=r.iterator.next();if(a.done)r.iterator=void 0;else return a}const{done:s,value:i}=t.nextFn(r.this);if(!s)if(Be(i))r.iterator=i[Symbol.iterator]();else return{done:!1,value:i}}while(r.iterator);return S})}head(){const t=this.iterator().next();if(!t.done)return t.value}tail(e=1){return new v(()=>{const t=this.startFn();for(let r=0;r({size:0,state:this.startFn()}),t=>(t.size++,t.size>e?S:this.nextFn(t.state)))}distinct(e){return new v(()=>({set:new Set,internalState:this.startFn()}),t=>{let r;do if(r=this.nextFn(t.internalState),!r.done){const s=e?e(r.value):r.value;if(!t.set.has(s))return t.set.add(s),r}while(!r.done);return S})}exclude(e,t){const r=new Set;for(const s of e){const i=t?t(s):s;r.add(i)}return this.filter(s=>{const i=t?t(s):s;return!r.has(i)})}}function Ur(n){return typeof n=="string"?n:typeof n>"u"?"undefined":typeof n.toString=="function"?n.toString():Object.prototype.toString.call(n)}function Be(n){return!!n&&typeof n[Symbol.iterator]=="function"}const jr=new v(()=>{},()=>S),S=Object.freeze({done:!0,value:void 0});function w(...n){if(n.length===1){const e=n[0];if(e instanceof v)return e;if(Be(e))return new v(()=>e[Symbol.iterator](),t=>t.next());if(typeof e.length=="number")return new v(()=>({index:0}),t=>t.index1?new v(()=>({collIndex:0,arrIndex:0}),e=>{do{if(e.iterator){const t=e.iterator.next();if(!t.done)return t;e.iterator=void 0}if(e.array){if(e.arrIndex({iterators:r?.includeRoot?[[e][Symbol.iterator]()]:[t(e)[Symbol.iterator]()],pruned:!1}),s=>{for(s.pruned&&(s.iterators.pop(),s.pruned=!1);s.iterators.length>0;){const a=s.iterators[s.iterators.length-1].next();if(a.done)s.iterators.pop();else return s.iterators.push(t(a.value)[Symbol.iterator]()),a}return S})}iterator(){const e={state:this.startFn(),next:()=>this.nextFn(e.state),prune:()=>{e.state.pruned=!0},[Symbol.iterator]:()=>e};return e}}var ct;(function(n){function e(i){return i.reduce((a,o)=>a+o,0)}n.sum=e;function t(i){return i.reduce((a,o)=>a*o,0)}n.product=t;function r(i){return i.reduce((a,o)=>Math.min(a,o))}n.min=r;function s(i){return i.reduce((a,o)=>Math.max(a,o))}n.max=s})(ct||(ct={}));function ut(n){return new vt(n,e=>ke(e)?e.content:[],{includeRoot:!0})}function zr(n,e){for(;n.container;)if(n=n.container,n===e)return!0;return!1}function lt(n){return{start:{character:n.startColumn-1,line:n.startLine-1},end:{character:n.endColumn,line:n.endLine-1}}}function Fe(n){if(!n)return;const{offset:e,end:t,range:r}=n;return{range:r,offset:e,end:t,length:t-e}}var E;(function(n){n[n.Before=0]="Before",n[n.After=1]="After",n[n.OverlapFront=2]="OverlapFront",n[n.OverlapBack=3]="OverlapBack",n[n.Inside=4]="Inside",n[n.Outside=5]="Outside"})(E||(E={}));function Vr(n,e){if(n.end.linee.end.line||n.start.line===e.end.line&&n.start.character>=e.end.character)return E.After;const t=n.start.line>e.start.line||n.start.line===e.start.line&&n.start.character>=e.start.character,r=n.end.lineE.After}const Kr=/^[\w\p{L}]$/u;function Hr(n,e){if(n){const t=Jr(n,!0);if(t&&$t(t,e))return t;if(Qt(n)){const r=n.content.findIndex(s=>!s.hidden);for(let s=r-1;s>=0;s--){const i=n.content[s];if($t(i,e))return i}}}}function $t(n,e){return qt(n)&&e.includes(n.tokenType.name)}function Jr(n,e=!0){for(;n.container;){const t=n.container;let r=t.content.indexOf(n);for(;r>0;){r--;const s=t.content[r];if(e||!s.hidden)return s}n=t}}class Yt extends Error{constructor(e,t){super(e?`${t} at ${e.range.start.line}:${e.range.start.character}`:t)}}function Se(n){throw new Error("Error! The input value was not handled.")}const Re="AbstractRule",De="AbstractType",Qe="Condition",It="TypeDefinition",Ye="ValueLiteral",W="AbstractElement";function qr(n){return p.isInstance(n,W)}const Te="ArrayLiteral",Ae="ArrayType",K="BooleanLiteral";function Qr(n){return p.isInstance(n,K)}const H="Conjunction";function Yr(n){return p.isInstance(n,H)}const J="Disjunction";function Xr(n){return p.isInstance(n,J)}const Ee="Grammar",Xe="GrammarImport",q="InferredType";function Xt(n){return p.isInstance(n,q)}const Q="Interface";function Zt(n){return p.isInstance(n,Q)}const Ze="NamedArgument",Y="Negation";function Zr(n){return p.isInstance(n,Y)}const Pe="NumberLiteral",Ce="Parameter",X="ParameterReference";function en(n){return p.isInstance(n,X)}const Z="ParserRule";function R(n){return p.isInstance(n,Z)}const Le="ReferenceType",_e="ReturnType";function tn(n){return p.isInstance(n,_e)}const ee="SimpleType";function rn(n){return p.isInstance(n,ee)}const $e="StringLiteral",U="TerminalRule";function G(n){return p.isInstance(n,U)}const te="Type";function er(n){return p.isInstance(n,te)}const et="TypeAttribute",Ie="UnionType",re="Action";function We(n){return p.isInstance(n,re)}const ne="Alternatives";function tr(n){return p.isInstance(n,ne)}const se="Assignment";function _(n){return p.isInstance(n,se)}const ie="CharacterRange";function nn(n){return p.isInstance(n,ie)}const ae="CrossReference";function wt(n){return p.isInstance(n,ae)}const oe="EndOfFile";function sn(n){return p.isInstance(n,oe)}const ce="Group";function xt(n){return p.isInstance(n,ce)}const ue="Keyword";function O(n){return p.isInstance(n,ue)}const le="NegatedToken";function an(n){return p.isInstance(n,le)}const de="RegexToken";function on(n){return p.isInstance(n,de)}const fe="RuleCall";function B(n){return p.isInstance(n,fe)}const he="TerminalAlternatives";function cn(n){return p.isInstance(n,he)}const pe="TerminalGroup";function un(n){return p.isInstance(n,pe)}const me="TerminalRuleCall";function ln(n){return p.isInstance(n,me)}const ge="UnorderedGroup";function rr(n){return p.isInstance(n,ge)}const ye="UntilToken";function dn(n){return p.isInstance(n,ye)}const ve="Wildcard";function fn(n){return p.isInstance(n,ve)}class nr extends Gr{getAllTypes(){return[W,Re,De,re,ne,Te,Ae,se,K,ie,Qe,H,ae,J,oe,Ee,Xe,ce,q,Q,ue,Ze,le,Y,Pe,Ce,X,Z,Le,de,_e,fe,ee,$e,he,pe,U,me,te,et,It,Ie,ge,ye,Ye,ve]}computeIsSubtype(e,t){switch(e){case re:case ne:case se:case ie:case ae:case oe:case ce:case ue:case le:case de:case fe:case he:case pe:case me:case ge:case ye:case ve:return this.isSubtype(W,t);case Te:case Pe:case $e:return this.isSubtype(Ye,t);case Ae:case Le:case ee:case Ie:return this.isSubtype(It,t);case K:return this.isSubtype(Qe,t)||this.isSubtype(Ye,t);case H:case J:case Y:case X:return this.isSubtype(Qe,t);case q:case Q:case te:return this.isSubtype(De,t);case Z:return this.isSubtype(Re,t)||this.isSubtype(De,t);case U:return this.isSubtype(Re,t);default:return!1}}getReferenceType(e){const t=`${e.container.$type}:${e.property}`;switch(t){case"Action:type":case"CrossReference:type":case"Interface:superTypes":case"ParserRule:returnType":case"SimpleType:typeRef":return De;case"Grammar:hiddenTokens":case"ParserRule:hiddenTokens":case"RuleCall:rule":return Re;case"Grammar:usedGrammars":return Ee;case"NamedArgument:parameter":case"ParameterReference:parameter":return Ce;case"TerminalRuleCall:rule":return U;default:throw new Error(`${t} is not a valid reference id.`)}}getTypeMetaData(e){switch(e){case W:return{name:W,properties:[{name:"cardinality"},{name:"lookahead"}]};case Te:return{name:Te,properties:[{name:"elements",defaultValue:[]}]};case Ae:return{name:Ae,properties:[{name:"elementType"}]};case K:return{name:K,properties:[{name:"true",defaultValue:!1}]};case H:return{name:H,properties:[{name:"left"},{name:"right"}]};case J:return{name:J,properties:[{name:"left"},{name:"right"}]};case Ee:return{name:Ee,properties:[{name:"definesHiddenTokens",defaultValue:!1},{name:"hiddenTokens",defaultValue:[]},{name:"imports",defaultValue:[]},{name:"interfaces",defaultValue:[]},{name:"isDeclared",defaultValue:!1},{name:"name"},{name:"rules",defaultValue:[]},{name:"types",defaultValue:[]},{name:"usedGrammars",defaultValue:[]}]};case Xe:return{name:Xe,properties:[{name:"path"}]};case q:return{name:q,properties:[{name:"name"}]};case Q:return{name:Q,properties:[{name:"attributes",defaultValue:[]},{name:"name"},{name:"superTypes",defaultValue:[]}]};case Ze:return{name:Ze,properties:[{name:"calledByName",defaultValue:!1},{name:"parameter"},{name:"value"}]};case Y:return{name:Y,properties:[{name:"value"}]};case Pe:return{name:Pe,properties:[{name:"value"}]};case Ce:return{name:Ce,properties:[{name:"name"}]};case X:return{name:X,properties:[{name:"parameter"}]};case Z:return{name:Z,properties:[{name:"dataType"},{name:"definesHiddenTokens",defaultValue:!1},{name:"definition"},{name:"entry",defaultValue:!1},{name:"fragment",defaultValue:!1},{name:"hiddenTokens",defaultValue:[]},{name:"inferredType"},{name:"name"},{name:"parameters",defaultValue:[]},{name:"returnType"},{name:"wildcard",defaultValue:!1}]};case Le:return{name:Le,properties:[{name:"referenceType"}]};case _e:return{name:_e,properties:[{name:"name"}]};case ee:return{name:ee,properties:[{name:"primitiveType"},{name:"stringType"},{name:"typeRef"}]};case $e:return{name:$e,properties:[{name:"value"}]};case U:return{name:U,properties:[{name:"definition"},{name:"fragment",defaultValue:!1},{name:"hidden",defaultValue:!1},{name:"name"},{name:"type"}]};case te:return{name:te,properties:[{name:"name"},{name:"type"}]};case et:return{name:et,properties:[{name:"defaultValue"},{name:"isOptional",defaultValue:!1},{name:"name"},{name:"type"}]};case Ie:return{name:Ie,properties:[{name:"types",defaultValue:[]}]};case re:return{name:re,properties:[{name:"cardinality"},{name:"feature"},{name:"inferredType"},{name:"lookahead"},{name:"operator"},{name:"type"}]};case ne:return{name:ne,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case se:return{name:se,properties:[{name:"cardinality"},{name:"feature"},{name:"lookahead"},{name:"operator"},{name:"terminal"}]};case ie:return{name:ie,properties:[{name:"cardinality"},{name:"left"},{name:"lookahead"},{name:"right"}]};case ae:return{name:ae,properties:[{name:"cardinality"},{name:"deprecatedSyntax",defaultValue:!1},{name:"lookahead"},{name:"terminal"},{name:"type"}]};case oe:return{name:oe,properties:[{name:"cardinality"},{name:"lookahead"}]};case ce:return{name:ce,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"guardCondition"},{name:"lookahead"}]};case ue:return{name:ue,properties:[{name:"cardinality"},{name:"lookahead"},{name:"value"}]};case le:return{name:le,properties:[{name:"cardinality"},{name:"lookahead"},{name:"terminal"}]};case de:return{name:de,properties:[{name:"cardinality"},{name:"lookahead"},{name:"regex"}]};case fe:return{name:fe,properties:[{name:"arguments",defaultValue:[]},{name:"cardinality"},{name:"lookahead"},{name:"rule"}]};case he:return{name:he,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case pe:return{name:pe,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case me:return{name:me,properties:[{name:"cardinality"},{name:"lookahead"},{name:"rule"}]};case ge:return{name:ge,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case ye:return{name:ye,properties:[{name:"cardinality"},{name:"lookahead"},{name:"terminal"}]};case ve:return{name:ve,properties:[{name:"cardinality"},{name:"lookahead"}]};default:return{name:e,properties:[]}}}}const p=new nr;function hn(n){for(const[e,t]of Object.entries(n))e.startsWith("$")||(Array.isArray(t)?t.forEach((r,s)=>{x(r)&&(r.$container=n,r.$containerProperty=e,r.$containerIndex=s)}):x(t)&&(t.$container=n,t.$containerProperty=e))}function Ke(n,e){let t=n;for(;t;){if(e(t))return t;t=t.$container}}function L(n){const t=dt(n).$document;if(!t)throw new Error("AST node has no document.");return t}function dt(n){for(;n.$container;)n=n.$container;return n}function kt(n,e){if(!n)throw new Error("Node must be an AstNode.");const t=e?.range;return new v(()=>({keys:Object.keys(n),keyIndex:0,arrayIndex:0}),r=>{for(;r.keyIndexkt(t,e))}function j(n,e){if(!n)throw new Error("Root node must be an AstNode.");return new vt(n,t=>kt(t,e),{includeRoot:!0})}function Mt(n,e){var t;if(!e)return!0;const r=(t=n.$cstNode)===null||t===void 0?void 0:t.range;return r?Wr(r,e):!1}function sr(n){return new v(()=>({keys:Object.keys(n),keyIndex:0,arrayIndex:0}),e=>{for(;e.keyIndexe.test(t))}function He(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function xn(n){return Array.prototype.map.call(n,e=>/\w/.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:He(e)).join("")}function kn(n,e){const t=Sn(n),r=e.match(t);return!!r&&r[0].length>0}function Sn(n){typeof n=="string"&&(n=new RegExp(n));const e=n,t=n.source;let r=0;function s(){let i="",a;function o(u){i+=t.substr(r,u),r+=u}function c(u){i+="(?:"+t.substr(r,u)+"|$)",r+=u}for(;r",r)-r+1);break;default:c(2);break}break;case"[":a=/\[(?:\\.|.)*?\]/g,a.lastIndex=r,a=a.exec(t)||[],c(a[0].length);break;case"|":case"^":case"$":case"*":case"+":case"?":o(1);break;case"{":a=/\{\d+,?\d*\}/g,a.lastIndex=r,a=a.exec(t),a?o(a[0].length):c(1);break;case"(":if(t[r+1]==="?")switch(t[r+2]){case":":i+="(?:",r+=3,i+=s()+"|$)";break;case"=":i+="(?=",r+=3,i+=s()+")";break;case"!":a=r,r+=3,s(),i+=t.substr(a,r-a);break;case"<":switch(t[r+3]){case"=":case"!":a=r,r+=4,s(),i+=t.substr(a,r-a);break;default:o(t.indexOf(">",r)-r+1),i+=s()+"|$)";break}break}else o(1),i+=s()+"|$)";break;case")":return++r,i;default:c(1);break}return i}return new RegExp(s(),n.flags)}function Nn(n){return n.rules.find(e=>R(e)&&e.entry)}function bn(n){return n.rules.filter(e=>G(e)&&e.hidden)}function ar(n,e){const t=new Set,r=Nn(n);if(!r)return new Set(n.rules);const s=[r].concat(bn(n));for(const a of s)or(a,t,e);const i=new Set;for(const a of n.rules)(t.has(a.name)||G(a)&&a.hidden)&&i.add(a);return i}function or(n,e,t){e.add(n.name),Ne(n).forEach(r=>{if(B(r)||t){const s=r.rule.ref;s&&!e.has(s.name)&&or(s,e,t)}})}function Rn(n){if(n.terminal)return n.terminal;if(n.type.ref){const e=ur(n.type.ref);return e?.terminal}}function Dn(n){return n.hidden&&!ft(Rt(n))}function Tn(n,e){return!n||!e?[]:St(n,e,n.astNode,!0)}function cr(n,e,t){if(!n||!e)return;const r=St(n,e,n.astNode,!0);if(r.length!==0)return t!==void 0?t=Math.max(0,Math.min(t,r.length-1)):t=0,r[t]}function St(n,e,t,r){if(!r){const s=Ke(n.grammarSource,_);if(s&&s.feature===e)return[n]}return ke(n)&&n.astNode===t?n.content.flatMap(s=>St(s,e,t,!1)):[]}function An(n,e,t){if(!n)return;const r=En(n,e,n?.astNode);if(r.length!==0)return t!==void 0?t=Math.max(0,Math.min(t,r.length-1)):t=0,r[t]}function En(n,e,t){if(n.astNode!==t)return[];if(O(n.grammarSource)&&n.grammarSource.value===e)return[n];const r=ut(n).iterator();let s;const i=[];do if(s=r.next(),!s.done){const a=s.value;a.astNode===t?O(a.grammarSource)&&a.grammarSource.value===e&&i.push(a):r.prune()}while(!s.done);return i}function Pn(n){var e;const t=n.astNode;for(;t===((e=n.container)===null||e===void 0?void 0:e.astNode);){const r=Ke(n.grammarSource,_);if(r)return r;n=n.container}}function ur(n){let e=n;return Xt(e)&&(We(e.$container)?e=e.$container.$container:R(e.$container)?e=e.$container:Se(e.$container)),lr(n,e,new Map)}function lr(n,e,t){var r;function s(i,a){let o;return Ke(i,_)||(o=lr(a,a,t)),t.set(n,o),o}if(t.has(n))return t.get(n);t.set(n,void 0);for(const i of Ne(e)){if(_(i)&&i.feature.toLowerCase()==="name")return t.set(n,i),i;if(B(i)&&R(i.rule.ref))return s(i,i.rule.ref);if(rn(i)&&(!((r=i.typeRef)===null||r===void 0)&&r.ref))return s(i,i.typeRef.ref)}}function dr(n){return fr(n,new Set)}function fr(n,e){if(e.has(n))return!0;e.add(n);for(const t of Ne(n))if(B(t)){if(!t.rule.ref||R(t.rule.ref)&&!fr(t.rule.ref,e))return!1}else{if(_(t))return!1;if(We(t))return!1}return!!n.definition}function Nt(n){if(n.inferredType)return n.inferredType.name;if(n.dataType)return n.dataType;if(n.returnType){const e=n.returnType.ref;if(e){if(R(e))return e.name;if(Zt(e)||er(e))return e.name}}}function bt(n){var e;if(R(n))return dr(n)?n.name:(e=Nt(n))!==null&&e!==void 0?e:n.name;if(Zt(n)||er(n)||tn(n))return n.name;if(We(n)){const t=Cn(n);if(t)return t}else if(Xt(n))return n.name;throw new Error("Cannot get name of Unknown Type")}function Cn(n){var e;if(n.inferredType)return n.inferredType.name;if(!((e=n.type)===null||e===void 0)&&e.ref)return bt(n.type.ref)}function Ln(n){var e,t,r;return G(n)?(t=(e=n.type)===null||e===void 0?void 0:e.name)!==null&&t!==void 0?t:"string":(r=Nt(n))!==null&&r!==void 0?r:n.name}function Rt(n){const e={s:!1,i:!1,u:!1},t=z(n.definition,e),r=Object.entries(e).filter(([,s])=>s).map(([s])=>s).join("");return new RegExp(t,r)}const Dt=/[\s\S]/.source;function z(n,e){if(cn(n))return $n(n);if(un(n))return In(n);if(nn(n))return On(n);if(ln(n)){const t=n.rule.ref;if(!t)throw new Error("Missing rule reference.");return C(z(t.definition),{cardinality:n.cardinality,lookahead:n.lookahead})}else{if(an(n))return _n(n);if(dn(n))return Mn(n);if(on(n)){const t=n.regex.lastIndexOf("/"),r=n.regex.substring(1,t),s=n.regex.substring(t+1);return e&&(e.i=s.includes("i"),e.s=s.includes("s"),e.u=s.includes("u")),C(r,{cardinality:n.cardinality,lookahead:n.lookahead,wrap:!1})}else{if(fn(n))return C(Dt,{cardinality:n.cardinality,lookahead:n.lookahead});throw new Error(`Invalid terminal element: ${n?.$type}`)}}}function $n(n){return C(n.elements.map(e=>z(e)).join("|"),{cardinality:n.cardinality,lookahead:n.lookahead})}function In(n){return C(n.elements.map(e=>z(e)).join(""),{cardinality:n.cardinality,lookahead:n.lookahead})}function Mn(n){return C(`${Dt}*?${z(n.terminal)}`,{cardinality:n.cardinality,lookahead:n.lookahead})}function _n(n){return C(`(?!${z(n.terminal)})${Dt}*?`,{cardinality:n.cardinality,lookahead:n.lookahead})}function On(n){return n.right?C(`[${rt(n.left)}-${rt(n.right)}]`,{cardinality:n.cardinality,lookahead:n.lookahead,wrap:!1}):C(rt(n.left),{cardinality:n.cardinality,lookahead:n.lookahead,wrap:!1})}function rt(n){return He(n.value)}function C(n,e){var t;return(e.wrap!==!1||e.lookahead)&&(n=`(${(t=e.lookahead)!==null&&t!==void 0?t:""}${n})`),e.cardinality?`${n}${e.cardinality}`:n}function Bn(n){const e=[],t=n.Grammar;for(const r of t.rules)G(r)&&Dn(r)&&vn(Rt(r))&&e.push(r.name);return{multilineCommentRules:e,nameRegexp:Kr}}class Fn{constructor(){this.nodeStack=[]}get current(){var e;return(e=this.nodeStack[this.nodeStack.length-1])!==null&&e!==void 0?e:this.rootNode}buildRootNode(e){return this.rootNode=new pr(e),this.rootNode.root=this.rootNode,this.nodeStack=[this.rootNode],this.rootNode}buildCompositeNode(e){const t=new Tt;return t.grammarSource=e,t.root=this.rootNode,this.current.content.push(t),this.nodeStack.push(t),t}buildLeafNode(e,t){const r=new ht(e.startOffset,e.image.length,lt(e),e.tokenType,!t);return r.grammarSource=t,r.root=this.rootNode,this.current.content.push(r),r}removeNode(e){const t=e.container;if(t){const r=t.content.indexOf(e);r>=0&&t.content.splice(r,1)}}addHiddenNodes(e){const t=[];for(const i of e){const a=new ht(i.startOffset,i.image.length,lt(i),i.tokenType,!0);a.root=this.rootNode,t.push(a)}let r=this.current,s=!1;if(r.content.length>0){r.content.push(...t);return}for(;r.container;){const i=r.container.content.indexOf(r);if(i>0){r.container.content.splice(i,0,...t),s=!0;break}r=r.container}s||this.rootNode.content.unshift(...t)}construct(e){const t=this.current;typeof e.$type=="string"&&(this.current.astNode=e),e.$cstNode=t;const r=this.nodeStack.pop();r?.content.length===0&&this.removeNode(r)}}class hr{get parent(){return this.container}get feature(){return this.grammarSource}get hidden(){return!1}get astNode(){var e,t;const r=typeof((e=this._astNode)===null||e===void 0?void 0:e.$type)=="string"?this._astNode:(t=this.container)===null||t===void 0?void 0:t.astNode;if(!r)throw new Error("This node has no associated AST element");return r}set astNode(e){this._astNode=e}get element(){return this.astNode}get text(){return this.root.fullText.substring(this.offset,this.end)}}class ht extends hr{get offset(){return this._offset}get length(){return this._length}get end(){return this._offset+this._length}get hidden(){return this._hidden}get tokenType(){return this._tokenType}get range(){return this._range}constructor(e,t,r,s,i=!1){super(),this._hidden=i,this._offset=e,this._tokenType=s,this._length=t,this._range=r}}class Tt extends hr{constructor(){super(...arguments),this.content=new At(this)}get children(){return this.content}get offset(){var e,t;return(t=(e=this.firstNonHiddenNode)===null||e===void 0?void 0:e.offset)!==null&&t!==void 0?t:0}get length(){return this.end-this.offset}get end(){var e,t;return(t=(e=this.lastNonHiddenNode)===null||e===void 0?void 0:e.end)!==null&&t!==void 0?t:0}get range(){const e=this.firstNonHiddenNode,t=this.lastNonHiddenNode;if(e&&t){if(this._rangeCache===void 0){const{range:r}=e,{range:s}=t;this._rangeCache={start:r.start,end:s.end.line=0;e--){const t=this.content[e];if(!t.hidden)return t}return this.content[this.content.length-1]}}class At extends Array{constructor(e){super(),this.parent=e,Object.setPrototypeOf(this,At.prototype)}push(...e){return this.addParents(e),super.push(...e)}unshift(...e){return this.addParents(e),super.unshift(...e)}splice(e,t,...r){return this.addParents(r),super.splice(e,t,...r)}addParents(e){for(const t of e)t.container=this.parent}}class pr extends Tt{get text(){return this._text.substring(this.offset,this.end)}get fullText(){return this._text}constructor(e){super(),this._text="",this._text=e??""}}const pt=Symbol("Datatype");function nt(n){return n.$type===pt}const _t="​",mr=n=>n.endsWith(_t)?n:n+_t;class gr{constructor(e){this._unorderedGroups=new Map,this.allRules=new Map,this.lexer=e.parser.Lexer;const t=this.lexer.definition,r=e.LanguageMetaData.mode==="production";this.wrapper=new Vn(t,Object.assign(Object.assign({},e.parser.ParserConfig),{skipValidations:r,errorMessageProvider:e.parser.ParserErrorMessageProvider}))}alternatives(e,t){this.wrapper.wrapOr(e,t)}optional(e,t){this.wrapper.wrapOption(e,t)}many(e,t){this.wrapper.wrapMany(e,t)}atLeastOne(e,t){this.wrapper.wrapAtLeastOne(e,t)}getRule(e){return this.allRules.get(e)}isRecording(){return this.wrapper.IS_RECORDING}get unorderedGroups(){return this._unorderedGroups}getRuleStack(){return this.wrapper.RULE_STACK}finalize(){this.wrapper.wrapSelfAnalysis()}}class Gn extends gr{get current(){return this.stack[this.stack.length-1]}constructor(e){super(e),this.nodeBuilder=new Fn,this.stack=[],this.assignmentMap=new Map,this.linker=e.references.Linker,this.converter=e.parser.ValueConverter,this.astReflection=e.shared.AstReflection}rule(e,t){const r=this.computeRuleType(e),s=this.wrapper.DEFINE_RULE(mr(e.name),this.startImplementation(r,t).bind(this));return this.allRules.set(e.name,s),e.entry&&(this.mainRule=s),s}computeRuleType(e){if(!e.fragment){if(dr(e))return pt;{const t=Nt(e);return t??e.name}}}parse(e,t={}){this.nodeBuilder.buildRootNode(e);const r=this.lexerResult=this.lexer.tokenize(e);this.wrapper.input=r.tokens;const s=t.rule?this.allRules.get(t.rule):this.mainRule;if(!s)throw new Error(t.rule?`No rule found with name '${t.rule}'`:"No main rule available.");const i=s.call(this.wrapper,{});return this.nodeBuilder.addHiddenNodes(r.hidden),this.unorderedGroups.clear(),this.lexerResult=void 0,{value:i,lexerErrors:r.errors,lexerReport:r.report,parserErrors:this.wrapper.errors}}startImplementation(e,t){return r=>{const s=!this.isRecording()&&e!==void 0;if(s){const a={$type:e};this.stack.push(a),e===pt&&(a.value="")}let i;try{i=t(r)}catch{i=void 0}return i===void 0&&s&&(i=this.construct()),i}}extractHiddenTokens(e){const t=this.lexerResult.hidden;if(!t.length)return[];const r=e.startOffset;for(let s=0;sr)return t.splice(0,s);return t.splice(0,t.length)}consume(e,t,r){const s=this.wrapper.wrapConsume(e,t);if(!this.isRecording()&&this.isValidToken(s)){const i=this.extractHiddenTokens(s);this.nodeBuilder.addHiddenNodes(i);const a=this.nodeBuilder.buildLeafNode(s,r),{assignment:o,isCrossRef:c}=this.getAssignment(r),u=this.current;if(o){const l=O(r)?s.image:this.converter.convert(s.image,a);this.assign(o.operator,o.feature,l,a,c)}else if(nt(u)){let l=s.image;O(r)||(l=this.converter.convert(l,a).toString()),u.value+=l}}}isValidToken(e){return!e.isInsertedInRecovery&&!isNaN(e.startOffset)&&typeof e.endOffset=="number"&&!isNaN(e.endOffset)}subrule(e,t,r,s,i){let a;!this.isRecording()&&!r&&(a=this.nodeBuilder.buildCompositeNode(s));const o=this.wrapper.wrapSubrule(e,t,i);!this.isRecording()&&a&&a.length>0&&this.performSubruleAssignment(o,s,a)}performSubruleAssignment(e,t,r){const{assignment:s,isCrossRef:i}=this.getAssignment(t);if(s)this.assign(s.operator,s.feature,e,r,i);else if(!s){const a=this.current;if(nt(a))a.value+=e.toString();else if(typeof e=="object"&&e){const c=this.assignWithoutOverride(e,a);this.stack.pop(),this.stack.push(c)}}}action(e,t){if(!this.isRecording()){let r=this.current;if(t.feature&&t.operator){r=this.construct(),this.nodeBuilder.removeNode(r.$cstNode),this.nodeBuilder.buildCompositeNode(t).content.push(r.$cstNode);const i={$type:e};this.stack.push(i),this.assign(t.operator,t.feature,r,r.$cstNode,!1)}else r.$type=e}}construct(){if(this.isRecording())return;const e=this.current;return hn(e),this.nodeBuilder.construct(e),this.stack.pop(),nt(e)?this.converter.convert(e.value,e.$cstNode):(pn(this.astReflection,e),e)}getAssignment(e){if(!this.assignmentMap.has(e)){const t=Ke(e,_);this.assignmentMap.set(e,{assignment:t,isCrossRef:t?wt(t.terminal):!1})}return this.assignmentMap.get(e)}assign(e,t,r,s,i){const a=this.current;let o;switch(i&&typeof r=="string"?o=this.linker.buildReference(a,t,s,r):o=r,e){case"=":{a[t]=o;break}case"?=":{a[t]=!0;break}case"+=":Array.isArray(a[t])||(a[t]=[]),a[t].push(o)}}assignWithoutOverride(e,t){for(const[s,i]of Object.entries(t)){const a=e[s];a===void 0?e[s]=i:Array.isArray(a)&&Array.isArray(i)&&(i.push(...a),e[s]=i)}const r=e.$cstNode;return r&&(r.astNode=void 0,e.$cstNode=void 0),e}get definitionErrors(){return this.wrapper.definitionErrors}}class Un{buildMismatchTokenMessage(e){return be.buildMismatchTokenMessage(e)}buildNotAllInputParsedMessage(e){return be.buildNotAllInputParsedMessage(e)}buildNoViableAltMessage(e){return be.buildNoViableAltMessage(e)}buildEarlyExitMessage(e){return be.buildEarlyExitMessage(e)}}class yr extends Un{buildMismatchTokenMessage({expected:e,actual:t}){return`Expecting ${e.LABEL?"`"+e.LABEL+"`":e.name.endsWith(":KW")?`keyword '${e.name.substring(0,e.name.length-3)}'`:`token of type '${e.name}'`} but found \`${t.image}\`.`}buildNotAllInputParsedMessage({firstRedundant:e}){return`Expecting end of file but found \`${e.image}\`.`}}class jn extends gr{constructor(){super(...arguments),this.tokens=[],this.elementStack=[],this.lastElementStack=[],this.nextTokenIndex=0,this.stackSize=0}action(){}construct(){}parse(e){this.resetState();const t=this.lexer.tokenize(e,{mode:"partial"});return this.tokens=t.tokens,this.wrapper.input=[...this.tokens],this.mainRule.call(this.wrapper,{}),this.unorderedGroups.clear(),{tokens:this.tokens,elementStack:[...this.lastElementStack],tokenIndex:this.nextTokenIndex}}rule(e,t){const r=this.wrapper.DEFINE_RULE(mr(e.name),this.startImplementation(t).bind(this));return this.allRules.set(e.name,r),e.entry&&(this.mainRule=r),r}resetState(){this.elementStack=[],this.lastElementStack=[],this.nextTokenIndex=0,this.stackSize=0}startImplementation(e){return t=>{const r=this.keepStackSize();try{e(t)}finally{this.resetStackSize(r)}}}removeUnexpectedElements(){this.elementStack.splice(this.stackSize)}keepStackSize(){const e=this.elementStack.length;return this.stackSize=e,e}resetStackSize(e){this.removeUnexpectedElements(),this.stackSize=e}consume(e,t,r){this.wrapper.wrapConsume(e,t),this.isRecording()||(this.lastElementStack=[...this.elementStack,r],this.nextTokenIndex=this.currIdx+1)}subrule(e,t,r,s,i){this.before(s),this.wrapper.wrapSubrule(e,t,i),this.after(s)}before(e){this.isRecording()||this.elementStack.push(e)}after(e){if(!this.isRecording()){const t=this.elementStack.lastIndexOf(e);t>=0&&this.elementStack.splice(t)}}get currIdx(){return this.wrapper.currIdx}}const zn={recoveryEnabled:!0,nodeLocationTracking:"full",skipValidations:!0,errorMessageProvider:new yr};class Vn extends Lr{constructor(e,t){const r=t&&"maxLookahead"in t;super(e,Object.assign(Object.assign(Object.assign({},zn),{lookaheadStrategy:r?new $r({maxLookahead:t.maxLookahead}):new Or({logging:t.skipValidations?()=>{}:void 0})}),t))}get IS_RECORDING(){return this.RECORDING_PHASE}DEFINE_RULE(e,t){return this.RULE(e,t)}wrapSelfAnalysis(){this.performSelfAnalysis()}wrapConsume(e,t){return this.consume(e,t)}wrapSubrule(e,t,r){return this.subrule(e,t,{ARGS:[r]})}wrapOr(e,t){this.or(e,t)}wrapOption(e,t){this.option(e,t)}wrapMany(e,t){this.many(e,t)}wrapAtLeastOne(e,t){this.atLeastOne(e,t)}}function vr(n,e,t){return Wn({parser:e,tokens:t,ruleNames:new Map},n),e}function Wn(n,e){const t=ar(e,!1),r=w(e.rules).filter(R).filter(s=>t.has(s));for(const s of r){const i=Object.assign(Object.assign({},n),{consume:1,optional:1,subrule:1,many:1,or:1});n.parser.rule(s,F(i,s.definition))}}function F(n,e,t=!1){let r;if(O(e))r=Xn(n,e);else if(We(e))r=Kn(n,e);else if(_(e))r=F(n,e.terminal);else if(wt(e))r=wr(n,e);else if(B(e))r=Hn(n,e);else if(tr(e))r=qn(n,e);else if(rr(e))r=Qn(n,e);else if(xt(e))r=Yn(n,e);else if(sn(e)){const s=n.consume++;r=()=>n.parser.consume(s,Ir,e)}else throw new Yt(e.$cstNode,`Unexpected element type: ${e.$type}`);return xr(n,t?void 0:Ge(e),r,e.cardinality)}function Kn(n,e){const t=bt(e);return()=>n.parser.action(t,e)}function Hn(n,e){const t=e.rule.ref;if(R(t)){const r=n.subrule++,s=t.fragment,i=e.arguments.length>0?Jn(t,e.arguments):()=>({});return a=>n.parser.subrule(r,kr(n,t),s,e,i(a))}else if(G(t)){const r=n.consume++,s=mt(n,t.name);return()=>n.parser.consume(r,s,e)}else if(t)Se();else throw new Yt(e.$cstNode,`Undefined rule: ${e.rule.$refText}`)}function Jn(n,e){const t=e.map(r=>P(r.value));return r=>{const s={};for(let i=0;ie(r)||t(r)}else if(Yr(n)){const e=P(n.left),t=P(n.right);return r=>e(r)&&t(r)}else if(Zr(n)){const e=P(n.value);return t=>!e(t)}else if(en(n)){const e=n.parameter.ref.name;return t=>t!==void 0&&t[e]===!0}else if(Qr(n)){const e=!!n.true;return()=>e}Se()}function qn(n,e){if(e.elements.length===1)return F(n,e.elements[0]);{const t=[];for(const s of e.elements){const i={ALT:F(n,s,!0)},a=Ge(s);a&&(i.GATE=P(a)),t.push(i)}const r=n.or++;return s=>n.parser.alternatives(r,t.map(i=>{const a={ALT:()=>i.ALT(s)},o=i.GATE;return o&&(a.GATE=()=>o(s)),a}))}}function Qn(n,e){if(e.elements.length===1)return F(n,e.elements[0]);const t=[];for(const o of e.elements){const c={ALT:F(n,o,!0)},u=Ge(o);u&&(c.GATE=P(u)),t.push(c)}const r=n.or++,s=(o,c)=>{const u=c.getRuleStack().join("-");return`uGroup_${o}_${u}`},i=o=>n.parser.alternatives(r,t.map((c,u)=>{const l={ALT:()=>!0},d=n.parser;l.ALT=()=>{if(c.ALT(o),!d.isRecording()){const f=s(r,d);d.unorderedGroups.get(f)||d.unorderedGroups.set(f,[]);const k=d.unorderedGroups.get(f);typeof k?.[u]>"u"&&(k[u]=!0)}};const h=c.GATE;return h?l.GATE=()=>h(o):l.GATE=()=>{const f=d.unorderedGroups.get(s(r,d));return!f?.[u]},l})),a=xr(n,Ge(e),i,"*");return o=>{a(o),n.parser.isRecording()||n.parser.unorderedGroups.delete(s(r,n.parser))}}function Yn(n,e){const t=e.elements.map(r=>F(n,r));return r=>t.forEach(s=>s(r))}function Ge(n){if(xt(n))return n.guardCondition}function wr(n,e,t=e.terminal){if(t)if(B(t)&&R(t.rule.ref)){const r=t.rule.ref,s=n.subrule++;return i=>n.parser.subrule(s,kr(n,r),!1,e,i)}else if(B(t)&&G(t.rule.ref)){const r=n.consume++,s=mt(n,t.rule.ref.name);return()=>n.parser.consume(r,s,e)}else if(O(t)){const r=n.consume++,s=mt(n,t.value);return()=>n.parser.consume(r,s,e)}else throw new Error("Could not build cross reference parser");else{if(!e.type.ref)throw new Error("Could not resolve reference to type: "+e.type.$refText);const r=ur(e.type.ref),s=r?.terminal;if(!s)throw new Error("Could not find name assignment for type: "+bt(e.type.ref));return wr(n,e,s)}}function Xn(n,e){const t=n.consume++,r=n.tokens[e.value];if(!r)throw new Error("Could not find token for keyword: "+e.value);return()=>n.parser.consume(t,r,e)}function xr(n,e,t,r){const s=e&&P(e);if(!r)if(s){const i=n.or++;return a=>n.parser.alternatives(i,[{ALT:()=>t(a),GATE:()=>s(a)},{ALT:Ct(),GATE:()=>!s(a)}])}else return t;if(r==="*"){const i=n.many++;return a=>n.parser.many(i,{DEF:()=>t(a),GATE:s?()=>s(a):void 0})}else if(r==="+"){const i=n.many++;if(s){const a=n.or++;return o=>n.parser.alternatives(a,[{ALT:()=>n.parser.atLeastOne(i,{DEF:()=>t(o)}),GATE:()=>s(o)},{ALT:Ct(),GATE:()=>!s(o)}])}else return a=>n.parser.atLeastOne(i,{DEF:()=>t(a)})}else if(r==="?"){const i=n.optional++;return a=>n.parser.optional(i,{DEF:()=>t(a),GATE:s?()=>s(a):void 0})}else Se()}function kr(n,e){const t=Zn(n,e),r=n.parser.getRule(t);if(!r)throw new Error(`Rule "${t}" not found."`);return r}function Zn(n,e){if(R(e))return e.name;if(n.ruleNames.has(e))return n.ruleNames.get(e);{let t=e,r=t.$container,s=e.$type;for(;!R(r);)(xt(r)||tr(r)||rr(r))&&(s=r.elements.indexOf(t).toString()+":"+s),t=r,r=r.$container;return s=r.name+":"+s,n.ruleNames.set(e,s),s}}function mt(n,e){const t=n.tokens[e];if(!t)throw new Error(`Token "${e}" not found."`);return t}function es(n){const e=n.Grammar,t=n.parser.Lexer,r=new jn(n);return vr(e,r,t.definition),r.finalize(),r}function ts(n){const e=rs(n);return e.finalize(),e}function rs(n){const e=n.Grammar,t=n.parser.Lexer,r=new Gn(n);return vr(e,r,t.definition)}class ns{constructor(){this.diagnostics=[]}buildTokens(e,t){const r=w(ar(e,!1)),s=this.buildTerminalTokens(r),i=this.buildKeywordTokens(r,s,t);return s.forEach(a=>{const o=a.PATTERN;typeof o=="object"&&o&&"test"in o&&ft(o)?i.unshift(a):i.push(a)}),i}flushLexingReport(e){return{diagnostics:this.popDiagnostics()}}popDiagnostics(){const e=[...this.diagnostics];return this.diagnostics=[],e}buildTerminalTokens(e){return e.filter(G).filter(t=>!t.fragment).map(t=>this.buildTerminalToken(t)).toArray()}buildTerminalToken(e){const t=Rt(e),r=this.requiresCustomPattern(t)?this.regexPatternFunction(t):t,s={name:e.name,PATTERN:r};return typeof r=="function"&&(s.LINE_BREAKS=!0),e.hidden&&(s.GROUP=ft(t)?Jt.SKIPPED:"hidden"),s}requiresCustomPattern(e){return e.flags.includes("u")||e.flags.includes("s")?!0:!!(e.source.includes("?<=")||e.source.includes("?(t.lastIndex=s,t.exec(r))}buildKeywordTokens(e,t,r){return e.filter(R).flatMap(s=>Ne(s).filter(O)).distinct(s=>s.value).toArray().sort((s,i)=>i.value.length-s.value.length).map(s=>this.buildKeywordToken(s,t,!!r?.caseInsensitive))}buildKeywordToken(e,t,r){const s=this.buildKeywordPattern(e,r),i={name:e.value,PATTERN:s,LONGER_ALT:this.findLongerAlt(e,t)};return typeof s=="function"&&(i.LINE_BREAKS=!0),i}buildKeywordPattern(e,t){return t?new RegExp(xn(e.value)):e.value}findLongerAlt(e,t){return t.reduce((r,s)=>{const i=s?.PATTERN;return i?.source&&kn("^"+i.source+"$",e.value)&&r.push(s),r},[])}}class ss{convert(e,t){let r=t.grammarSource;if(wt(r)&&(r=Rn(r)),B(r)){const s=r.rule.ref;if(!s)throw new Error("This cst node was not parsed by a rule.");return this.runConverter(s,e,t)}return e}runConverter(e,t,r){var s;switch(e.name.toUpperCase()){case"INT":return A.convertInt(t);case"STRING":return A.convertString(t);case"ID":return A.convertID(t)}switch((s=Ln(e))===null||s===void 0?void 0:s.toLowerCase()){case"number":return A.convertNumber(t);case"boolean":return A.convertBoolean(t);case"bigint":return A.convertBigint(t);case"date":return A.convertDate(t);default:return t}}}var A;(function(n){function e(u){let l="";for(let d=1;d{typeof setImmediate>"u"?setTimeout(n,0):setImmediate(n)})}let Oe=0,as=10;function os(){return Oe=performance.now(),new g.CancellationTokenSource}const Ue=Symbol("OperationCancelled");function Je(n){return n===Ue}async function b(n){if(n===g.CancellationToken.None)return;const e=performance.now();if(e-Oe>=as&&(Oe=e,await is(),Oe=performance.now()),n.isCancellationRequested)throw Ue}class Et{constructor(){this.promise=new Promise((e,t)=>{this.resolve=r=>(e(r),this),this.reject=r=>(t(r),this)})}}var $;(function(n){n.basename=V.basename,n.dirname=V.dirname,n.extname=V.extname,n.joinPath=V.joinPath,n.resolvePath=V.resolvePath;function e(s,i){return s?.toString()===i?.toString()}n.equals=e;function t(s,i){const a=typeof s=="string"?s:s.path,o=typeof i=="string"?i:i.path,c=a.split("/").filter(f=>f.length>0),u=o.split("/").filter(f=>f.length>0);let l=0;for(;ls??(s=Br.create(e.toString(),r.getServices(e).LanguageMetaData.languageId,0,t??""))}}class us{constructor(e){this.documentMap=new Map,this.langiumDocumentFactory=e.workspace.LangiumDocumentFactory,this.serviceRegistry=e.ServiceRegistry}get all(){return w(this.documentMap.values())}addDocument(e){const t=e.uri.toString();if(this.documentMap.has(t))throw new Error(`A document with the URI '${t}' is already present.`);this.documentMap.set(t,e)}getDocument(e){const t=e.toString();return this.documentMap.get(t)}async getOrCreateDocument(e,t){let r=this.getDocument(e);return r||(r=await this.langiumDocumentFactory.fromUri(e,t),this.addDocument(r),r)}createDocument(e,t,r){if(r)return this.langiumDocumentFactory.fromString(t,e,r).then(s=>(this.addDocument(s),s));{const s=this.langiumDocumentFactory.fromString(t,e);return this.addDocument(s),s}}hasDocument(e){return this.documentMap.has(e.toString())}invalidateDocument(e){const t=e.toString(),r=this.documentMap.get(t);return r&&(this.serviceRegistry.getServices(e).references.Linker.unlink(r),r.state=m.Changed,r.precomputedScopes=void 0,r.diagnostics=void 0),r}deleteDocument(e){const t=e.toString(),r=this.documentMap.get(t);return r&&(r.state=m.Changed,this.documentMap.delete(t)),r}}const st=Symbol("ref_resolving");class ls{constructor(e){this.reflection=e.shared.AstReflection,this.langiumDocuments=()=>e.shared.workspace.LangiumDocuments,this.scopeProvider=e.references.ScopeProvider,this.astNodeLocator=e.workspace.AstNodeLocator}async link(e,t=g.CancellationToken.None){for(const r of j(e.parseResult.value))await b(t),sr(r).forEach(s=>this.doLink(s,e))}doLink(e,t){var r;const s=e.reference;if(s._ref===void 0){s._ref=st;try{const i=this.getCandidate(e);if(Me(i))s._ref=i;else if(s._nodeDescription=i,this.langiumDocuments().hasDocument(i.documentUri)){const a=this.loadAstNode(i);s._ref=a??this.createLinkingError(e,i)}else s._ref=void 0}catch(i){console.error(`An error occurred while resolving reference to '${s.$refText}':`,i);const a=(r=i.message)!==null&&r!==void 0?r:String(i);s._ref=Object.assign(Object.assign({},e),{message:`An error occurred while resolving reference to '${s.$refText}': ${a}`})}t.references.push(s)}}unlink(e){for(const t of e.references)delete t._ref,delete t._nodeDescription;e.references=[]}getCandidate(e){const r=this.scopeProvider.getScope(e).getElement(e.reference.$refText);return r??this.createLinkingError(e)}buildReference(e,t,r,s){const i=this,a={$refNode:r,$refText:s,get ref(){var o;if(x(this._ref))return this._ref;if(Fr(this._nodeDescription)){const c=i.loadAstNode(this._nodeDescription);this._ref=c??i.createLinkingError({reference:a,container:e,property:t},this._nodeDescription)}else if(this._ref===void 0){this._ref=st;const c=dt(e).$document,u=i.getLinkedNode({reference:a,container:e,property:t});if(u.error&&c&&c.state=e.end)return i.ref}}if(r){const s=this.nameProvider.getNameNode(r);if(s&&(s===e||zr(e,s)))return r}}}findDeclarationNode(e){const t=this.findDeclaration(e);if(t?.$cstNode){const r=this.nameProvider.getNameNode(t);return r??t.$cstNode}}findReferences(e,t){const r=[];if(t.includeDeclaration){const i=this.getReferenceToSelf(e);i&&r.push(i)}let s=this.index.findAllReferences(e,this.nodeLocator.getAstNodePath(e));return t.documentUri&&(s=s.filter(i=>$.equals(i.sourceUri,t.documentUri))),r.push(...s),w(r)}getReferenceToSelf(e){const t=this.nameProvider.getNameNode(e);if(t){const r=L(e),s=this.nodeLocator.getAstNodePath(e);return{sourceUri:r.uri,sourcePath:s,targetUri:r.uri,targetPath:s,segment:Fe(t),local:!0}}}}class je{constructor(e){if(this.map=new Map,e)for(const[t,r]of e)this.add(t,r)}get size(){return ct.sum(w(this.map.values()).map(e=>e.length))}clear(){this.map.clear()}delete(e,t){if(t===void 0)return this.map.delete(e);{const r=this.map.get(e);if(r){const s=r.indexOf(t);if(s>=0)return r.length===1?this.map.delete(e):r.splice(s,1),!0}return!1}}get(e){var t;return(t=this.map.get(e))!==null&&t!==void 0?t:[]}has(e,t){if(t===void 0)return this.map.has(e);{const r=this.map.get(e);return r?r.indexOf(t)>=0:!1}}add(e,t){return this.map.has(e)?this.map.get(e).push(t):this.map.set(e,[t]),this}addAll(e,t){return this.map.has(e)?this.map.get(e).push(...t):this.map.set(e,Array.from(t)),this}forEach(e){this.map.forEach((t,r)=>t.forEach(s=>e(s,r,this)))}[Symbol.iterator](){return this.entries().iterator()}entries(){return w(this.map.entries()).flatMap(([e,t])=>t.map(r=>[e,r]))}keys(){return w(this.map.keys())}values(){return w(this.map.values()).flat()}entriesGroupedByKey(){return w(this.map.entries())}}class Ot{get size(){return this.map.size}constructor(e){if(this.map=new Map,this.inverse=new Map,e)for(const[t,r]of e)this.set(t,r)}clear(){this.map.clear(),this.inverse.clear()}set(e,t){return this.map.set(e,t),this.inverse.set(t,e),this}get(e){return this.map.get(e)}getKey(e){return this.inverse.get(e)}delete(e){const t=this.map.get(e);return t!==void 0?(this.map.delete(e),this.inverse.delete(t),!0):!1}}class ps{constructor(e){this.nameProvider=e.references.NameProvider,this.descriptions=e.workspace.AstNodeDescriptionProvider}async computeExports(e,t=g.CancellationToken.None){return this.computeExportsForNode(e.parseResult.value,e,void 0,t)}async computeExportsForNode(e,t,r=kt,s=g.CancellationToken.None){const i=[];this.exportNode(e,i,t);for(const a of r(e))await b(s),this.exportNode(a,i,t);return i}exportNode(e,t,r){const s=this.nameProvider.getName(e);s&&t.push(this.descriptions.createDescription(e,s,r))}async computeLocalScopes(e,t=g.CancellationToken.None){const r=e.parseResult.value,s=new je;for(const i of Ne(r))await b(t),this.processNode(i,e,s);return s}processNode(e,t,r){const s=e.$container;if(s){const i=this.nameProvider.getName(e);i&&r.add(s,this.descriptions.createDescription(e,i,t))}}}class Bt{constructor(e,t,r){var s;this.elements=e,this.outerScope=t,this.caseInsensitive=(s=r?.caseInsensitive)!==null&&s!==void 0?s:!1}getAllElements(){return this.outerScope?this.elements.concat(this.outerScope.getAllElements()):this.elements}getElement(e){const t=this.caseInsensitive?this.elements.find(r=>r.name.toLowerCase()===e.toLowerCase()):this.elements.find(r=>r.name===e);if(t)return t;if(this.outerScope)return this.outerScope.getElement(e)}}class ms{constructor(e,t,r){var s;this.elements=new Map,this.caseInsensitive=(s=r?.caseInsensitive)!==null&&s!==void 0?s:!1;for(const i of e){const a=this.caseInsensitive?i.name.toLowerCase():i.name;this.elements.set(a,i)}this.outerScope=t}getElement(e){const t=this.caseInsensitive?e.toLowerCase():e,r=this.elements.get(t);if(r)return r;if(this.outerScope)return this.outerScope.getElement(e)}getAllElements(){let e=w(this.elements.values());return this.outerScope&&(e=e.concat(this.outerScope.getAllElements())),e}}class Sr{constructor(){this.toDispose=[],this.isDisposed=!1}onDispose(e){this.toDispose.push(e)}dispose(){this.throwIfDisposed(),this.clear(),this.isDisposed=!0,this.toDispose.forEach(e=>e.dispose())}throwIfDisposed(){if(this.isDisposed)throw new Error("This cache has already been disposed")}}class gs extends Sr{constructor(){super(...arguments),this.cache=new Map}has(e){return this.throwIfDisposed(),this.cache.has(e)}set(e,t){this.throwIfDisposed(),this.cache.set(e,t)}get(e,t){if(this.throwIfDisposed(),this.cache.has(e))return this.cache.get(e);if(t){const r=t();return this.cache.set(e,r),r}else return}delete(e){return this.throwIfDisposed(),this.cache.delete(e)}clear(){this.throwIfDisposed(),this.cache.clear()}}class ys extends Sr{constructor(e){super(),this.cache=new Map,this.converter=e??(t=>t)}has(e,t){return this.throwIfDisposed(),this.cacheForContext(e).has(t)}set(e,t,r){this.throwIfDisposed(),this.cacheForContext(e).set(t,r)}get(e,t,r){this.throwIfDisposed();const s=this.cacheForContext(e);if(s.has(t))return s.get(t);if(r){const i=r();return s.set(t,i),i}else return}delete(e,t){return this.throwIfDisposed(),this.cacheForContext(e).delete(t)}clear(e){if(this.throwIfDisposed(),e){const t=this.converter(e);this.cache.delete(t)}else this.cache.clear()}cacheForContext(e){const t=this.converter(e);let r=this.cache.get(t);return r||(r=new Map,this.cache.set(t,r)),r}}class vs extends gs{constructor(e,t){super(),t?(this.toDispose.push(e.workspace.DocumentBuilder.onBuildPhase(t,()=>{this.clear()})),this.toDispose.push(e.workspace.DocumentBuilder.onUpdate((r,s)=>{s.length>0&&this.clear()}))):this.toDispose.push(e.workspace.DocumentBuilder.onUpdate(()=>{this.clear()}))}}class ws{constructor(e){this.reflection=e.shared.AstReflection,this.nameProvider=e.references.NameProvider,this.descriptions=e.workspace.AstNodeDescriptionProvider,this.indexManager=e.shared.workspace.IndexManager,this.globalScopeCache=new vs(e.shared)}getScope(e){const t=[],r=this.reflection.getReferenceType(e),s=L(e.container).precomputedScopes;if(s){let a=e.container;do{const o=s.get(a);o.length>0&&t.push(w(o).filter(c=>this.reflection.isSubtype(c.type,r))),a=a.$container}while(a)}let i=this.getGlobalScope(r,e);for(let a=t.length-1;a>=0;a--)i=this.createScope(t[a],i);return i}createScope(e,t,r){return new Bt(w(e),t,r)}createScopeForNodes(e,t,r){const s=w(e).map(i=>{const a=this.nameProvider.getName(i);if(a)return this.descriptions.createDescription(i,a)}).nonNullable();return new Bt(s,t,r)}getGlobalScope(e,t){return this.globalScopeCache.get(e,()=>new ms(this.indexManager.allElements(e)))}}function xs(n){return typeof n.$comment=="string"}function Ft(n){return typeof n=="object"&&!!n&&("$ref"in n||"$error"in n)}class ks{constructor(e){this.ignoreProperties=new Set(["$container","$containerProperty","$containerIndex","$document","$cstNode"]),this.langiumDocuments=e.shared.workspace.LangiumDocuments,this.astNodeLocator=e.workspace.AstNodeLocator,this.nameProvider=e.references.NameProvider,this.commentProvider=e.documentation.CommentProvider}serialize(e,t){const r=t??{},s=t?.replacer,i=(o,c)=>this.replacer(o,c,r),a=s?(o,c)=>s(o,c,i):i;try{return this.currentDocument=L(e),JSON.stringify(e,a,t?.space)}finally{this.currentDocument=void 0}}deserialize(e,t){const r=t??{},s=JSON.parse(e);return this.linkNode(s,s,r),s}replacer(e,t,{refText:r,sourceText:s,textRegions:i,comments:a,uriConverter:o}){var c,u,l,d;if(!this.ignoreProperties.has(e))if(T(t)){const h=t.ref,f=r?t.$refText:void 0;if(h){const k=L(h);let I="";this.currentDocument&&this.currentDocument!==k&&(o?I=o(k.uri,t):I=k.uri.toString());const qe=this.astNodeLocator.getAstNodePath(h);return{$ref:`${I}#${qe}`,$refText:f}}else return{$error:(u=(c=t.error)===null||c===void 0?void 0:c.message)!==null&&u!==void 0?u:"Could not resolve reference",$refText:f}}else if(x(t)){let h;if(i&&(h=this.addAstNodeRegionWithAssignmentsTo(Object.assign({},t)),(!e||t.$document)&&h?.$textRegion&&(h.$textRegion.documentURI=(l=this.currentDocument)===null||l===void 0?void 0:l.uri.toString())),s&&!e&&(h??(h=Object.assign({},t)),h.$sourceText=(d=t.$cstNode)===null||d===void 0?void 0:d.text),a){h??(h=Object.assign({},t));const f=this.commentProvider.getComment(t);f&&(h.$comment=f.replace(/\r/g,""))}return h??t}else return t}addAstNodeRegionWithAssignmentsTo(e){const t=r=>({offset:r.offset,end:r.end,length:r.length,range:r.range});if(e.$cstNode){const r=e.$textRegion=t(e.$cstNode),s=r.assignments={};return Object.keys(e).filter(i=>!i.startsWith("$")).forEach(i=>{const a=Tn(e.$cstNode,i).map(t);a.length!==0&&(s[i]=a)}),e}}linkNode(e,t,r,s,i,a){for(const[c,u]of Object.entries(e))if(Array.isArray(u))for(let l=0;l{await this.handleException(()=>e.call(t,r,s,i),"An error occurred during validation",s,r)}}async handleException(e,t,r,s){try{await e()}catch(i){if(Je(i))throw i;console.error(`${t}:`,i),i instanceof Error&&i.stack&&console.error(i.stack);const a=i instanceof Error?i.message:String(i);r("error",`${t}: ${a}`,{node:s})}}addEntry(e,t){if(e==="AstNode"){this.entries.add("AstNode",t);return}for(const r of this.reflection.getAllSubTypes(e))this.entries.add(r,t)}getChecks(e,t){let r=w(this.entries.get(e)).concat(this.entries.get("AstNode"));return t&&(r=r.filter(s=>t.includes(s.category))),r.map(s=>s.check)}registerBeforeDocument(e,t=this){this.entriesBefore.push(this.wrapPreparationException(e,"An error occurred during set-up of the validation",t))}registerAfterDocument(e,t=this){this.entriesAfter.push(this.wrapPreparationException(e,"An error occurred during tear-down of the validation",t))}wrapPreparationException(e,t,r){return async(s,i,a,o)=>{await this.handleException(()=>e.call(r,s,i,a,o),t,i,s)}}get checksBefore(){return this.entriesBefore}get checksAfter(){return this.entriesAfter}}class bs{constructor(e){this.validationRegistry=e.validation.ValidationRegistry,this.metadata=e.LanguageMetaData}async validateDocument(e,t={},r=g.CancellationToken.None){const s=e.parseResult,i=[];if(await b(r),(!t.categories||t.categories.includes("built-in"))&&(this.processLexingErrors(s,i,t),t.stopAfterLexingErrors&&i.some(a=>{var o;return((o=a.data)===null||o===void 0?void 0:o.code)===D.LexingError})||(this.processParsingErrors(s,i,t),t.stopAfterParsingErrors&&i.some(a=>{var o;return((o=a.data)===null||o===void 0?void 0:o.code)===D.ParsingError}))||(this.processLinkingErrors(e,i,t),t.stopAfterLinkingErrors&&i.some(a=>{var o;return((o=a.data)===null||o===void 0?void 0:o.code)===D.LinkingError}))))return i;try{i.push(...await this.validateAst(s.value,t,r))}catch(a){if(Je(a))throw a;console.error("An error occurred during validation:",a)}return await b(r),i}processLexingErrors(e,t,r){var s,i,a;const o=[...e.lexerErrors,...(i=(s=e.lexerReport)===null||s===void 0?void 0:s.diagnostics)!==null&&i!==void 0?i:[]];for(const c of o){const u=(a=c.severity)!==null&&a!==void 0?a:"error",l={severity:it(u),range:{start:{line:c.line-1,character:c.column-1},end:{line:c.line-1,character:c.column+c.length-1}},message:c.message,data:Ds(u),source:this.getSource()};t.push(l)}}processParsingErrors(e,t,r){for(const s of e.parserErrors){let i;if(isNaN(s.token.startOffset)){if("previousToken"in s){const a=s.previousToken;if(isNaN(a.startOffset)){const o={line:0,character:0};i={start:o,end:o}}else{const o={line:a.endLine-1,character:a.endColumn};i={start:o,end:o}}}}else i=lt(s.token);if(i){const a={severity:it("error"),range:i,message:s.message,data:we(D.ParsingError),source:this.getSource()};t.push(a)}}}processLinkingErrors(e,t,r){for(const s of e.references){const i=s.error;if(i){const a={node:i.container,property:i.property,index:i.index,data:{code:D.LinkingError,containerType:i.container.$type,property:i.property,refText:i.reference.$refText}};t.push(this.toDiagnostic("error",i.message,a))}}}async validateAst(e,t,r=g.CancellationToken.None){const s=[],i=(a,o,c)=>{s.push(this.toDiagnostic(a,o,c))};return await this.validateAstBefore(e,t,i,r),await this.validateAstNodes(e,t,i,r),await this.validateAstAfter(e,t,i,r),s}async validateAstBefore(e,t,r,s=g.CancellationToken.None){var i;const a=this.validationRegistry.checksBefore;for(const o of a)await b(s),await o(e,r,(i=t.categories)!==null&&i!==void 0?i:[],s)}async validateAstNodes(e,t,r,s=g.CancellationToken.None){await Promise.all(j(e).map(async i=>{await b(s);const a=this.validationRegistry.getChecks(i.$type,t.categories);for(const o of a)await o(i,r,s)}))}async validateAstAfter(e,t,r,s=g.CancellationToken.None){var i;const a=this.validationRegistry.checksAfter;for(const o of a)await b(s),await o(e,r,(i=t.categories)!==null&&i!==void 0?i:[],s)}toDiagnostic(e,t,r){return{message:t,range:Rs(r),severity:it(e),code:r.code,codeDescription:r.codeDescription,tags:r.tags,relatedInformation:r.relatedInformation,data:r.data,source:this.getSource()}}getSource(){return this.metadata.languageId}}function Rs(n){if(n.range)return n.range;let e;return typeof n.property=="string"?e=cr(n.node.$cstNode,n.property,n.index):typeof n.keyword=="string"&&(e=An(n.node.$cstNode,n.keyword,n.index)),e??(e=n.node.$cstNode),e?e.range:{start:{line:0,character:0},end:{line:0,character:0}}}function it(n){switch(n){case"error":return 1;case"warning":return 2;case"info":return 3;case"hint":return 4;default:throw new Error("Invalid diagnostic severity: "+n)}}function Ds(n){switch(n){case"error":return we(D.LexingError);case"warning":return we(D.LexingWarning);case"info":return we(D.LexingInfo);case"hint":return we(D.LexingHint);default:throw new Error("Invalid diagnostic severity: "+n)}}var D;(function(n){n.LexingError="lexing-error",n.LexingWarning="lexing-warning",n.LexingInfo="lexing-info",n.LexingHint="lexing-hint",n.ParsingError="parsing-error",n.LinkingError="linking-error"})(D||(D={}));class Ts{constructor(e){this.astNodeLocator=e.workspace.AstNodeLocator,this.nameProvider=e.references.NameProvider}createDescription(e,t,r){const s=r??L(e);t??(t=this.nameProvider.getName(e));const i=this.astNodeLocator.getAstNodePath(e);if(!t)throw new Error(`Node at path ${i} has no name.`);let a;const o=()=>{var c;return a??(a=Fe((c=this.nameProvider.getNameNode(e))!==null&&c!==void 0?c:e.$cstNode))};return{node:e,name:t,get nameSegment(){return o()},selectionSegment:Fe(e.$cstNode),type:e.$type,documentUri:s.uri,path:i}}}class As{constructor(e){this.nodeLocator=e.workspace.AstNodeLocator}async createDescriptions(e,t=g.CancellationToken.None){const r=[],s=e.parseResult.value;for(const i of j(s))await b(t),sr(i).filter(a=>!Me(a)).forEach(a=>{const o=this.createDescription(a);o&&r.push(o)});return r}createDescription(e){const t=e.reference.$nodeDescription,r=e.reference.$refNode;if(!t||!r)return;const s=L(e.container).uri;return{sourceUri:s,sourcePath:this.nodeLocator.getAstNodePath(e.container),targetUri:t.documentUri,targetPath:t.path,segment:Fe(r),local:$.equals(t.documentUri,s)}}}class Es{constructor(){this.segmentSeparator="/",this.indexSeparator="@"}getAstNodePath(e){if(e.$container){const t=this.getAstNodePath(e.$container),r=this.getPathSegment(e);return t+this.segmentSeparator+r}return""}getPathSegment({$containerProperty:e,$containerIndex:t}){if(!e)throw new Error("Missing '$containerProperty' in AST node.");return t!==void 0?e+this.indexSeparator+t:e}getAstNode(e,t){return t.split(this.segmentSeparator).reduce((s,i)=>{if(!s||i.length===0)return s;const a=i.indexOf(this.indexSeparator);if(a>0){const o=i.substring(0,a),c=parseInt(i.substring(a+1)),u=s[o];return u?.[c]}return s[i]},e)}}class Ps{constructor(e){this._ready=new Et,this.settings={},this.workspaceConfig=!1,this.onConfigurationSectionUpdateEmitter=new Cr.Emitter,this.serviceRegistry=e.ServiceRegistry}get ready(){return this._ready.promise}initialize(e){var t,r;this.workspaceConfig=(r=(t=e.capabilities.workspace)===null||t===void 0?void 0:t.configuration)!==null&&r!==void 0?r:!1}async initialized(e){if(this.workspaceConfig){if(e.register){const t=this.serviceRegistry.all;e.register({section:t.map(r=>this.toSectionName(r.LanguageMetaData.languageId))})}if(e.fetchConfiguration){const t=this.serviceRegistry.all.map(s=>({section:this.toSectionName(s.LanguageMetaData.languageId)})),r=await e.fetchConfiguration(t);t.forEach((s,i)=>{this.updateSectionConfiguration(s.section,r[i])})}}this._ready.resolve()}updateConfiguration(e){e.settings&&Object.keys(e.settings).forEach(t=>{const r=e.settings[t];this.updateSectionConfiguration(t,r),this.onConfigurationSectionUpdateEmitter.fire({section:t,configuration:r})})}updateSectionConfiguration(e,t){this.settings[e]=t}async getConfiguration(e,t){await this.ready;const r=this.toSectionName(e);if(this.settings[r])return this.settings[r][t]}toSectionName(e){return`${e}`}get onConfigurationSectionUpdate(){return this.onConfigurationSectionUpdateEmitter.event}}var xe;(function(n){function e(t){return{dispose:async()=>await t()}}n.create=e})(xe||(xe={}));class Cs{constructor(e){this.updateBuildOptions={validation:{categories:["built-in","fast"]}},this.updateListeners=[],this.buildPhaseListeners=new je,this.documentPhaseListeners=new je,this.buildState=new Map,this.documentBuildWaiters=new Map,this.currentState=m.Changed,this.langiumDocuments=e.workspace.LangiumDocuments,this.langiumDocumentFactory=e.workspace.LangiumDocumentFactory,this.textDocuments=e.workspace.TextDocuments,this.indexManager=e.workspace.IndexManager,this.serviceRegistry=e.ServiceRegistry}async build(e,t={},r=g.CancellationToken.None){var s,i;for(const a of e){const o=a.uri.toString();if(a.state===m.Validated){if(typeof t.validation=="boolean"&&t.validation)a.state=m.IndexedReferences,a.diagnostics=void 0,this.buildState.delete(o);else if(typeof t.validation=="object"){const c=this.buildState.get(o),u=(s=c?.result)===null||s===void 0?void 0:s.validationChecks;if(u){const d=((i=t.validation.categories)!==null&&i!==void 0?i:ze.all).filter(h=>!u.includes(h));d.length>0&&(this.buildState.set(o,{completed:!1,options:{validation:Object.assign(Object.assign({},t.validation),{categories:d})},result:c.result}),a.state=m.IndexedReferences)}}}else this.buildState.delete(o)}this.currentState=m.Changed,await this.emitUpdate(e.map(a=>a.uri),[]),await this.buildDocuments(e,t,r)}async update(e,t,r=g.CancellationToken.None){this.currentState=m.Changed;for(const a of t)this.langiumDocuments.deleteDocument(a),this.buildState.delete(a.toString()),this.indexManager.remove(a);for(const a of e){if(!this.langiumDocuments.invalidateDocument(a)){const c=this.langiumDocumentFactory.fromModel({$type:"INVALID"},a);c.state=m.Changed,this.langiumDocuments.addDocument(c)}this.buildState.delete(a.toString())}const s=w(e).concat(t).map(a=>a.toString()).toSet();this.langiumDocuments.all.filter(a=>!s.has(a.uri.toString())&&this.shouldRelink(a,s)).forEach(a=>{this.serviceRegistry.getServices(a.uri).references.Linker.unlink(a),a.state=Math.min(a.state,m.ComputedScopes),a.diagnostics=void 0}),await this.emitUpdate(e,t),await b(r);const i=this.sortDocuments(this.langiumDocuments.all.filter(a=>{var o;return a.stater(e,t)))}sortDocuments(e){let t=0,r=e.length-1;for(;t=0&&!this.hasTextDocument(e[r]);)r--;tr.error!==void 0)?!0:this.indexManager.isAffected(e,t)}onUpdate(e){return this.updateListeners.push(e),xe.create(()=>{const t=this.updateListeners.indexOf(e);t>=0&&this.updateListeners.splice(t,1)})}async buildDocuments(e,t,r){this.prepareBuild(e,t),await this.runCancelable(e,m.Parsed,r,i=>this.langiumDocumentFactory.update(i,r)),await this.runCancelable(e,m.IndexedContent,r,i=>this.indexManager.updateContent(i,r)),await this.runCancelable(e,m.ComputedScopes,r,async i=>{const a=this.serviceRegistry.getServices(i.uri).references.ScopeComputation;i.precomputedScopes=await a.computeLocalScopes(i,r)}),await this.runCancelable(e,m.Linked,r,i=>this.serviceRegistry.getServices(i.uri).references.Linker.link(i,r)),await this.runCancelable(e,m.IndexedReferences,r,i=>this.indexManager.updateReferences(i,r));const s=e.filter(i=>this.shouldValidate(i));await this.runCancelable(s,m.Validated,r,i=>this.validate(i,r));for(const i of e){const a=this.buildState.get(i.uri.toString());a&&(a.completed=!0)}}prepareBuild(e,t){for(const r of e){const s=r.uri.toString(),i=this.buildState.get(s);(!i||i.completed)&&this.buildState.set(s,{completed:!1,options:t,result:i?.result})}}async runCancelable(e,t,r,s){const i=e.filter(o=>o.stateo.state===t);await this.notifyBuildPhase(a,t,r),this.currentState=t}onBuildPhase(e,t){return this.buildPhaseListeners.add(e,t),xe.create(()=>{this.buildPhaseListeners.delete(e,t)})}onDocumentPhase(e,t){return this.documentPhaseListeners.add(e,t),xe.create(()=>{this.documentPhaseListeners.delete(e,t)})}waitUntil(e,t,r){let s;if(t&&"path"in t?s=t:r=t,r??(r=g.CancellationToken.None),s){const i=this.langiumDocuments.getDocument(s);if(i&&i.state>e)return Promise.resolve(s)}return this.currentState>=e?Promise.resolve(void 0):r.isCancellationRequested?Promise.reject(Ue):new Promise((i,a)=>{const o=this.onBuildPhase(e,()=>{if(o.dispose(),c.dispose(),s){const u=this.langiumDocuments.getDocument(s);i(u?.uri)}else i(void 0)}),c=r.onCancellationRequested(()=>{o.dispose(),c.dispose(),a(Ue)})})}async notifyDocumentPhase(e,t,r){const i=this.documentPhaseListeners.get(t).slice();for(const a of i)try{await a(e,r)}catch(o){if(!Je(o))throw o}}async notifyBuildPhase(e,t,r){if(e.length===0)return;const i=this.buildPhaseListeners.get(t).slice();for(const a of i)await b(r),await a(e,r)}shouldValidate(e){return!!this.getBuildOptions(e).validation}async validate(e,t){var r,s;const i=this.serviceRegistry.getServices(e.uri).validation.DocumentValidator,a=this.getBuildOptions(e).validation,o=typeof a=="object"?a:void 0,c=await i.validateDocument(e,o,t);e.diagnostics?e.diagnostics.push(...c):e.diagnostics=c;const u=this.buildState.get(e.uri.toString());if(u){(r=u.result)!==null&&r!==void 0||(u.result={});const l=(s=o?.categories)!==null&&s!==void 0?s:ze.all;u.result.validationChecks?u.result.validationChecks.push(...l):u.result.validationChecks=[...l]}}getBuildOptions(e){var t,r;return(r=(t=this.buildState.get(e.uri.toString()))===null||t===void 0?void 0:t.options)!==null&&r!==void 0?r:{}}}class Ls{constructor(e){this.symbolIndex=new Map,this.symbolByTypeIndex=new ys,this.referenceIndex=new Map,this.documents=e.workspace.LangiumDocuments,this.serviceRegistry=e.ServiceRegistry,this.astReflection=e.AstReflection}findAllReferences(e,t){const r=L(e).uri,s=[];return this.referenceIndex.forEach(i=>{i.forEach(a=>{$.equals(a.targetUri,r)&&a.targetPath===t&&s.push(a)})}),w(s)}allElements(e,t){let r=w(this.symbolIndex.keys());return t&&(r=r.filter(s=>!t||t.has(s))),r.map(s=>this.getFileDescriptions(s,e)).flat()}getFileDescriptions(e,t){var r;return t?this.symbolByTypeIndex.get(e,t,()=>{var i;return((i=this.symbolIndex.get(e))!==null&&i!==void 0?i:[]).filter(o=>this.astReflection.isSubtype(o.type,t))}):(r=this.symbolIndex.get(e))!==null&&r!==void 0?r:[]}remove(e){const t=e.toString();this.symbolIndex.delete(t),this.symbolByTypeIndex.clear(t),this.referenceIndex.delete(t)}async updateContent(e,t=g.CancellationToken.None){const s=await this.serviceRegistry.getServices(e.uri).references.ScopeComputation.computeExports(e,t),i=e.uri.toString();this.symbolIndex.set(i,s),this.symbolByTypeIndex.clear(i)}async updateReferences(e,t=g.CancellationToken.None){const s=await this.serviceRegistry.getServices(e.uri).workspace.ReferenceDescriptionProvider.createDescriptions(e,t);this.referenceIndex.set(e.uri.toString(),s)}isAffected(e,t){const r=this.referenceIndex.get(e.uri.toString());return r?r.some(s=>!s.local&&t.has(s.targetUri.toString())):!1}}class $s{constructor(e){this.initialBuildOptions={},this._ready=new Et,this.serviceRegistry=e.ServiceRegistry,this.langiumDocuments=e.workspace.LangiumDocuments,this.documentBuilder=e.workspace.DocumentBuilder,this.fileSystemProvider=e.workspace.FileSystemProvider,this.mutex=e.workspace.WorkspaceLock}get ready(){return this._ready.promise}get workspaceFolders(){return this.folders}initialize(e){var t;this.folders=(t=e.workspaceFolders)!==null&&t!==void 0?t:void 0}initialized(e){return this.mutex.write(t=>{var r;return this.initializeWorkspace((r=this.folders)!==null&&r!==void 0?r:[],t)})}async initializeWorkspace(e,t=g.CancellationToken.None){const r=await this.performStartup(e);await b(t),await this.documentBuilder.build(r,this.initialBuildOptions,t)}async performStartup(e){const t=this.serviceRegistry.all.flatMap(i=>i.LanguageMetaData.fileExtensions),r=[],s=i=>{r.push(i),this.langiumDocuments.hasDocument(i.uri)||this.langiumDocuments.addDocument(i)};return await this.loadAdditionalDocuments(e,s),await Promise.all(e.map(i=>[i,this.getRootFolder(i)]).map(async i=>this.traverseFolder(...i,t,s))),this._ready.resolve(),r}loadAdditionalDocuments(e,t){return Promise.resolve()}getRootFolder(e){return M.parse(e.uri)}async traverseFolder(e,t,r,s){const i=await this.fileSystemProvider.readDirectory(t);await Promise.all(i.map(async a=>{if(this.includeEntry(e,a,r)){if(a.isDirectory)await this.traverseFolder(e,a.uri,r,s);else if(a.isFile){const o=await this.langiumDocuments.getOrCreateDocument(a.uri);s(o)}}}))}includeEntry(e,t,r){const s=$.basename(t.uri);if(s.startsWith("."))return!1;if(t.isDirectory)return s!=="node_modules"&&s!=="out";if(t.isFile){const i=$.extname(t.uri);return r.includes(i)}return!1}}class Is{buildUnexpectedCharactersMessage(e,t,r,s,i){return Lt.buildUnexpectedCharactersMessage(e,t,r,s,i)}buildUnableToPopLexerModeMessage(e){return Lt.buildUnableToPopLexerModeMessage(e)}}const Ms={mode:"full"};class _s{constructor(e){this.errorMessageProvider=e.parser.LexerErrorMessageProvider,this.tokenBuilder=e.parser.TokenBuilder;const t=this.tokenBuilder.buildTokens(e.Grammar,{caseInsensitive:e.LanguageMetaData.caseInsensitive});this.tokenTypes=this.toTokenTypeDictionary(t);const r=Gt(t)?Object.values(t):t,s=e.LanguageMetaData.mode==="production";this.chevrotainLexer=new Jt(r,{positionTracking:"full",skipValidations:s,errorMessageProvider:this.errorMessageProvider})}get definition(){return this.tokenTypes}tokenize(e,t=Ms){var r,s,i;const a=this.chevrotainLexer.tokenize(e);return{tokens:a.tokens,errors:a.errors,hidden:(r=a.groups.hidden)!==null&&r!==void 0?r:[],report:(i=(s=this.tokenBuilder).flushLexingReport)===null||i===void 0?void 0:i.call(s,e)}}toTokenTypeDictionary(e){if(Gt(e))return e;const t=Nr(e)?Object.values(e.modes).flat():e,r={};return t.forEach(s=>r[s.name]=s),r}}function Os(n){return Array.isArray(n)&&(n.length===0||"name"in n[0])}function Nr(n){return n&&"modes"in n&&"defaultMode"in n}function Gt(n){return!Os(n)&&!Nr(n)}function Bs(n,e,t){let r,s;typeof n=="string"?(s=e,r=t):(s=n.range.start,r=e),s||(s=y.create(0,0));const i=br(n),a=Pt(r),o=Us({lines:i,position:s,options:a});return Ks({index:0,tokens:o,position:s})}function Fs(n,e){const t=Pt(e),r=br(n);if(r.length===0)return!1;const s=r[0],i=r[r.length-1],a=t.start,o=t.end;return!!a?.exec(s)&&!!o?.exec(i)}function br(n){let e="";return typeof n=="string"?e=n:e=n.text,e.split(mn)}const Ut=/\s*(@([\p{L}][\p{L}\p{N}]*)?)/uy,Gs=/\{(@[\p{L}][\p{L}\p{N}]*)(\s*)([^\r\n}]+)?\}/gu;function Us(n){var e,t,r;const s=[];let i=n.position.line,a=n.position.character;for(let o=0;o=l.length){if(s.length>0){const f=y.create(i,a);s.push({type:"break",content:"",range:N.create(f,f)})}}else{Ut.lastIndex=d;const f=Ut.exec(l);if(f){const k=f[0],I=f[1],qe=y.create(i,a+d),Pr=y.create(i,a+d+k.length);s.push({type:"tag",content:I,range:N.create(qe,Pr)}),d+=k.length,d=gt(l,d)}if(d0&&s[s.length-1].type==="break"?s.slice(0,-1):s}function js(n,e,t,r){const s=[];if(n.length===0){const i=y.create(t,r),a=y.create(t,r+e.length);s.push({type:"text",content:e,range:N.create(i,a)})}else{let i=0;for(const o of n){const c=o.index,u=e.substring(i,c);u.length>0&&s.push({type:"text",content:e.substring(i,c),range:N.create(y.create(t,i+r),y.create(t,c+r))});let l=u.length+1;const d=o[1];if(s.push({type:"inline-tag",content:d,range:N.create(y.create(t,i+l+r),y.create(t,i+l+d.length+r))}),l+=d.length,o.length===4){l+=o[2].length;const h=o[3];s.push({type:"text",content:h,range:N.create(y.create(t,i+l+r),y.create(t,i+l+h.length+r))})}else s.push({type:"text",content:"",range:N.create(y.create(t,i+l+r),y.create(t,i+l+r))});i=c+o[0].length}const a=e.substring(i);a.length>0&&s.push({type:"text",content:a,range:N.create(y.create(t,i+r),y.create(t,i+r+a.length))})}return s}const zs=/\S/,Vs=/\s*$/;function gt(n,e){const t=n.substring(e).match(zs);return t?e+t.index:n.length}function Ws(n){const e=n.match(Vs);if(e&&typeof e.index=="number")return e.index}function Ks(n){var e,t,r,s;const i=y.create(n.position.line,n.position.character);if(n.tokens.length===0)return new jt([],N.create(i,i));const a=[];for(;n.indext.name===e)}getTags(e){return this.getAllTags().filter(t=>t.name===e)}getAllTags(){return this.elements.filter(e=>"name"in e)}toString(){let e="";for(const t of this.elements)if(e.length===0)e=t.toString();else{const r=t.toString();e+=zt(e)+r}return e.trim()}toMarkdown(e){let t="";for(const r of this.elements)if(t.length===0)t=r.toMarkdown(e);else{const s=r.toMarkdown(e);t+=zt(t)+s}return t.trim()}}class ot{constructor(e,t,r,s){this.name=e,this.content=t,this.inline=r,this.range=s}toString(){let e=`@${this.name}`;const t=this.content.toString();return this.content.inlines.length===1?e=`${e} ${t}`:this.content.inlines.length>1&&(e=`${e} ${t}`),this.inline?`{${e}}`:e}toMarkdown(e){var t,r;return(r=(t=e?.renderTag)===null||t===void 0?void 0:t.call(e,this))!==null&&r!==void 0?r:this.toMarkdownDefault(e)}toMarkdownDefault(e){const t=this.content.toMarkdown(e);if(this.inline){const i=Qs(this.name,t,e??{});if(typeof i=="string")return i}let r="";e?.tag==="italic"||e?.tag===void 0?r="*":e?.tag==="bold"?r="**":e?.tag==="bold-italic"&&(r="***");let s=`${r}@${this.name}${r}`;return this.content.inlines.length===1?s=`${s} — ${t}`:this.content.inlines.length>1&&(s=`${s} ${t}`),this.inline?`{${s}}`:s}}function Qs(n,e,t){var r,s;if(n==="linkplain"||n==="linkcode"||n==="link"){const i=e.indexOf(" ");let a=e;if(i>0){const c=gt(e,i);a=e.substring(c),e=e.substring(0,i)}return(n==="linkcode"||n==="link"&&t.link==="code")&&(a=`\`${a}\``),(s=(r=t.renderLink)===null||r===void 0?void 0:r.call(t,e,a))!==null&&s!==void 0?s:Ys(e,a)}}function Ys(n,e){try{return M.parse(n,!0),`[${e}](${n})`}catch{return n}}class yt{constructor(e,t){this.inlines=e,this.range=t}toString(){let e="";for(let t=0;tr.range.start.line&&(e+=` `)}return e}toMarkdown(e){let t="";for(let r=0;rs.range.start.line&&(t+=` `)}return t}}class Ar{constructor(e,t){this.text=e,this.range=t}toString(){return this.text}toMarkdown(){return this.text}}function zt(n){return n.endsWith(` `)?` `:` `}class Xs{constructor(e){this.indexManager=e.shared.workspace.IndexManager,this.commentProvider=e.documentation.CommentProvider}getDocumentation(e){const t=this.commentProvider.getComment(e);if(t&&Fs(t))return Bs(t).toMarkdown({renderLink:(s,i)=>this.documentationLinkRenderer(e,s,i),renderTag:s=>this.documentationTagRenderer(e,s)})}documentationLinkRenderer(e,t,r){var s;const i=(s=this.findNameInPrecomputedScopes(e,t))!==null&&s!==void 0?s:this.findNameInGlobalScope(e,t);if(i&&i.nameSegment){const a=i.nameSegment.range.start.line+1,o=i.nameSegment.range.start.character+1,c=i.documentUri.with({fragment:`L${a},${o}`});return`[${r}](${c.toString()})`}else return}documentationTagRenderer(e,t){}findNameInPrecomputedScopes(e,t){const s=L(e).precomputedScopes;if(!s)return;let i=e;do{const o=s.get(i).find(c=>c.name===t);if(o)return o;i=i.$container}while(i)}findNameInGlobalScope(e,t){return this.indexManager.allElements().find(s=>s.name===t)}}class Zs{constructor(e){this.grammarConfig=()=>e.parser.GrammarConfig}getComment(e){var t;return xs(e)?e.$comment:(t=Hr(e.$cstNode,this.grammarConfig().multilineCommentRules))===null||t===void 0?void 0:t.text}}class ei{constructor(e){this.syncParser=e.parser.LangiumParser}parse(e,t){return Promise.resolve(this.syncParser.parse(e))}}class ti{constructor(){this.previousTokenSource=new g.CancellationTokenSource,this.writeQueue=[],this.readQueue=[],this.done=!0}write(e){this.cancelWrite();const t=os();return this.previousTokenSource=t,this.enqueue(this.writeQueue,e,t.token)}read(e){return this.enqueue(this.readQueue,e)}enqueue(e,t,r=g.CancellationToken.None){const s=new Et,i={action:t,deferred:s,cancellationToken:r};return e.push(i),this.performNextOperation(),s.promise}async performNextOperation(){if(!this.done)return;const e=[];if(this.writeQueue.length>0)e.push(this.writeQueue.shift());else if(this.readQueue.length>0)e.push(...this.readQueue.splice(0,this.readQueue.length));else return;this.done=!1,await Promise.all(e.map(async({action:t,deferred:r,cancellationToken:s})=>{try{const i=await Promise.resolve().then(()=>t(s));r.resolve(i)}catch(i){Je(i)?r.resolve(void 0):r.reject(i)}})),this.done=!0,this.performNextOperation()}cancelWrite(){this.previousTokenSource.cancel()}}class ri{constructor(e){this.grammarElementIdMap=new Ot,this.tokenTypeIdMap=new Ot,this.grammar=e.Grammar,this.lexer=e.parser.Lexer,this.linker=e.references.Linker}dehydrate(e){return{lexerErrors:e.lexerErrors,lexerReport:e.lexerReport?this.dehydrateLexerReport(e.lexerReport):void 0,parserErrors:e.parserErrors.map(t=>Object.assign(Object.assign({},t),{message:t.message})),value:this.dehydrateAstNode(e.value,this.createDehyrationContext(e.value))}}dehydrateLexerReport(e){return e}createDehyrationContext(e){const t=new Map,r=new Map;for(const s of j(e))t.set(s,{});if(e.$cstNode)for(const s of ut(e.$cstNode))r.set(s,{});return{astNodes:t,cstNodes:r}}dehydrateAstNode(e,t){const r=t.astNodes.get(e);r.$type=e.$type,r.$containerIndex=e.$containerIndex,r.$containerProperty=e.$containerProperty,e.$cstNode!==void 0&&(r.$cstNode=this.dehydrateCstNode(e.$cstNode,t));for(const[s,i]of Object.entries(e))if(!s.startsWith("$"))if(Array.isArray(i)){const a=[];r[s]=a;for(const o of i)x(o)?a.push(this.dehydrateAstNode(o,t)):T(o)?a.push(this.dehydrateReference(o,t)):a.push(o)}else x(i)?r[s]=this.dehydrateAstNode(i,t):T(i)?r[s]=this.dehydrateReference(i,t):i!==void 0&&(r[s]=i);return r}dehydrateReference(e,t){const r={};return r.$refText=e.$refText,e.$refNode&&(r.$refNode=t.cstNodes.get(e.$refNode)),r}dehydrateCstNode(e,t){const r=t.cstNodes.get(e);return Qt(e)?r.fullText=e.fullText:r.grammarSource=this.getGrammarElementId(e.grammarSource),r.hidden=e.hidden,r.astNode=t.astNodes.get(e.astNode),ke(e)?r.content=e.content.map(s=>this.dehydrateCstNode(s,t)):qt(e)&&(r.tokenType=e.tokenType.name,r.offset=e.offset,r.length=e.length,r.startLine=e.range.start.line,r.startColumn=e.range.start.character,r.endLine=e.range.end.line,r.endColumn=e.range.end.character),r}hydrate(e){const t=e.value,r=this.createHydrationContext(t);return"$cstNode"in t&&this.hydrateCstNode(t.$cstNode,r),{lexerErrors:e.lexerErrors,lexerReport:e.lexerReport,parserErrors:e.parserErrors,value:this.hydrateAstNode(t,r)}}createHydrationContext(e){const t=new Map,r=new Map;for(const i of j(e))t.set(i,{});let s;if(e.$cstNode)for(const i of ut(e.$cstNode)){let a;"fullText"in i?(a=new pr(i.fullText),s=a):"content"in i?a=new Tt:"tokenType"in i&&(a=this.hydrateCstLeafNode(i)),a&&(r.set(i,a),a.root=s)}return{astNodes:t,cstNodes:r}}hydrateAstNode(e,t){const r=t.astNodes.get(e);r.$type=e.$type,r.$containerIndex=e.$containerIndex,r.$containerProperty=e.$containerProperty,e.$cstNode&&(r.$cstNode=t.cstNodes.get(e.$cstNode));for(const[s,i]of Object.entries(e))if(!s.startsWith("$"))if(Array.isArray(i)){const a=[];r[s]=a;for(const o of i)x(o)?a.push(this.setParent(this.hydrateAstNode(o,t),r)):T(o)?a.push(this.hydrateReference(o,r,s,t)):a.push(o)}else x(i)?r[s]=this.setParent(this.hydrateAstNode(i,t),r):T(i)?r[s]=this.hydrateReference(i,r,s,t):i!==void 0&&(r[s]=i);return r}setParent(e,t){return e.$container=t,e}hydrateReference(e,t,r,s){return this.linker.buildReference(t,r,s.cstNodes.get(e.$refNode),e.$refText)}hydrateCstNode(e,t,r=0){const s=t.cstNodes.get(e);if(typeof e.grammarSource=="number"&&(s.grammarSource=this.getGrammarElement(e.grammarSource)),s.astNode=t.astNodes.get(e.astNode),ke(s))for(const i of e.content){const a=this.hydrateCstNode(i,t,r++);s.content.push(a)}return s}hydrateCstLeafNode(e){const t=this.getTokenType(e.tokenType),r=e.offset,s=e.length,i=e.startLine,a=e.startColumn,o=e.endLine,c=e.endColumn,u=e.hidden;return new ht(r,s,{start:{line:i,character:a},end:{line:o,character:c}},t,u)}getTokenType(e){return this.lexer.definition[e]}getGrammarElementId(e){if(e)return this.grammarElementIdMap.size===0&&this.createGrammarElementIdMap(),this.grammarElementIdMap.get(e)}getGrammarElement(e){return this.grammarElementIdMap.size===0&&this.createGrammarElementIdMap(),this.grammarElementIdMap.getKey(e)}createGrammarElementIdMap(){let e=0;for(const t of j(this.grammar))qr(t)&&this.grammarElementIdMap.set(t,e++)}}function ni(n){return{documentation:{CommentProvider:e=>new Zs(e),DocumentationProvider:e=>new Xs(e)},parser:{AsyncParser:e=>new ei(e),GrammarConfig:e=>Bn(e),LangiumParser:e=>ts(e),CompletionParser:e=>es(e),ValueConverter:()=>new ss,TokenBuilder:()=>new ns,Lexer:e=>new _s(e),ParserErrorMessageProvider:()=>new yr,LexerErrorMessageProvider:()=>new Is},workspace:{AstNodeLocator:()=>new Es,AstNodeDescriptionProvider:e=>new Ts(e),ReferenceDescriptionProvider:e=>new As(e)},references:{Linker:e=>new ls(e),NameProvider:()=>new fs,ScopeProvider:e=>new ws(e),ScopeComputation:e=>new ps(e),References:e=>new hs(e)},serializer:{Hydrator:e=>new ri(e),JsonSerializer:e=>new ks(e)},validation:{DocumentValidator:e=>new bs(e),ValidationRegistry:e=>new Ns(e)},shared:()=>n.shared}}function si(n){return{ServiceRegistry:e=>new Ss(e),workspace:{LangiumDocuments:e=>new us(e),LangiumDocumentFactory:e=>new cs(e),DocumentBuilder:e=>new Cs(e),IndexManager:e=>new Ls(e),WorkspaceManager:e=>new $s(e),FileSystemProvider:e=>n.fileSystemProvider(e),WorkspaceLock:()=>new ti,ConfigurationProvider:e=>new Ps(e)}}}var Vt;(function(n){n.merge=(e,t)=>Ve(Ve({},e),t)})(Vt||(Vt={}));function Wt(n,e,t,r,s,i,a,o,c){const u=[n,e,t,r,s,i,a,o,c].reduce(Ve,{});return Er(u)}const ii=Symbol("isProxy");function Er(n,e){const t=new Proxy({},{deleteProperty:()=>!1,set:()=>{throw new Error("Cannot set property on injected service container")},get:(r,s)=>s===ii?!0:Ht(r,s,n,e||t),getOwnPropertyDescriptor:(r,s)=>(Ht(r,s,n,e||t),Object.getOwnPropertyDescriptor(r,s)),has:(r,s)=>s in n,ownKeys:()=>[...Object.getOwnPropertyNames(n)]});return t}const Kt=Symbol();function Ht(n,e,t,r){if(e in n){if(n[e]instanceof Error)throw new Error("Construction failure. Please make sure that your dependencies are constructable.",{cause:n[e]});if(n[e]===Kt)throw new Error('Cycle detected. Please make "'+String(e)+'" lazy. Visit https://langium.org/docs/reference/configuration-services/#resolving-cyclic-dependencies');return n[e]}else if(e in t){const s=t[e];n[e]=Kt;try{n[e]=typeof s=="function"?s(r):Er(s,r)}catch(i){throw n[e]=i instanceof Error?i:void 0,i}return n[e]}else return}function Ve(n,e){if(e){for(const[t,r]of Object.entries(e))if(r!==void 0){const s=n[t];s!==null&&r!==null&&typeof s=="object"&&typeof r=="object"?n[t]=Ve(s,r):n[t]=r}}return n}class ai{readFile(){throw new Error("No file system is available.")}async readDirectory(){return[]}}const oi={fileSystemProvider:()=>new ai},ci={Grammar:()=>{},LanguageMetaData:()=>({caseInsensitive:!1,fileExtensions:[".langium"],languageId:"langium"})},ui={AstReflection:()=>new nr};function li(){const n=Wt(si(oi),ui),e=Wt(ni({shared:n}),ci);return n.ServiceRegistry.register(e),e}function vi(n){var e;const t=li(),r=t.serializer.JsonSerializer.deserialize(n);return t.shared.workspace.LangiumDocumentFactory.fromModel(r,M.parse(`memory://${(e=r.name)!==null&&e!==void 0?e:"grammar"}.langium`)),r}export{Gr as A,ss as D,oi as E,ns as a,ni as b,si as c,Wt as i,vi as l};