diff --git "a/.output/public/assets/langium-BVNt58jJ.js" "b/.output/public/assets/langium-BVNt58jJ.js" new file mode 100644--- /dev/null +++ "b/.output/public/assets/langium-BVNt58jJ.js" @@ -0,0 +1,261 @@ +import{c as e,e as t}from"./vscode-jsonrpc-B7fdjHWu.js";import{d as n,E as r,L as s,b as i,c as o,e as a,f as c}from"./chevrotain-Cp5uJ8YW.js";import{g as u,B as l}from"./@chevrotain-DFy4Htpj.js";import{L as d}from"./chevrotain-allstar-WPou0XcH.js";import{P as h,R as f}from"./vscode-languageserver-types-BtnkyLj9.js";import{T as p}from"./vscode-languageserver-textdocument-ygi3JyHC.js";import{U as m,a as g}from"./vscode-uri-DEKkV-x5.js";function v(e){return"object"==typeof e&&null!==e&&"string"==typeof e.$type}function y(e){return"object"==typeof e&&null!==e&&"string"==typeof e.$refText}function w(e){return"object"==typeof e&&null!==e&&v(e.container)&&y(e.reference)&&"string"==typeof e.message}class x{constructor(){this.subtypes={},this.allSubtypes={}}isInstance(e,t){return v(e)&&this.isSubtype(e.$type,t)}isSubtype(e,t){if(e===t)return!0;let n=this.subtypes[e];n||(n=this.subtypes[e]={});const r=n[t];if(void 0!==r)return r;{const r=this.computeIsSubtype(e,t);return n[t]=r,r}}getAllSubTypes(e){const t=this.allSubtypes[e];if(t)return t;{const t=this.getAllTypes(),n=[];for(const r of t)this.isSubtype(r,e)&&n.push(r);return this.allSubtypes[e]=n,n}}}function k(e){return"object"==typeof e&&null!==e&&Array.isArray(e.content)}function S(e){return"object"==typeof e&&null!==e&&"object"==typeof e.tokenType}function b(e){return k(e)&&"string"==typeof e.fullText}class N{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(){const e=this.iterator();return Boolean(e.next().done)}count(){const e=this.iterator();let t=0,n=e.next();for(;!n.done;)t++,n=e.next();return t}toArray(){const e=[],t=this.iterator();let n;do{n=t.next(),void 0!==n.value&&e.push(n.value)}while(!n.done);return e}toSet(){return new Set(this)}toMap(e,t){const n=this.map((n=>[e?e(n):n,t?t(n):n]));return new Map(n)}toString(){return this.join()}concat(e){return new N((()=>({first:this.startFn(),firstDone:!1,iterator:e[Symbol.iterator]()})),(e=>{let t;if(!e.firstDone){do{if(t=this.nextFn(e.first),!t.done)return t}while(!t.done);e.firstDone=!0}do{if(t=e.iterator.next(),!t.done)return t}while(!t.done);return E}))}join(e=","){const t=this.iterator();let n,r="",s=!1;do{n=t.next(),n.done||(s&&(r+=e),r+=T(n.value)),s=!0}while(!n.done);return r}indexOf(e,t=0){const n=this.iterator();let r=0,s=n.next();for(;!s.done;){if(r>=t&&s.value===e)return r;s=n.next(),r++}return-1}every(e){const t=this.iterator();let n=t.next();for(;!n.done;){if(!e(n.value))return!1;n=t.next()}return!0}some(e){const t=this.iterator();let n=t.next();for(;!n.done;){if(e(n.value))return!0;n=t.next()}return!1}forEach(e){const t=this.iterator();let n=0,r=t.next();for(;!r.done;)e(r.value,n),r=t.next(),n++}map(e){return new N(this.startFn,(t=>{const{done:n,value:r}=this.nextFn(t);return n?E:{done:!1,value:e(r)}}))}filter(e){return new N(this.startFn,(t=>{let n;do{if(n=this.nextFn(t),!n.done&&e(n.value))return n}while(!n.done);return E}))}nonNullable(){return this.filter((e=>null!=e))}reduce(e,t){const n=this.iterator();let r=t,s=n.next();for(;!s.done;)r=void 0===r?s.value:e(r,s.value),s=n.next();return r}reduceRight(e,t){return this.recursiveReduce(this.iterator(),e,t)}recursiveReduce(e,t,n){const r=e.next();if(r.done)return n;const s=this.recursiveReduce(e,t,n);return void 0===s?r.value:t(s,r.value)}find(e){const t=this.iterator();let n=t.next();for(;!n.done;){if(e(n.value))return n.value;n=t.next()}}findIndex(e){const t=this.iterator();let n=0,r=t.next();for(;!r.done;){if(e(r.value))return n;r=t.next(),n++}return-1}includes(e){const t=this.iterator();let n=t.next();for(;!n.done;){if(n.value===e)return!0;n=t.next()}return!1}flatMap(e){return new N((()=>({this:this.startFn()})),(t=>{do{if(t.iterator){const e=t.iterator.next();if(!e.done)return e;t.iterator=void 0}const{done:n,value:r}=this.nextFn(t.this);if(!n){const n=e(r);if(!$(n))return{done:!1,value:n};t.iterator=n[Symbol.iterator]()}}while(t.iterator);return E}))}flat(e){if(void 0===e&&(e=1),e<=0)return this;const t=e>1?this.flat(e-1):this;return new N((()=>({this:t.startFn()})),(e=>{do{if(e.iterator){const t=e.iterator.next();if(!t.done)return t;e.iterator=void 0}const{done:n,value:r}=t.nextFn(e.this);if(!n){if(!$(r))return{done:!1,value:r};e.iterator=r[Symbol.iterator]()}}while(e.iterator);return E}))}head(){const e=this.iterator().next();if(!e.done)return e.value}tail(e=1){return new N((()=>{const t=this.startFn();for(let n=0;n({size:0,state:this.startFn()})),(t=>(t.size++,t.size>e?E:this.nextFn(t.state))))}distinct(e){return new N((()=>({set:new Set,internalState:this.startFn()})),(t=>{let n;do{if(n=this.nextFn(t.internalState),!n.done){const r=e?e(n.value):n.value;if(!t.set.has(r))return t.set.add(r),n}}while(!n.done);return E}))}exclude(e,t){const n=new Set;for(const r of e){const e=t?t(r):r;n.add(e)}return this.filter((e=>{const r=t?t(e):e;return!n.has(r)}))}}function T(e){return"string"==typeof e?e:void 0===e?"undefined":"function"==typeof e.toString?e.toString():Object.prototype.toString.call(e)}function $(e){return!!e&&"function"==typeof e[Symbol.iterator]}const R=new N((()=>{}),(()=>E)),E=Object.freeze({done:!0,value:void 0});function D(...e){if(1===e.length){const t=e[0];if(t instanceof N)return t;if($(t))return new N((()=>t[Symbol.iterator]()),(e=>e.next()));if("number"==typeof t.length)return new N((()=>({index:0})),(e=>e.index1?new N((()=>({collIndex:0,arrIndex:0})),(t=>{do{if(t.iterator){const e=t.iterator.next();if(!e.done)return e;t.iterator=void 0}if(t.array){if(t.arrIndex({iterators:(null==n?void 0:n.includeRoot)?[[e][Symbol.iterator]()]:[t(e)[Symbol.iterator]()],pruned:!1})),(e=>{for(e.pruned&&(e.iterators.pop(),e.pruned=!1);e.iterators.length>0;){const n=e.iterators[e.iterators.length-1].next();if(!n.done)return e.iterators.push(t(n.value)[Symbol.iterator]()),n;e.iterators.pop()}return E}))}iterator(){const e={state:this.startFn(),next:()=>this.nextFn(e.state),prune:()=>{e.state.pruned=!0},[Symbol.iterator]:()=>e};return e}}var I,L,P,C;function M(e){return new A(e,(e=>k(e)?e.content:[]),{includeRoot:!0})}function O(e){return{start:{character:e.startColumn-1,line:e.startLine-1},end:{character:e.endColumn, +// endColumn uses the correct index +line:e.endLine-1}}}function j(e){if(!e)return;const{offset:t,end:n,range:r}=e;return{range:r,offset:t,end:n,length:n-t}}function B(e,t){const n=function(e,t){if(e.end.linet.end.line||e.start.line===t.end.line&&e.start.character>=t.end.character)return P.After;const n=e.start.line>t.start.line||e.start.line===t.start.line&&e.start.character>=t.start.character,r=e.end.lineP.After}(L=I||(I={})).sum=function(e){return e.reduce(((e,t)=>e+t),0)},L.product=function(e){return e.reduce(((e,t)=>e*t),0)},L.min=function(e){return e.reduce(((e,t)=>Math.min(e,t)))},L.max=function(e){return e.reduce(((e,t)=>Math.max(e,t)))},(C=P||(P={}))[C.Before=0]="Before",C[C.After=1]="After",C[C.OverlapFront=2]="OverlapFront",C[C.OverlapBack=3]="OverlapBack",C[C.Inside=4]="Inside",C[C.Outside=5]="Outside";const F=/^[\w\p{L}]$/u;function _(e,t){return S(e)&&t.includes(e.tokenType.name)}class G extends Error{constructor(e,t){super(e?`${t} at ${e.range.start.line}:${e.range.start.character}`:t)}}function V(e){throw new Error("Error! The input value was not handled.")}const U="AbstractRule",z="AbstractType",W="Condition",H="TypeDefinition",q="ValueLiteral",K="AbstractElement";const Q="ArrayLiteral",J="ArrayType",X="BooleanLiteral";const Y="Conjunction";const Z="Disjunction";const ee="Grammar",te="GrammarImport",ne="InferredType";function re(e){return Qe.isInstance(e,ne)}const se="Interface";function ie(e){return Qe.isInstance(e,se)}const oe="NamedArgument",ae="Negation";const ce="NumberLiteral",ue="Parameter",le="ParameterReference";const de="ParserRule";function he(e){return Qe.isInstance(e,de)}const fe="ReferenceType",pe="ReturnType";const me="SimpleType";const ge="StringLiteral",ve="TerminalRule";function ye(e){return Qe.isInstance(e,ve)}const we="Type";function xe(e){return Qe.isInstance(e,we)}const ke="TypeAttribute",Se="UnionType",be="Action";function Ne(e){return Qe.isInstance(e,be)}const Te="Alternatives";function $e(e){return Qe.isInstance(e,Te)}const Re="Assignment";function Ee(e){return Qe.isInstance(e,Re)}const De="CharacterRange";const Ae="CrossReference";function Ie(e){return Qe.isInstance(e,Ae)}const Le="EndOfFile";const Pe="Group";function Ce(e){return Qe.isInstance(e,Pe)}const Me="Keyword";function Oe(e){return Qe.isInstance(e,Me)}const je="NegatedToken";const Be="RegexToken";const Fe="RuleCall";function _e(e){return Qe.isInstance(e,Fe)}const Ge="TerminalAlternatives";const Ve="TerminalGroup";const Ue="TerminalRuleCall";const ze="UnorderedGroup";function We(e){return Qe.isInstance(e,ze)}const He="UntilToken";const qe="Wildcard";class Ke extends x{getAllTypes(){return[K,U,z,be,Te,Q,J,Re,X,De,W,Y,Ae,Z,Le,ee,te,Pe,ne,se,Me,oe,je,ae,ce,ue,le,de,fe,Be,pe,Fe,me,ge,Ge,Ve,ve,Ue,we,ke,H,Se,ze,He,q,qe]}computeIsSubtype(e,t){switch(e){case be:case Te:case Re:case De:case Ae:case Le:case Pe:case Me:case je:case Be:case Fe:case Ge:case Ve:case Ue:case ze:case He:case qe:return this.isSubtype(K,t);case Q:case ce:case ge:return this.isSubtype(q,t);case J:case fe:case me:case Se:return this.isSubtype(H,t);case X:return this.isSubtype(W,t)||this.isSubtype(q,t);case Y:case Z:case ae:case le:return this.isSubtype(W,t);case ne:case se:case we:return this.isSubtype(z,t);case de:return this.isSubtype(U,t)||this.isSubtype(z,t);case ve:return this.isSubtype(U,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 z;case"Grammar:hiddenTokens":case"ParserRule:hiddenTokens":case"RuleCall:rule":return U;case"Grammar:usedGrammars":return ee;case"NamedArgument:parameter":case"ParameterReference:parameter":return ue;case"TerminalRuleCall:rule":return ve;default:throw new Error(`${t} is not a valid reference id.`)}}getTypeMetaData(e){switch(e){case K:return{name:K,properties:[{name:"cardinality"},{name:"lookahead"}]};case Q:return{name:Q,properties:[{name:"elements",defaultValue:[]}]};case J:return{name:J,properties:[{name:"elementType"}]};case X:return{name:X,properties:[{name:"true",defaultValue:!1}]};case Y:return{name:Y,properties:[{name:"left"},{name:"right"}]};case Z:return{name:Z,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 te:return{name:te,properties:[{name:"path"}]};case ne:return{name:ne,properties:[{name:"name"}]};case se:return{name:se,properties:[{name:"attributes",defaultValue:[]},{name:"name"},{name:"superTypes",defaultValue:[]}]};case oe:return{name:oe,properties:[{name:"calledByName",defaultValue:!1},{name:"parameter"},{name:"value"}]};case ae:return{name:ae,properties:[{name:"value"}]};case ce:return{name:ce,properties:[{name:"value"}]};case ue:return{name:ue,properties:[{name:"name"}]};case le:return{name:le,properties:[{name:"parameter"}]};case de:return{name:de,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 fe:return{name:fe,properties:[{name:"referenceType"}]};case pe:return{name:pe,properties:[{name:"name"}]};case me:return{name:me,properties:[{name:"primitiveType"},{name:"stringType"},{name:"typeRef"}]};case ge:return{name:ge,properties:[{name:"value"}]};case ve:return{name:ve,properties:[{name:"definition"},{name:"fragment",defaultValue:!1},{name:"hidden",defaultValue:!1},{name:"name"},{name:"type"}]};case we:return{name:we,properties:[{name:"name"},{name:"type"}]};case ke:return{name:ke,properties:[{name:"defaultValue"},{name:"isOptional",defaultValue:!1},{name:"name"},{name:"type"}]};case Se:return{name:Se,properties:[{name:"types",defaultValue:[]}]};case be:return{name:be,properties:[{name:"cardinality"},{name:"feature"},{name:"inferredType"},{name:"lookahead"},{name:"operator"},{name:"type"}]};case Te:return{name:Te,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case Re:return{name:Re,properties:[{name:"cardinality"},{name:"feature"},{name:"lookahead"},{name:"operator"},{name:"terminal"}]};case De:return{name:De,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 Le:return{name:Le,properties:[{name:"cardinality"},{name:"lookahead"}]};case Pe:return{name:Pe,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"guardCondition"},{name:"lookahead"}]};case Me:return{name:Me,properties:[{name:"cardinality"},{name:"lookahead"},{name:"value"}]};case je:return{name:je,properties:[{name:"cardinality"},{name:"lookahead"},{name:"terminal"}]};case Be:return{name:Be,properties:[{name:"cardinality"},{name:"lookahead"},{name:"regex"}]};case Fe:return{name:Fe,properties:[{name:"arguments",defaultValue:[]},{name:"cardinality"},{name:"lookahead"},{name:"rule"}]};case Ge:return{name:Ge,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case Ve:return{name:Ve,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case Ue:return{name:Ue,properties:[{name:"cardinality"},{name:"lookahead"},{name:"rule"}]};case ze:return{name:ze,properties:[{name:"cardinality"},{name:"elements",defaultValue:[]},{name:"lookahead"}]};case He:return{name:He,properties:[{name:"cardinality"},{name:"lookahead"},{name:"terminal"}]};case qe:return{name:qe,properties:[{name:"cardinality"},{name:"lookahead"}]};default:return{name:e,properties:[]}}}}const Qe=new Ke;function Je(e,t){let n=e;for(;n;){if(t(n))return n;n=n.$container}}function Xe(e){const t=Ye(e).$document;if(!t)throw new Error("AST node has no document.");return t}function Ye(e){for(;e.$container;)e=e.$container;return e}function Ze(e,t){if(!e)throw new Error("Node must be an AstNode.");const n=null==t?void 0:t.range;return new N((()=>({keys:Object.keys(e),keyIndex:0,arrayIndex:0})),(t=>{for(;t.keyIndexZe(e,t)))}function tt(e,t){if(!e)throw new Error("Root node must be an AstNode.");return new A(e,(e=>Ze(e,t)),{includeRoot:!0})}function nt(e,t){var n;if(!t)return!0;const r=null===(n=e.$cstNode)||void 0===n?void 0:n.range;return!!r&&B(r,t)}function rt(e){return new N((()=>({keys:Object.keys(e),keyIndex:0,arrayIndex:0})),(t=>{for(;t.keyIndext.test(e)))}function dt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ht(e,t){const n=function(e){"string"==typeof e&&(e=new RegExp(e));const t=e,n=e.source;let r=0;function s(){let e,i="";function o(e){i+=n.substr(r,e),r+=e}function a(e){i+="(?:"+n.substr(r,e)+"|$)",r+=e}for(;r",r)-r+1);break;default:a(2)}break;case"[":e=/\[(?:\\.|.)*?\]/g,e.lastIndex=r,e=e.exec(n)||[],a(e[0].length);break;case"|":case"^":case"$":case"*":case"+":case"?":o(1);break;case"{":e=/\{\d+,?\d*\}/g,e.lastIndex=r,e=e.exec(n),e?o(e[0].length):a(1);break;case"(":if("?"===n[r+1])switch(n[r+2]){case":":i+="(?:",r+=3,i+=s()+"|$)";break;case"=":i+="(?=",r+=3,i+=s()+")";break;case"!":e=r,r+=3,s(),i+=n.substr(e,r-e);break;case"<":switch(n[r+3]){case"=":case"!":e=r,r+=4,s(),i+=n.substr(e,r-e);break;default:o(n.indexOf(">",r)-r+1),i+=s()+"|$)"}}else o(1),i+=s()+"|$)";break;case")":return++r,i;default:a(1)}return i}return new RegExp(s(),e.flags)}(e),r=t.match(n);return!!r&&r[0].length>0}function ft(e,t){const n=new Set,r=function(e){return e.rules.find((e=>he(e)&&e.entry))}(e);if(!r)return new Set(e.rules);const s=[r].concat(function(e){return e.rules.filter((e=>ye(e)&&e.hidden))}(e));for(const o of s)pt(o,n,t);const i=new Set;for(const o of e.rules)(n.has(o.name)||ye(o)&&o.hidden)&&i.add(o);return i}function pt(e,t,n){t.add(e.name),et(e).forEach((e=>{if(_e(e)||n){const r=e.rule.ref;r&&!t.has(r.name)&&pt(r,t,n)}}))}function mt(e,t,n){if(!e||!t)return;const r=gt(e,t,e.astNode,!0);return 0!==r.length?r[n=void 0!==n?Math.max(0,Math.min(n,r.length-1)):0]:void 0}function gt(e,t,n,r){if(!r){const n=Je(e.grammarSource,Ee);if(n&&n.feature===t)return[e]}return k(e)&&e.astNode===n?e.content.flatMap((e=>gt(e,t,n,!1))):[]}function vt(e,t,n){if(!e)return;const r=function(e,t,n){if(e.astNode!==n)return[];if(Oe(e.grammarSource)&&e.grammarSource.value===t)return[e];const r=M(e).iterator();let s;const i=[];do{if(s=r.next(),!s.done){const e=s.value;e.astNode===n?Oe(e.grammarSource)&&e.grammarSource.value===t&&i.push(e):r.prune()}}while(!s.done);return i}(e,t,null==e?void 0:e.astNode);return 0!==r.length?r[n=void 0!==n?Math.max(0,Math.min(n,r.length-1)):0]:void 0}function yt(e){let t=e;return re(t)&&(Ne(t.$container)?t=t.$container.$container:he(t.$container)?t=t.$container:V(t.$container)),wt(e,t,new Map)}function wt(e,t,n){var r,s;function i(t,r){let s;return Je(t,Ee)||(s=wt(r,r,n)),n.set(e,s),s}if(n.has(e))return n.get(e);n.set(e,void 0);for(const o of et(t)){if(Ee(o)&&"name"===o.feature.toLowerCase())return n.set(e,o),o;if(_e(o)&&he(o.rule.ref))return i(o,o.rule.ref);if(s=o,Qe.isInstance(s,me)&&(null===(r=o.typeRef)||void 0===r?void 0:r.ref))return i(o,o.typeRef.ref)}}function xt(e){return kt(e,new Set)}function kt(e,t){if(t.has(e))return!0;t.add(e);for(const n of et(e))if(_e(n)){if(!n.rule.ref)return!1;if(he(n.rule.ref)&&!kt(n.rule.ref,t))return!1}else{if(Ee(n))return!1;if(Ne(n))return!1}return Boolean(e.definition)}function St(e){if(e.inferredType)return e.inferredType.name;if(e.dataType)return e.dataType;if(e.returnType){const t=e.returnType.ref;if(t){if(he(t))return t.name;if(ie(t)||xe(t))return t.name}}}function bt(e){var t,n;if(he(e))return xt(e)?e.name:null!==(t=St(e))&&void 0!==t?t:e.name;if(ie(e)||xe(e)||(n=e,Qe.isInstance(n,pe)))return e.name;if(Ne(e)){const t=function(e){var t;if(e.inferredType)return e.inferredType.name;if(null===(t=e.type)||void 0===t?void 0:t.ref)return bt(e.type.ref);return}(e);if(t)return t}else if(re(e))return e.name;throw new Error("Cannot get name of Unknown Type")}function Nt(e){const t={s:!1,i:!1,u:!1},n=$t(e.definition,t),r=Object.entries(t).filter((([,e])=>e)).map((([e])=>e)).join("");return new RegExp(n,r)}const Tt=/[\s\S]/.source;function $t(e,t){if(o=e,Qe.isInstance(o,Ge))return Et((i=e).elements.map((e=>$t(e))).join("|"),{cardinality:i.cardinality,lookahead:i.lookahead});if(function(e){return Qe.isInstance(e,Ve)}(e))return Et((s=e).elements.map((e=>$t(e))).join(""),{cardinality:s.cardinality,lookahead:s.lookahead});if(function(e){return Qe.isInstance(e,De)}(e))return function(e){if(e.right)return Et(`[${Rt(e.left)}-${Rt(e.right)}]`,{cardinality:e.cardinality,lookahead:e.lookahead,wrap:!1});return Et(Rt(e.left),{cardinality:e.cardinality,lookahead:e.lookahead,wrap:!1})}(e);if(function(e){return Qe.isInstance(e,Ue)}(e)){const t=e.rule.ref;if(!t)throw new Error("Missing rule reference.");return Et($t(t.definition),{cardinality:e.cardinality,lookahead:e.lookahead})}if(function(e){return Qe.isInstance(e,je)}(e))return Et(`(?!${$t((r=e).terminal)})${Tt}*?`,{cardinality:r.cardinality,lookahead:r.lookahead});if(function(e){return Qe.isInstance(e,He)}(e))return Et(`${Tt}*?${$t((n=e).terminal)}`,{cardinality:n.cardinality,lookahead:n.lookahead});if(function(e){return Qe.isInstance(e,Be)}(e)){const n=e.regex.lastIndexOf("/"),r=e.regex.substring(1,n),s=e.regex.substring(n+1);return t&&(t.i=s.includes("i"),t.s=s.includes("s"),t.u=s.includes("u")),Et(r,{cardinality:e.cardinality,lookahead:e.lookahead,wrap:!1})}if(function(e){return Qe.isInstance(e,qe)}(e))return Et(Tt,{cardinality:e.cardinality,lookahead:e.lookahead});throw new Error(`Invalid terminal element: ${null==e?void 0:e.$type}`);var n,r,s,i,o}function Rt(e){return dt(e.value)}function Et(e,t){var n;return(!1!==t.wrap||t.lookahead)&&(e=`(${null!==(n=t.lookahead)&&void 0!==n?n:""}${e})`),t.cardinality?`${e}${t.cardinality}`:e}class Dt{constructor(){this.nodeStack=[]}get current(){var e;return null!==(e=this.nodeStack[this.nodeStack.length-1])&&void 0!==e?e:this.rootNode}buildRootNode(e){return this.rootNode=new Ct(e),this.rootNode.root=this.rootNode,this.nodeStack=[this.rootNode],this.rootNode}buildCompositeNode(e){const t=new Lt;return t.grammarSource=e,t.root=this.rootNode,this.current.content.push(t),this.nodeStack.push(t),t}buildLeafNode(e,t){const n=new It(e.startOffset,e.image.length,O(e),e.tokenType,!t);return n.grammarSource=t,n.root=this.rootNode,this.current.content.push(n),n}removeNode(e){const t=e.container;if(t){const n=t.content.indexOf(e);n>=0&&t.content.splice(n,1)}}addHiddenNodes(e){const t=[];for(const s of e){const e=new It(s.startOffset,s.image.length,O(s),s.tokenType,!0);e.root=this.rootNode,t.push(e)}let n=this.current,r=!1;if(n.content.length>0)n.content.push(...t);else{for(;n.container;){const e=n.container.content.indexOf(n);if(e>0){n.container.content.splice(e,0,...t),r=!0;break}n=n.container}r||this.rootNode.content.unshift(...t)}}construct(e){const t=this.current;"string"==typeof e.$type&&(this.current.astNode=e),e.$cstNode=t;const n=this.nodeStack.pop();0===(null==n?void 0:n.content.length)&&this.removeNode(n)}}class At{ +/** @deprecated use `container` instead. */ +get parent(){return this.container} +/** @deprecated use `grammarSource` instead. */get feature(){return this.grammarSource}get hidden(){return!1}get astNode(){var e,t;const n="string"==typeof(null===(e=this._astNode)||void 0===e?void 0:e.$type)?this._astNode:null===(t=this.container)||void 0===t?void 0:t.astNode;if(!n)throw new Error("This node has no associated AST element");return n}set astNode(e){this._astNode=e} +/** @deprecated use `astNode` instead. */get element(){return this.astNode}get text(){return this.root.fullText.substring(this.offset,this.end)}}class It extends At{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,n,r,s=!1){super(),this._hidden=s,this._offset=e,this._tokenType=r,this._length=t,this._range=n}}class Lt extends At{constructor(){super(...arguments),this.content=new Pt(this)} +/** @deprecated use `content` instead. */get children(){return this.content}get offset(){var e,t;return null!==(t=null===(e=this.firstNonHiddenNode)||void 0===e?void 0:e.offset)&&void 0!==t?t:0}get length(){return this.end-this.offset}get end(){var e,t;return null!==(t=null===(e=this.lastNonHiddenNode)||void 0===e?void 0:e.end)&&void 0!==t?t:0}get range(){const e=this.firstNonHiddenNode,t=this.lastNonHiddenNode;if(e&&t){if(void 0===this._rangeCache){const{range:n}=e,{range:r}=t;this._rangeCache={start:n.start,end:r.end.line=0;e--){const t=this.content[e];if(!t.hidden)return t}return this.content[this.content.length-1]}}class Pt extends Array{constructor(e){super(),this.parent=e,Object.setPrototypeOf(this,Pt.prototype)}push(...e){return this.addParents(e),super.push(...e)}unshift(...e){return this.addParents(e),super.unshift(...e)}splice(e,t,...n){return this.addParents(n),super.splice(e,t,...n)}addParents(e){for(const t of e)t.container=this.parent}}class Ct extends Lt{get text(){return this._text.substring(this.offset,this.end)}get fullText(){return this._text}constructor(e){super(),this._text="",this._text=null!=e?e:""}}const Mt=Symbol("Datatype");function Ot(e){return e.$type===Mt}const jt=e=>e.endsWith("​")?e:e+"​";class Bt{constructor(e){this._unorderedGroups=new Map,this.allRules=new Map,this.lexer=e.parser.Lexer;const t=this.lexer.definition,n="production"===e.LanguageMetaData.mode;this.wrapper=new zt(t,Object.assign(Object.assign({},e.parser.ParserConfig),{skipValidations:n,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 Ft extends Bt{get current(){return this.stack[this.stack.length-1]}constructor(e){super(e),this.nodeBuilder=new Dt,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 n=this.computeRuleType(e),r=this.wrapper.DEFINE_RULE(jt(e.name),this.startImplementation(n,t).bind(this));return this.allRules.set(e.name,r),e.entry&&(this.mainRule=r),r}computeRuleType(e){if(!e.fragment){if(xt(e))return Mt;{const t=St(e);return null!=t?t:e.name}}}parse(e,t={}){this.nodeBuilder.buildRootNode(e);const n=this.lexerResult=this.lexer.tokenize(e);this.wrapper.input=n.tokens;const r=t.rule?this.allRules.get(t.rule):this.mainRule;if(!r)throw new Error(t.rule?`No rule found with name '${t.rule}'`:"No main rule available.");const s=r.call(this.wrapper,{});return this.nodeBuilder.addHiddenNodes(n.hidden),this.unorderedGroups.clear(),this.lexerResult=void 0,{value:s,lexerErrors:n.errors,lexerReport:n.report,parserErrors:this.wrapper.errors}}startImplementation(e,t){return n=>{const r=!this.isRecording()&&void 0!==e;if(r){const t={$type:e};this.stack.push(t),e===Mt&&(t.value="")}let s;try{s=t(n)}catch(i){s=void 0}return void 0===s&&r&&(s=this.construct()),s}}extractHiddenTokens(e){const t=this.lexerResult.hidden;if(!t.length)return[];const n=e.startOffset;for(let r=0;rn)return t.splice(0,r)}return t.splice(0,t.length)}consume(e,t,n){const r=this.wrapper.wrapConsume(e,t);if(!this.isRecording()&&this.isValidToken(r)){const e=this.extractHiddenTokens(r);this.nodeBuilder.addHiddenNodes(e);const t=this.nodeBuilder.buildLeafNode(r,n),{assignment:s,isCrossRef:i}=this.getAssignment(n),o=this.current;if(s){const e=Oe(n)?r.image:this.converter.convert(r.image,t);this.assign(s.operator,s.feature,e,t,i)}else if(Ot(o)){let e=r.image;Oe(n)||(e=this.converter.convert(e,t).toString()),o.value+=e}}} +/** + * Most consumed parser tokens are valid. However there are two cases in which they are not valid: + * + * 1. They were inserted during error recovery by the parser. These tokens don't really exist and should not be further processed + * 2. They contain invalid token ranges. This might include the special EOF token, or other tokens produced by invalid token builders. + */isValidToken(e){return!e.isInsertedInRecovery&&!isNaN(e.startOffset)&&"number"==typeof e.endOffset&&!isNaN(e.endOffset)}subrule(e,t,n,r,s){let i;this.isRecording()||n||(i=this.nodeBuilder.buildCompositeNode(r));const o=this.wrapper.wrapSubrule(e,t,s);!this.isRecording()&&i&&i.length>0&&this.performSubruleAssignment(o,r,i)}performSubruleAssignment(e,t,n){const{assignment:r,isCrossRef:s}=this.getAssignment(t);if(r)this.assign(r.operator,r.feature,e,n,s);else if(!r){const t=this.current;if(Ot(t))t.value+=e.toString();else if("object"==typeof e&&e){const n=this.assignWithoutOverride(e,t);this.stack.pop(),this.stack.push(n)}}}action(e,t){if(!this.isRecording()){let n=this.current;if(t.feature&&t.operator){n=this.construct(),this.nodeBuilder.removeNode(n.$cstNode);this.nodeBuilder.buildCompositeNode(t).content.push(n.$cstNode);const r={$type:e};this.stack.push(r),this.assign(t.operator,t.feature,n,n.$cstNode,!1)}else n.$type=e}}construct(){if(this.isRecording())return;const e=this.current;return function(e){for(const[t,n]of Object.entries(e))t.startsWith("$")||(Array.isArray(n)?n.forEach(((n,r)=>{v(n)&&(n.$container=e,n.$containerProperty=t,n.$containerIndex=r)})):v(n)&&(n.$container=e,n.$containerProperty=t))}(e),this.nodeBuilder.construct(e),this.stack.pop(),Ot(e)?this.converter.convert(e.value,e.$cstNode):(function(e,t){const n=e.getTypeMetaData(t.$type),r=t;for(const s of n.properties)void 0!==s.defaultValue&&void 0===r[s.name]&&(r[s.name]=st(s.defaultValue))}(this.astReflection,e),e)}getAssignment(e){if(!this.assignmentMap.has(e)){const t=Je(e,Ee);this.assignmentMap.set(e,{assignment:t,isCrossRef:!!t&&Ie(t.terminal)})}return this.assignmentMap.get(e)}assign(e,t,n,r,s){const i=this.current;let o;switch(o=s&&"string"==typeof n?this.linker.buildReference(i,t,r,n):n,e){case"=":i[t]=o;break;case"?=":i[t]=!0;break;case"+=":Array.isArray(i[t])||(i[t]=[]),i[t].push(o)}}assignWithoutOverride(e,t){for(const[r,s]of Object.entries(t)){const t=e[r];void 0===t?e[r]=s:Array.isArray(t)&&Array.isArray(s)&&(s.push(...t),e[r]=s)}const n=e.$cstNode;return n&&(n.astNode=void 0,e.$cstNode=void 0),e}get definitionErrors(){return this.wrapper.definitionErrors}}class _t{buildMismatchTokenMessage(e){return n.buildMismatchTokenMessage(e)}buildNotAllInputParsedMessage(e){return n.buildNotAllInputParsedMessage(e)}buildNoViableAltMessage(e){return n.buildNoViableAltMessage(e)}buildEarlyExitMessage(e){return n.buildEarlyExitMessage(e)}}class Gt extends _t{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 Vt extends Bt{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 n=this.wrapper.DEFINE_RULE(jt(e.name),this.startImplementation(t).bind(this));return this.allRules.set(e.name,n),e.entry&&(this.mainRule=n),n}resetState(){this.elementStack=[],this.lastElementStack=[],this.nextTokenIndex=0,this.stackSize=0}startImplementation(e){return t=>{const n=this.keepStackSize();try{e(t)}finally{this.resetStackSize(n)}}}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,n){this.wrapper.wrapConsume(e,t),this.isRecording()||(this.lastElementStack=[...this.elementStack,n],this.nextTokenIndex=this.currIdx+1)}subrule(e,t,n,r,s){this.before(r),this.wrapper.wrapSubrule(e,t,s),this.after(r)}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 Ut={recoveryEnabled:!0,nodeLocationTracking:"full",skipValidations:!0,errorMessageProvider:new Gt};class zt extends r{constructor(e,t){const n=t&&"maxLookahead"in t;super(e,Object.assign(Object.assign(Object.assign({},Ut),{lookaheadStrategy:n?new s({maxLookahead:t.maxLookahead}):new d({ +// If validations are skipped, don't log the lookahead warnings +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,n){return this.subrule(e,t,{ARGS:[n]})}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 Wt(e,t,n){return function(e,t){const n=ft(t,!1),r=D(t.rules).filter(he).filter((e=>n.has(e)));for(const s of r){const t=Object.assign(Object.assign({},e),{consume:1,optional:1,subrule:1,many:1,or:1});e.parser.rule(s,Ht(t,s.definition))}}({parser:t,tokens:n,ruleNames:new Map},e),t}function Ht(e,t,n=!1){let r;if(Oe(t))r=function(e,t){const n=e.consume++,r=e.tokens[t.value];if(!r)throw new Error("Could not find token for keyword: "+t.value);return()=>e.parser.consume(n,r,t)}(e,t);else if(Ne(t))r=function(e,t){const n=bt(t);return()=>e.parser.action(n,t)}(e,t);else if(Ee(t))r=Ht(e,t.terminal);else if(Ie(t))r=Qt(e,t);else if(_e(t))r=function(e,t){const n=t.rule.ref;if(he(n)){const r=e.subrule++,s=n.fragment,i=t.arguments.length>0?function(e,t){const n=t.map((e=>qt(e.value)));return t=>{const r={};for(let s=0;s({});return o=>e.parser.subrule(r,Xt(e,n),s,t,i(o))}if(ye(n)){const r=e.consume++,s=Yt(e,n.name);return()=>e.parser.consume(r,s,t)}if(!n)throw new G(t.$cstNode,`Undefined rule: ${t.rule.$refText}`);V()}(e,t);else if($e(t))r=function(e,t){if(1===t.elements.length)return Ht(e,t.elements[0]);{const n=[];for(const s of t.elements){const t={ +// Since we handle the guard condition in the alternative already +// We can ignore the group guard condition inside +ALT:Ht(e,s,!0)},r=Kt(s);r&&(t.GATE=qt(r)),n.push(t)}const r=e.or++;return t=>e.parser.alternatives(r,n.map((e=>{const n={ALT:()=>e.ALT(t)},r=e.GATE;return r&&(n.GATE=()=>r(t)),n})))}}(e,t);else if(We(t))r=function(e,t){if(1===t.elements.length)return Ht(e,t.elements[0]);const n=[];for(const a of t.elements){const t={ +// Since we handle the guard condition in the alternative already +// We can ignore the group guard condition inside +ALT:Ht(e,a,!0)},r=Kt(a);r&&(t.GATE=qt(r)),n.push(t)}const r=e.or++,s=(e,t)=>`uGroup_${e}_${t.getRuleStack().join("-")}`,i=t=>e.parser.alternatives(r,n.map(((n,i)=>{const o={ALT:()=>!0},a=e.parser;o.ALT=()=>{if(n.ALT(t),!a.isRecording()){const e=s(r,a);a.unorderedGroups.get(e)||a.unorderedGroups.set(e,[]);const t=a.unorderedGroups.get(e);void 0===(null==t?void 0:t[i])&&(t[i]=!0)}};const c=n.GATE;return o.GATE=c?()=>c(t):()=>{const e=a.unorderedGroups.get(s(r,a));return!(null==e?void 0:e[i])},o}))),o=Jt(e,Kt(t),i,"*");return t=>{o(t),e.parser.isRecording()||e.parser.unorderedGroups.delete(s(r,e.parser))}}(e,t);else if(Ce(t))r=function(e,t){const n=t.elements.map((t=>Ht(e,t)));return e=>n.forEach((t=>t(e)))}(e,t);else{if(s=t,!Qe.isInstance(s,Le))throw new G(t.$cstNode,`Unexpected element type: ${t.$type}`);{const n=e.consume++;r=()=>e.parser.consume(n,o,t)}}var s;return Jt(e,n?void 0:Kt(t),r,t.cardinality)}function qt(e){if(t=e,Qe.isInstance(t,Z)){const t=qt(e.left),n=qt(e.right);return e=>t(e)||n(e)}if(function(e){return Qe.isInstance(e,Y)}(e)){const t=qt(e.left),n=qt(e.right);return e=>t(e)&&n(e)}if(function(e){return Qe.isInstance(e,ae)}(e)){const t=qt(e.value);return e=>!t(e)}if(function(e){return Qe.isInstance(e,le)}(e)){const t=e.parameter.ref.name;return e=>void 0!==e&&!0===e[t]}if(function(e){return Qe.isInstance(e,X)}(e)){const t=Boolean(e.true);return()=>t}var t;V()}function Kt(e){if(Ce(e))return e.guardCondition}function Qt(e,t,n=t.terminal){if(n){if(_e(n)&&he(n.rule.ref)){const r=n.rule.ref,s=e.subrule++;return n=>e.parser.subrule(s,Xt(e,r),!1,t,n)}if(_e(n)&&ye(n.rule.ref)){const r=e.consume++,s=Yt(e,n.rule.ref.name);return()=>e.parser.consume(r,s,t)}if(Oe(n)){const r=e.consume++,s=Yt(e,n.value);return()=>e.parser.consume(r,s,t)}throw new Error("Could not build cross reference parser")}{if(!t.type.ref)throw new Error("Could not resolve reference to type: "+t.type.$refText);const n=yt(t.type.ref),r=null==n?void 0:n.terminal;if(!r)throw new Error("Could not find name assignment for type: "+bt(t.type.ref));return Qt(e,t,r)}}function Jt(e,t,n,r){const s=t&&qt(t);if(!r){if(s){const t=e.or++;return r=>e.parser.alternatives(t,[{ALT:()=>n(r),GATE:()=>s(r)},{ALT:i(),GATE:()=>!s(r)}])}return n}if("*"===r){const t=e.many++;return r=>e.parser.many(t,{DEF:()=>n(r),GATE:s?()=>s(r):void 0})}if("+"===r){const t=e.many++;if(s){const r=e.or++;return o=>e.parser.alternatives(r,[{ALT:()=>e.parser.atLeastOne(t,{DEF:()=>n(o)}),GATE:()=>s(o)},{ALT:i(),GATE:()=>!s(o)}])}return r=>e.parser.atLeastOne(t,{DEF:()=>n(r)})}if("?"===r){const t=e.optional++;return r=>e.parser.optional(t,{DEF:()=>n(r),GATE:s?()=>s(r):void 0})}V()}function Xt(e,t){const n=function(e,t){if(he(t))return t.name;if(e.ruleNames.has(t))return e.ruleNames.get(t);{let n=t,r=n.$container,s=t.$type;for(;!he(r);){if(Ce(r)||$e(r)||We(r)){s=r.elements.indexOf(n).toString()+":"+s}n=r,r=r.$container}return s=r.name+":"+s,e.ruleNames.set(t,s),s}}(e,t),r=e.parser.getRule(n);if(!r)throw new Error(`Rule "${n}" not found."`);return r}function Yt(e,t){const n=e.tokens[t];if(!n)throw new Error(`Token "${t}" not found."`);return n}function Zt(e){const t=function(e){const t=e.Grammar,n=e.parser.Lexer,r=new Ft(e);return Wt(t,r,n.definition)}(e);return t.finalize(),t}class en{constructor(){this.diagnostics=[]}buildTokens(e,t){const n=D(ft(e,!1)),r=this.buildTerminalTokens(n),s=this.buildKeywordTokens(n,r,t);return r.forEach((e=>{const t=e.PATTERN;"object"==typeof t&&t&&"test"in t&<(t)?s.unshift(e):s.push(e)})),s} +// eslint-disable-next-line @typescript-eslint/no-unused-vars +flushLexingReport(e){return{diagnostics:this.popDiagnostics()}}popDiagnostics(){const e=[...this.diagnostics];return this.diagnostics=[],e}buildTerminalTokens(e){return e.filter(ye).filter((e=>!e.fragment)).map((e=>this.buildTerminalToken(e))).toArray()}buildTerminalToken(e){const t=Nt(e),n=this.requiresCustomPattern(t)?this.regexPatternFunction(t):t,r={name:e.name,PATTERN:n};return"function"==typeof n&&(r.LINE_BREAKS=!0),e.hidden&&(r.GROUP=lt(t)?a.SKIPPED:"hidden"),r}requiresCustomPattern(e){return!(!e.flags.includes("u")&&!e.flags.includes("s"))||!(!e.source.includes("?<=")&&!e.source.includes("?{t.lastIndex=n;return t.exec(e)}}buildKeywordTokens(e,t,n){return e.filter(he).flatMap((e=>et(e).filter(Oe))).distinct((e=>e.value)).toArray().sort(((e,t)=>t.value.length-e.value.length)).map((e=>this.buildKeywordToken(e,t,Boolean(null==n?void 0:n.caseInsensitive))))}buildKeywordToken(e,t,n){const r=this.buildKeywordPattern(e,n),s={name:e.value,PATTERN:r,LONGER_ALT:this.findLongerAlt(e,t)};return"function"==typeof r&&(s.LINE_BREAKS=!0),s}buildKeywordPattern(e,t){return t?new RegExp(function(e){return Array.prototype.map.call(e,(e=>/\w/.test(e)?`[${e.toLowerCase()}${e.toUpperCase()}]`:dt(e))).join("")}(e.value)):e.value}findLongerAlt(e,t){return t.reduce(((t,n)=>{const r=null==n?void 0:n.PATTERN;return(null==r?void 0:r.source)&&ht("^"+r.source+"$",e.value)&&t.push(n),t}),[])}}class tn{convert(e,t){let n=t.grammarSource;if(Ie(n)&&(n=function(e){if(e.terminal)return e.terminal;if(e.type.ref){const t=yt(e.type.ref);return null==t?void 0:t.terminal}}(n)),_e(n)){const r=n.rule.ref;if(!r)throw new Error("This cst node was not parsed by a rule.");return this.runConverter(r,e,t)}return e} +// eslint-disable-next-line @typescript-eslint/no-unused-vars +runConverter(e,t,n){var r;switch(e.name.toUpperCase()){case"INT":return nn.convertInt(t);case"STRING":return nn.convertString(t);case"ID":return nn.convertID(t)}switch(null===(r=function(e){var t,n,r;return ye(e)?null!==(n=null===(t=e.type)||void 0===t?void 0:t.name)&&void 0!==n?n:"string":null!==(r=St(e))&&void 0!==r?r:e.name}(e))||void 0===r?void 0:r.toLowerCase()){case"number":return nn.convertNumber(t);case"boolean":return nn.convertBoolean(t);case"bigint":return nn.convertBigint(t);case"date":return nn.convertDate(t);default:return t}}}var nn;!function(e){function t(e){switch(e){case"b":return"\b";case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case"v":return"\v";case"0":return"\0";default:return e}}e.convertString=function(e){let n="";for(let r=1;r=10&&(rn=n,await new Promise((e=>{"undefined"==typeof setImmediate?setTimeout(e,0):setImmediate(e)})),rn=performance.now()),t.isCancellationRequested)throw sn}class cn{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=t=>(e(t),this),this.reject=e=>(t(e),this)}))}}var un,ln,dn,hn;(ln=un||(un={})).basename=m.basename,ln.dirname=m.dirname,ln.extname=m.extname,ln.joinPath=m.joinPath,ln.resolvePath=m.resolvePath,ln.equals=function(e,t){return(null==e?void 0:e.toString())===(null==t?void 0:t.toString())},ln.relative=function(e,t){const n="string"==typeof e?e:e.path,r="string"==typeof t?t:t.path,s=n.split("/").filter((e=>e.length>0)),i=r.split("/").filter((e=>e.length>0));let o=0;for(;onull!=r?r:r=p.create(e.toString(),n.getServices(e).LanguageMetaData.languageId,0,null!=t?t:"")}}class pn{constructor(e){this.documentMap=new Map,this.langiumDocumentFactory=e.workspace.LangiumDocumentFactory,this.serviceRegistry=e.ServiceRegistry}get all(){return D(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 n=this.getDocument(e);return n||(n=await this.langiumDocumentFactory.fromUri(e,t),this.addDocument(n),n)}createDocument(e,t,n){if(n)return this.langiumDocumentFactory.fromString(t,e,n).then((e=>(this.addDocument(e),e)));{const n=this.langiumDocumentFactory.fromString(t,e);return this.addDocument(n),n}}hasDocument(e){return this.documentMap.has(e.toString())}invalidateDocument(e){const t=e.toString(),n=this.documentMap.get(t);if(n){this.serviceRegistry.getServices(e).references.Linker.unlink(n),n.state=dn.Changed,n.precomputedScopes=void 0,n.diagnostics=void 0}return n}deleteDocument(e){const t=e.toString(),n=this.documentMap.get(t);return n&&(n.state=dn.Changed,this.documentMap.delete(t)),n}}const mn=Symbol("ref_resolving");class gn{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(t,n=e.CancellationToken.None){for(const e of tt(t.parseResult.value))await an(n),rt(e).forEach((e=>this.doLink(e,t)))}doLink(e,t){var n;const r=e.reference;if(void 0===r._ref){r._ref=mn;try{const t=this.getCandidate(e);if(w(t))r._ref=t;else if(r._nodeDescription=t,this.langiumDocuments().hasDocument(t.documentUri)){const n=this.loadAstNode(t);r._ref=null!=n?n:this.createLinkingError(e,t)}else r._ref=void 0}catch(s){const t=null!==(n=s.message)&&void 0!==n?n:String(s);r._ref=Object.assign(Object.assign({},e),{message:`An error occurred while resolving reference to '${r.$refText}': ${t}`})}t.references.push(r)}}unlink(e){for(const t of e.references)delete t._ref,delete t._nodeDescription;e.references=[]}getCandidate(e){const t=this.scopeProvider.getScope(e).getElement(e.reference.$refText);return null!=t?t:this.createLinkingError(e)}buildReference(e,t,n,r){const s=this,i={$refNode:n,$refText:r,get ref(){var n,o;if(v(this._ref))return this._ref;if("object"==typeof(o=this._nodeDescription)&&null!==o&&"string"==typeof o.name&&"string"==typeof o.type&&"string"==typeof o.path){const n=s.loadAstNode(this._nodeDescription);this._ref=null!=n?n:s.createLinkingError({reference:i,container:e,property:t},this._nodeDescription)}else if(void 0===this._ref){this._ref=mn;const r=Ye(e).$document,o=s.getLinkedNode({reference:i,container:e,property:t});if(o.error&&r&&r.state=e.end)return t.ref}if(n){const t=this.nameProvider.getNameNode(n);if(t&&(t===e||function(e,t){for(;e.container;)if((e=e.container)===t)return!0;return!1}(e,t)))return n}}}findDeclarationNode(e){const t=this.findDeclaration(e);if(null==t?void 0:t.$cstNode){const e=this.nameProvider.getNameNode(t);return null!=e?e:t.$cstNode}}findReferences(e,t){const n=[];if(t.includeDeclaration){const t=this.getReferenceToSelf(e);t&&n.push(t)}let r=this.index.findAllReferences(e,this.nodeLocator.getAstNodePath(e));return t.documentUri&&(r=r.filter((e=>un.equals(e.sourceUri,t.documentUri)))),n.push(...r),D(n)}getReferenceToSelf(e){const t=this.nameProvider.getNameNode(e);if(t){const n=Xe(e),r=this.nodeLocator.getAstNodePath(e);return{sourceUri:n.uri,sourcePath:r,targetUri:n.uri,targetPath:r,segment:j(t),local:!0}}}}class wn{constructor(e){if(this.map=new Map,e)for(const[t,n]of e)this.add(t,n)} +/** + * The total number of values in the multimap. + */get size(){return I.sum(D(this.map.values()).map((e=>e.length)))} +/** + * Clear all entries in the multimap. + */clear(){this.map.clear()} +/** + * Operates differently depending on whether a `value` is given: + * * With a value, this method deletes the specific key / value pair from the multimap. + * * Without a value, all values associated with the given key are deleted. + * + * @returns `true` if a value existed and has been removed, or `false` if the specified + * key / value does not exist. + */delete(e,t){if(void 0===t)return this.map.delete(e);{const n=this.map.get(e);if(n){const r=n.indexOf(t);if(r>=0)return 1===n.length?this.map.delete(e):n.splice(r,1),!0}return!1}} +/** + * Returns an array of all values associated with the given key. If no value exists, + * an empty array is returned. + * + * _Note:_ The returned array is assumed not to be modified. Use the `set` method to add a + * value and `delete` to remove a value from the multimap. + */get(e){var t;return null!==(t=this.map.get(e))&&void 0!==t?t:[]} +/** + * Operates differently depending on whether a `value` is given: + * * With a value, this method returns `true` if the specific key / value pair is present in the multimap. + * * Without a value, this method returns `true` if the given key is present in the multimap. + */has(e,t){if(void 0===t)return this.map.has(e);{const n=this.map.get(e);return!!n&&n.indexOf(t)>=0}} +/** + * Add the given key / value pair to the multimap. + */add(e,t){return this.map.has(e)?this.map.get(e).push(t):this.map.set(e,[t]),this} +/** + * Add the given set of key / value pairs to the multimap. + */addAll(e,t){return this.map.has(e)?this.map.get(e).push(...t):this.map.set(e,Array.from(t)),this} +/** + * Invokes the given callback function for every key / value pair in the multimap. + */forEach(e){this.map.forEach(((t,n)=>t.forEach((t=>e(t,n,this)))))} +/** + * Returns an iterator of key, value pairs for every entry in the map. + */[Symbol.iterator](){return this.entries().iterator()} +/** + * Returns a stream of key, value pairs for every entry in the map. + */entries(){return D(this.map.entries()).flatMap((([e,t])=>t.map((t=>[e,t]))))} +/** + * Returns a stream of keys in the map. + */keys(){return D(this.map.keys())} +/** + * Returns a stream of values in the map. + */values(){return D(this.map.values()).flat()} +/** + * Returns a stream of key, value set pairs for every key in the map. + */entriesGroupedByKey(){return D(this.map.entries())}}class xn{get size(){return this.map.size}constructor(e){if(this.map=new Map,this.inverse=new Map,e)for(const[t,n]of e)this.set(t,n)}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 void 0!==t&&(this.map.delete(e),this.inverse.delete(t),!0)}}class kn{constructor(e){this.nameProvider=e.references.NameProvider,this.descriptions=e.workspace.AstNodeDescriptionProvider}async computeExports(t,n=e.CancellationToken.None){return this.computeExportsForNode(t.parseResult.value,t,void 0,n)} +/** + * Creates {@link AstNodeDescription AstNodeDescriptions} for the given {@link AstNode parentNode} and its children. + * The list of children to be considered is determined by the function parameter {@link children}. + * By default only the direct children of {@link parentNode} are visited, nested nodes are not exported. + * + * @param parentNode AST node to be exported, i.e., of which an {@link AstNodeDescription} shall be added to the returned list. + * @param document The document containing the AST node to be exported. + * @param children A function called with {@link parentNode} as single argument and returning an {@link Iterable} supplying the children to be visited, which must be directly or transitively contained in {@link parentNode}. + * @param cancelToken Indicates when to cancel the current operation. + * @throws `OperationCancelled` if a user action occurs during execution. + * @returns A list of {@link AstNodeDescription AstNodeDescriptions} to be published to index. + */async computeExportsForNode(t,n,r=Ze,s=e.CancellationToken.None){const i=[];this.exportNode(t,i,n);for(const e of r(t))await an(s),this.exportNode(e,i,n);return i} +/** + * Add a single node to the list of exports if it has a name. Override this method to change how + * symbols are exported, e.g. by modifying their exported name. + */exportNode(e,t,n){const r=this.nameProvider.getName(e);r&&t.push(this.descriptions.createDescription(e,r,n))}async computeLocalScopes(t,n=e.CancellationToken.None){const r=t.parseResult.value,s=new wn;for(const e of et(r))await an(n),this.processNode(e,t,s);return s} +/** + * Process a single node during scopes computation. The default implementation makes the node visible + * in the subtree of its container (if the node has a name). Override this method to change this, + * e.g. by increasing the visibility to a higher level in the AST. + */processNode(e,t,n){const r=e.$container;if(r){const s=this.nameProvider.getName(e);s&&n.add(r,this.descriptions.createDescription(e,s,t))}}}class Sn{constructor(e,t,n){var r;this.elements=e,this.outerScope=t,this.caseInsensitive=null!==(r=null==n?void 0:n.caseInsensitive)&&void 0!==r&&r}getAllElements(){return this.outerScope?this.elements.concat(this.outerScope.getAllElements()):this.elements}getElement(e){const t=this.caseInsensitive?this.elements.find((t=>t.name.toLowerCase()===e.toLowerCase())):this.elements.find((t=>t.name===e));return t||(this.outerScope?this.outerScope.getElement(e):void 0)}}class bn{constructor(e,t,n){var r;this.elements=new Map,this.caseInsensitive=null!==(r=null==n?void 0:n.caseInsensitive)&&void 0!==r&&r;for(const s of e){const e=this.caseInsensitive?s.name.toLowerCase():s.name;this.elements.set(e,s)}this.outerScope=t}getElement(e){const t=this.caseInsensitive?e.toLowerCase():e,n=this.elements.get(t);return n||(this.outerScope?this.outerScope.getElement(e):void 0)}getAllElements(){let e=D(this.elements.values());return this.outerScope&&(e=e.concat(this.outerScope.getAllElements())),e}}class Nn{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 Tn extends Nn{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 n=t();return this.cache.set(e,n),n}}delete(e){return this.throwIfDisposed(),this.cache.delete(e)}clear(){this.throwIfDisposed(),this.cache.clear()}}class $n extends Nn{constructor(e){super(),this.cache=new Map,this.converter=null!=e?e:e=>e}has(e,t){return this.throwIfDisposed(),this.cacheForContext(e).has(t)}set(e,t,n){this.throwIfDisposed(),this.cacheForContext(e).set(t,n)}get(e,t,n){this.throwIfDisposed();const r=this.cacheForContext(e);if(r.has(t))return r.get(t);if(n){const e=n();return r.set(t,e),e}}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 n=this.cache.get(t);return n||(n=new Map,this.cache.set(t,n)),n}}class Rn extends Tn{ +/** + * Creates a new workspace cache. + * + * @param sharedServices Service container instance to hook into document lifecycle events. + * @param state Optional document state on which the cache should evict. + * If not provided, the cache will evict on `DocumentBuilder#onUpdate`. + * *Deleted* documents are considered in both cases. + */ +constructor(e,t){super(),t?(this.toDispose.push(e.workspace.DocumentBuilder.onBuildPhase(t,(()=>{this.clear()}))),this.toDispose.push(e.workspace.DocumentBuilder.onUpdate(((e,t)=>{t.length>0&&this.clear()})))):this.toDispose.push(e.workspace.DocumentBuilder.onUpdate((()=>{this.clear()})))}}class En{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 Rn(e.shared)}getScope(e){const t=[],n=this.reflection.getReferenceType(e),r=Xe(e.container).precomputedScopes;if(r){let s=e.container;do{const e=r.get(s);e.length>0&&t.push(D(e).filter((e=>this.reflection.isSubtype(e.type,n)))),s=s.$container}while(s)}let s=this.getGlobalScope(n,e);for(let i=t.length-1;i>=0;i--)s=this.createScope(t[i],s);return s} +/** + * Create a scope for the given collection of AST node descriptions. + */createScope(e,t,n){return new Sn(D(e),t,n)} +/** + * Create a scope for the given collection of AST nodes, which need to be transformed into respective + * descriptions first. This is done using the `NameProvider` and `AstNodeDescriptionProvider` services. + */createScopeForNodes(e,t,n){const r=D(e).map((e=>{const t=this.nameProvider.getName(e);if(t)return this.descriptions.createDescription(e,t)})).nonNullable();return new Sn(r,t,n)} +/** + * Create a global scope filtered for the given reference type. + */getGlobalScope(e,t){return this.globalScopeCache.get(e,(()=>new bn(this.indexManager.allElements(e))))}}function Dn(e){return"object"==typeof e&&!!e&&("$ref"in e||"$error"in e)}class An{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 n=null!=t?t:{},r=null==t?void 0:t.replacer,s=(e,t)=>this.replacer(e,t,n),i=r?(e,t)=>r(e,t,s):s;try{return this.currentDocument=Xe(e),JSON.stringify(e,i,null==t?void 0:t.space)}finally{this.currentDocument=void 0}}deserialize(e,t){const n=null!=t?t:{},r=JSON.parse(e);return this.linkNode(r,r,n),r}replacer(e,t,{refText:n,sourceText:r,textRegions:s,comments:i,uriConverter:o}){var a,c,u,l;if(!this.ignoreProperties.has(e)){if(y(t)){const e=t.ref,r=n?t.$refText:void 0;if(e){const n=Xe(e);let s="";this.currentDocument&&this.currentDocument!==n&&(s=o?o(n.uri,t):n.uri.toString());return{$ref:`${s}#${this.astNodeLocator.getAstNodePath(e)}`,$refText:r}}return{$error:null!==(c=null===(a=t.error)||void 0===a?void 0:a.message)&&void 0!==c?c:"Could not resolve reference",$refText:r}}if(v(t)){let n;if(s&&(n=this.addAstNodeRegionWithAssignmentsTo(Object.assign({},t)),e&&!t.$document||!(null==n?void 0:n.$textRegion)||(n.$textRegion.documentURI=null===(u=this.currentDocument)||void 0===u?void 0:u.uri.toString())),r&&!e&&(null!=n||(n=Object.assign({},t)),n.$sourceText=null===(l=t.$cstNode)||void 0===l?void 0:l.text),i){null!=n||(n=Object.assign({},t));const e=this.commentProvider.getComment(t);e&&(n.$comment=e.replace(/\r/g,""))}return null!=n?n:t}return t}}addAstNodeRegionWithAssignmentsTo(e){const t=e=>({offset:e.offset,end:e.end,length:e.length,range:e.range});if(e.$cstNode){const n=(e.$textRegion=t(e.$cstNode)).assignments={};return Object.keys(e).filter((e=>!e.startsWith("$"))).forEach((r=>{const s=function(e,t){return e&&t?gt(e,t,e.astNode,!0):[]}(e.$cstNode,r).map(t);0!==s.length&&(n[r]=s)})),e}}linkNode(e,t,n,r,s,i){for(const[a,c]of Object.entries(e))if(Array.isArray(c))for(let r=0;r{await this.handleException((()=>e.call(t,n,r,s)),"An error occurred during validation",r,n)}}async handleException(e,t,n,r){try{await e()}catch(s){if(on(s))throw s;s instanceof Error&&s.stack;n("error",`${t}: ${s instanceof Error?s.message:String(s)}`,{node:r})}}addEntry(e,t){if("AstNode"!==e)for(const n of this.reflection.getAllSubTypes(e))this.entries.add(n,t);else this.entries.add("AstNode",t)}getChecks(e,t){let n=D(this.entries.get(e)).concat(this.entries.get("AstNode"));return t&&(n=n.filter((e=>t.includes(e.category)))),n.map((e=>e.check))} +/** + * Register logic which will be executed once before validating all the nodes of an AST/Langium document. + * This helps to prepare or initialize some information which are required or reusable for the following checks on the AstNodes. + * + * As an example, for validating unique fully-qualified names of nodes in the AST, + * here the map for mapping names to nodes could be established. + * During the usual checks on the nodes, they are put into this map with their name. + * + * Note that this approach makes validations stateful, which is relevant e.g. when cancelling the validation. + * Therefore it is recommended to clear stored information + * _before_ validating an AST to validate each AST unaffected from other ASTs + * AND _after_ validating the AST to free memory by information which are no longer used. + * + * @param checkBefore a set-up function which will be called once before actually validating an AST + * @param thisObj Optional object to be used as `this` when calling the validation check functions. + */registerBeforeDocument(e,t=this){this.entriesBefore.push(this.wrapPreparationException(e,"An error occurred during set-up of the validation",t))} +/** + * Register logic which will be executed once after validating all the nodes of an AST/Langium document. + * This helps to finally evaluate information which are collected during the checks on the AstNodes. + * + * As an example, for validating unique fully-qualified names of nodes in the AST, + * here the map with all the collected nodes and their names is checked + * and validation hints are created for all nodes with the same name. + * + * Note that this approach makes validations stateful, which is relevant e.g. when cancelling the validation. + * Therefore it is recommended to clear stored information + * _before_ validating an AST to validate each AST unaffected from other ASTs + * AND _after_ validating the AST to free memory by information which are no longer used. + * + * @param checkBefore a set-up function which will be called once before actually validating an AST + * @param thisObj Optional object to be used as `this` when calling the validation check functions. + */registerAfterDocument(e,t=this){this.entriesAfter.push(this.wrapPreparationException(e,"An error occurred during tear-down of the validation",t))}wrapPreparationException(e,t,n){return async(r,s,i,o)=>{await this.handleException((()=>e.call(n,r,s,i,o)),t,s,r)}}get checksBefore(){return this.entriesBefore}get checksAfter(){return this.entriesAfter}}class Bn{constructor(e){this.validationRegistry=e.validation.ValidationRegistry,this.metadata=e.LanguageMetaData}async validateDocument(t,n={},r=e.CancellationToken.None){const s=t.parseResult,i=[];if(await an(r),!n.categories||n.categories.includes("built-in")){if(this.processLexingErrors(s,i,n),n.stopAfterLexingErrors&&i.some((e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.code)===Cn.LexingError})))return i;if(this.processParsingErrors(s,i,n),n.stopAfterParsingErrors&&i.some((e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.code)===Cn.ParsingError})))return i;if(this.processLinkingErrors(t,i,n),n.stopAfterLinkingErrors&&i.some((e=>{var t;return(null===(t=e.data)||void 0===t?void 0:t.code)===Cn.LinkingError})))return i}try{i.push(...await this.validateAst(s.value,n,r))}catch(o){if(on(o))throw o}return await an(r),i}processLexingErrors(e,t,n){var r,s,i;const o=[...e.lexerErrors,...null!==(s=null===(r=e.lexerReport)||void 0===r?void 0:r.diagnostics)&&void 0!==s?s:[]];for(const a of o){const e=null!==(i=a.severity)&&void 0!==i?i:"error",n={severity:_n(e),range:{start:{line:a.line-1,character:a.column-1},end:{line:a.line-1,character:a.column+a.length-1}},message:a.message,data:Gn(e),source:this.getSource()};t.push(n)}}processParsingErrors(e,t,n){for(const r of e.parserErrors){let e;if(isNaN(r.token.startOffset)){if("previousToken"in r){const t=r.previousToken;if(isNaN(t.startOffset)){const t={line:0,character:0};e={start:t,end:t}}else{const n={line:t.endLine-1,character:t.endColumn};e={start:n,end:n}}}}else e=O(r.token);if(e){const n={severity:_n("error"),range:e,message:r.message,data:Ln(Cn.ParsingError),source:this.getSource()};t.push(n)}}}processLinkingErrors(e,t,n){for(const r of e.references){const e=r.error;if(e){const n={node:e.container,property:e.property,index:e.index,data:{code:Cn.LinkingError,containerType:e.container.$type,property:e.property,refText:e.reference.$refText}};t.push(this.toDiagnostic("error",e.message,n))}}}async validateAst(t,n,r=e.CancellationToken.None){const s=[],i=(e,t,n)=>{s.push(this.toDiagnostic(e,t,n))};return await this.validateAstBefore(t,n,i,r),await this.validateAstNodes(t,n,i,r),await this.validateAstAfter(t,n,i,r),s}async validateAstBefore(t,n,r,s=e.CancellationToken.None){var i;const o=this.validationRegistry.checksBefore;for(const e of o)await an(s),await e(t,r,null!==(i=n.categories)&&void 0!==i?i:[],s)}async validateAstNodes(t,n,r,s=e.CancellationToken.None){await Promise.all(tt(t).map((async e=>{await an(s);const t=this.validationRegistry.getChecks(e.$type,n.categories);for(const n of t)await n(e,r,s)})))}async validateAstAfter(t,n,r,s=e.CancellationToken.None){var i;const o=this.validationRegistry.checksAfter;for(const e of o)await an(s),await e(t,r,null!==(i=n.categories)&&void 0!==i?i:[],s)}toDiagnostic(e,t,n){return{message:t,range:Fn(n),severity:_n(e),code:n.code,codeDescription:n.codeDescription,tags:n.tags,relatedInformation:n.relatedInformation,data:n.data,source:this.getSource()}}getSource(){return this.metadata.languageId}}function Fn(e){if(e.range)return e.range;let t;return"string"==typeof e.property?t=mt(e.node.$cstNode,e.property,e.index):"string"==typeof e.keyword&&(t=vt(e.node.$cstNode,e.keyword,e.index)),null!=t||(t=e.node.$cstNode),t?t.range:{start:{line:0,character:0},end:{line:0,character:0}}}function _n(e){switch(e){case"error":return 1;case"warning":return 2;case"info":return 3;case"hint":return 4;default:throw new Error("Invalid diagnostic severity: "+e)}}function Gn(e){switch(e){case"error":return Ln(Cn.LexingError);case"warning":return Ln(Cn.LexingWarning);case"info":return Ln(Cn.LexingInfo);case"hint":return Ln(Cn.LexingHint);default:throw new Error("Invalid diagnostic severity: "+e)}}(Mn=Cn||(Cn={})).LexingError="lexing-error",Mn.LexingWarning="lexing-warning",Mn.LexingInfo="lexing-info",Mn.LexingHint="lexing-hint",Mn.ParsingError="parsing-error",Mn.LinkingError="linking-error";class Vn{constructor(e){this.astNodeLocator=e.workspace.AstNodeLocator,this.nameProvider=e.references.NameProvider}createDescription(e,t,n){const r=null!=n?n:Xe(e);null!=t||(t=this.nameProvider.getName(e));const s=this.astNodeLocator.getAstNodePath(e);if(!t)throw new Error(`Node at path ${s} has no name.`);let i;const o=()=>{var t;return null!=i?i:i=j(null!==(t=this.nameProvider.getNameNode(e))&&void 0!==t?t:e.$cstNode)};return{node:e,name:t,get nameSegment(){return o()},selectionSegment:j(e.$cstNode),type:e.$type,documentUri:r.uri,path:s}}}class Un{constructor(e){this.nodeLocator=e.workspace.AstNodeLocator}async createDescriptions(t,n=e.CancellationToken.None){const r=[],s=t.parseResult.value;for(const e of tt(s))await an(n),rt(e).filter((e=>!w(e))).forEach((e=>{const t=this.createDescription(e);t&&r.push(t)}));return r}createDescription(e){const t=e.reference.$nodeDescription,n=e.reference.$refNode;if(!t||!n)return;const r=Xe(e.container).uri;return{sourceUri:r,sourcePath:this.nodeLocator.getAstNodePath(e.container),targetUri:t.documentUri,targetPath:t.path,segment:j(n),local:un.equals(t.documentUri,r)}}}class zn{constructor(){this.segmentSeparator="/",this.indexSeparator="@"}getAstNodePath(e){if(e.$container){const t=this.getAstNodePath(e.$container),n=this.getPathSegment(e);return t+this.segmentSeparator+n}return""}getPathSegment({$containerProperty:e,$containerIndex:t}){if(!e)throw new Error("Missing '$containerProperty' in AST node.");return void 0!==t?e+this.indexSeparator+t:e}getAstNode(e,t){return t.split(this.segmentSeparator).reduce(((e,t)=>{if(!e||0===t.length)return e;const n=t.indexOf(this.indexSeparator);if(n>0){const r=t.substring(0,n),s=parseInt(t.substring(n+1)),i=e[r];return null==i?void 0:i[s]}return e[t]}),e)}}class Wn{constructor(e){this._ready=new cn,this.settings={},this.workspaceConfig=!1,this.onConfigurationSectionUpdateEmitter=new t.Emitter,this.serviceRegistry=e.ServiceRegistry}get ready(){return this._ready.promise}initialize(e){var t,n;this.workspaceConfig=null!==(n=null===(t=e.capabilities.workspace)||void 0===t?void 0:t.configuration)&&void 0!==n&&n}async initialized(e){if(this.workspaceConfig){if(e.register){const t=this.serviceRegistry.all;e.register({ +// Listen to configuration changes for all languages +section:t.map((e=>this.toSectionName(e.LanguageMetaData.languageId)))})}if(e.fetchConfiguration){const t=this.serviceRegistry.all.map((e=>({ +// Fetch the configuration changes for all languages +section:this.toSectionName(e.LanguageMetaData.languageId)}))),n=await e.fetchConfiguration(t);t.forEach(((e,t)=>{this.updateSectionConfiguration(e.section,n[t])}))}}this._ready.resolve()} +/** + * Updates the cached configurations using the `change` notification parameters. + * + * @param change The parameters of a change configuration notification. + * `settings` property of the change object could be expressed as `Record>` + */updateConfiguration(e){e.settings&&Object.keys(e.settings).forEach((t=>{const n=e.settings[t];this.updateSectionConfiguration(t,n),this.onConfigurationSectionUpdateEmitter.fire({section:t,configuration:n})}))}updateSectionConfiguration(e,t){this.settings[e]=t} +/** + * Returns a configuration value stored for the given language. + * + * @param language The language id + * @param configuration Configuration name + */async getConfiguration(e,t){await this.ready;const n=this.toSectionName(e);if(this.settings[n])return this.settings[n][t]}toSectionName(e){return`${e}`}get onConfigurationSectionUpdate(){return this.onConfigurationSectionUpdateEmitter.event}}(On||(On={})).create=function(e){return{dispose:async()=>await e()}};class Hn{constructor(e){this.updateBuildOptions={ +// Default: run only the built-in validation checks and those in the _fast_ category (includes those without category) +validation:{categories:["built-in","fast"]}},this.updateListeners=[],this.buildPhaseListeners=new wn,this.documentPhaseListeners=new wn,this.buildState=new Map,this.documentBuildWaiters=new Map,this.currentState=dn.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(t,n={},r=e.CancellationToken.None){var s,i;for(const e of t){const t=e.uri.toString();if(e.state===dn.Validated){if("boolean"==typeof n.validation&&n.validation)e.state=dn.IndexedReferences,e.diagnostics=void 0,this.buildState.delete(t);else if("object"==typeof n.validation){const r=this.buildState.get(t),o=null===(s=null==r?void 0:r.result)||void 0===s?void 0:s.validationChecks;if(o){const s=(null!==(i=n.validation.categories)&&void 0!==i?i:Pn.all).filter((e=>!o.includes(e)));s.length>0&&(this.buildState.set(t,{completed:!1,options:{validation:Object.assign(Object.assign({},n.validation),{categories:s})},result:r.result}),e.state=dn.IndexedReferences)}}}else this.buildState.delete(t)}this.currentState=dn.Changed,await this.emitUpdate(t.map((e=>e.uri)),[]),await this.buildDocuments(t,n,r)}async update(t,n,r=e.CancellationToken.None){this.currentState=dn.Changed;for(const e of n)this.langiumDocuments.deleteDocument(e),this.buildState.delete(e.toString()),this.indexManager.remove(e);for(const e of t){if(!this.langiumDocuments.invalidateDocument(e)){const t=this.langiumDocumentFactory.fromModel({$type:"INVALID"},e);t.state=dn.Changed,this.langiumDocuments.addDocument(t)}this.buildState.delete(e.toString())}const s=D(t).concat(n).map((e=>e.toString())).toSet();this.langiumDocuments.all.filter((e=>!s.has(e.uri.toString())&&this.shouldRelink(e,s))).forEach((e=>{this.serviceRegistry.getServices(e.uri).references.Linker.unlink(e),e.state=Math.min(e.state,dn.ComputedScopes),e.diagnostics=void 0})),await this.emitUpdate(t,n),await an(r);const i=this.sortDocuments(this.langiumDocuments.all.filter((e=>{var t;return e.staten(e,t))))} +/** + * Sort the given documents by priority. By default, documents with an open text document are prioritized. + * This is useful to ensure that visible documents show their diagnostics before all other documents. + * + * This improves the responsiveness in large workspaces as users usually don't care about diagnostics + * in files that are currently not opened in the editor. + */sortDocuments(e){let t=0,n=e.length-1;for(;t=0&&!this.hasTextDocument(e[n]);)n--;tvoid 0!==e.error))||this.indexManager.isAffected(e,t)}onUpdate(e){return this.updateListeners.push(e),On.create((()=>{const t=this.updateListeners.indexOf(e);t>=0&&this.updateListeners.splice(t,1)}))} +/** + * Build the given documents by stepping through all build phases. If a document's state indicates + * that a certain build phase is already done, the phase is skipped for that document. + * + * @param documents The documents to build. + * @param options the {@link BuildOptions} to use. + * @param cancelToken A cancellation token that can be used to cancel the build. + * @returns A promise that resolves when the build is done. + */async buildDocuments(e,t,n){this.prepareBuild(e,t),await this.runCancelable(e,dn.Parsed,n,(e=>this.langiumDocumentFactory.update(e,n))),await this.runCancelable(e,dn.IndexedContent,n,(e=>this.indexManager.updateContent(e,n))),await this.runCancelable(e,dn.ComputedScopes,n,(async e=>{const t=this.serviceRegistry.getServices(e.uri).references.ScopeComputation;e.precomputedScopes=await t.computeLocalScopes(e,n)})),await this.runCancelable(e,dn.Linked,n,(e=>this.serviceRegistry.getServices(e.uri).references.Linker.link(e,n))),await this.runCancelable(e,dn.IndexedReferences,n,(e=>this.indexManager.updateReferences(e,n)));const r=e.filter((e=>this.shouldValidate(e)));await this.runCancelable(r,dn.Validated,n,(e=>this.validate(e,n)));for(const s of e){const e=this.buildState.get(s.uri.toString());e&&(e.completed=!0)}} +/** + * Runs prior to beginning the build process to update the {@link DocumentBuildState} for each document + * + * @param documents collection of documents to be built + * @param options the {@link BuildOptions} to use + */prepareBuild(e,t){for(const n of e){const e=n.uri.toString(),r=this.buildState.get(e);r&&!r.completed||this.buildState.set(e,{completed:!1,options:t,result:null==r?void 0:r.result})}} +/** + * Runs a cancelable operation on a set of documents to bring them to a specified {@link DocumentState}. + * + * @param documents The array of documents to process. + * @param targetState The target {@link DocumentState} to bring the documents to. + * @param cancelToken A token that can be used to cancel the operation. + * @param callback A function to be called for each document. + * @returns A promise that resolves when all documents have been processed or the operation is canceled. + * @throws Will throw `OperationCancelled` if the operation is canceled via a `CancellationToken`. + */async runCancelable(e,t,n,r){const s=e.filter((e=>e.statee.state===t));await this.notifyBuildPhase(i,t,n),this.currentState=t}onBuildPhase(e,t){return this.buildPhaseListeners.add(e,t),On.create((()=>{this.buildPhaseListeners.delete(e,t)}))}onDocumentPhase(e,t){return this.documentPhaseListeners.add(e,t),On.create((()=>{this.documentPhaseListeners.delete(e,t)}))}waitUntil(t,n,r){let s;if(n&&"path"in n?s=n:r=n,null!=r||(r=e.CancellationToken.None),s){const e=this.langiumDocuments.getDocument(s);if(e&&e.state>t)return Promise.resolve(s)}return this.currentState>=t?Promise.resolve(void 0):r.isCancellationRequested?Promise.reject(sn):new Promise(((e,n)=>{const i=this.onBuildPhase(t,(()=>{if(i.dispose(),o.dispose(),s){const t=this.langiumDocuments.getDocument(s);e(null==t?void 0:t.uri)}else e(void 0)})),o=r.onCancellationRequested((()=>{i.dispose(),o.dispose(),n(sn)}))}))}async notifyDocumentPhase(e,t,n){const r=this.documentPhaseListeners.get(t).slice();for(const i of r)try{await i(e,n)}catch(s){if(!on(s))throw s}}async notifyBuildPhase(e,t,n){if(0===e.length)return;const r=this.buildPhaseListeners.get(t).slice();for(const s of r)await an(n),await s(e,n)} +/** + * Determine whether the given document should be validated during a build. The default + * implementation checks the `validation` property of the build options. If it's set to `true` + * or a `ValidationOptions` object, the document is included in the validation phase. + */shouldValidate(e){return Boolean(this.getBuildOptions(e).validation)} +/** + * Run validation checks on the given document and store the resulting diagnostics in the document. + * If the document already contains diagnostics, the new ones are added to the list. + */async validate(e,t){var n,r;const s=this.serviceRegistry.getServices(e.uri).validation.DocumentValidator,i=this.getBuildOptions(e).validation,o="object"==typeof i?i:void 0,a=await s.validateDocument(e,o,t);e.diagnostics?e.diagnostics.push(...a):e.diagnostics=a;const c=this.buildState.get(e.uri.toString());if(c){null!==(n=c.result)&&void 0!==n||(c.result={});const e=null!==(r=null==o?void 0:o.categories)&&void 0!==r?r:Pn.all;c.result.validationChecks?c.result.validationChecks.push(...e):c.result.validationChecks=[...e]}}getBuildOptions(e){var t,n;return null!==(n=null===(t=this.buildState.get(e.uri.toString()))||void 0===t?void 0:t.options)&&void 0!==n?n:{}}}class qn{constructor(e){this.symbolIndex=new Map,this.symbolByTypeIndex=new $n,this.referenceIndex=new Map,this.documents=e.workspace.LangiumDocuments,this.serviceRegistry=e.ServiceRegistry,this.astReflection=e.AstReflection}findAllReferences(e,t){const n=Xe(e).uri,r=[];return this.referenceIndex.forEach((e=>{e.forEach((e=>{un.equals(e.targetUri,n)&&e.targetPath===t&&r.push(e)}))})),D(r)}allElements(e,t){let n=D(this.symbolIndex.keys());return t&&(n=n.filter((e=>!t||t.has(e)))),n.map((t=>this.getFileDescriptions(t,e))).flat()}getFileDescriptions(e,t){var n;if(!t)return null!==(n=this.symbolIndex.get(e))&&void 0!==n?n:[];return this.symbolByTypeIndex.get(e,t,(()=>{var n;return(null!==(n=this.symbolIndex.get(e))&&void 0!==n?n:[]).filter((e=>this.astReflection.isSubtype(e.type,t)))}))}remove(e){const t=e.toString();this.symbolIndex.delete(t),this.symbolByTypeIndex.clear(t),this.referenceIndex.delete(t)}async updateContent(t,n=e.CancellationToken.None){const r=this.serviceRegistry.getServices(t.uri),s=await r.references.ScopeComputation.computeExports(t,n),i=t.uri.toString();this.symbolIndex.set(i,s),this.symbolByTypeIndex.clear(i)}async updateReferences(t,n=e.CancellationToken.None){const r=this.serviceRegistry.getServices(t.uri),s=await r.workspace.ReferenceDescriptionProvider.createDescriptions(t,n);this.referenceIndex.set(t.uri.toString(),s)}isAffected(e,t){const n=this.referenceIndex.get(e.uri.toString());return!!n&&n.some((e=>!e.local&&t.has(e.targetUri.toString())))}}class Kn{constructor(e){this.initialBuildOptions={},this._ready=new cn,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=null!==(t=e.workspaceFolders)&&void 0!==t?t:void 0}initialized(e){return this.mutex.write((e=>{var t;return this.initializeWorkspace(null!==(t=this.folders)&&void 0!==t?t:[],e)}))}async initializeWorkspace(t,n=e.CancellationToken.None){const r=await this.performStartup(t);await an(n),await this.documentBuilder.build(r,this.initialBuildOptions,n)} +/** + * Performs the uninterruptable startup sequence of the workspace manager. + * This methods loads all documents in the workspace and other documents and returns them. + */async performStartup(e){const t=this.serviceRegistry.all.flatMap((e=>e.LanguageMetaData.fileExtensions)),n=[],r=e=>{n.push(e),this.langiumDocuments.hasDocument(e.uri)||this.langiumDocuments.addDocument(e)};return await this.loadAdditionalDocuments(e,r),await Promise.all(e.map((e=>[e,this.getRootFolder(e)])).map((async e=>this.traverseFolder(...e,t,r)))),this._ready.resolve(),n} +/** + * Load all additional documents that shall be visible in the context of the given workspace + * folders and add them to the collector. This can be used to include built-in libraries of + * your language, which can be either loaded from provided files or constructed in memory. + */loadAdditionalDocuments(e,t){return Promise.resolve()} +/** + * Determine the root folder of the source documents in the given workspace folder. + * The default implementation returns the URI of the workspace folder, but you can override + * this to return a subfolder like `src` instead. + */getRootFolder(e){return g.parse(e.uri)} +/** + * Traverse the file system folder identified by the given URI and its subfolders. All + * contained files that match the file extensions are added to the collector. + */async traverseFolder(e,t,n,r){const s=await this.fileSystemProvider.readDirectory(t);await Promise.all(s.map((async t=>{if(this.includeEntry(e,t,n))if(t.isDirectory)await this.traverseFolder(e,t.uri,n,r);else if(t.isFile){const e=await this.langiumDocuments.getOrCreateDocument(t.uri);r(e)}})))} +/** + * Determine whether the given folder entry shall be included while indexing the workspace. + */includeEntry(e,t,n){const r=un.basename(t.uri);if(r.startsWith("."))return!1;if(t.isDirectory)return"node_modules"!==r&&"out"!==r;if(t.isFile){const e=un.extname(t.uri);return n.includes(e)}return!1}}class Qn{buildUnexpectedCharactersMessage(e,t,n,r,s){return c.buildUnexpectedCharactersMessage(e,t,n,r,s)}buildUnableToPopLexerModeMessage(e){return c.buildUnableToPopLexerModeMessage(e)}}const Jn={mode:"full"};class Xn{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 n=Zn(t)?Object.values(t):t,r="production"===e.LanguageMetaData.mode;this.chevrotainLexer=new a(n,{positionTracking:"full",skipValidations:r,errorMessageProvider:this.errorMessageProvider})}get definition(){return this.tokenTypes}tokenize(e,t=Jn){var n,r,s;const i=this.chevrotainLexer.tokenize(e);return{tokens:i.tokens,errors:i.errors,hidden:null!==(n=i.groups.hidden)&&void 0!==n?n:[],report:null===(s=(r=this.tokenBuilder).flushLexingReport)||void 0===s?void 0:s.call(r,e)}}toTokenTypeDictionary(e){if(Zn(e))return e;const t=Yn(e)?Object.values(e.modes).flat():e,n={};return t.forEach((e=>n[e.name]=e)),n}}function Yn(e){return e&&"modes"in e&&"defaultMode"in e}function Zn(e){return!function(e){return Array.isArray(e)&&(0===e.length||"name"in e[0])}(e)&&!Yn(e)}function er(e,t,n){let r,s;"string"==typeof e?(s=t,r=n):(s=e.range.start,r=t),s||(s=h.create(0,0));const i=function(e){var t,n,r;const s=[];let i=e.position.line,o=e.position.character;for(let a=0;a=l.length){if(s.length>0){const e=h.create(i,o);s.push({type:"break",content:"",range:f.create(e,e)})}}else{nr.lastIndex=d;const e=nr.exec(l);if(e){const t=e[0],n=e[1],r=h.create(i,o+d),a=h.create(i,o+d+t.length);s.push({type:"tag",content:n,range:f.create(r,a)}),d+=t.length,d=ar(l,d)}if(d0&&"break"===s[s.length-1].type)return s.slice(0,-1);return s}({lines:tr(e),position:s,options:pr(r)});return function(e){var t,n,r,s;const i=h.create(e.position.line,e.position.character);if(0===e.tokens.length)return new gr([],f.create(i,i));const o=[];for(;e.index0&&s.push({type:"text",content:t.substring(i,e),range:f.create(h.create(n,i+r),h.create(n,e+r))});let c=o.length+1;const u=a[1];if(s.push({type:"inline-tag",content:u,range:f.create(h.create(n,i+c+r),h.create(n,i+c+u.length+r))}),c+=u.length,4===a.length){c+=a[2].length;const e=a[3];s.push({type:"text",content:e,range:f.create(h.create(n,i+c+r),h.create(n,i+c+e.length+r))})}else s.push({type:"text",content:"",range:f.create(h.create(n,i+c+r),h.create(n,i+c+r))});i=e+a[0].length}const o=t.substring(i);o.length>0&&s.push({type:"text",content:o,range:f.create(h.create(n,i+r),h.create(n,i+r+o.length))})}return s}const ir=/\S/,or=/\s*$/;function ar(e,t){const n=e.substring(t).match(ir);return n?t+n.index:e.length}function cr(e){const t=e.match(or);if(t&&"number"==typeof t.index)return t.index}function ur(e,t){const n=e.tokens[e.index];return"tag"===n.type?hr(e,!1):"text"===n.type||"inline-tag"===n.type?lr(e):(function(e,t){if(t){const n=new wr("",e.range);"inlines"in t?t.inlines.push(n):t.content.inlines.push(n)}}(n,t),void e.index++)}function lr(e){let t=e.tokens[e.index];const n=t;let r=t;const s=[];for(;t&&"break"!==t.type&&"tag"!==t.type;)s.push(dr(e)),r=t,t=e.tokens[e.index];return new yr(s,f.create(n.range.start,r.range.end))}function dr(e){return"inline-tag"===e.tokens[e.index].type?hr(e,!0):fr(e)}function hr(e,t){const n=e.tokens[e.index++],r=n.content.substring(1),s=e.tokens[e.index];if("text"===(null==s?void 0:s.type)){if(t){const s=fr(e);return new vr(r,new yr([s],s.range),t,f.create(n.range.start,s.range.end))}{const s=lr(e);return new vr(r,s,t,f.create(n.range.start,s.range.end))}}{const e=n.range;return new vr(r,new yr([],e),t,e)}}function fr(e){const t=e.tokens[e.index++];return new wr(t.content,t.range)}function pr(e){if(!e)return pr({start:"/**",end:"*/",line:"*"});const{start:t,end:n,line:r}=e;return{start:mr(t,!0),end:mr(n,!1),line:mr(r,!0)}}function mr(e,t){if("string"==typeof e||"object"==typeof e){const n="string"==typeof e?dt(e):e.source;return t?new RegExp(`^\\s*${n}`):new RegExp(`\\s*${n}\\s*$`)}return e}class gr{constructor(e,t){this.elements=e,this.range=t}getTag(e){return this.getAllTags().find((t=>t.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(0===e.length)e=t.toString();else{const n=t.toString();e+=xr(e)+n}return e.trim()}toMarkdown(e){let t="";for(const n of this.elements)if(0===t.length)t=n.toMarkdown(e);else{const r=n.toMarkdown(e);t+=xr(t)+r}return t.trim()}}class vr{constructor(e,t,n,r){this.name=e,this.content=t,this.inline=n,this.range=r}toString(){let e=`@${this.name}`;const t=this.content.toString();return 1===this.content.inlines.length?e=`${e} ${t}`:this.content.inlines.length>1&&(e=`${e}\n${t}`),this.inline?`{${e}}`:e}toMarkdown(e){var t,n;return null!==(n=null===(t=null==e?void 0:e.renderTag)||void 0===t?void 0:t.call(e,this))&&void 0!==n?n:this.toMarkdownDefault(e)}toMarkdownDefault(e){const t=this.content.toMarkdown(e);if(this.inline){const n=function(e,t,n){var r,s;if("linkplain"===e||"linkcode"===e||"link"===e){const i=t.indexOf(" ");let o=t;if(i>0){const e=ar(t,i);o=t.substring(e),t=t.substring(0,i)}("linkcode"===e||"link"===e&&"code"===n.link)&&(o=`\`${o}\``);const a=null!==(s=null===(r=n.renderLink)||void 0===r?void 0:r.call(n,t,o))&&void 0!==s?s:function(e,t){try{return g.parse(e,!0),`[${t}](${e})`}catch(r){return e}}(t,o);return a}return}(this.name,t,null!=e?e:{});if("string"==typeof n)return n}let n="";"italic"===(null==e?void 0:e.tag)||void 0===(null==e?void 0:e.tag)?n="*":"bold"===(null==e?void 0:e.tag)?n="**":"bold-italic"===(null==e?void 0:e.tag)&&(n="***");let r=`${n}@${this.name}${n}`;return 1===this.content.inlines.length?r=`${r} — ${t}`:this.content.inlines.length>1&&(r=`${r}\n${t}`),this.inline?`{${r}}`:r}}class yr{constructor(e,t){this.inlines=e,this.range=t}toString(){let e="";for(let t=0;tn.range.start.line&&(e+="\n")}return e}toMarkdown(e){let t="";for(let n=0;nr.range.start.line&&(t+="\n")}return t}}class wr{constructor(e,t){this.text=e,this.range=t}toString(){return this.text}toMarkdown(){return this.text}}function xr(e){return e.endsWith("\n")?"\n":"\n\n"}class kr{constructor(e){this.indexManager=e.shared.workspace.IndexManager,this.commentProvider=e.documentation.CommentProvider}getDocumentation(e){const t=this.commentProvider.getComment(e);if(t&&function(e,t){const n=pr(t),r=tr(e);if(0===r.length)return!1;const s=r[0],i=r[r.length-1],o=n.start,a=n.end;return Boolean(null==o?void 0:o.exec(s))&&Boolean(null==a?void 0:a.exec(i))}(t)){return er(t).toMarkdown({renderLink:(t,n)=>this.documentationLinkRenderer(e,t,n),renderTag:t=>this.documentationTagRenderer(e,t)})}}documentationLinkRenderer(e,t,n){var r;const s=null!==(r=this.findNameInPrecomputedScopes(e,t))&&void 0!==r?r:this.findNameInGlobalScope(e,t);if(s&&s.nameSegment){const e=s.nameSegment.range.start.line+1,t=s.nameSegment.range.start.character+1;return`[${n}](${s.documentUri.with({fragment:`L${e},${t}`}).toString()})`}}documentationTagRenderer(e,t){}findNameInPrecomputedScopes(e,t){const n=Xe(e).precomputedScopes;if(!n)return;let r=e;do{const e=n.get(r).find((e=>e.name===t));if(e)return e;r=r.$container}while(r)}findNameInGlobalScope(e,t){return this.indexManager.allElements().find((e=>e.name===t))}}class Sr{constructor(e){this.grammarConfig=()=>e.parser.GrammarConfig}getComment(e){var t;return function(e){return"string"==typeof e.$comment}(e)?e.$comment:null===(t=function(e,t){if(e){const n=function(e,t=!0){for(;e.container;){const n=e.container;let r=n.content.indexOf(e);for(;r>0;){r--;const e=n.content[r];if(t||!e.hidden)return e}e=n}}(e,!0);if(n&&_(n,t))return n;if(b(e))for(let r=e.content.findIndex((e=>!e.hidden))-1;r>=0;r--){const n=e.content[r];if(_(n,t))return n}}}(e.$cstNode,this.grammarConfig().multilineCommentRules))||void 0===t?void 0:t.text}}class br{constructor(e){this.syncParser=e.parser.LangiumParser}parse(e,t){return Promise.resolve(this.syncParser.parse(e))}}class Nr{constructor(){this.previousTokenSource=new e.CancellationTokenSource,this.writeQueue=[],this.readQueue=[],this.done=!0}write(t){this.cancelWrite();const n=(rn=performance.now(),new e.CancellationTokenSource);return this.previousTokenSource=n,this.enqueue(this.writeQueue,t,n.token)}read(e){return this.enqueue(this.readQueue,e)}enqueue(t,n,r=e.CancellationToken.None){const s=new cn,i={action:n,deferred:s,cancellationToken:r};return t.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))return;e.push(...this.readQueue.splice(0,this.readQueue.length))}this.done=!1,await Promise.all(e.map((async({action:e,deferred:t,cancellationToken:n})=>{try{const r=await Promise.resolve().then((()=>e(n)));t.resolve(r)}catch(r){on(r)?t.resolve(void 0):t.reject(r)}}))),this.done=!0,this.performNextOperation()}cancelWrite(){this.previousTokenSource.cancel()}}class Tr{constructor(e){this.grammarElementIdMap=new xn,this.tokenTypeIdMap=new xn,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, +// We need to create shallow copies of the errors +// The original errors inherit from the `Error` class, which is not transferable across worker threads +parserErrors:e.parserErrors.map((e=>Object.assign(Object.assign({},e),{message:e.message}))),value:this.dehydrateAstNode(e.value,this.createDehyrationContext(e.value))}}dehydrateLexerReport(e){return e}createDehyrationContext(e){const t=new Map,n=new Map;for(const r of tt(e))t.set(r,{});if(e.$cstNode)for(const r of M(e.$cstNode))n.set(r,{});return{astNodes:t,cstNodes:n}}dehydrateAstNode(e,t){const n=t.astNodes.get(e);n.$type=e.$type,n.$containerIndex=e.$containerIndex,n.$containerProperty=e.$containerProperty,void 0!==e.$cstNode&&(n.$cstNode=this.dehydrateCstNode(e.$cstNode,t));for(const[r,s]of Object.entries(e))if(!r.startsWith("$"))if(Array.isArray(s)){const e=[];n[r]=e;for(const n of s)v(n)?e.push(this.dehydrateAstNode(n,t)):y(n)?e.push(this.dehydrateReference(n,t)):e.push(n)}else v(s)?n[r]=this.dehydrateAstNode(s,t):y(s)?n[r]=this.dehydrateReference(s,t):void 0!==s&&(n[r]=s);return n}dehydrateReference(e,t){const n={};return n.$refText=e.$refText,e.$refNode&&(n.$refNode=t.cstNodes.get(e.$refNode)),n}dehydrateCstNode(e,t){const n=t.cstNodes.get(e);return b(e)?n.fullText=e.fullText:n.grammarSource=this.getGrammarElementId(e.grammarSource),n.hidden=e.hidden,n.astNode=t.astNodes.get(e.astNode),k(e)?n.content=e.content.map((e=>this.dehydrateCstNode(e,t))):S(e)&&(n.tokenType=e.tokenType.name,n.offset=e.offset,n.length=e.length,n.startLine=e.range.start.line,n.startColumn=e.range.start.character,n.endLine=e.range.end.line,n.endColumn=e.range.end.character),n}hydrate(e){const t=e.value,n=this.createHydrationContext(t);return"$cstNode"in t&&this.hydrateCstNode(t.$cstNode,n),{lexerErrors:e.lexerErrors,lexerReport:e.lexerReport,parserErrors:e.parserErrors,value:this.hydrateAstNode(t,n)}}createHydrationContext(e){const t=new Map,n=new Map;for(const s of tt(e))t.set(s,{});let r;if(e.$cstNode)for(const s of M(e.$cstNode)){let e;"fullText"in s?(e=new Ct(s.fullText),r=e):"content"in s?e=new Lt:"tokenType"in s&&(e=this.hydrateCstLeafNode(s)),e&&(n.set(s,e),e.root=r)}return{astNodes:t,cstNodes:n}}hydrateAstNode(e,t){const n=t.astNodes.get(e);n.$type=e.$type,n.$containerIndex=e.$containerIndex,n.$containerProperty=e.$containerProperty,e.$cstNode&&(n.$cstNode=t.cstNodes.get(e.$cstNode));for(const[r,s]of Object.entries(e))if(!r.startsWith("$"))if(Array.isArray(s)){const e=[];n[r]=e;for(const i of s)v(i)?e.push(this.setParent(this.hydrateAstNode(i,t),n)):y(i)?e.push(this.hydrateReference(i,n,r,t)):e.push(i)}else v(s)?n[r]=this.setParent(this.hydrateAstNode(s,t),n):y(s)?n[r]=this.hydrateReference(s,n,r,t):void 0!==s&&(n[r]=s);return n}setParent(e,t){return e.$container=t,e}hydrateReference(e,t,n,r){return this.linker.buildReference(t,n,r.cstNodes.get(e.$refNode),e.$refText)}hydrateCstNode(e,t,n=0){const r=t.cstNodes.get(e);if("number"==typeof e.grammarSource&&(r.grammarSource=this.getGrammarElement(e.grammarSource)),r.astNode=t.astNodes.get(e.astNode),k(r))for(const s of e.content){const e=this.hydrateCstNode(s,t,n++);r.content.push(e)}return r}hydrateCstLeafNode(e){const t=this.getTokenType(e.tokenType),n=e.offset,r=e.length,s=e.startLine,i=e.startColumn,o=e.endLine,a=e.endColumn,c=e.hidden;return new It(n,r,{start:{line:s,character:i},end:{line:o,character:a}},t,c)}getTokenType(e){return this.lexer.definition[e]}getGrammarElementId(e){if(e)return 0===this.grammarElementIdMap.size&&this.createGrammarElementIdMap(),this.grammarElementIdMap.get(e)}getGrammarElement(e){0===this.grammarElementIdMap.size&&this.createGrammarElementIdMap();return this.grammarElementIdMap.getKey(e)}createGrammarElementIdMap(){let e=0;for(const n of tt(this.grammar))t=n,Qe.isInstance(t,K)&&this.grammarElementIdMap.set(n,e++);var t}}function $r(e){return{documentation:{CommentProvider:e=>new Sr(e),DocumentationProvider:e=>new kr(e)},parser:{AsyncParser:e=>new br(e),GrammarConfig:e=>function(e){const t=[],n=e.Grammar;for(const s of n.rules)ye(s)&&(r=s).hidden&&!lt(Nt(r))&&ct(Nt(s))&&t.push(s.name);var r;return{multilineCommentRules:t,nameRegexp:F}}(e),LangiumParser:e=>Zt(e),CompletionParser:e=>function(e){const t=e.Grammar,n=e.parser.Lexer,r=new Vt(e);return Wt(t,r,n.definition),r.finalize(),r}(e),ValueConverter:()=>new tn,TokenBuilder:()=>new en,Lexer:e=>new Xn(e),ParserErrorMessageProvider:()=>new Gt,LexerErrorMessageProvider:()=>new Qn},workspace:{AstNodeLocator:()=>new zn,AstNodeDescriptionProvider:e=>new Vn(e),ReferenceDescriptionProvider:e=>new Un(e)},references:{Linker:e=>new gn(e),NameProvider:()=>new vn,ScopeProvider:e=>new En(e),ScopeComputation:e=>new kn(e),References:e=>new yn(e)},serializer:{Hydrator:e=>new Tr(e),JsonSerializer:e=>new An(e)},validation:{DocumentValidator:e=>new Bn(e),ValidationRegistry:e=>new jn(e)},shared:()=>e.shared}}function Rr(e){return{ServiceRegistry:e=>new In(e),workspace:{LangiumDocuments:e=>new pn(e),LangiumDocumentFactory:e=>new fn(e),DocumentBuilder:e=>new Hn(e),IndexManager:e=>new qn(e),WorkspaceManager:e=>new Kn(e),FileSystemProvider:t=>e.fileSystemProvider(t),WorkspaceLock:()=>new Nr,ConfigurationProvider:e=>new Wn(e)}}}var Er;function Dr(e,t,n,r,s,i,o,a,c){return Ir([e,t,n,r,s,i,o,a,c].reduce(Cr,{}))}(Er||(Er={})).merge=(e,t)=>Cr(Cr({},e),t);const Ar=Symbol("isProxy");function Ir(e,t){const n=new Proxy({},{deleteProperty:()=>!1,set:()=>{throw new Error("Cannot set property on injected service container")},get:(r,s)=>s===Ar||Pr(r,s,e,t||n),getOwnPropertyDescriptor:(r,s)=>(Pr(r,s,e,t||n),Object.getOwnPropertyDescriptor(r,s)) +// used by for..in +,has:(t,n)=>n in e +// used by ..in.. +,ownKeys:()=>[...Object.getOwnPropertyNames(e)]});return n}const Lr=Symbol();function Pr(e,t,n,r){if(t in e){if(e[t]instanceof Error)throw new Error("Construction failure. Please make sure that your dependencies are constructable.",{cause:e[t]});if(e[t]===Lr)throw new Error('Cycle detected. Please make "'+String(t)+'" lazy. Visit https://langium.org/docs/reference/configuration-services/#resolving-cyclic-dependencies');return e[t]}if(t in n){const i=n[t];e[t]=Lr;try{e[t]="function"==typeof i?i(r):Ir(i,r)}catch(s){throw e[t]=s instanceof Error?s:void 0,s}return e[t]}}function Cr(e,t){if(t)for(const[n,r]of Object.entries(t))if(void 0!==r){const t=e[n];e[n]=null!==t&&null!==r&&"object"==typeof t&&"object"==typeof r?Cr(t,r):r}return e}class Mr{readFile(){throw new Error("No file system is available.")}async readDirectory(){return[]}}const Or={fileSystemProvider:()=>new Mr},jr={Grammar:()=>{},LanguageMetaData:()=>({caseInsensitive:!1,fileExtensions:[".langium"],languageId:"langium"})},Br={AstReflection:()=>new Ke};function Fr(e){var t;const n=function(){const e=Dr(Rr(Or),Br),t=Dr($r({shared:e}),jr);return e.ServiceRegistry.register(t),t}(),r=n.serializer.JsonSerializer.deserialize(e);return n.shared.workspace.LangiumDocumentFactory.fromModel(r,g.parse(`memory://${null!==(t=r.name)&&void 0!==t?t:"grammar"}.langium`)),r}export{x as A,tn as D,Or as E,en as a,$r as b,Rr as c,Dr as i,Fr as l};