devicetree-language-server 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.js +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -232,7 +232,7 @@ ${"".padEnd(Hi(u[m].uri,f)*ji().length,ji())}${r}${d};`))})]}return[]}let o=fM(s
|
|
|
232
232
|
`,`
|
|
233
233
|
`).split(/\n/).map(r=>`${r}
|
|
234
234
|
`),this.lines[this.lines.length-1]=this.lines[this.lines.length-1].slice(0,-1),e.endsWith(`
|
|
235
|
-
`)&&this.lines.splice(-1,1),this.lexIt()}get tokens(){return this._tokens}isWhiteSpace(){return!!this.currentChar?.match(/\s/)}get endOfFile(){return this.isOnLastLine&&this.isOnLastCharOfLine}get isOnLastLine(){return this.lineNumber===this.lines.length-1}get isOnLastCharOfLine(){return this.lines[this.lineNumber].length<=this.columnNumber}moveToNextLine(){return this.isOnLastLine?!1:(this.columnNumber=0,this.lineNumberOfEscapedChars=0,this.lineNumber++,this.lines[this.lineNumber].length===0&&this.moveToNextLine(),!0)}moveOnLine(){return this.isOnLastCharOfLine?this.moveToNextLine():(this.columnNumber++,this.isOnLastCharOfLine&&this.moveToNextLine(),!0)}move(){return this.endOfFile?!1:this.moveOnLine()}get currentChar(){return this.endOfFile?null:this.lines[this.lineNumber].at(this.columnNumber)}static isSyntaxChar(e){return e==="^"||e==="~"||e==="|"||e==="!"||e==="\\"||e==="<"||e===">"||e===";"||e==="="||e==="/"||e==="{"||e==="}"||e==="["||e==="]"||e==="("||e===")"||e==="*"||e==="%"||e==="&"||e==="."||e===":"||e==="+"||e==="@"||e==="-"||e==="_"||e===","||e==="x"||e==="?"}getWord(){let e="";for(;!this.isWhiteSpace()&&(e.length&&!n.isSyntaxChar(this.currentChar)||!e.length);){if(e+=this.currentChar??"",e.length===1&&n.isSyntaxChar(this.currentChar)){this.move();break}let t=this.lineNumber;if(!this.move()||this.lineNumber!==t)return e}return e==="/"&&this.currentChar==="*"?this.inComment=!0:this.inComment&&e==="*"&&this.currentChar==="/"&&(this.inComment=!1),e}getString(e){let t=e;for(this.numberOfEscapedCharsLastString=0;this.currentChar!==e;){if(t+=this.currentChar??"",this.currentChar==="\\"){let r=this.lineNumber;if(this.move())this.lineNumberOfEscapedChars++,this.numberOfEscapedCharsLastString++,r===this.lineNumber&&(t+=this.currentChar??"");else return t}if(!this.move())return t}return this.move(),t+=e,t}lexIt(){for(;!this.endOfFile&&(this.whiteSpace(),!this.endOfFile);){let e=this.getWord();e&&this.process(e)}}process(e){let t=this.isString(e)||this.isCDefine(e)||this.isCInclude(e)||this.isCLine(e)||this.isCUndef(e)||this.isCError(e)||this.isCPragma(e)||this.isCDefined(e)||this.isCIfDef(e)||this.isCIfNDef(e)||this.isCIf(e)||this.isCElIf(e)||this.isCElse(e)||this.isCEndIf(e)||this.isCFalse(e)||this.isCTrue(e)||this.isDigit(e)||this.isHexDigit(e)||this.isLetters(e)||this.isComma(e)||this.isBitwiseNot(e)||this.isBitwiseXOr(e)||this.isBitwiseOr(e)||this.isLogicalNot(e)||this.isGtSym(e)||this.isLtSym(e)||this.isSemicolon(e)||this.isColon(e)||this.isAssignOperator(e)||this.isForwardSlash(e)||this.isRoundOpen(e)||this.isRoundClose(e)||this.isCurlyOpen(e)||this.isCurlyClose(e)||this.isSquareOpen(e)||this.isSquareClose(e)||this.isBackSlash(e)||this.isMultiplicationOperator(e)||this.isModulusOperator(e)||this.isAmpersand(e)||this.isNegateOperator(e)||this.isAddOperator(e)||this.isQuestionMark(e)||this.isPeriod(e)||this.isHash(e)||this.isUnderScore(e)||this.isAt(e)||this.unknownToken(e);if(!t)throw new Error(`Lexer is not complete!!! Could not find token for "${e}"`);let r=this._tokens.at(-1);return t&&!r?.tokens.some(s=>s===21)&&r&&r.pos.len<e.length?this.process(e.slice(r.pos.len)):!0}whiteSpace(){for(;this.isWhiteSpace();)this.move()}pushToken(e){let t={...e,uri:this.uri},r=this._tokens.at(-1);t.prevToken=r,r&&(r.nextToken=t),this._tokens.push(t)}isLetters(e){let t=e.match(/^[A-Za-z]+/);return t?.[0]?(this.pushToken({tokens:[47],value:t?.[0],pos:this.generatePos(e,t?.[0])}),!0):!1}isDigit(e){let t=e.match(/^[0-9]/);return t?.[0]?(this.pushToken({tokens:[20,19],value:t[0],pos:this.generatePos(e,t[0])}),!0):!1}isHexDigit(e){let t=e.match(/^[A-Fa-f]/);return t?.[0]?(this.pushToken({tokens:[20,47],value:t[0],pos:this.generatePos(e,t[0])}),!0):!1}isCurlyOpen(e){let t="{";return e===t?(this.pushToken({tokens:[2],pos:this.generatePos(e,t),value:"{"}),!0):!1}isCurlyClose(e){let t="}";return e===t?(this.pushToken({tokens:[3],pos:this.generatePos(e,t),value:"}"}),!0):!1}isSemicolon(e){let t=";";return e===t?(this.pushToken({tokens:[1],pos:this.generatePos(e,t),value:t}),!0):!1}isColon(e){let t=":";return e===t?(this.pushToken({tokens:[50],pos:this.generatePos(e,t),value:t}),!0):!1}isHash(e){let t="#";return e.startsWith(t)?(this.pushToken({tokens:[46],pos:this.generatePos(e,t),value:t}),!0):!1}unknownToken(e){return this.pushToken({tokens:[41],pos:this.generatePos(e," "),value:e}),!0}isAssignOperator(e){let t="=";return e===t?(this.pushToken({tokens:[0],pos:this.generatePos(e,t),value:t}),!0):!1}isGtSym(e){let t=">";return e===t?(this.pushToken({tokens:[4],pos:this.generatePos(e,t),value:t}),!0):!1}isLtSym(e){let t="<";return e===t?(this.pushToken({tokens:[5],pos:this.generatePos(e,t),value:t}),!0):!1}isLogicalNot(e){let t="!";return e===t?(this.pushToken({tokens:[6],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseOr(e){let t="|";return e===t?(this.pushToken({tokens:[8],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseXOr(e){let t="^";return e===t?(this.pushToken({tokens:[9],pos:this.generatePos(e,t),value:t}),!0):!1}isAmpersand(e){let t="&";return e===t?(this.pushToken({tokens:[40,7],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseNot(e){let t="~";return e===t?(this.pushToken({tokens:[10],pos:this.generatePos(e,t),value:t}),!0):!1}isRoundOpen(e){let t="(";return e===t?(this.pushToken({tokens:[42],pos:this.generatePos(e,t),value:t}),!0):!1}isRoundClose(e){let t=")";return e===t?(this.pushToken({tokens:[43],pos:this.generatePos(e,t),value:t}),!0):!1}isSquareOpen(e){let t="[";return e===t?(this.pushToken({tokens:[11],pos:this.generatePos(e,t),value:t}),!0):!1}isSquareClose(e){let t="]";return e===t?(this.pushToken({tokens:[12],pos:this.generatePos(e,t),value:t}),!0):!1}isComma(e){let t=",";return e===t?(this.pushToken({tokens:[24],pos:this.generatePos(e,t),value:t}),!0):!1}rewind(e){if(this.columnNumber+1<e.length)throw new Error("Error while rewinding");this.columnNumber-=e.length}isString(e){if(this.inComment)return!1;let t=e.match(/^["']/);if(t?.[0]){this.rewind(e.slice(1));let r=this.lineNumber,s=this.columnNumber,i=this.getString(t[0]);return this.pushToken({tokens:[21],value:i,pos:{col:s-1,line:r,len:i.length+this.numberOfEscapedCharsLastString}}),!0}return!1}isForwardSlash(e){let t="/";return e===t?(this.pushToken({tokens:[13],pos:this.generatePos(e,t),value:"/"}),!0):!1}isBackSlash(e){let t="\\";return e===t?(this.pushToken({tokens:[14],pos:this.generatePos(e,t),value:"\\"}),!0):!1}isAddOperator(e){let t="+";return e===t?(this.pushToken({tokens:[15],pos:this.generatePos(e,t),value:t}),!0):!1}isQuestionMark(e){let t="?";return e===t?(this.pushToken({tokens:[44],pos:this.generatePos(e,t),value:t}),!0):!1}isPeriod(e){let t=".";return e===t?(this.pushToken({tokens:[45],pos:this.generatePos(e,t),value:t}),!0):!1}isNegateOperator(e){let t="-";return e===t?(this.pushToken({tokens:[16],pos:this.generatePos(e,t),value:t}),!0):!1}isUnderScore(e){let t="_";return e===t?(this.pushToken({tokens:[48],pos:this.generatePos(e,t),value:t}),!0):!1}isAt(e){let t="@";return e===t?(this.pushToken({tokens:[49],pos:this.generatePos(e,t),value:t}),!0):!1}isMultiplicationOperator(e){let t="*";return e===t?(this.pushToken({tokens:[17],pos:this.generatePos(e,t),value:t}),!0):!1}isModulusOperator(e){let t="%";return e===t?(this.pushToken({tokens:[18],pos:this.generatePos(e,t),value:t}),!0):!1}isCDefine(e){let t="#define";return e.toLowerCase()===t?(this.pushToken({tokens:[25],pos:this.generatePos(e,t),value:t}),!0):!1}isCInclude(e){let t="#include";return e.toLowerCase()===t?(this.pushToken({tokens:[26],pos:this.generatePos(e,t),value:t}),!0):!1}isCLine(e){let t="#line";return e.toLowerCase()===t?(this.pushToken({tokens:[27],pos:this.generatePos(e,t),value:t}),!0):!1}isCUndef(e){let t="#undef";return e.toLowerCase()===t?(this.pushToken({tokens:[28],pos:this.generatePos(e,t),value:t}),!0):!1}isCError(e){let t="#error";return e.toLowerCase()===t?(this.pushToken({tokens:[29],pos:this.generatePos(e,t),value:t}),!0):!1}isCPragma(e){let t="#pragma";return e.toLowerCase()===t?(this.pushToken({tokens:[30],pos:this.generatePos(e,t),value:t}),!0):!1}isCDefined(e){let t="#defined";return e.toLowerCase()===t?(this.pushToken({tokens:[31],pos:this.generatePos(e,t),value:t}),!0):!1}isCIf(e){let t="#if";return e.toLowerCase()===t?(this.pushToken({tokens:[32],pos:this.generatePos(e,t),value:t}),!0):!1}isCIfDef(e){let t="#ifdef";return e.toLowerCase()===t?(this.pushToken({tokens:[33],pos:this.generatePos(e,t),value:t}),!0):!1}isCIfNDef(e){let t="#ifndef";return e.toLowerCase()===t?(this.pushToken({tokens:[34],pos:this.generatePos(e,t),value:t}),!0):!1}isCElIf(e){let t="#elif";return e.toLowerCase()===t?(this.pushToken({tokens:[35],pos:this.generatePos(e,t),value:t}),!0):!1}isCElse(e){let t="#else";return e.toLowerCase()===t?(this.pushToken({tokens:[36],pos:this.generatePos(e,t),value:t}),!0):!1}isCEndIf(e){let t="#endif";return e.toLowerCase()===t?(this.pushToken({tokens:[37],pos:this.generatePos(e,t),value:t}),!0):!1}isCTrue(e){let t="true";return e==t?(this.pushToken({tokens:[38],value:t,pos:this.generatePos(e,t)}),!0):!1}isCFalse(e){let t="false";return e==t?(this.pushToken({tokens:[39],value:t,pos:this.generatePos(e,t)}),!0):!1}generatePos(e,t){return{line:this.lineNumber,col:this.columnNumber-e.length+this.lineNumberOfEscapedChars,len:t.length}}};var Hk,sm=class n{constructor(){this.fileMap=new Map}static clone(e){let t=e.map(r=>({...r}));return t.forEach((r,s)=>{r.prevToken=t[s-1],r.nextToken=t[s+1]}),t}needsRenew(e,t){return this.fileMap.get(e)?.text!==t}renewLexer(e,t){if(!e||!(0,Pu.existsSync)(e))return[];try{t??=(0,Pu.readFileSync)(e).toString();let r=new Nu(t,e);return this.fileMap.set(e,r),n.clone(r.tokens)}catch{}return[]}requestTokens(e,t){let r=this.fileMap.get(e)?.tokens;return!r&&t?[...this.renewLexer(e)]:n.clone(r??[])}reset(e){this.fileMap.delete(e)}};function Vn(){return Hk??=new sm,Hk}var Ru=class n{constructor(e){this.context=e;this.comments=[];this.includes=[];this.roots=[];this.references=[];this.unlinkedDeletes=[];this.unlinkedRefNodes=[];this.globalDeletes=[];this.rootNode=new Ee(this.context.bindingLoader,"/");this.labelsUsedCache=new Map}static{this.getFileTopMostAst=(e,t)=>e.uri===t?[e]:e.children.flatMap(r=>n.getFileTopMostAst(r,t))}fileTopMostAst(e){return[...this.roots,...this.references,...this.unlinkedDeletes,...this.unlinkedRefNodes,...this.globalDeletes,...this.includes,...this.comments].flatMap(t=>n.getFileTopMostAst(t,e))}getDeepestAstNode(e,t){let s=this.fileTopMostAst(e).find(i=>hn(i,e,t)||tk(Vn().requestTokens(e,!1),i,t));if(s instanceof kt){let o=this.rootNode.getReferenceBy(s)?.getDeepestAstNode(e,t);return o?{...o,runtime:this}:{item:null,runtime:this,ast:sr(s,e,t)}}else if(s instanceof Ht&&s.path){let i=this.rootNode.getDeepestAstNode(e,t);return i?{...i,runtime:this}:void 0}else if(s instanceof we&&s.path){let i=n.getNodeFromPath(s.path.slice(1),this.rootNode)?.getDeepestAstNode(e,t);return i?{...i,runtime:this}:void 0}else if(s)return{runtime:this,item:null,ast:sr(s,e,t)}}static getNodeFromPath(e,t,r=!0){if(e.length===0)return t;let s=e[0].split("@"),i=s[0],a=s.at(1)?.split(",").map(u=>Number.parseInt(u,16)),c=e.slice(1),l=t.getNode(i,a,r);return l?n.getNodeFromPath(c,l,r):void 0}resolvePath(e,t){if(!e.at(0)?.startsWith("&"))return e;let r=this.labelsUsedCache.get(e[0].slice(1));return r||(t??=this.rootNode.allDescendantsLabels,t.find(i=>i.label.value===e.at(0)?.slice(1)&&i.parentNode instanceof Be)?.lastLinkedTo?.path)}get issues(){return[...this.labelIssues(),...this.rootNode.issues]}labelIssues(){let e=[],t=new Map;return this.rootNode.allDescendantsLabelsMapped.forEach(r=>{t.has(r.label.label.value)?t.get(r.label.label.value)?.push(r):t.set(r.label.label.value,[r])}),Array.from(t).forEach(r=>{let s=r[1];if(s.length>1){let i=s.find(a=>a.owner instanceof Ee);if(!s.every(a=>a&&a.owner===i?.owner)||!i){let a=s.filter(c=>!(c&&c.owner===i?.owner));e.push(A(4,s.at(0).label,Kk.DiagnosticSeverity.Error,s.slice(1).map(c=>c.label),[],[s.at(0).label.label.value]))}}}),e}get typesIssues(){let e=t=>[...t.nodeType?.getIssue(this,t)??[],...t.nodes.flatMap(r=>e(r))];return e(this.rootNode)}getOrderedNodeAst(e){return nk([...e.definitions,...e.referencedBy])}};var mt=class extends B{constructor(e){super(e),this.semanticTokenType="keyword",this.semanticTokenModifiers="declaration"}};var zk=G(X()),Du=class extends B{constructor(t){super();this.values=t;this.docSymbolsMeta={name:"Values",kind:zk.SymbolKind.String},this.values.forEach(r=>this.addChild(r))}toString(){return this.values.map(t=>t?.toString()).join(",")}toJson(){return this.values.length===1?this.values[0]?.toJson():this.values.map(t=>t?.toJson())}};var Gk=G(X()),Cu=class extends B{constructor(t){super();this.keyword=t;this.addChild(t),this.docSymbolsMeta={name:"DTS Document version",kind:Gk.SymbolKind.Function}}};var ur=class extends B{constructor(t,r){super();this.value=t;this.labels=r;this.labels.forEach(s=>{this.addChild(s)}),this.addChild(this.value)}toString(){return`${this.labels.map(t=>t.toString()).join(" ")}${this.value?.toString()??"NULL"}`}};var im=G(X());var Ou=class extends or{constructor(t,r,s){super(r);this.value=t;this.docSymbolsMeta={name:`param${s+1}`,kind:im.SymbolKind.Variable},this.semanticTokenType="variable",this.semanticTokenModifiers="declaration"}toString(){return this.value}},Au=class extends or{constructor(t,r){super();this.functionName=t;this.params=r;this.addChild(t),this.params.forEach(s=>this.addChild(s))}getDocumentSymbols(t){return this.uri!==t?[]:[{name:this.functionName.name,kind:im.SymbolKind.Function,range:oe(this),selectionRange:oe(this),children:this.params.flatMap(r=>r?.getDocumentSymbols(t)??[])}]}toString(){return`${this.functionName.toString()}(${this.params.map(t=>t?.toString()??"<NULL>").join(",")})`}};var Yk=G(X());var Xi=class extends or{constructor(t,r){super(r);this.name=t;this.docSymbolsMeta={name:this.name.toString(),kind:Yk.SymbolKind.Variable},this.semanticTokenType="macro",this.semanticTokenModifiers="declaration"}toString(){return this.name}};var Iu=class extends B{constructor(t,r){super(r);this.operator=t;this.semanticTokenType="operator",this.semanticTokenModifiers="declaration"}toString(){return this.operator}};var ss=class{constructor(){this.positionStack=[];this._issues=[];this.issueLengthPositionStack=[];this.moveEndOfLine=(e,t=!0)=>{let r=e.pos.line;if(this.currentToken?.pos.line!==r||this.currentToken?.uri!==e.uri)return;let s=this.currentToken,i=s;for(;this.currentToken?.pos.line===r;)i=this.moveToNextToken;if(t){let o=new B(J(s,i));this._issues.push(A(22,o))}return i};this.parsing=new Promise(e=>{setTimeout(()=>{this.parse().then(e)})})}reset(){this.issueLengthPositionStack=[],this.positionStack=[],this._issues=[]}get issues(){return this._issues}get stable(){return this.parsing}get done(){return this.peekIndex()>=this.tokens.length}get moveToNextToken(){let e=this.currentToken;return this.moveStackIndex(),e}enqueueToStack(){this.issueLengthPositionStack.push(this._issues.length),this.positionStack.push(this.peekIndex())}popStack(){let e=this.issueLengthPositionStack.pop()??0;e!==this._issues.length&&this._issues.splice(e),this.positionStack.pop()}mergeStack(){let e=this.issueLengthPositionStack.pop(),t=this.positionStack.pop();if(t===void 0||e===void 0)throw new Error("Index out of bounds");this.positionStack[this.positionStack.length-1]=t}peekIndex(e=1){let t=this.positionStack.at(-1*e);if(t===void 0)throw new Error("Index out of bounds");return t}get currentToken(){return this.tokens.at(this.peekIndex())}get prevToken(){let e=this.peekIndex()-1;if(e!==-1)return this.tokens[e]}moveStackIndex(){if(this.positionStack[this.positionStack.length-1]===void 0)throw new Error("Index out of bounds");this.positionStack[this.positionStack.length-1]++}checkConcurrentTokens(e){this.enqueueToStack();let t=[];return e.every(r=>{let s=this.currentToken,i=r(s),o=!1;return i!=="no"&&s&&(t.push(s),this.moveToNextToken,o=pn(s,this.currentToken)),i==="yes"&&o}),this.mergeStack(),t}consumeAnyConcurrentTokens(e){this.enqueueToStack();let t=[],r,s=!0;for(;e.some(i=>i(this.currentToken)==="yes"&&s);)t.push(this.currentToken),r=this.currentToken,this.moveToNextToken,s=pn(r,this.currentToken);return this.mergeStack(),t}getDocumentSymbols(e){return this.allAstItems.flatMap(t=>t.getDocumentSymbols(e))}getWorkspaceSymbols(){return this.allAstItems.flatMap(e=>e.getWorkspaceSymbols())}buildSemanticTokens(e,t){let r=[],s=(i,o,a)=>{if(!a?.start||!a?.end||a.start.uri!==t||a.end.uri!==t)return;let c=a.end.pos.col-a.start.pos.col+a.end.pos.len;r.push({line:a.start.pos.line,char:a.start.pos.col,length:a.end===a.start?a.end.pos.len:c,tokenType:i,tokenModifiers:o})};this.allAstItems.forEach(i=>{i.buildSemanticTokens(s)}),r.sort((i,o)=>i.line===o.line?i.char-o.char:i.line-o.line).forEach(i=>e.push(i.line,i.char,i.length,i.tokenType,i.tokenModifiers))}processCIdentifier(){this.enqueueToStack();let e=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!e.length){this.popStack();return}let t=e.map(s=>s.value).join("");if(!t.match(/^[_A-Za-z]/)){this.popStack();return}let r=new Xi(t,J(e[0],e.at(-1)));return this.mergeStack(),r}isOperator(){this.enqueueToStack();let e=this.moveToNextToken;if(!e){this.popStack();return}let t=e,r;if(x(e,40)?(r="&",x(this.currentToken,40)&&(r="&&",t=this.moveToNextToken)):x(e,10)?(r="!",x(this.currentToken,0)&&(r="==",t=this.moveToNextToken)):x(e,8)?(r="|",x(this.currentToken,8)&&(r="||",t=this.moveToNextToken)):x(e,9)?r="^":x(e,4)?(r=">",x(this.currentToken,4)?(r="<<",t=this.moveToNextToken):x(this.currentToken,0)&&(r=">=",t=this.moveToNextToken)):x(e,5)?(r=">",x(this.currentToken,5)?(r=">>",t=this.moveToNextToken):x(this.currentToken,0)&&(r="<=",t=this.moveToNextToken)):x(e,15)?r="+":x(e,16)?r="-":x(e,17)?r="*":x(e,13)?r="/":x(e,18)?r="%":x(e,46)&&x(this.currentToken,46)&&(r="##",t=this.moveToNextToken),r){let s=new Iu(r,J(e,t));return this.mergeStack(),s}this.popStack()}parseScopedBlock(e,t,r){this.enqueueToStack();let s=this.moveToNextToken;if(!s||!e(s)){this.popStack();return}let i=[],o=[];for(o[0]=[];!t(this.currentToken);){let l=this.moveToNextToken;if(r?.(l)&&(o[o.length]=[]),l&&(i.push(l),o[o.length-1].push(l)),e(this.currentToken)){let u=this.parseScopedBlock(e,t,r);u&&(i.push(u),o[o.length-1].push(u.startToken,...u.splitTokens.flat(),u.endToken))}}let a=this.moveToNextToken,c={startToken:s,items:i,splitTokens:o,endToken:a};return this.mergeStack(),c}getTokenIndex(e){return e?this.tokens.findIndex(t=>t===e):-1}};var om=require("fs"),Qi=require("path");var $u=class n extends ss{constructor(t){super();this.uri=t;this.comments=[];this.tokens=[]}cleanUpComments(){let t=[];for(let r=0;r<this.tokens.length;r++){let s=n.processBlockComments(this.tokens,r)||n.processLineComments(this.tokens,r);s&&(r=s.index,t.push(...s.tokenUsed),this.comments.push(...s.comments))}t.reverse().forEach(r=>this.tokens.splice(r,1))}get allAstItems(){return this.comments}reset(){super.reset(),this.comments=[]}reparse(){return this.reset(),this.parse()}async parse(){this.tokens=Vn().requestTokens(this.uri,!0),this.cleanUpComments()}static processBlockComments(t,r){let s=[],i=()=>(s.push(r++),t[r]),o=()=>t[r],a=()=>t[r-1],c=o(),l=c;if(!c||!x(c,13)||(l=i(),!x(l,17)||c.pos.line!==l.pos.line||c.pos.col+1!==l.pos.col))return;let u=()=>!(!x(a(),17)||!x(o(),13)||!pn(a(),o())),d=l.pos.line,f=c,m=[];l=i();do{if(o()?.pos.line!==d){let g=new cr(J(f,a()));m.push(g),d=o().pos.line??0,f=o()}l=i()}while(r<t.length&&!u());let T=new cr(J(f,o()));return m.push(T),i(),{comments:m,tokenUsed:s,index:r-1}}static processLineComments(t,r){let s=[];if(!x(t[r],13)||t.length===r+1||!x(t[r+1],13)||!pn(t[r],t[r+1]))return;let i=[];for(;t[r].pos.line===t.at(r+1)?.pos.line;)s.push(r++);s.push(r++);let o=t[s.at(-1)],a=new cr(J(t[s[0]],t[s.at(-1)]));return i.push(a),{comments:i,tokenUsed:s,index:r-1}}};var Lu=class extends B{constructor(t,r){super(t);this.content=r}toString(){let t=this.content.filter(r=>!x(r,14));return t.map((r,s)=>{let i=r.value;return r.pos.line===t.at(s+1)?.pos.line?i=i.padEnd(t[s+1].pos.col-r.pos.col," "):t.at(s+1)&&(i=i.padEnd(i.length+1," ")),i}).join("")}},xu=class extends B{constructor(t,r,s){super();this.keyword=t;this.identifier=r;this.content=s;this.addChild(t),this.addChild(this.identifier),this.content&&this.addChild(this.content)}get name(){return this.identifier instanceof Xi?this.identifier.name:this.identifier.functionName.name}toString(){return[this.identifier.toString(),...this.content?[this.content?.toString()]:[]].join(" ")}};var Jk=G(X());var qu=class extends mt{toString(){return"..."}},ju=class extends B{constructor(t,r){super();this.functionName=t;this.params=r;this.addChild(t),this.params.forEach(s=>this.addChild(s))}getDocumentSymbols(t){return this.uri!==t?[]:[{name:this.functionName.name,kind:Jk.SymbolKind.Function,range:oe(this),selectionRange:oe(this),children:this.params.flatMap(r=>r.getDocumentSymbols(t))}]}toString(){return`${this.functionName}(${this.params.map(t=>t.toString()).join(",")})`}};var ca=class extends B{constructor(e){super(e)}},Fu=class extends B{constructor(t,r){super();this.keyword=t;this.content=r;this.addChild(t)}},la=class extends Fu{constructor(t,r,s){super(t,s);this.identifier=r;this.addChild(r),this.addChild(s)}useBlock(t){return this.identifier&&t.has(this.identifier.name)}},Bu=class extends la{useBlock(e){return this.identifier&&!e.has(this.identifier.name)}},Uu=class extends Fu{};var Vu=class extends B{constructor(t,r,s){super();this.ifDef=t;this.endIf=r;this.elseOption=s;this.addChild(t),s&&this.addChild(s),this.addChild(r)}getInValidTokenRange(t,r){let s=[],i=a=>r.findIndex(c=>c===a);if(!this.ifDef.identifier?.name)return[{start:i(this.tokenIndexes.start),end:i(this.tokenIndexes.end)}];s.push({start:i(this.ifDef.tokenIndexes.start),end:i(this.ifDef.identifier.tokenIndexes.end)});let o=this.ifDef.useBlock(t);return!o&&this.ifDef.content&&s.push({start:i(this.ifDef.content.tokenIndexes.start),end:i(this.ifDef.content.tokenIndexes.end)}),this.elseOption&&(s.push({start:i(this.elseOption.tokenIndexes.start),end:i(this.elseOption.keyword.tokenIndexes.end)}),o&&this.elseOption.content&&s.push({start:i(this.elseOption.content.tokenIndexes.start),end:i(this.elseOption.content.tokenIndexes.end)})),this.endIf&&s.push({start:i(this.endIf.tokenIndexes.start),end:i(this.endIf.tokenIndexes.end)}),s}};var Xk=G(X()),Wu=class n extends ss{constructor(t,r,s=new Map){super();this.uri=t;this.incudes=r;this.macros=s;this.tokens=[];this.nodes=[];this.dtsIncludes=[];this.macroSnapShot=new Map;Array.from(s).forEach(([i,o])=>this.macroSnapShot.set(i,o))}reset(){super.reset(),this.macros.clear(),Array.from(this.macroSnapShot).forEach(([t,r])=>this.macros.set(t,r)),this.nodes=[],this.dtsIncludes=[]}async reparse(){let t=this.stable;return this.parsing=new Promise(r=>{t.then(()=>{this.reset(),this.parse().then(r)})}),this.parsing}async parse(){let t=new $u(this.uri);if(await t.stable,this.tokens=t.tokens,this.nodes.push(...t.allAstItems),this.positionStack.push(0),this.tokens.length!==0){for(;!this.done;)await this.lineProcessor();if(this.positionStack.length!==1)throw new Error("Incorrect final stack size")}}async lineProcessor(){if(this.enqueueToStack(),!(!this.prevToken||this.prevToken.pos.line!==this.currentToken?.pos.line||this.prevToken.uri!==this.currentToken?.uri)){this.moveEndOfLine(this.prevToken,!1),this.mergeStack();return}let r=this.currentToken,s=this.currentToken?.uri,i=await this.processInclude()||this.processDefinitions()||this.processIfDefBlocks();r&&this.moveEndOfLine(r,!!i),this.mergeStack()}processDefinitions(){this.enqueueToStack();let t=this.peekIndex(),r=this.moveToNextToken;if(!r||!x(r,25))return this.popStack(),!1;let s=new mt(J(r)),i=this.isFunctionDefinition()||this.processCIdentifier();if(!i)return this._issues.push(A(30,s)),this.mergeStack(),!0;let o=this.consumeDefinitionContent(),a;o.length&&(a=new Lu(J(o[0],o.at(-1)),o));let c=new xu(s,i,a);this.macros.set(c.name,c),this.nodes.push(c);let l=this.peekIndex();return this.tokens.splice(t,l-t),this.positionStack[this.positionStack.length-1]=t,this.mergeStack(),!0}consumeDefinitionContent(){let t=[],r=this.prevToken;for(;ir(r,this.currentToken)||r&&x(r,14)&&r.pos.line+1===this.currentToken?.pos.line;)r=this.moveToNextToken,r&&t.push(r);return t}isFunctionDefinition(){this.enqueueToStack();let t=this.processCIdentifier();if(!t){this.popStack();return}let r=this.moveToNextToken;if(!x(r,42)){this.popStack();return}let s=[],i=this.processCIdentifier()||this.processVariadic();for(;i;)s.push(i),!x(this.currentToken,24)&&!x(this.currentToken,43)?this._issues.push(A(28,i)):x(this.currentToken,43)||(r=this.moveToNextToken),i=this.processCIdentifier()||this.processVariadic();let o=new ju(t,s);return x(this.currentToken,43)?(r=this.moveToNextToken,o.lastToken=r):(o.lastToken=this.prevToken,this._issues.push(A(26,s.at(-1)??o))),this.mergeStack(),o}processVariadic(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(45),Pe(45),Pe(45)]);if(t.length!==3){this.popStack();return}let r=new qu(J(t[0],t.at(-1)));return this.mergeStack(),r}processIfDefBlocks(){let t=this.peekIndex(),r=this.parseScopedBlock(s=>{let i=this.getTokenIndex(s)-1;return!!s&&[33,34].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)},s=>{let i=this.getTokenIndex(s)-1;return!!s&&[37].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)},s=>{let i=this.getTokenIndex(s)-1;return!!s&&[36].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)});if(r&&(x(r.startToken,33)||x(r.startToken,34))){let s;x(r.startToken,33)?s=this.processIfDefBlock(r,(o,a,c)=>new la(o,a??null,c)):s=this.processIfDefBlock(r,(o,a,c)=>new Bu(o,a??null,c)),this.nodes.push(s),s.getInValidTokenRange(this.macros,this.tokens).reverse().forEach(o=>{this.tokens.splice(o.start,o.end-o.start+1)}),this.positionStack[this.positionStack.length-1]=t;return}}processIfDefBlock(t,r){this.enqueueToStack();let s=new mt(J(t.startToken)),i=new mt(J(t.endToken));this.positionStack[this.positionStack.length-1]=this.getTokenIndex(t.startToken)+1;let o=this.processCIdentifier();o||this._issues.push(A(31,s));let a=this.getTokenIndex(t.splitTokens[0].at(-1)),c=new ca(J(this.currentToken,this.tokens[a])),l=r(s,o??null,c),u;if(t.splitTokens.length>1){let f=this.getTokenIndex(t.splitTokens[1][0]),m=new mt(J(this.tokens[f])),T=new ca(J(this.tokens[f+1],t.splitTokens[1].at(-1)));u=new Uu(m,T)}let d=new Vu(l,i,u);return this.mergeStack(),d}get allAstItems(){return[...this.dtsIncludes,...this.nodes]}resolveInclude(t){if(t.path.path)return t.path.relative?[(0,Qi.resolve)((0,Qi.dirname)(t.uri),t.path.path),...this.incudes.map(r=>(0,Qi.resolve)(r,t.path.path))].find(r=>(0,om.existsSync)(r)):this.incudes.map(r=>(0,Qi.resolve)(r,t.path.path)).find(r=>(0,om.existsSync)(r))}async processInclude(){this.enqueueToStack();let t=this.peekIndex(),r=this.currentToken;if(!r)return this.popStack(),!1;let s=r,i=r;if(x(r,26))this.moveToNextToken;else{let g=this.checkConcurrentTokens([Pe(13),Xe("include"),Pe(13)]);if(g.length!==3)return this.popStack(),!1;s=g[0],i=g.at(-1)}let o=s,a=new mt(J(s,i));r=this.moveToNextToken;let c=r,l=!!x(r,21);if(!c||!l&&!x(r,5))return o&&this.moveEndOfLine(o),this.mergeStack(),!0;let u="";if(l)u=r?.value??"";else for(;this.currentToken?.pos.line===o.pos.line&&!x(this.currentToken,4);)u+=this.currentToken?.value??"",r=this.moveToNextToken;let d=new Vi(u,l,J(c,r)),f=new es(a,d);this.dtsIncludes.push(f),l||(this.currentToken?.pos.line!==o.pos.line||!x(this.currentToken,4)?this._issues.push(A(12,f)):(r=this.moveToNextToken,d.lastToken=r)),this.mergeStack();let m=this.peekIndex(),T=this.resolveInclude(f);if(f.reolvedPath=T,T||this._issues.push(A(36,f.path,Xk.DiagnosticSeverity.Warning)),T&&!T.endsWith(".h")){Vn().requestTokens(T,!0);let g=new n(T,this.incudes,this.macros);await g.stable,this.tokens.splice(t,m-t,...g.tokens),this.nodes.push(...g.nodes),this.dtsIncludes.push(...g.dtsIncludes)}else this.tokens.splice(t,m-t);return this.positionStack[this.positionStack.length-1]=t,!0}};var Qk=G(X()),Hu=class extends B{constructor(t,r,s){super();this.keyword=t;this.startAddress=r;this.endAddress=s;this.addChild(t),this.docSymbolsMeta={name:"Memreserve",kind:Qk.SymbolKind.Function},this.addChild(r),this.addChild(s)}toString(){return`/memreserve/ 0x${this.startAddress?.value?.toString(16)} 0x${this.endAddress?.value?.toString(16)}`}};var Zk=G(X()),Ku=class extends B{constructor(t,r){super();this.keyword=t;this.bitsSize=r;this.addChild(t),this.docSymbolsMeta={name:"bits",kind:Zk.SymbolKind.Function},this.addChild(r)}toString(){return`/bits/ ${this.bitsSize?.value?.toString()}`}};var eE=G(X()),ua=class extends ss{constructor(t,r,s=new Map){super();this.uri=t;this.incudes=r;this.tokens=[];this.others=[];this.rootDocument=new Be;this.unhandledStatements=new Ht;this.cPreprocessorParser=new Wu(this.uri,this.incudes,s)}get issues(){return[...this._issues,...this.cPreprocessorParser.issues]}getFiles(){return[this.uri,...this.cPreprocessorParser.dtsIncludes.flatMap(t=>t.reolvedPath).filter(t=>!!t)]}reset(){super.reset(),this.others=[],this.rootDocument=new Be,this._issues=[],this.unhandledStatements=new Ht}async reparse(){let t=performance.now(),r=this.stable;return this.parsing=new Promise(s=>{r.then(async()=>{this.reset(),await this.cPreprocessorParser.reparse(),await this.parse(),console.log("parsing",performance.now()-t),s()})}),this.parsing}async parse(){let t=performance.now();if(await this.cPreprocessorParser.stable,this.tokens=this.cPreprocessorParser.tokens,this.uri.endsWith(".h")||(this.positionStack.push(0),this.tokens.length===0))return;let r=async()=>{if(!(this.isDtsDocumentVersion()||this.isMemreserve()||this.isRootNodeDefinition(this.rootDocument)||this.isDeleteNode(this.rootDocument,"Ref")||this.isChildNode(this.rootDocument,"Ref")||this.isProperty(this.unhandledStatements)||this.isDeleteProperty(this.unhandledStatements))){let s=this.moveToNextToken;if(s){let i=new B(J(s));this._issues.push(A(22,i)),this.reportExtraEndStatements()}}};for(;!this.done;)await r();if(this.unhandledStatements.properties.forEach(s=>{this._issues.push(A(32,s))}),this.unhandledStatements.deleteProperties.forEach(s=>{this._issues.push(A(33,s))}),this.positionStack.length!==1)throw new Error("Incorrect final stack size")}isRootNodeDefinition(t){this.enqueueToStack();let r=this.moveToNextToken,s=r,i=13;if(!r||!x(r,i))return this.popStack(),!1;if(s=this.moveToNextToken,i=2,!s||!x(s,i))return this.popStack(),!1;let o=new Ht;o.openScope=s,t.addNodeChild(o),this.processNode(o,"Name");let a=this.nodeEnd(o)??s;return o.firstToken=r,o.lastToken=a,this.mergeStack(),!0}nodeEnd(t){let r=this.currentToken;if(x(r,3))this.moveToNextToken;else{let s=this.prevToken;if(s){let i=new B(J(s));this._issues.push(A(3,i))}return this.endStatement(!1)}return this.prevToken?.value==="}"&&(t.closeScope=this.prevToken),this.endStatement()}isNodeEnd(){return x(this.currentToken,3)||x(this.currentToken,1)}endStatement(t=!0){let r=this.currentToken;if(!x(r,1)){let s=this.prevToken;if(s&&t){let i=new B(J(this.prevToken));return this._issues.push(A(1,i)),s}}return this.moveToNextToken,this.reportExtraEndStatements(),r}reportExtraEndStatements(){for(;x(this.currentToken,1);){let t=this.moveToNextToken;if(t){let r=new B(J(t));this._issues.push(A(23,r))}}}processNode(t,r){if(this.done)return!1;let s=!1,i=!1;do{if(i=this.isChildNode(t,r)||this.isProperty(t)||this.isDeleteNode(t,r)||this.isDeleteProperty(t),!i&&!this.isNodeEnd()&&!this.done){let o=this.moveToNextToken;if(o){let a=new B(J(o));this._issues.push(A(22,a)),this.reportExtraEndStatements()}}else if(this.done)break;s=s||i}while(!this.isNodeEnd());return s}processOptionalLabelAssign(t=!1){let r=[],s=this.isLabelAssign(t);for(;s;)r.push(s),s=this.isLabelAssign(t);return r}isChildNode(t,r){this.enqueueToStack();let s;r==="Name"&&(s=this.isOmitIfNoRefNode());let i=this.processOptionalLabelAssign(),o,a,c=r==="Ref"?new kt(i):new we(i,s);if(r==="Ref"?a=this.isLabelRef():r==="Name"&&(o=this.isNodeName()),!a&&!o){if(!x(this.currentToken,2))return this.popStack(),!1;c.firstToken=this.currentToken,this._issues.push(A(r==="Name"?[7]:[10,11],c))}let l=!1;if(a&&c instanceof kt?(c.labelReference=a,l=!0):o&&c instanceof we&&(l=o.address!==void 0,c.name=o),x(this.currentToken,2)){this.moveToNextToken,c.openScope=this.prevToken;let u=!1;do u=this.processNode(c,"Name");while(u);let d=this.nodeEnd(c);c.lastToken=d}else if(l){let u=a??o;u&&this._issues.push(A(2,u))}else return this.popStack(),!1;return t.addNodeChild(c),this.mergeStack(),!0}processNodeAddress(){let t=this.prevToken,r=this.consumeAnyConcurrentTokens([19,20].map(Pe)),s=r.length?Number.parseInt(r.map(o=>o.value).join(""),16):NaN;if(t){if(Number.isNaN(s)){let o=new B(J(t));this._issues.push(A(8,o))}else if(!Number.isNaN(s)&&!pn(t,r[0])){let o=new B(J(t,r.at(0)));this._issues.push(A(29,o))}}return new Tu(s,J(r[0]??this.prevToken,r.at(-1)))}processNodeAddresse(t){this.enqueueToStack();let r=this.checkConcurrentTokens([Pe(49)]);if(r.length){if(!pn(t.lastToken,r[0])){let o=new B(J(t.lastToken,r[0]));this._issues.push(A(29,o))}let s=[],i=()=>{if(s.push(this.processNodeAddress()),x(this.currentToken,24)){if(this.prevToken&&!pn(this.prevToken,this.currentToken)){let o=new B(J(this.prevToken,this.currentToken));this._issues.push(A(29,o))}this.moveToNextToken,i()}};return i(),this.mergeStack(),s}this.popStack()}isNodeName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,24,45,48,15,16].map(Pe));if(!t.length){this.popStack();return}let r=t.map(o=>o.value).join("");if(!r.match(/^[A-Za-z]/)){this.popStack();return}let s=new Ie(r,J(t[0],t.at(-1))),i=this.processNodeAddresse(s);return s.address=i,this.mergeStack(),s}isPropertyName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,24,45,48,15,16,44,46].map(Pe));if(!t.length){this.popStack();return}let r=new Fe(t.map(s=>s.value).join(""),J(t[0],t.at(-1)));return this.mergeStack(),r}isLabelName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!t.length){this.popStack();return}let r=t.map(i=>i.value).join("");if(!r.match(/^[A-Za-z]/)){this.popStack();return}let s=new ht(r,J(t[0],t.at(-1)));return this.mergeStack(),s}isLabelAssign(t){this.enqueueToStack();let r=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!r.length){this.popStack();return}let s=r.map(c=>c.value).join("");if(!s.match(/^[A-Za-z]/)){this.popStack();return}let i=this.currentToken,o=i&&x(i,50),a=new rs(new ht(s,J(r[0],r.at(-1))),J(r[0],o?i:r.at(-1)));if(o){let c=r.at(-1);c&&(i.pos.line!==a.firstToken.pos.line||i.pos.col!==c.pos.col+c.pos.len)&&this._issues.push(A(29,new B(J(c,i)))),this.moveToNextToken}else if(t)this._issues.push(A(24,a));else{this.popStack();return}return this.mergeStack(),a}isProperty(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(),s=this.isPropertyName();if(!s)return this.popStack(),!1;if(x(this.currentToken,2)||x(this.currentToken,49))return this.popStack(),!1;let i=new Qe(s,r),o;x(this.currentToken,0)?(this.moveToNextToken,o=this.processValue(i),o?.values.filter(c=>!!c).length||this._issues.push(A(0,i)),i.values=o??null):i.values=void 0;let a=this.endStatement();return i.lastToken=a,t.addNodeChild(i),this.mergeStack(),!0}isDtsDocumentVersion(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("ts"),Pe(16),Xe("v"),Xe("1")]);if(t.length!==6)return this.popStack(),!1;let r=t[0],s=r,i=new mt;i.firstToken=r;let o=new Cu(i);if(this.others.push(o),x(this.currentToken,13))s=this.moveToNextToken;else return i.lastToken=t.at(-1),this._issues.push(A(21,o)),this.mergeStack(),!0;return i.lastToken=s,o.lastToken=this.endStatement(),this.mergeStack(),!0}isMemreserve(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("memreserve")]);if(t.length!==2)return this.popStack(),!1;let r=new mt;r.firstToken=t[0];let i=t[0];x(this.currentToken,13)?(i=this.moveToNextToken,r.lastToken=i):(r.lastToken=t.at(-1),this._issues.push(A(21,r)));let o=this.processHex()||this.processDec(),a=o&&(this.processHex()||this.processDec()),c=new Hu(r,o,a);return this.others.push(c),o||this._issues.push(A(37,r)),a||this._issues.push(A(38,o??r)),c.lastToken=this.endStatement(),this.mergeStack(),!0}processBits(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("b"),Xe("its")]);if(t.length!==3){this.popStack();return}let r=new mt;r.firstToken=t[0];let i=t[0];x(this.currentToken,13)?(i=this.moveToNextToken,r.lastToken=i):(r.lastToken=t.at(-1),this._issues.push(A(21,r)));let o=this.processDec(),a=new Ku(r,o);return this.others.push(a),o?o.value!==8&&o.value!==16&&o.value!==32&&o.value!==64&&this._issues.push(A(40,o)):this._issues.push(A(39,r)),this._issues.push(A(41,a,eE.DiagnosticSeverity.Warning)),this.mergeStack(),a}isOmitIfNoRefNode(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("omit"),Pe(16),Xe("if"),Pe(16),Xe("no"),Pe(16),Xe("ref"),Pe(13)]);if(t.length!==9){this.popStack();return}let r=new mt(J(t[0],t.at(-1)));return this.mergeStack(),r}isDeleteNode(t,r){this.enqueueToStack();let s=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("e"),Xe("lete"),Pe(16),Xe("node")]);if(!s.length)return this.popStack(),!1;let i=s[0],o=i,a=new mt;if(a.firstToken=i,s.length===1&&!x(this.currentToken,2)){this._issues.push(A(25,a)),a.lastToken=s.at(-1);let d=new kn(a);return t.addNodeChild(d),this.mergeStack(),!0}let c=s.map(d=>d.value??"").join("");if(!"/delete-node/".startsWith(c)||c.endsWith("-"))return this.popStack(),!1;a.lastToken=s.at(-1),c!=="/delete-node"?this._issues.push(A(c.startsWith("/delete-n")?34:25,a)):x(this.currentToken,13)?(o=this.moveToNextToken,a.lastToken=o):this._issues.push(A(21,a));let l=new kn(a);if(ir(a.tokenIndexes?.end,i)){let d=this.processNodePathRef();d&&r==="Name"&&this._issues.push(A(7,d));let f=d?void 0:this.isLabelRef();f&&r==="Name"&&this._issues.push(A(7,f));let m=d||f?void 0:this.isNodeName();m&&r==="Ref"&&this._issues.push(A(10,m)),!d&&!m&&!f&&this._issues.push(A([7,10],l)),l.nodeNameOrRef=d??f??m??null}else r==="Name"?this._issues.push(A(7,a)):r==="Ref"&&this._issues.push(A(10,a));let u=this.endStatement();return l.lastToken=u,t.addNodeChild(l),this.mergeStack(),!0}isDeleteProperty(t){this.enqueueToStack();let r=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("e"),Xe("lete"),Pe(16),Xe("property")]);if(!r.length)return this.popStack(),!1;let s=r[0],i=s,o=new mt;if(o.firstToken=s,r.length===1&&!x(this.currentToken,2)){this._issues.push(A(25,o)),o.lastToken=r.at(-1);let u=new He(o);return t.addNodeChild(u),this.mergeStack(),!0}let a=r.map(u=>u.value??"").join("");if(!"/delete-property/".startsWith(a)||a.endsWith("-"))return this.popStack(),!1;o.lastToken=r.at(-1),a!=="/delete-property"?this._issues.push(A(a.startsWith("/delete-p")?35:25,o)):x(this.currentToken,13)?(i=this.moveToNextToken,o.lastToken=i):this._issues.push(A(21,o));let c=new He(o);if(ir(o.tokenIndexes?.end,s)){let u=this.isPropertyName();u||this._issues.push(A(6,c)),c.propertyName=u??null}else this._issues.push(A(6,o));let l=this.endStatement();return c.lastToken=l,t.addNodeChild(c),this.mergeStack(),!0}isNodePathRef(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.processNodePathRef();if(!r){this.popStack();return}let s=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&s.push(...this.processOptionalLabelAssign(!0));let i=new Bn(t,r,s);return this.mergeStack(),i}processValue(t){this.enqueueToStack();let s=(()=>{let o=()=>(this.processStringValue()||this.isNodePathRef()||this.isLabelRefValue(t)||this.arrayValues(t)||this.processByteStringValue()||this.isExpressionValue())??null,a=o();if(!a)return[];let c=[a];for(;!x(this.currentToken,1);){let l=this.prevToken,u=this.currentToken,d=x(this.currentToken,24);if(d)this.moveToNextToken;else if(!ir(this.prevToken,this.currentToken))break;let f=o();if(u&&f===null&&d){let m=new B(J(u,this.currentToken));this._issues.push(A(0,m))}if(!d&&f===null)break;if(l&&!d&&f){let m=new B(J(l));this._issues.push(A(28,m))}c.push(f)}return c})();if(s.length===0){this.popStack();return}return this.mergeStack(),new Du(s)}processStringValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.moveToNextToken;if(!x(r,21)){this.popStack();return}if(!r?.value)throw new Error("Token must have value");let s=r.value;s.match(/["']$/)&&(s=s.slice(1,-1));let i=new lt(s,J(r));r.value.match(/["']$/)||this._issues.push(A(r.value.startsWith('"')?16:17,i));let o=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(o=this.processOptionalLabelAssign(!0));let a=new Bn(t,i,o);return this.mergeStack(),a}arrayValues(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(!0),s=this.processBits(),i=this.currentToken;if(x(i,5))this.moveToNextToken;else{this.popStack();return}let o=this.processArrayValues(t)??null;o.openBracket=i;let a=this.processOptionalLabelAssign(!0)??[],c=new Bn(r,o,a,s);x(this.currentToken,4)?(o&&(o.closeBracket=this.currentToken),this.moveToNextToken):this._issues.push(A(12,c));let l=[];return this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(l=this.processOptionalLabelAssign(!0)),this.mergeStack(),c.endLabels.push(...l),c.firstToken=i,c.lastToken=this.prevToken,c}processByteStringValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.moveToNextToken,s=r;if(!x(s,11)){this.popStack();return}let i=this.processLabeledValue(()=>this.processHexString()),o=this.processOptionalLabelAssign(!0)??[];i.forEach(u=>{let d=0;u.value?.tokenIndexes?.start===u.value?.tokenIndexes?.end&&(d=u.value?.tokenIndexes?.start?.pos.len??0),d%2!==0&&this._issues.push(A(15,u))});let a=new Zr(i??[]);a.openBracket=s,a.values.length===0&&(a.firstToken=r,this._issues.push(A(14,a)));let c=new Bn(t,a,o);x(this.currentToken,12)?a.openBracket=this.moveToNextToken:this._issues.push(A(5,c));let l=[];return this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(l=this.processOptionalLabelAssign(!0)),this.mergeStack(),c.endLabels.push(...l),c.firstToken=r,a.lastToken=this.prevToken,c}processLabeledValue(t){this.enqueueToStack();let r=t(),s=[];if(!r)return this.popStack(),[];for(;r;)s=[...s,r],r=t();if(s){let i=t();i&&(s=[...s,i])}return this.mergeStack(),s}processArrayValues(t){this.enqueueToStack();let r=this.processLabeledValue(()=>this.processRefValue(!1,t)||this.processLabeledHex(!1)||this.processLabeledDec(!1)||this.processLabeledExpression(!0,!1)),s=new ut(r);return r.length===0&&(s.firstToken=this.currentToken),this.mergeStack(),s}processLabeledHex(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(t),s=this.processHex();if(!s){this.popStack();return}let i=new ur(s,r);return this.mergeStack(),i}processHex(){this.enqueueToStack();let t=this.checkConcurrentTokens([Xe("0"),Xe("x")]);if(t.length!==2){this.popStack();return}let r=this.consumeAnyConcurrentTokens([19,20].map(Pe));if(!r.length){this.popStack();return}let s=Number.parseInt(r.map(o=>o.value).join(""),16),i=new wt(s,J(t[0],r.at(-1)));return this.mergeStack(),i}processHexString(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!1),r=this.checkConcurrentTokens([20,20].map(Pe));if(!r.length){this.popStack();return}let s=Number.parseInt(r.map(a=>a.value).join(""),16),i=new wt(s,J(r[0],r.at(-1))),o=new ur(i,t);return this.mergeStack(),o}processLabeledDec(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(t),s=this.processDec();if(!s){this.popStack();return}let i=new ur(s,r);return this.mergeStack(),i}processDec(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19].map(Pe));if(!t.length){this.popStack();return}let r=Number.parseInt(t.map(i=>i.value).join(""),10),s=new wt(r,J(t[0],t.at(-1)));return this.mergeStack(),s}processLabeledExpression(t=!0,r=t){this.enqueueToStack();let s=[];t&&(s=this.processOptionalLabelAssign(r));let i=this.processExpression();if(!i){this.popStack();return}let o=new ur(i,s);return this.mergeStack(),o}isFunctionCall(){this.enqueueToStack();let t=this.processCIdentifier();if(!t){this.popStack();return}let r=this.processMacroCallParams();if(!r){this.popStack();return}let s=new Au(t,r);return this.mergeStack(),s}isExpressionValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!1),r=this.processExpression();if(!r){this.popStack();return}let s=this.processOptionalLabelAssign(!0),i=new Bn(t,r,s);return this.mergeStack(),i}processExpression(){this.enqueueToStack();let t=!1,r,s;x(this.currentToken,42)&&(t=!0,r=this.moveToNextToken,s=r);let i=this.isFunctionCall()||this.processCIdentifier()||this.processHex()||this.processDec();if(!i){this.popStack();return}if(t){let o=this.isOperator();for(;o;){let a=this.processExpression();a?i instanceof ia?i.addExpression(o,a):i=new ia(i,{operator:o,expression:a}):this._issues.push(A(27,o)),o=this.isOperator()}x(this.currentToken,43)?s=this.moveToNextToken:this._issues.push(A(26,o??i))}return this.mergeStack(),i}processMacroCallParams(){return x(this.currentToken,42)?this.parseScopedBlock(s=>!!x(s,42),s=>!!x(s,43),s=>!!x(s,24))?.splitTokens.map((s,i)=>{if(s.length===0||x(s[0],24)&&s.length===1)return null;let o=i?s.slice(1):s;return new Ou(o.map((a,c)=>{let l=a.value;return a.pos.line===o.at(c+1)?.pos.line&&(l=l.padEnd(o[c+1].pos.col-a.pos.col," ")),l}).join(""),J(o[0],o.at(-1)),i)}):void 0}isLabelRef(t){this.enqueueToStack();let r=this.currentToken;if(x(r,40))this.moveToNextToken;else{this.popStack();return}let s=this.isLabelName();if(!s){let o=new ke(null);return this._issues.push(A(18,t??o)),o.firstToken=r,this.mergeStack(),o}r&&(s.firstToken.pos.line!==r.pos.line||s.firstToken.pos.col!==r.pos.col+r.pos.len)&&this._issues.push(A(29,new B(J(r,s.firstToken))));let i=new ke(s);return i.firstToken=r,this.mergeStack(),i}isLabelRefValue(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(!0),s=this.isLabelRef(t);if(!s){this.popStack();return}let i=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(i=this.processOptionalLabelAssign(!0));let o=new Bn(r,s,i);return this.mergeStack(),o}processRefValue(t,r){this.enqueueToStack();let s=this.processOptionalLabelAssign(t),i=this.currentToken;if(!x(this.currentToken,40)){this.popStack();return}let o=this.processNodePathRef();if(o!==void 0){let l=new ur(o,s);return this.mergeStack(),l}let a=this.isLabelRef(r);if(a===void 0){this._issues.push(A([18,9],r));let l=new ur(null,s);return l.firstToken=s.at(0)?.firstToken??i,this.mergeStack(),l}let c=new ur(a,s);return c.firstToken=s.at(0)?.firstToken??i,this.mergeStack(),c}processNodePath(t=!0,r=new Cr){this.enqueueToStack();let s;if(x(this.currentToken,13))s=this.moveToNextToken;else{if(!t){this.popStack();return}this.prevToken&&this._issues.push(A(19,new B(J(this.prevToken))))}let i=this.isNodeName();return i||this._issues.push(A(7,new B(J(s??this.prevToken)))),r.addPath(i??null,s?new B(J(s)):void 0),this.processNodePath(!1,r),this.mergeStack(),r}processNodePathRef(){this.enqueueToStack();let t=this.moveToNextToken,r=t;if(!x(r,40)){this.popStack();return}let s=this.moveToNextToken;if(r=s,!x(r,2)){this.popStack();return}let i=this.processNodePath(),o=new Fn(i??null),a=this.currentToken??this.prevToken,c=a;return i?.children.forEach((l,u)=>{if(u===i?.children.length-1&&l&&c&&!pn(l.lastToken,c)){this._issues.push(A(29,new B(J(l.lastToken,c))));return}if(u===0&&s&&!pn(s,l?.firstToken)){this._issues.push(A(29,new B(J(s,l?.firstToken))));return}let d=i?.children[u+1];l&&d&&!pn(l.lastToken,d.firstToken)&&this._issues.push(A(29,new B(J(l.lastToken,d?.firstToken))))}),x(a,3)?this.moveToNextToken:this.prevToken&&this._issues.push(A(3,new B(J(this.prevToken)))),o.firstToken=t,o.lastToken=a??this.prevToken,this.mergeStack(),o}get includes(){return this.allAstItems.filter(t=>t instanceof es)}get allAstItems(){return[...this.cPreprocessorParser.allAstItems,...this.rootDocument.children,...this.others,...this.unhandledStatements.properties,...this.unhandledStatements.deleteProperties]}};var Zi=G(X());var tE=require("fs"),nE=require("path");var eo=class{constructor(e,t,r,s=[],i){this.includePaths=t;this.bindingLoader=r;this._issues=[];this.overlays=[];this.overlays=Array.isArray(s)?s:[s],this.overlays.filter(tE.existsSync),this.parser=new ua(e,t),this.name=i??(0,nE.basename)(e),this.overlayParsers=this.overlays?.map(o=>new ua(o,t))??[]}async getContextIssues(){return[...(await this.getRuntime()).issues,...this._issues]}async stable(){await Promise.all([this.parser.stable,...this.overlayParsers.map(e=>e.stable)])}async getRuntime(){return await this.stable(),this._runtime??=this.evaluate(),this._runtime}getContextFiles(){return[...this.overlayParsers.map(e=>e.uri),this.parser.uri,...this.parser.cPreprocessorParser.dtsIncludes.flatMap(e=>e.reolvedPath).filter(e=>!!e)]}isInContext(e){return this.getContextFiles().some(t=>t===e)}async getAllParsers(){return await this.stable(),[this.parser,...this.overlayParsers]}async getDocumentLinks(e,t){if(!this.isInContext(e))return[];let s=(await this.getRuntime()).rootNode.allBindingsProperties.filter(i=>i.ast.uri===e&&(!t||hn(i.ast,e,t))).flatMap(i=>i.ast.values?.values.flatMap(o=>{let c=i.parent?.nodeTypes.find(l=>o?.value instanceof lt&&l.compatible===o.value.value);return c?{range:oe(o.value),target:`file://${c.bindingsPath}`}:void 0})).filter(i=>i)??[];return[...this.parser.cPreprocessorParser.dtsIncludes.filter(i=>i.uri===e&&(!t||hn(i,e,t))).map(i=>{let o=this.parser.cPreprocessorParser.resolveInclude(i);if(o)return{range:oe(i.path),target:`file://${o}`}}).filter(i=>i)??[],...s]}linkPropertiesLabelsAndNodePaths(e){let t=i=>[...i.property,...i.nodes.flatMap(t)],r=t(e.rootNode),s=e.rootNode.allDescendantsLabels;r.forEach(i=>i.ast.allDescendants.forEach(o=>{if(o instanceof ke){let a=e.resolvePath([`&${o.label?.value}`],s);if(a){let c=e.rootNode.getChild(a);o.linksTo=c,c?.linkedRefLabels.push(o)}else o.value&&this._issues.push(A(3,o,Zi.DiagnosticSeverity.Error,[],[],[o.value]))}else if(o instanceof Cr){let a=e.rootNode,c=o.pathParts;for(let l=0;l<c.length&&c[l];l++){let u=!1,d=c[l];if(d){let f=a?.getNode(d.name,d.address?.map(m=>m.address),!1);d.linksTo=f,!u&&!f&&(u=!0,this._issues.push(A(8,d,Zi.DiagnosticSeverity.Error,[],[],[d.toString(),`${o.pathParts.filter(m=>m?.linksTo).map(m=>m?.toString()).join("/")}`]))),f?.linkedNodeNamePaths.push(d),a=f}else break}}}))}async reevaluate(e){return this.isInContext(e)?(await this.parser.reparse(),this._runtime=this.evaluate(),this._runtime):this._runtime}async evaluate(){let e=performance.now();await this.stable();let t=new Ru(this);this._issues=[],this.processRoot(this.parser.rootDocument,t);for(let r=0;r<this.overlayParsers.length;r++)this.processRoot(this.overlayParsers[r].rootDocument,t);return t.includes=this.parser.includes,t.comments=this.parser.cPreprocessorParser.allAstItems.filter(r=>r instanceof cr),(await this.getAllParsers()).flatMap(r=>r.tokens).forEach((r,s)=>r.sortKey=s),this.linkPropertiesLabelsAndNodePaths(t),console.log("evaluate",performance.now()-e),t}processRoot(e,t){for(let r=0;r<e.children.length;r++){let s=e.children[r];this.processChild(s,t.rootNode,t)}}processChild(e,t,r){e instanceof Be?this.processDtcBaseNode(e,t,r):e instanceof Qe?this.processDtcProperty(e,t,r):e instanceof kn?this.processDeleteNode(e,t,r):e instanceof He&&this.processDeleteProperty(e,t,r)}checkNodeUniqueNames(e,t){let r=(o,a)=>o.some(c=>c.name===a.name&&(c.address===void 0||a.address===void 0||c.address.every((l,u)=>a.address?.at(u)?.address===l))),s=t.nodes.map(o=>({name:o.name,address:o.address})),i=[];e.children.forEach(o=>{if(o instanceof we&&o.name)r(i.map(a=>({name:a.name,address:a.address?.map(c=>c.address)})),o.name)&&this._issues.push(A(2,o.name)),i.push(o.name);else if(o instanceof kn&&o.nodeNameOrRef instanceof Ie){let a=o.nodeNameOrRef;r(s,a)&&(i=i.filter(c=>r(i.map(l=>({name:l.name,address:l.address?.map(u=>u.address)})),c)))}})}processDtcBaseNode(e,t,r){e instanceof Ht?this.processDtcRootNode(e,r):e instanceof we?this.processDtcChildNode(e,t,r):e instanceof kt&&this.processDtcRefNode(e,r)}processDtcRootNode(e,t){t.roots.push(e),t.rootNode.definitions.push(e),this.checkNodeUniqueNames(e,t.rootNode),[...e.children].sort((r,s)=>r instanceof Qe&&s instanceof He||s instanceof Qe&&r instanceof He?0:s instanceof Qe?1:0).forEach(r=>this.processChild(r,t.rootNode,t))}processDtcChildNode(e,t,r){if(e.name?.name){let s=e.path?r.resolvePath(e.path):void 0,o=(s?r.rootNode.getChild(s):void 0)??new Ee(this.bindingLoader,e.name.name,e.name.address?.map(a=>a.address),t);o.definitions.push(e),e.labels.forEach(a=>a.lastLinkedTo=o),t=o,this.checkNodeUniqueNames(e,o)}[...e.children].sort((s,i)=>s instanceof Be&&i instanceof Be?0:s instanceof Be?-1:0).forEach(s=>this.processChild(s,t,r))}processDtcRefNode(e,t){let r;if(e.labelReference){let s=e.resolveNodePath??(e.pathName?t.resolvePath([e.pathName]):void 0);s?(e.resolveNodePath??=[...s],r=t.rootNode.getChild(s),e.labelReference.linksTo=r,e.labels.forEach(i=>i.lastLinkedTo=r),r?.linkedRefLabels.push(e.labelReference),r?.referencedBy.push(e),e.labels.forEach(i=>{t.labelsUsedCache.set(i.label.value,s)}),r?(t.references.push(e),this.checkNodeUniqueNames(e,r)):t.unlinkedRefNodes.push(e)):(this._issues.push(A(3,e.labelReference,Zi.DiagnosticSeverity.Error,[],[],[e.labelReference.label?.value??""])),t.unlinkedRefNodes.push(e))}else t.unlinkedRefNodes.push(e);[...e.children].sort((s,i)=>s instanceof Be&&i instanceof Be?0:s instanceof Be?-1:0).forEach(s=>this.processChild(s,r??new Ee(this.bindingLoader,""),t))}processDtcProperty(e,t,r){e.propertyName?.name&&t.addProperty(new pt(e,t)),e.children.forEach(s=>this.processChild(s,t,r))}processDeleteNode(e,t,r){if(e.nodeNameOrRef instanceof Ie&&e.nodeNameOrRef.value){if(e.parentNode?.parentNode)if(!t.hasNode(e.nodeNameOrRef.name,e.nodeNameOrRef.address?.map(s=>s.address)))this._issues.push(A(5,e.nodeNameOrRef));else{t.deletes.push(e);let s=t.getNode(e.nodeNameOrRef.name,e.nodeNameOrRef.address?.map(i=>i.address));e.nodeNameOrRef.linksTo=s,t.deleteNode(e.nodeNameOrRef.name,e,e.nodeNameOrRef.address?.map(i=>i.address)),s?.labels.forEach(i=>{r.labelsUsedCache.delete(i.label.value)})}}else if(e.nodeNameOrRef instanceof ke&&e.nodeNameOrRef.value){let s=r.resolvePath([`&${e.nodeNameOrRef.value}`]),i;s?(i=r.rootNode.getChild(s),t.deletes.push(e),e.nodeNameOrRef.linksTo=i,i?.labels.forEach(o=>{r.labelsUsedCache.delete(o.label.value)}),i?.linkedRefLabels.push(e.nodeNameOrRef),i?.parent?.deleteNode(i.name,e,i.address),e.parentNode instanceof Be&&!e.parentNode.pathName&&r.globalDeletes.push(e)):(r.unlinkedDeletes.push(e),this._issues.push(A(3,e.nodeNameOrRef,Zi.DiagnosticSeverity.Error,[],[],[e.nodeNameOrRef.value])))}else if(e.nodeNameOrRef instanceof Fn&&e.nodeNameOrRef.path&&!e.nodeNameOrRef.path.pathParts.some(s=>!s)){let s=["/",...e.nodeNameOrRef.path.pathParts.map(u=>u.toString())],i=r.rootNode,o=e.nodeNameOrRef.path.pathParts;for(let u=0;u<o.length&&o[u];u++){let d=o[u];if(d){let f=i?.getNode(d.name,d.address?.map(m=>m.address),!1);d.linksTo=f,f?.linkedNodeNamePaths.push(d),i=f}}let a=e.nodeNameOrRef.path.pathParts.every(u=>u),c=e.nodeNameOrRef.path.pathParts.find(u=>u&&!u.linksTo),l=e.nodeNameOrRef.path.pathParts.at(-1)?.linksTo;l||(r.unlinkedDeletes.push(e),c&&this._issues.push(A(8,c,Zi.DiagnosticSeverity.Error,[],[],[c.toString(),`${e.nodeNameOrRef.path.pathParts.filter(u=>u?.linksTo).map(u=>u?.toString()).join("/")}`]))),t.deletes.push(e),l?.labels.forEach(u=>{r.labelsUsedCache.delete(u.label.value)}),l?.parent?.deleteNode(l.name,e,l.address),e.parentNode instanceof Be&&!e.parentNode.pathName&&r.globalDeletes.push(e)}else r.unlinkedDeletes.push(e);e.children.forEach(s=>this.processChild(s,t,r))}processDeleteProperty(e,t,r){e.propertyName?.name&&!t.hasProperty(e.propertyName.name)?this._issues.push(A(1,e.propertyName)):e.propertyName?.name&&(t.deletes.push(e),t.deleteProperty(e.propertyName.name,e)),e.children.forEach(s=>this.processChild(s,t,r))}};var Et=G(X());var rE=require("fs"),to=require("path");function pM(n){if(!n||!(n.ast instanceof Vi))return[];let e=r=>r.flatMap(s=>(0,rE.readdirSync)(s,{withFileTypes:!0,recursive:!0}).filter(i=>i.name.toLowerCase().endsWith(".dtsi")||i.name.toLowerCase().endsWith(".h")).map(i=>({label:`${(0,to.join)((0,to.relative)(s,i.parentPath),i.name)}`,kind:Et.CompletionItemKind.File})));if(n.ast.relative)return e([(0,to.dirname)(n.ast.uri)]);let t=n.runtime.context.includePaths;return e(t)}var zu=(n,e)=>[...n.labels.filter(e),...n.deletedNodes.filter(t=>!e(t.by)).flatMap(t=>zu(t.node,e)),...n.nodes.flatMap(t=>zu(t,e))],am=(n,e)=>[...n.labels,...n.deletedNodes.filter(t=>!e(t.by)).flatMap(t=>am(t.node,e)),...n.nodes.flatMap(t=>am(t,e))];function mM(n,e){if(!n||!(n.item instanceof pt)||!(n.ast instanceof ke))return[];let t=r=>am(r,e);return Array.from(new Set(t(n.runtime.rootNode).map(r=>r.label.value))).map(r=>({label:`${r}`,kind:Et.CompletionItemKind.Method}))}function gM(n,e){if(!n||n.item!==null||!(n.ast instanceof ke)||!(n.ast.parentNode instanceof kt))return[];let t=r=>zu(r,e).filter(s=>e(s));return[...Array.from(new Set(t(n.runtime.rootNode).map(r=>r.label.value))).map(r=>({label:r,insertText:`${r} {
|
|
235
|
+
`)&&this.lines.splice(-1,1),this.lexIt()}get tokens(){return this._tokens}isWhiteSpace(){return!!this.currentChar?.match(/\s/)}get endOfFile(){return this.isOnLastLine&&this.isOnLastCharOfLine}get isOnLastLine(){return this.lineNumber===this.lines.length-1}get isOnLastCharOfLine(){return this.lines[this.lineNumber].length<=this.columnNumber}moveToNextLine(){return this.isOnLastLine?!1:(this.columnNumber=0,this.lineNumberOfEscapedChars=0,this.lineNumber++,this.lines[this.lineNumber].length===0&&this.moveToNextLine(),!0)}moveOnLine(){return this.isOnLastCharOfLine?this.moveToNextLine():(this.columnNumber++,this.isOnLastCharOfLine&&this.moveToNextLine(),!0)}move(){return this.endOfFile?!1:this.moveOnLine()}get currentChar(){return this.endOfFile?null:this.lines[this.lineNumber].at(this.columnNumber)}static isSyntaxChar(e){return e==="^"||e==="~"||e==="|"||e==="!"||e==="\\"||e==="<"||e===">"||e===";"||e==="="||e==="/"||e==="{"||e==="}"||e==="["||e==="]"||e==="("||e===")"||e==="*"||e==="%"||e==="&"||e==="."||e===":"||e==="+"||e==="@"||e==="-"||e==="_"||e===","||e==="x"||e==="?"}getWord(){let e="";for(;!this.isWhiteSpace()&&(e.length&&!n.isSyntaxChar(this.currentChar)||!e.length);){if(e+=this.currentChar??"",e.length===1&&n.isSyntaxChar(this.currentChar)){this.move();break}let t=this.lineNumber;if(!this.move()||this.lineNumber!==t)return e}return e==="/"&&this.currentChar==="*"?this.inComment=!0:this.inComment&&e==="*"&&this.currentChar==="/"&&(this.inComment=!1),e}getString(e){let t=e;for(this.numberOfEscapedCharsLastString=0;this.currentChar!==e;){if(t+=this.currentChar??"",this.currentChar==="\\"){let r=this.lineNumber;if(this.move())this.lineNumberOfEscapedChars++,this.numberOfEscapedCharsLastString++,r===this.lineNumber&&(t+=this.currentChar??"");else return t}if(!this.move())return t}return this.move(),t+=e,t}lexIt(){for(;!this.endOfFile&&(this.whiteSpace(),!this.endOfFile);){let e=this.getWord();e&&this.process(e)}}process(e){let t=this.isString(e)||this.isCDefine(e)||this.isCInclude(e)||this.isCLine(e)||this.isCUndef(e)||this.isCError(e)||this.isCPragma(e)||this.isCDefined(e)||this.isCIfDef(e)||this.isCIfNDef(e)||this.isCIf(e)||this.isCElIf(e)||this.isCElse(e)||this.isCEndIf(e)||this.isCFalse(e)||this.isCTrue(e)||this.isDigit(e)||this.isHexDigit(e)||this.isLetters(e)||this.isComma(e)||this.isBitwiseNot(e)||this.isBitwiseXOr(e)||this.isBitwiseOr(e)||this.isLogicalNot(e)||this.isGtSym(e)||this.isLtSym(e)||this.isSemicolon(e)||this.isColon(e)||this.isAssignOperator(e)||this.isForwardSlash(e)||this.isRoundOpen(e)||this.isRoundClose(e)||this.isCurlyOpen(e)||this.isCurlyClose(e)||this.isSquareOpen(e)||this.isSquareClose(e)||this.isBackSlash(e)||this.isMultiplicationOperator(e)||this.isModulusOperator(e)||this.isAmpersand(e)||this.isNegateOperator(e)||this.isAddOperator(e)||this.isQuestionMark(e)||this.isPeriod(e)||this.isHash(e)||this.isUnderScore(e)||this.isAt(e)||this.unknownToken(e);if(!t)throw new Error(`Lexer is not complete!!! Could not find token for "${e}"`);let r=this._tokens.at(-1);return t&&!r?.tokens.some(s=>s===21)&&r&&r.pos.len<e.length?this.process(e.slice(r.pos.len)):!0}whiteSpace(){for(;this.isWhiteSpace();)this.move()}pushToken(e){let t={...e,uri:this.uri},r=this._tokens.at(-1);t.prevToken=r,r&&(r.nextToken=t),this._tokens.push(t)}isLetters(e){let t=e.match(/^[A-Za-z]+/);return t?.[0]?(this.pushToken({tokens:[47],value:t?.[0],pos:this.generatePos(e,t?.[0])}),!0):!1}isDigit(e){let t=e.match(/^[0-9]/);return t?.[0]?(this.pushToken({tokens:[20,19],value:t[0],pos:this.generatePos(e,t[0])}),!0):!1}isHexDigit(e){let t=e.match(/^[A-Fa-f]/);return t?.[0]?(this.pushToken({tokens:[20,47],value:t[0],pos:this.generatePos(e,t[0])}),!0):!1}isCurlyOpen(e){let t="{";return e===t?(this.pushToken({tokens:[2],pos:this.generatePos(e,t),value:"{"}),!0):!1}isCurlyClose(e){let t="}";return e===t?(this.pushToken({tokens:[3],pos:this.generatePos(e,t),value:"}"}),!0):!1}isSemicolon(e){let t=";";return e===t?(this.pushToken({tokens:[1],pos:this.generatePos(e,t),value:t}),!0):!1}isColon(e){let t=":";return e===t?(this.pushToken({tokens:[50],pos:this.generatePos(e,t),value:t}),!0):!1}isHash(e){let t="#";return e.startsWith(t)?(this.pushToken({tokens:[46],pos:this.generatePos(e,t),value:t}),!0):!1}unknownToken(e){return this.pushToken({tokens:[41],pos:this.generatePos(e," "),value:e}),!0}isAssignOperator(e){let t="=";return e===t?(this.pushToken({tokens:[0],pos:this.generatePos(e,t),value:t}),!0):!1}isGtSym(e){let t=">";return e===t?(this.pushToken({tokens:[4],pos:this.generatePos(e,t),value:t}),!0):!1}isLtSym(e){let t="<";return e===t?(this.pushToken({tokens:[5],pos:this.generatePos(e,t),value:t}),!0):!1}isLogicalNot(e){let t="!";return e===t?(this.pushToken({tokens:[6],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseOr(e){let t="|";return e===t?(this.pushToken({tokens:[8],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseXOr(e){let t="^";return e===t?(this.pushToken({tokens:[9],pos:this.generatePos(e,t),value:t}),!0):!1}isAmpersand(e){let t="&";return e===t?(this.pushToken({tokens:[40,7],pos:this.generatePos(e,t),value:t}),!0):!1}isBitwiseNot(e){let t="~";return e===t?(this.pushToken({tokens:[10],pos:this.generatePos(e,t),value:t}),!0):!1}isRoundOpen(e){let t="(";return e===t?(this.pushToken({tokens:[42],pos:this.generatePos(e,t),value:t}),!0):!1}isRoundClose(e){let t=")";return e===t?(this.pushToken({tokens:[43],pos:this.generatePos(e,t),value:t}),!0):!1}isSquareOpen(e){let t="[";return e===t?(this.pushToken({tokens:[11],pos:this.generatePos(e,t),value:t}),!0):!1}isSquareClose(e){let t="]";return e===t?(this.pushToken({tokens:[12],pos:this.generatePos(e,t),value:t}),!0):!1}isComma(e){let t=",";return e===t?(this.pushToken({tokens:[24],pos:this.generatePos(e,t),value:t}),!0):!1}rewind(e){if(this.columnNumber+1<e.length)throw new Error("Error while rewinding");this.columnNumber-=e.length}isString(e){if(this.inComment)return!1;let t=e.match(/^["']/);if(t?.[0]){this.rewind(e.slice(1));let r=this.lineNumber,s=this.columnNumber,i=this.getString(t[0]);return this.pushToken({tokens:[21],value:i,pos:{col:s-1,line:r,len:i.length+this.numberOfEscapedCharsLastString}}),!0}return!1}isForwardSlash(e){let t="/";return e===t?(this.pushToken({tokens:[13],pos:this.generatePos(e,t),value:"/"}),!0):!1}isBackSlash(e){let t="\\";return e===t?(this.pushToken({tokens:[14],pos:this.generatePos(e,t),value:"\\"}),!0):!1}isAddOperator(e){let t="+";return e===t?(this.pushToken({tokens:[15],pos:this.generatePos(e,t),value:t}),!0):!1}isQuestionMark(e){let t="?";return e===t?(this.pushToken({tokens:[44],pos:this.generatePos(e,t),value:t}),!0):!1}isPeriod(e){let t=".";return e===t?(this.pushToken({tokens:[45],pos:this.generatePos(e,t),value:t}),!0):!1}isNegateOperator(e){let t="-";return e===t?(this.pushToken({tokens:[16],pos:this.generatePos(e,t),value:t}),!0):!1}isUnderScore(e){let t="_";return e===t?(this.pushToken({tokens:[48],pos:this.generatePos(e,t),value:t}),!0):!1}isAt(e){let t="@";return e===t?(this.pushToken({tokens:[49],pos:this.generatePos(e,t),value:t}),!0):!1}isMultiplicationOperator(e){let t="*";return e===t?(this.pushToken({tokens:[17],pos:this.generatePos(e,t),value:t}),!0):!1}isModulusOperator(e){let t="%";return e===t?(this.pushToken({tokens:[18],pos:this.generatePos(e,t),value:t}),!0):!1}isCDefine(e){let t="#define";return e.toLowerCase()===t?(this.pushToken({tokens:[25],pos:this.generatePos(e,t),value:t}),!0):!1}isCInclude(e){let t="#include";return e.toLowerCase()===t?(this.pushToken({tokens:[26],pos:this.generatePos(e,t),value:t}),!0):!1}isCLine(e){let t="#line";return e.toLowerCase()===t?(this.pushToken({tokens:[27],pos:this.generatePos(e,t),value:t}),!0):!1}isCUndef(e){let t="#undef";return e.toLowerCase()===t?(this.pushToken({tokens:[28],pos:this.generatePos(e,t),value:t}),!0):!1}isCError(e){let t="#error";return e.toLowerCase()===t?(this.pushToken({tokens:[29],pos:this.generatePos(e,t),value:t}),!0):!1}isCPragma(e){let t="#pragma";return e.toLowerCase()===t?(this.pushToken({tokens:[30],pos:this.generatePos(e,t),value:t}),!0):!1}isCDefined(e){let t="#defined";return e.toLowerCase()===t?(this.pushToken({tokens:[31],pos:this.generatePos(e,t),value:t}),!0):!1}isCIf(e){let t="#if";return e.toLowerCase()===t?(this.pushToken({tokens:[32],pos:this.generatePos(e,t),value:t}),!0):!1}isCIfDef(e){let t="#ifdef";return e.toLowerCase()===t?(this.pushToken({tokens:[33],pos:this.generatePos(e,t),value:t}),!0):!1}isCIfNDef(e){let t="#ifndef";return e.toLowerCase()===t?(this.pushToken({tokens:[34],pos:this.generatePos(e,t),value:t}),!0):!1}isCElIf(e){let t="#elif";return e.toLowerCase()===t?(this.pushToken({tokens:[35],pos:this.generatePos(e,t),value:t}),!0):!1}isCElse(e){let t="#else";return e.toLowerCase()===t?(this.pushToken({tokens:[36],pos:this.generatePos(e,t),value:t}),!0):!1}isCEndIf(e){let t="#endif";return e.toLowerCase()===t?(this.pushToken({tokens:[37],pos:this.generatePos(e,t),value:t}),!0):!1}isCTrue(e){let t="true";return e==t?(this.pushToken({tokens:[38],value:t,pos:this.generatePos(e,t)}),!0):!1}isCFalse(e){let t="false";return e==t?(this.pushToken({tokens:[39],value:t,pos:this.generatePos(e,t)}),!0):!1}generatePos(e,t){return{line:this.lineNumber,col:this.columnNumber-e.length+this.lineNumberOfEscapedChars,len:t.length}}};var Hk,sm=class n{constructor(){this.fileMap=new Map}static clone(e){let t=e.map(r=>({...r}));return t.forEach((r,s)=>{r.prevToken=t[s-1],r.nextToken=t[s+1]}),t}needsRenew(e,t){return this.fileMap.get(e)?.text!==t}renewLexer(e,t){if(!e||!(0,Pu.existsSync)(e))return[];try{t??=(0,Pu.readFileSync)(e).toString();let r=new Nu(t,e);return this.fileMap.set(e,r),n.clone(r.tokens)}catch{}return[]}requestTokens(e,t){let r=this.fileMap.get(e)?.tokens;return!r&&t?[...this.renewLexer(e)]:n.clone(r??[])}reset(e){this.fileMap.delete(e)}};function Vn(){return Hk??=new sm,Hk}var Ru=class n{constructor(e){this.context=e;this.comments=[];this.includes=[];this.roots=[];this.references=[];this.unlinkedDeletes=[];this.unlinkedRefNodes=[];this.globalDeletes=[];this.rootNode=new Ee(this.context.bindingLoader,"/");this.labelsUsedCache=new Map}static{this.getFileTopMostAst=(e,t)=>e.uri===t?[e]:e.children.flatMap(r=>n.getFileTopMostAst(r,t))}fileTopMostAst(e){return[...this.roots,...this.references,...this.unlinkedDeletes,...this.unlinkedRefNodes,...this.globalDeletes,...this.includes,...this.comments].flatMap(t=>n.getFileTopMostAst(t,e))}getDeepestAstNode(e,t){let s=this.fileTopMostAst(e).find(i=>hn(i,e,t)||tk(Vn().requestTokens(e,!1),i,t));if(s instanceof kt){let o=this.rootNode.getReferenceBy(s)?.getDeepestAstNode(e,t);return o?{...o,runtime:this}:{item:null,runtime:this,ast:sr(s,e,t)}}else if(s instanceof Ht&&s.path){let i=this.rootNode.getDeepestAstNode(e,t);return i?{...i,runtime:this}:void 0}else if(s instanceof we&&s.path){let i=n.getNodeFromPath(s.path.slice(1),this.rootNode)?.getDeepestAstNode(e,t);return i?{...i,runtime:this}:void 0}else if(s)return{runtime:this,item:null,ast:sr(s,e,t)}}static getNodeFromPath(e,t,r=!0){if(e.length===0)return t;let s=e[0].split("@"),i=s[0],a=s.at(1)?.split(",").map(u=>Number.parseInt(u,16)),c=e.slice(1),l=t.getNode(i,a,r);return l?n.getNodeFromPath(c,l,r):void 0}resolvePath(e,t){if(!e.at(0)?.startsWith("&"))return e;let r=this.labelsUsedCache.get(e[0].slice(1));return r||(t??=this.rootNode.allDescendantsLabels,t.find(i=>i.label.value===e.at(0)?.slice(1)&&i.parentNode instanceof Be)?.lastLinkedTo?.path)}get issues(){return[...this.labelIssues(),...this.rootNode.issues]}labelIssues(){let e=[],t=new Map;return this.rootNode.allDescendantsLabelsMapped.forEach(r=>{t.has(r.label.label.value)?t.get(r.label.label.value)?.push(r):t.set(r.label.label.value,[r])}),Array.from(t).forEach(r=>{let s=r[1];if(s.length>1){let i=s.find(a=>a.owner instanceof Ee);if(!s.every(a=>a&&a.owner===i?.owner)||!i){let a=s.filter(c=>!(c&&c.owner===i?.owner));e.push(A(4,s.at(0).label,Kk.DiagnosticSeverity.Error,s.slice(1).map(c=>c.label),[],[s.at(0).label.label.value]))}}}),e}get typesIssues(){let e=t=>[...t.nodeType?.getIssue(this,t)??[],...t.nodes.flatMap(r=>e(r))];return e(this.rootNode)}getOrderedNodeAst(e){return nk([...e.definitions,...e.referencedBy])}};var mt=class extends B{constructor(e){super(e),this.semanticTokenType="keyword",this.semanticTokenModifiers="declaration"}};var zk=G(X()),Du=class extends B{constructor(t){super();this.values=t;this.docSymbolsMeta={name:"Values",kind:zk.SymbolKind.String},this.values.forEach(r=>this.addChild(r))}toString(){return this.values.map(t=>t?.toString()).join(",")}toJson(){return this.values.length===1?this.values[0]?.toJson():this.values.map(t=>t?.toJson())}};var Gk=G(X()),Cu=class extends B{constructor(t){super();this.keyword=t;this.addChild(t),this.docSymbolsMeta={name:"DTS Document version",kind:Gk.SymbolKind.Function}}};var ur=class extends B{constructor(t,r){super();this.value=t;this.labels=r;this.labels.forEach(s=>{this.addChild(s)}),this.addChild(this.value)}toString(){return`${this.labels.map(t=>t.toString()).join(" ")}${this.value?.toString()??"NULL"}`}};var im=G(X());var Ou=class extends or{constructor(t,r,s){super(r);this.value=t;this.docSymbolsMeta={name:`param${s+1}`,kind:im.SymbolKind.Variable},this.semanticTokenType="variable",this.semanticTokenModifiers="declaration"}toString(){return this.value}},Au=class extends or{constructor(t,r){super();this.functionName=t;this.params=r;this.addChild(t),this.params.forEach(s=>this.addChild(s))}getDocumentSymbols(t){return this.uri!==t?[]:[{name:this.functionName.name,kind:im.SymbolKind.Function,range:oe(this),selectionRange:oe(this),children:this.params.flatMap(r=>r?.getDocumentSymbols(t)??[])}]}toString(){return`${this.functionName.toString()}(${this.params.map(t=>t?.toString()??"<NULL>").join(",")})`}};var Yk=G(X());var Xi=class extends or{constructor(t,r){super(r);this.name=t;this.docSymbolsMeta={name:this.name.toString(),kind:Yk.SymbolKind.Variable},this.semanticTokenType="macro",this.semanticTokenModifiers="declaration"}toString(){return this.name}};var Iu=class extends B{constructor(t,r){super(r);this.operator=t;this.semanticTokenType="operator",this.semanticTokenModifiers="declaration"}toString(){return this.operator}};var ss=class{constructor(){this.positionStack=[];this._issues=[];this.issueLengthPositionStack=[];this.moveEndOfLine=(e,t=!0)=>{let r=e.pos.line;if(this.currentToken?.pos.line!==r||this.currentToken?.uri!==e.uri)return;let s=this.currentToken,i=s;for(;this.currentToken?.pos.line===r;)i=this.moveToNextToken;if(t){let o=new B(J(s,i));this._issues.push(A(22,o))}return i};this.parsing=new Promise(e=>{setTimeout(()=>{this.parse().then(e)})})}reset(){this.issueLengthPositionStack=[],this.positionStack=[],this._issues=[]}get issues(){return this._issues}get stable(){return this.parsing}get done(){return this.peekIndex()>=this.tokens.length}get moveToNextToken(){let e=this.currentToken;return this.moveStackIndex(),e}enqueueToStack(){this.issueLengthPositionStack.push(this._issues.length),this.positionStack.push(this.peekIndex())}popStack(){let e=this.issueLengthPositionStack.pop()??0;e!==this._issues.length&&this._issues.splice(e),this.positionStack.pop()}mergeStack(){let e=this.issueLengthPositionStack.pop(),t=this.positionStack.pop();if(t===void 0||e===void 0)throw new Error("Index out of bounds");this.positionStack[this.positionStack.length-1]=t}peekIndex(e=1){let t=this.positionStack.at(-1*e);if(t===void 0)throw new Error("Index out of bounds");return t}get currentToken(){return this.tokens.at(this.peekIndex())}get prevToken(){let e=this.peekIndex()-1;if(e!==-1)return this.tokens[e]}moveStackIndex(){if(this.positionStack[this.positionStack.length-1]===void 0)throw new Error("Index out of bounds");this.positionStack[this.positionStack.length-1]++}checkConcurrentTokens(e){this.enqueueToStack();let t=[];return e.every(r=>{let s=this.currentToken,i=r(s),o=!1;return i!=="no"&&s&&(t.push(s),this.moveToNextToken,o=pn(s,this.currentToken)),i==="yes"&&o}),this.mergeStack(),t}consumeAnyConcurrentTokens(e){this.enqueueToStack();let t=[],r,s=!0;for(;e.some(i=>i(this.currentToken)==="yes"&&s);)t.push(this.currentToken),r=this.currentToken,this.moveToNextToken,s=pn(r,this.currentToken);return this.mergeStack(),t}getDocumentSymbols(e){return this.allAstItems.flatMap(t=>t.getDocumentSymbols(e))}getWorkspaceSymbols(){return this.allAstItems.flatMap(e=>e.getWorkspaceSymbols())}buildSemanticTokens(e,t){let r=[],s=(i,o,a)=>{if(!a?.start||!a?.end||a.start.uri!==t||a.end.uri!==t)return;let c=a.end.pos.col-a.start.pos.col+a.end.pos.len;r.push({line:a.start.pos.line,char:a.start.pos.col,length:a.end===a.start?a.end.pos.len:c,tokenType:i,tokenModifiers:o})};this.allAstItems.forEach(i=>{i.buildSemanticTokens(s)}),r.sort((i,o)=>i.line===o.line?i.char-o.char:i.line-o.line).forEach(i=>e.push(i.line,i.char,i.length,i.tokenType,i.tokenModifiers))}processCIdentifier(){this.enqueueToStack();let e=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!e.length){this.popStack();return}let t=e.map(s=>s.value).join("");if(!t.match(/^[_A-Za-z]/)){this.popStack();return}let r=new Xi(t,J(e[0],e.at(-1)));return this.mergeStack(),r}isOperator(){this.enqueueToStack();let e=this.moveToNextToken;if(!e){this.popStack();return}let t=e,r;if(x(e,40)?(r="&",x(this.currentToken,40)&&(r="&&",t=this.moveToNextToken)):x(e,10)?(r="!",x(this.currentToken,0)&&(r="==",t=this.moveToNextToken)):x(e,8)?(r="|",x(this.currentToken,8)&&(r="||",t=this.moveToNextToken)):x(e,9)?r="^":x(e,4)?(r=">",x(this.currentToken,4)?(r="<<",t=this.moveToNextToken):x(this.currentToken,0)&&(r=">=",t=this.moveToNextToken)):x(e,5)?(r=">",x(this.currentToken,5)?(r=">>",t=this.moveToNextToken):x(this.currentToken,0)&&(r="<=",t=this.moveToNextToken)):x(e,15)?r="+":x(e,16)?r="-":x(e,17)?r="*":x(e,13)?r="/":x(e,18)?r="%":x(e,46)&&x(this.currentToken,46)&&(r="##",t=this.moveToNextToken),r){let s=new Iu(r,J(e,t));return this.mergeStack(),s}this.popStack()}parseScopedBlock(e,t,r){this.enqueueToStack();let s=this.moveToNextToken;if(!s||!e(s)){this.popStack();return}let i=[],o=[];for(o[0]=[];!t(this.currentToken);){let l=this.moveToNextToken;if(r?.(l)&&(o[o.length]=[]),l&&(i.push(l),o[o.length-1].push(l)),e(this.currentToken)){let u=this.parseScopedBlock(e,t,r);u&&(i.push(u),o[o.length-1].push(u.startToken,...u.splitTokens.flat(),u.endToken))}}let a=this.moveToNextToken,c={startToken:s,items:i,splitTokens:o,endToken:a};return this.mergeStack(),c}getTokenIndex(e){return e?this.tokens.findIndex(t=>t===e):-1}};var om=require("fs"),Qi=require("path");var $u=class n extends ss{constructor(t){super();this.uri=t;this.comments=[];this.tokens=[]}cleanUpComments(){let t=[];for(let r=0;r<this.tokens.length;r++){let s=n.processBlockComments(this.tokens,r)||n.processLineComments(this.tokens,r);s&&(r=s.index,t.push(...s.tokenUsed),this.comments.push(...s.comments))}t.reverse().forEach(r=>this.tokens.splice(r,1))}get allAstItems(){return this.comments}reset(){super.reset(),this.comments=[]}reparse(){return this.reset(),this.parse()}async parse(){this.tokens=Vn().requestTokens(this.uri,!0),this.cleanUpComments()}static processBlockComments(t,r){let s=[],i=()=>(s.push(r++),t[r]),o=()=>t[r],a=()=>t[r-1],c=o(),l=c;if(!c||!x(c,13)||(l=i(),!x(l,17)||c.pos.line!==l.pos.line||c.pos.col+1!==l.pos.col))return;let u=()=>!(!x(a(),17)||!x(o(),13)||!pn(a(),o())),d=l.pos.line,f=c,m=[];l=i();do{if(o()?.pos.line!==d){let g=new cr(J(f,a()));m.push(g),d=o().pos.line??0,f=o()}l=i()}while(r<t.length&&!u());let T=new cr(J(f,o()));return m.push(T),i(),{comments:m,tokenUsed:s,index:r-1}}static processLineComments(t,r){let s=[];if(!x(t[r],13)||t.length===r+1||!x(t[r+1],13)||!pn(t[r],t[r+1]))return;let i=[];for(;t[r].pos.line===t.at(r+1)?.pos.line;)s.push(r++);s.push(r++);let o=t[s.at(-1)],a=new cr(J(t[s[0]],t[s.at(-1)]));return i.push(a),{comments:i,tokenUsed:s,index:r-1}}};var Lu=class extends B{constructor(t,r){super(t);this.content=r}toString(){let t=this.content.filter(r=>!x(r,14));return t.map((r,s)=>{let i=r.value;return r.pos.line===t.at(s+1)?.pos.line?i=i.padEnd(t[s+1].pos.col-r.pos.col," "):t.at(s+1)&&(i=i.padEnd(i.length+1," ")),i}).join("")}},xu=class extends B{constructor(t,r,s){super();this.keyword=t;this.identifier=r;this.content=s;this.addChild(t),this.addChild(this.identifier),this.content&&this.addChild(this.content)}get name(){return this.identifier instanceof Xi?this.identifier.name:this.identifier.functionName.name}toString(){return[this.identifier.toString(),...this.content?[this.content?.toString()]:[]].join(" ")}};var Jk=G(X());var qu=class extends mt{toString(){return"..."}},ju=class extends B{constructor(t,r){super();this.functionName=t;this.params=r;this.addChild(t),this.params.forEach(s=>this.addChild(s))}getDocumentSymbols(t){return this.uri!==t?[]:[{name:this.functionName.name,kind:Jk.SymbolKind.Function,range:oe(this),selectionRange:oe(this),children:this.params.flatMap(r=>r.getDocumentSymbols(t))}]}toString(){return`${this.functionName}(${this.params.map(t=>t.toString()).join(",")})`}};var ca=class extends B{constructor(e){super(e)}},Fu=class extends B{constructor(t,r){super();this.keyword=t;this.content=r;this.addChild(t)}},la=class extends Fu{constructor(t,r,s){super(t,s);this.identifier=r;this.addChild(r),this.addChild(s)}useBlock(t){return this.identifier&&t.has(this.identifier.name)}},Bu=class extends la{useBlock(e){return this.identifier&&!e.has(this.identifier.name)}},Uu=class extends Fu{};var Vu=class extends B{constructor(t,r,s){super();this.ifDef=t;this.endIf=r;this.elseOption=s;this.addChild(t),s&&this.addChild(s),this.addChild(r)}getInValidTokenRange(t,r){let s=[],i=a=>r.findIndex(c=>c===a);if(!this.ifDef.identifier?.name)return[{start:i(this.tokenIndexes.start),end:i(this.tokenIndexes.end)}];s.push({start:i(this.ifDef.tokenIndexes.start),end:i(this.ifDef.identifier.tokenIndexes.end)});let o=this.ifDef.useBlock(t);return!o&&this.ifDef.content&&s.push({start:i(this.ifDef.content.tokenIndexes.start),end:i(this.ifDef.content.tokenIndexes.end)}),this.elseOption&&(s.push({start:i(this.elseOption.tokenIndexes.start),end:i(this.elseOption.keyword.tokenIndexes.end)}),o&&this.elseOption.content&&s.push({start:i(this.elseOption.content.tokenIndexes.start),end:i(this.elseOption.content.tokenIndexes.end)})),this.endIf&&s.push({start:i(this.endIf.tokenIndexes.start),end:i(this.endIf.tokenIndexes.end)}),s}};var Xk=G(X()),Wu=class n extends ss{constructor(t,r,s=new Map){super();this.uri=t;this.incudes=r;this.macros=s;this.tokens=[];this.nodes=[];this.dtsIncludes=[];this.macroSnapShot=new Map;Array.from(s).forEach(([i,o])=>this.macroSnapShot.set(i,o))}reset(){super.reset(),this.macros.clear(),Array.from(this.macroSnapShot).forEach(([t,r])=>this.macros.set(t,r)),this.nodes=[],this.dtsIncludes=[]}async reparse(){let t=this.stable;return this.parsing=new Promise(r=>{t.then(()=>{this.reset(),this.parse().then(r)})}),this.parsing}async parse(){let t=new $u(this.uri);if(await t.stable,this.tokens=t.tokens,this.nodes.push(...t.allAstItems),this.positionStack.push(0),this.tokens.length!==0){for(;!this.done;)await this.lineProcessor();if(this.positionStack.length!==1)throw new Error("Incorrect final stack size")}}async lineProcessor(){if(this.enqueueToStack(),!(!this.prevToken||this.prevToken.pos.line!==this.currentToken?.pos.line||this.prevToken.uri!==this.currentToken?.uri)){this.moveEndOfLine(this.prevToken,!1),this.mergeStack();return}let r=this.currentToken,s=await this.processInclude()||this.processDefinitions()||this.processIfDefBlocks();r&&this.moveEndOfLine(r,!!s),this.mergeStack()}processDefinitions(){this.enqueueToStack();let t=this.peekIndex(),r=this.moveToNextToken;if(!r||!x(r,25))return this.popStack(),!1;let s=new mt(J(r)),i=this.isFunctionDefinition()||this.processCIdentifier();if(!i)return this._issues.push(A(30,s)),this.mergeStack(),!0;let o=this.consumeDefinitionContent(),a;o.length&&(a=new Lu(J(o[0],o.at(-1)),o));let c=new xu(s,i,a);this.macros.set(c.name,c),this.nodes.push(c);let l=this.peekIndex();return this.tokens.splice(t,l-t),this.positionStack[this.positionStack.length-1]=t,this.mergeStack(),!0}consumeDefinitionContent(){let t=[],r=this.prevToken;for(;ir(r,this.currentToken)||r&&x(r,14)&&r.pos.line+1===this.currentToken?.pos.line;)r=this.moveToNextToken,r&&t.push(r);return t}isFunctionDefinition(){this.enqueueToStack();let t=this.processCIdentifier();if(!t){this.popStack();return}let r=this.moveToNextToken;if(!x(r,42)){this.popStack();return}let s=[],i=this.processCIdentifier()||this.processVariadic();for(;i;)s.push(i),!x(this.currentToken,24)&&!x(this.currentToken,43)?this._issues.push(A(28,i)):x(this.currentToken,43)||(r=this.moveToNextToken),i=this.processCIdentifier()||this.processVariadic();let o=new ju(t,s);return x(this.currentToken,43)?(r=this.moveToNextToken,o.lastToken=r):(o.lastToken=this.prevToken,this._issues.push(A(26,s.at(-1)??o))),this.mergeStack(),o}processVariadic(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(45),Pe(45),Pe(45)]);if(t.length!==3){this.popStack();return}let r=new qu(J(t[0],t.at(-1)));return this.mergeStack(),r}processIfDefBlocks(){let t=this.peekIndex(),r=this.parseScopedBlock(s=>{let i=this.getTokenIndex(s)-1;return!!s&&[33,34].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)},s=>{let i=this.getTokenIndex(s)-1;return!!s&&[37].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)},s=>{let i=this.getTokenIndex(s)-1;return!!s&&[36].some(o=>x(s,o))&&!ir(this.tokens.at(i),s)});if(r&&(x(r.startToken,33)||x(r.startToken,34))){let s;x(r.startToken,33)?s=this.processIfDefBlock(r,(o,a,c)=>new la(o,a??null,c)):s=this.processIfDefBlock(r,(o,a,c)=>new Bu(o,a??null,c)),this.nodes.push(s),s.getInValidTokenRange(this.macros,this.tokens).reverse().forEach(o=>{this.tokens.splice(o.start,o.end-o.start+1)}),this.positionStack[this.positionStack.length-1]=t;return}}processIfDefBlock(t,r){this.enqueueToStack();let s=new mt(J(t.startToken)),i=new mt(J(t.endToken));this.positionStack[this.positionStack.length-1]=this.getTokenIndex(t.startToken)+1;let o=this.processCIdentifier();o||this._issues.push(A(31,s));let a=this.getTokenIndex(t.splitTokens[0].at(-1)),c=new ca(J(this.currentToken,this.tokens[a])),l=r(s,o??null,c),u;if(t.splitTokens.length>1){let f=this.getTokenIndex(t.splitTokens[1][0]),m=new mt(J(this.tokens[f])),T=new ca(J(this.tokens[f+1],t.splitTokens[1].at(-1)));u=new Uu(m,T)}let d=new Vu(l,i,u);return this.mergeStack(),d}get allAstItems(){return[...this.dtsIncludes,...this.nodes]}resolveInclude(t){if(t.path.path)return t.path.relative?[(0,Qi.resolve)((0,Qi.dirname)(t.uri),t.path.path),...this.incudes.map(r=>(0,Qi.resolve)(r,t.path.path))].find(r=>(0,om.existsSync)(r)):this.incudes.map(r=>(0,Qi.resolve)(r,t.path.path)).find(r=>(0,om.existsSync)(r))}async processInclude(){this.enqueueToStack();let t=this.peekIndex(),r=this.currentToken;if(!r)return this.popStack(),!1;let s=r,i=r;if(x(r,26))this.moveToNextToken;else{let g=this.checkConcurrentTokens([Pe(13),Xe("include"),Pe(13)]);if(g.length!==3)return this.popStack(),!1;s=g[0],i=g.at(-1)}let o=s,a=new mt(J(s,i));r=this.moveToNextToken;let c=r,l=!!x(r,21);if(!c||!l&&!x(r,5))return o&&this.moveEndOfLine(o),this.mergeStack(),!0;let u="";if(l)u=r?.value??"";else for(;this.currentToken?.pos.line===o.pos.line&&!x(this.currentToken,4);)u+=this.currentToken?.value??"",r=this.moveToNextToken;let d=new Vi(u,l,J(c,r)),f=new es(a,d);this.dtsIncludes.push(f),l||(this.currentToken?.pos.line!==o.pos.line||!x(this.currentToken,4)?this._issues.push(A(12,f)):(r=this.moveToNextToken,d.lastToken=r)),this.mergeStack();let m=this.peekIndex(),T=this.resolveInclude(f);if(f.reolvedPath=T,T||this._issues.push(A(36,f.path,Xk.DiagnosticSeverity.Warning)),T&&!T.endsWith(".h")){Vn().requestTokens(T,!0);let g=new n(T,this.incudes,this.macros);await g.stable,this.tokens.splice(t,m-t,...g.tokens),this.nodes.push(...g.nodes),this.dtsIncludes.push(...g.dtsIncludes)}else this.tokens.splice(t,m-t);return this.positionStack[this.positionStack.length-1]=t,!0}};var Qk=G(X()),Hu=class extends B{constructor(t,r,s){super();this.keyword=t;this.startAddress=r;this.endAddress=s;this.addChild(t),this.docSymbolsMeta={name:"Memreserve",kind:Qk.SymbolKind.Function},this.addChild(r),this.addChild(s)}toString(){return`/memreserve/ 0x${this.startAddress?.value?.toString(16)} 0x${this.endAddress?.value?.toString(16)}`}};var Zk=G(X()),Ku=class extends B{constructor(t,r){super();this.keyword=t;this.bitsSize=r;this.addChild(t),this.docSymbolsMeta={name:"bits",kind:Zk.SymbolKind.Function},this.addChild(r)}toString(){return`/bits/ ${this.bitsSize?.value?.toString()}`}};var eE=G(X()),ua=class extends ss{constructor(t,r,s=new Map){super();this.uri=t;this.incudes=r;this.tokens=[];this.others=[];this.rootDocument=new Be;this.unhandledStatements=new Ht;this.cPreprocessorParser=new Wu(this.uri,this.incudes,s)}get issues(){return[...this._issues,...this.cPreprocessorParser.issues]}getFiles(){return[this.uri,...this.cPreprocessorParser.dtsIncludes.flatMap(t=>t.reolvedPath).filter(t=>!!t)]}reset(){super.reset(),this.others=[],this.rootDocument=new Be,this._issues=[],this.unhandledStatements=new Ht}async reparse(){let t=performance.now(),r=this.stable;return this.parsing=new Promise(s=>{r.then(async()=>{this.reset(),await this.cPreprocessorParser.reparse(),await this.parse(),console.log("parsing",performance.now()-t),s()})}),this.parsing}async parse(){let t=performance.now();if(await this.cPreprocessorParser.stable,this.tokens=this.cPreprocessorParser.tokens,this.uri.endsWith(".h")||(this.positionStack.push(0),this.tokens.length===0))return;let r=async()=>{if(!(this.isDtsDocumentVersion()||this.isMemreserve()||this.isRootNodeDefinition(this.rootDocument)||this.isDeleteNode(this.rootDocument,"Ref")||this.isChildNode(this.rootDocument,"Ref")||this.isProperty(this.unhandledStatements)||this.isDeleteProperty(this.unhandledStatements))){let s=this.moveToNextToken;if(s){let i=new B(J(s));this._issues.push(A(22,i)),this.reportExtraEndStatements()}}};for(;!this.done;)await r();if(this.unhandledStatements.properties.forEach(s=>{this._issues.push(A(32,s))}),this.unhandledStatements.deleteProperties.forEach(s=>{this._issues.push(A(33,s))}),this.positionStack.length!==1)throw new Error("Incorrect final stack size")}isRootNodeDefinition(t){this.enqueueToStack();let r=this.moveToNextToken,s=r,i=13;if(!r||!x(r,i))return this.popStack(),!1;if(s=this.moveToNextToken,i=2,!s||!x(s,i))return this.popStack(),!1;let o=new Ht;o.openScope=s,t.addNodeChild(o),this.processNode(o,"Name");let a=this.nodeEnd(o)??s;return o.firstToken=r,o.lastToken=a,this.mergeStack(),!0}nodeEnd(t){let r=this.currentToken;if(x(r,3))this.moveToNextToken;else{let s=this.prevToken;if(s){let i=new B(J(s));this._issues.push(A(3,i))}return this.endStatement(!1)}return this.prevToken?.value==="}"&&(t.closeScope=this.prevToken),this.endStatement()}isNodeEnd(){return x(this.currentToken,3)||x(this.currentToken,1)}endStatement(t=!0){let r=this.currentToken;if(!x(r,1)){let s=this.prevToken;if(s&&t){let i=new B(J(this.prevToken));return this._issues.push(A(1,i)),s}}return this.moveToNextToken,this.reportExtraEndStatements(),r}reportExtraEndStatements(){for(;x(this.currentToken,1);){let t=this.moveToNextToken;if(t){let r=new B(J(t));this._issues.push(A(23,r))}}}processNode(t,r){if(this.done)return!1;let s=!1,i=!1;do{if(i=this.isChildNode(t,r)||this.isProperty(t)||this.isDeleteNode(t,r)||this.isDeleteProperty(t),!i&&!this.isNodeEnd()&&!this.done){let o=this.moveToNextToken;if(o){let a=new B(J(o));this._issues.push(A(22,a)),this.reportExtraEndStatements()}}else if(this.done)break;s=s||i}while(!this.isNodeEnd());return s}processOptionalLabelAssign(t=!1){let r=[],s=this.isLabelAssign(t);for(;s;)r.push(s),s=this.isLabelAssign(t);return r}isChildNode(t,r){this.enqueueToStack();let s;r==="Name"&&(s=this.isOmitIfNoRefNode());let i=this.processOptionalLabelAssign(),o,a,c=r==="Ref"?new kt(i):new we(i,s);if(r==="Ref"?a=this.isLabelRef():r==="Name"&&(o=this.isNodeName()),!a&&!o){if(!x(this.currentToken,2))return this.popStack(),!1;c.firstToken=this.currentToken,this._issues.push(A(r==="Name"?[7]:[10,11],c))}let l=!1;if(a&&c instanceof kt?(c.labelReference=a,l=!0):o&&c instanceof we&&(l=o.address!==void 0,c.name=o),x(this.currentToken,2)){this.moveToNextToken,c.openScope=this.prevToken;let u=!1;do u=this.processNode(c,"Name");while(u);let d=this.nodeEnd(c);c.lastToken=d}else if(l){let u=a??o;u&&this._issues.push(A(2,u))}else return this.popStack(),!1;return t.addNodeChild(c),this.mergeStack(),!0}processNodeAddress(){let t=this.prevToken,r=this.consumeAnyConcurrentTokens([19,20].map(Pe)),s=r.length?Number.parseInt(r.map(o=>o.value).join(""),16):NaN;if(t){if(Number.isNaN(s)){let o=new B(J(t));this._issues.push(A(8,o))}else if(!Number.isNaN(s)&&!pn(t,r[0])){let o=new B(J(t,r.at(0)));this._issues.push(A(29,o))}}return new Tu(s,J(r[0]??this.prevToken,r.at(-1)))}processNodeAddresse(t){this.enqueueToStack();let r=this.checkConcurrentTokens([Pe(49)]);if(r.length){if(!pn(t.lastToken,r[0])){let o=new B(J(t.lastToken,r[0]));this._issues.push(A(29,o))}let s=[],i=()=>{if(s.push(this.processNodeAddress()),x(this.currentToken,24)){if(this.prevToken&&!pn(this.prevToken,this.currentToken)){let o=new B(J(this.prevToken,this.currentToken));this._issues.push(A(29,o))}this.moveToNextToken,i()}};return i(),this.mergeStack(),s}this.popStack()}isNodeName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,24,45,48,15,16].map(Pe));if(!t.length){this.popStack();return}let r=t.map(o=>o.value).join("");if(!r.match(/^[A-Za-z]/)){this.popStack();return}let s=new Ie(r,J(t[0],t.at(-1))),i=this.processNodeAddresse(s);return s.address=i,this.mergeStack(),s}isPropertyName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,24,45,48,15,16,44,46].map(Pe));if(!t.length){this.popStack();return}let r=new Fe(t.map(s=>s.value).join(""),J(t[0],t.at(-1)));return this.mergeStack(),r}isLabelName(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!t.length){this.popStack();return}let r=t.map(i=>i.value).join("");if(!r.match(/^[A-Za-z]/)){this.popStack();return}let s=new ht(r,J(t[0],t.at(-1)));return this.mergeStack(),s}isLabelAssign(t){this.enqueueToStack();let r=this.consumeAnyConcurrentTokens([19,47,48].map(Pe));if(!r.length){this.popStack();return}let s=r.map(c=>c.value).join("");if(!s.match(/^[A-Za-z]/)){this.popStack();return}let i=this.currentToken,o=i&&x(i,50),a=new rs(new ht(s,J(r[0],r.at(-1))),J(r[0],o?i:r.at(-1)));if(o){let c=r.at(-1);c&&(i.pos.line!==a.firstToken.pos.line||i.pos.col!==c.pos.col+c.pos.len)&&this._issues.push(A(29,new B(J(c,i)))),this.moveToNextToken}else if(t)this._issues.push(A(24,a));else{this.popStack();return}return this.mergeStack(),a}isProperty(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(),s=this.isPropertyName();if(!s)return this.popStack(),!1;if(x(this.currentToken,2)||x(this.currentToken,49))return this.popStack(),!1;let i=new Qe(s,r),o;x(this.currentToken,0)?(this.moveToNextToken,o=this.processValue(i),o?.values.filter(c=>!!c).length||this._issues.push(A(0,i)),i.values=o??null):i.values=void 0;let a=this.endStatement();return i.lastToken=a,t.addNodeChild(i),this.mergeStack(),!0}isDtsDocumentVersion(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("ts"),Pe(16),Xe("v"),Xe("1")]);if(t.length!==6)return this.popStack(),!1;let r=t[0],s=r,i=new mt;i.firstToken=r;let o=new Cu(i);if(this.others.push(o),x(this.currentToken,13))s=this.moveToNextToken;else return i.lastToken=t.at(-1),this._issues.push(A(21,o)),this.mergeStack(),!0;return i.lastToken=s,o.lastToken=this.endStatement(),this.mergeStack(),!0}isMemreserve(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("memreserve")]);if(t.length!==2)return this.popStack(),!1;let r=new mt;r.firstToken=t[0];let i=t[0];x(this.currentToken,13)?(i=this.moveToNextToken,r.lastToken=i):(r.lastToken=t.at(-1),this._issues.push(A(21,r)));let o=this.processHex()||this.processDec(),a=o&&(this.processHex()||this.processDec()),c=new Hu(r,o,a);return this.others.push(c),o||this._issues.push(A(37,r)),a||this._issues.push(A(38,o??r)),c.lastToken=this.endStatement(),this.mergeStack(),!0}processBits(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("b"),Xe("its")]);if(t.length!==3){this.popStack();return}let r=new mt;r.firstToken=t[0];let i=t[0];x(this.currentToken,13)?(i=this.moveToNextToken,r.lastToken=i):(r.lastToken=t.at(-1),this._issues.push(A(21,r)));let o=this.processDec(),a=new Ku(r,o);return this.others.push(a),o?o.value!==8&&o.value!==16&&o.value!==32&&o.value!==64&&this._issues.push(A(40,o)):this._issues.push(A(39,r)),this._issues.push(A(41,a,eE.DiagnosticSeverity.Warning)),this.mergeStack(),a}isOmitIfNoRefNode(){this.enqueueToStack();let t=this.checkConcurrentTokens([Pe(13),Xe("omit"),Pe(16),Xe("if"),Pe(16),Xe("no"),Pe(16),Xe("ref"),Pe(13)]);if(t.length!==9){this.popStack();return}let r=new mt(J(t[0],t.at(-1)));return this.mergeStack(),r}isDeleteNode(t,r){this.enqueueToStack();let s=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("e"),Xe("lete"),Pe(16),Xe("node")]);if(!s.length)return this.popStack(),!1;let i=s[0],o=i,a=new mt;if(a.firstToken=i,s.length===1&&!x(this.currentToken,2)){this._issues.push(A(25,a)),a.lastToken=s.at(-1);let d=new kn(a);return t.addNodeChild(d),this.mergeStack(),!0}let c=s.map(d=>d.value??"").join("");if(!"/delete-node/".startsWith(c)||c.endsWith("-"))return this.popStack(),!1;a.lastToken=s.at(-1),c!=="/delete-node"?this._issues.push(A(c.startsWith("/delete-n")?34:25,a)):x(this.currentToken,13)?(o=this.moveToNextToken,a.lastToken=o):this._issues.push(A(21,a));let l=new kn(a);if(ir(a.tokenIndexes?.end,i)){let d=this.processNodePathRef();d&&r==="Name"&&this._issues.push(A(7,d));let f=d?void 0:this.isLabelRef();f&&r==="Name"&&this._issues.push(A(7,f));let m=d||f?void 0:this.isNodeName();m&&r==="Ref"&&this._issues.push(A(10,m)),!d&&!m&&!f&&this._issues.push(A([7,10],l)),l.nodeNameOrRef=d??f??m??null}else r==="Name"?this._issues.push(A(7,a)):r==="Ref"&&this._issues.push(A(10,a));let u=this.endStatement();return l.lastToken=u,t.addNodeChild(l),this.mergeStack(),!0}isDeleteProperty(t){this.enqueueToStack();let r=this.checkConcurrentTokens([Pe(13),Xe("d"),Xe("e"),Xe("lete"),Pe(16),Xe("property")]);if(!r.length)return this.popStack(),!1;let s=r[0],i=s,o=new mt;if(o.firstToken=s,r.length===1&&!x(this.currentToken,2)){this._issues.push(A(25,o)),o.lastToken=r.at(-1);let u=new He(o);return t.addNodeChild(u),this.mergeStack(),!0}let a=r.map(u=>u.value??"").join("");if(!"/delete-property/".startsWith(a)||a.endsWith("-"))return this.popStack(),!1;o.lastToken=r.at(-1),a!=="/delete-property"?this._issues.push(A(a.startsWith("/delete-p")?35:25,o)):x(this.currentToken,13)?(i=this.moveToNextToken,o.lastToken=i):this._issues.push(A(21,o));let c=new He(o);if(ir(o.tokenIndexes?.end,s)){let u=this.isPropertyName();u||this._issues.push(A(6,c)),c.propertyName=u??null}else this._issues.push(A(6,o));let l=this.endStatement();return c.lastToken=l,t.addNodeChild(c),this.mergeStack(),!0}isNodePathRef(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.processNodePathRef();if(!r){this.popStack();return}let s=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&s.push(...this.processOptionalLabelAssign(!0));let i=new Bn(t,r,s);return this.mergeStack(),i}processValue(t){this.enqueueToStack();let s=(()=>{let o=()=>(this.processStringValue()||this.isNodePathRef()||this.isLabelRefValue(t)||this.arrayValues(t)||this.processByteStringValue()||this.isExpressionValue())??null,a=o();if(!a)return[];let c=[a];for(;!x(this.currentToken,1);){let l=this.prevToken,u=this.currentToken,d=x(this.currentToken,24);if(d)this.moveToNextToken;else if(!ir(this.prevToken,this.currentToken))break;let f=o();if(u&&f===null&&d){let m=new B(J(u,this.currentToken));this._issues.push(A(0,m))}if(!d&&f===null)break;if(l&&!d&&f){let m=new B(J(l));this._issues.push(A(28,m))}c.push(f)}return c})();if(s.length===0){this.popStack();return}return this.mergeStack(),new Du(s)}processStringValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.moveToNextToken;if(!x(r,21)){this.popStack();return}if(!r?.value)throw new Error("Token must have value");let s=r.value;s.match(/["']$/)&&(s=s.slice(1,-1));let i=new lt(s,J(r));r.value.match(/["']$/)||this._issues.push(A(r.value.startsWith('"')?16:17,i));let o=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(o=this.processOptionalLabelAssign(!0));let a=new Bn(t,i,o);return this.mergeStack(),a}arrayValues(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(!0),s=this.processBits(),i=this.currentToken;if(x(i,5))this.moveToNextToken;else{this.popStack();return}let o=this.processArrayValues(t)??null;o.openBracket=i;let a=this.processOptionalLabelAssign(!0)??[],c=new Bn(r,o,a,s);x(this.currentToken,4)?(o&&(o.closeBracket=this.currentToken),this.moveToNextToken):this._issues.push(A(12,c));let l=[];return this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(l=this.processOptionalLabelAssign(!0)),this.mergeStack(),c.endLabels.push(...l),c.firstToken=i,c.lastToken=this.prevToken,c}processByteStringValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!0),r=this.moveToNextToken,s=r;if(!x(s,11)){this.popStack();return}let i=this.processLabeledValue(()=>this.processHexString()),o=this.processOptionalLabelAssign(!0)??[];i.forEach(u=>{let d=0;u.value?.tokenIndexes?.start===u.value?.tokenIndexes?.end&&(d=u.value?.tokenIndexes?.start?.pos.len??0),d%2!==0&&this._issues.push(A(15,u))});let a=new Zr(i??[]);a.openBracket=s,a.values.length===0&&(a.firstToken=r,this._issues.push(A(14,a)));let c=new Bn(t,a,o);x(this.currentToken,12)?a.openBracket=this.moveToNextToken:this._issues.push(A(5,c));let l=[];return this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(l=this.processOptionalLabelAssign(!0)),this.mergeStack(),c.endLabels.push(...l),c.firstToken=r,a.lastToken=this.prevToken,c}processLabeledValue(t){this.enqueueToStack();let r=t(),s=[];if(!r)return this.popStack(),[];for(;r;)s=[...s,r],r=t();if(s){let i=t();i&&(s=[...s,i])}return this.mergeStack(),s}processArrayValues(t){this.enqueueToStack();let r=this.processLabeledValue(()=>this.processRefValue(!1,t)||this.processLabeledHex(!1)||this.processLabeledDec(!1)||this.processLabeledExpression(!0,!1)),s=new ut(r);return r.length===0&&(s.firstToken=this.currentToken),this.mergeStack(),s}processLabeledHex(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(t),s=this.processHex();if(!s){this.popStack();return}let i=new ur(s,r);return this.mergeStack(),i}processHex(){this.enqueueToStack();let t=this.checkConcurrentTokens([Xe("0"),Xe("x")]);if(t.length!==2){this.popStack();return}let r=this.consumeAnyConcurrentTokens([19,20].map(Pe));if(!r.length){this.popStack();return}let s=Number.parseInt(r.map(o=>o.value).join(""),16),i=new wt(s,J(t[0],r.at(-1)));return this.mergeStack(),i}processHexString(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!1),r=this.checkConcurrentTokens([20,20].map(Pe));if(!r.length){this.popStack();return}let s=Number.parseInt(r.map(a=>a.value).join(""),16),i=new wt(s,J(r[0],r.at(-1))),o=new ur(i,t);return this.mergeStack(),o}processLabeledDec(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(t),s=this.processDec();if(!s){this.popStack();return}let i=new ur(s,r);return this.mergeStack(),i}processDec(){this.enqueueToStack();let t=this.consumeAnyConcurrentTokens([19].map(Pe));if(!t.length){this.popStack();return}let r=Number.parseInt(t.map(i=>i.value).join(""),10),s=new wt(r,J(t[0],t.at(-1)));return this.mergeStack(),s}processLabeledExpression(t=!0,r=t){this.enqueueToStack();let s=[];t&&(s=this.processOptionalLabelAssign(r));let i=this.processExpression();if(!i){this.popStack();return}let o=new ur(i,s);return this.mergeStack(),o}isFunctionCall(){this.enqueueToStack();let t=this.processCIdentifier();if(!t){this.popStack();return}let r=this.processMacroCallParams();if(!r){this.popStack();return}let s=new Au(t,r);return this.mergeStack(),s}isExpressionValue(){this.enqueueToStack();let t=this.processOptionalLabelAssign(!1),r=this.processExpression();if(!r){this.popStack();return}let s=this.processOptionalLabelAssign(!0),i=new Bn(t,r,s);return this.mergeStack(),i}processExpression(){this.enqueueToStack();let t=!1,r,s;x(this.currentToken,42)&&(t=!0,r=this.moveToNextToken,s=r);let i=this.isFunctionCall()||this.processCIdentifier()||this.processHex()||this.processDec();if(!i){this.popStack();return}if(t){let o=this.isOperator();for(;o;){let a=this.processExpression();a?i instanceof ia?i.addExpression(o,a):i=new ia(i,{operator:o,expression:a}):this._issues.push(A(27,o)),o=this.isOperator()}x(this.currentToken,43)?s=this.moveToNextToken:this._issues.push(A(26,o??i))}return this.mergeStack(),i}processMacroCallParams(){return x(this.currentToken,42)?this.parseScopedBlock(s=>!!x(s,42),s=>!!x(s,43),s=>!!x(s,24))?.splitTokens.map((s,i)=>{if(s.length===0||x(s[0],24)&&s.length===1)return null;let o=i?s.slice(1):s;return new Ou(o.map((a,c)=>{let l=a.value;return a.pos.line===o.at(c+1)?.pos.line&&(l=l.padEnd(o[c+1].pos.col-a.pos.col," ")),l}).join(""),J(o[0],o.at(-1)),i)}):void 0}isLabelRef(t){this.enqueueToStack();let r=this.currentToken;if(x(r,40))this.moveToNextToken;else{this.popStack();return}let s=this.isLabelName();if(!s){let o=new ke(null);return this._issues.push(A(18,t??o)),o.firstToken=r,this.mergeStack(),o}r&&(s.firstToken.pos.line!==r.pos.line||s.firstToken.pos.col!==r.pos.col+r.pos.len)&&this._issues.push(A(29,new B(J(r,s.firstToken))));let i=new ke(s);return i.firstToken=r,this.mergeStack(),i}isLabelRefValue(t){this.enqueueToStack();let r=this.processOptionalLabelAssign(!0),s=this.isLabelRef(t);if(!s){this.popStack();return}let i=[];this.currentToken&&this.currentToken.pos.line===this.currentToken.prevToken?.pos.line&&(i=this.processOptionalLabelAssign(!0));let o=new Bn(r,s,i);return this.mergeStack(),o}processRefValue(t,r){this.enqueueToStack();let s=this.processOptionalLabelAssign(t),i=this.currentToken;if(!x(this.currentToken,40)){this.popStack();return}let o=this.processNodePathRef();if(o!==void 0){let l=new ur(o,s);return this.mergeStack(),l}let a=this.isLabelRef(r);if(a===void 0){this._issues.push(A([18,9],r));let l=new ur(null,s);return l.firstToken=s.at(0)?.firstToken??i,this.mergeStack(),l}let c=new ur(a,s);return c.firstToken=s.at(0)?.firstToken??i,this.mergeStack(),c}processNodePath(t=!0,r=new Cr){this.enqueueToStack();let s;if(x(this.currentToken,13))s=this.moveToNextToken;else{if(!t){this.popStack();return}this.prevToken&&this._issues.push(A(19,new B(J(this.prevToken))))}let i=this.isNodeName();return i||this._issues.push(A(7,new B(J(s??this.prevToken)))),r.addPath(i??null,s?new B(J(s)):void 0),this.processNodePath(!1,r),this.mergeStack(),r}processNodePathRef(){this.enqueueToStack();let t=this.moveToNextToken,r=t;if(!x(r,40)){this.popStack();return}let s=this.moveToNextToken;if(r=s,!x(r,2)){this.popStack();return}let i=this.processNodePath(),o=new Fn(i??null),a=this.currentToken??this.prevToken,c=a;return i?.children.forEach((l,u)=>{if(u===i?.children.length-1&&l&&c&&!pn(l.lastToken,c)){this._issues.push(A(29,new B(J(l.lastToken,c))));return}if(u===0&&s&&!pn(s,l?.firstToken)){this._issues.push(A(29,new B(J(s,l?.firstToken))));return}let d=i?.children[u+1];l&&d&&!pn(l.lastToken,d.firstToken)&&this._issues.push(A(29,new B(J(l.lastToken,d?.firstToken))))}),x(a,3)?this.moveToNextToken:this.prevToken&&this._issues.push(A(3,new B(J(this.prevToken)))),o.firstToken=t,o.lastToken=a??this.prevToken,this.mergeStack(),o}get includes(){return this.allAstItems.filter(t=>t instanceof es)}get allAstItems(){return[...this.cPreprocessorParser.allAstItems,...this.rootDocument.children,...this.others,...this.unhandledStatements.properties,...this.unhandledStatements.deleteProperties]}};var Zi=G(X());var tE=require("fs"),nE=require("path");var eo=class{constructor(e,t,r,s=[],i){this.includePaths=t;this.bindingLoader=r;this._issues=[];this.overlays=[];this.overlays=Array.isArray(s)?s:[s],this.overlays.filter(tE.existsSync),this.parser=new ua(e,t),this.name=i??(0,nE.basename)(e),this.overlayParsers=this.overlays?.map(o=>new ua(o,t))??[]}async getContextIssues(){return[...(await this.getRuntime()).issues,...this._issues]}async stable(){await Promise.all([this.parser.stable,...this.overlayParsers.map(e=>e.stable)])}async getRuntime(){return await this.stable(),this._runtime??=this.evaluate(),this._runtime}getContextFiles(){return[...this.overlayParsers.map(e=>e.uri),this.parser.uri,...this.parser.cPreprocessorParser.dtsIncludes.flatMap(e=>e.reolvedPath).filter(e=>!!e)]}isInContext(e){return this.getContextFiles().some(t=>t===e)}async getAllParsers(){return await this.stable(),[this.parser,...this.overlayParsers]}async getDocumentLinks(e,t){if(!this.isInContext(e))return[];let s=(await this.getRuntime()).rootNode.allBindingsProperties.filter(i=>i.ast.uri===e&&(!t||hn(i.ast,e,t))).flatMap(i=>i.ast.values?.values.flatMap(o=>{let c=i.parent?.nodeTypes.find(l=>o?.value instanceof lt&&l.compatible===o.value.value);return c?{range:oe(o.value),target:`file://${c.bindingsPath}`}:void 0})).filter(i=>i)??[];return[...this.parser.cPreprocessorParser.dtsIncludes.filter(i=>i.uri===e&&(!t||hn(i,e,t))).map(i=>{let o=this.parser.cPreprocessorParser.resolveInclude(i);if(o)return{range:oe(i.path),target:`file://${o}`}}).filter(i=>i)??[],...s]}linkPropertiesLabelsAndNodePaths(e){let t=i=>[...i.property,...i.nodes.flatMap(t)],r=t(e.rootNode),s=e.rootNode.allDescendantsLabels;r.forEach(i=>i.ast.allDescendants.forEach(o=>{if(o instanceof ke){let a=e.resolvePath([`&${o.label?.value}`],s);if(a){let c=e.rootNode.getChild(a);o.linksTo=c,c?.linkedRefLabels.push(o)}else o.value&&this._issues.push(A(3,o,Zi.DiagnosticSeverity.Error,[],[],[o.value]))}else if(o instanceof Cr){let a=e.rootNode,c=o.pathParts;for(let l=0;l<c.length&&c[l];l++){let u=!1,d=c[l];if(d){let f=a?.getNode(d.name,d.address?.map(m=>m.address),!1);d.linksTo=f,!u&&!f&&(u=!0,this._issues.push(A(8,d,Zi.DiagnosticSeverity.Error,[],[],[d.toString(),`${o.pathParts.filter(m=>m?.linksTo).map(m=>m?.toString()).join("/")}`]))),f?.linkedNodeNamePaths.push(d),a=f}else break}}}))}async reevaluate(e){return this.isInContext(e)?(await this.parser.reparse(),this._runtime=this.evaluate(),this._runtime):this._runtime}async evaluate(){let e=performance.now();await this.stable();let t=new Ru(this);this._issues=[],this.processRoot(this.parser.rootDocument,t);for(let r=0;r<this.overlayParsers.length;r++)this.processRoot(this.overlayParsers[r].rootDocument,t);return t.includes=this.parser.includes,t.comments=this.parser.cPreprocessorParser.allAstItems.filter(r=>r instanceof cr),(await this.getAllParsers()).flatMap(r=>r.tokens).forEach((r,s)=>r.sortKey=s),this.linkPropertiesLabelsAndNodePaths(t),console.log("evaluate",performance.now()-e),t}processRoot(e,t){for(let r=0;r<e.children.length;r++){let s=e.children[r];this.processChild(s,t.rootNode,t)}}processChild(e,t,r){e instanceof Be?this.processDtcBaseNode(e,t,r):e instanceof Qe?this.processDtcProperty(e,t,r):e instanceof kn?this.processDeleteNode(e,t,r):e instanceof He&&this.processDeleteProperty(e,t,r)}checkNodeUniqueNames(e,t){let r=(o,a)=>o.some(c=>c.name===a.name&&(c.address===void 0||a.address===void 0||c.address.every((l,u)=>a.address?.at(u)?.address===l))),s=t.nodes.map(o=>({name:o.name,address:o.address})),i=[];e.children.forEach(o=>{if(o instanceof we&&o.name)r(i.map(a=>({name:a.name,address:a.address?.map(c=>c.address)})),o.name)&&this._issues.push(A(2,o.name)),i.push(o.name);else if(o instanceof kn&&o.nodeNameOrRef instanceof Ie){let a=o.nodeNameOrRef;r(s,a)&&(i=i.filter(c=>r(i.map(l=>({name:l.name,address:l.address?.map(u=>u.address)})),c)))}})}processDtcBaseNode(e,t,r){e instanceof Ht?this.processDtcRootNode(e,r):e instanceof we?this.processDtcChildNode(e,t,r):e instanceof kt&&this.processDtcRefNode(e,r)}processDtcRootNode(e,t){t.roots.push(e),t.rootNode.definitions.push(e),this.checkNodeUniqueNames(e,t.rootNode),[...e.children].sort((r,s)=>r instanceof Qe&&s instanceof He||s instanceof Qe&&r instanceof He?0:s instanceof Qe?1:0).forEach(r=>this.processChild(r,t.rootNode,t))}processDtcChildNode(e,t,r){if(e.name?.name){let s=e.path?r.resolvePath(e.path):void 0,o=(s?r.rootNode.getChild(s):void 0)??new Ee(this.bindingLoader,e.name.name,e.name.address?.map(a=>a.address),t);o.definitions.push(e),e.labels.forEach(a=>a.lastLinkedTo=o),t=o,this.checkNodeUniqueNames(e,o)}[...e.children].sort((s,i)=>s instanceof Be&&i instanceof Be?0:s instanceof Be?-1:0).forEach(s=>this.processChild(s,t,r))}processDtcRefNode(e,t){let r;if(e.labelReference){let s=e.resolveNodePath??(e.pathName?t.resolvePath([e.pathName]):void 0);s?(e.resolveNodePath??=[...s],r=t.rootNode.getChild(s),e.labelReference.linksTo=r,e.labels.forEach(i=>i.lastLinkedTo=r),r?.linkedRefLabels.push(e.labelReference),r?.referencedBy.push(e),e.labels.forEach(i=>{t.labelsUsedCache.set(i.label.value,s)}),r?(t.references.push(e),this.checkNodeUniqueNames(e,r)):t.unlinkedRefNodes.push(e)):(this._issues.push(A(3,e.labelReference,Zi.DiagnosticSeverity.Error,[],[],[e.labelReference.label?.value??""])),t.unlinkedRefNodes.push(e))}else t.unlinkedRefNodes.push(e);[...e.children].sort((s,i)=>s instanceof Be&&i instanceof Be?0:s instanceof Be?-1:0).forEach(s=>this.processChild(s,r??new Ee(this.bindingLoader,""),t))}processDtcProperty(e,t,r){e.propertyName?.name&&t.addProperty(new pt(e,t)),e.children.forEach(s=>this.processChild(s,t,r))}processDeleteNode(e,t,r){if(e.nodeNameOrRef instanceof Ie&&e.nodeNameOrRef.value){if(e.parentNode?.parentNode)if(!t.hasNode(e.nodeNameOrRef.name,e.nodeNameOrRef.address?.map(s=>s.address)))this._issues.push(A(5,e.nodeNameOrRef));else{t.deletes.push(e);let s=t.getNode(e.nodeNameOrRef.name,e.nodeNameOrRef.address?.map(i=>i.address));e.nodeNameOrRef.linksTo=s,t.deleteNode(e.nodeNameOrRef.name,e,e.nodeNameOrRef.address?.map(i=>i.address)),s?.labels.forEach(i=>{r.labelsUsedCache.delete(i.label.value)})}}else if(e.nodeNameOrRef instanceof ke&&e.nodeNameOrRef.value){let s=r.resolvePath([`&${e.nodeNameOrRef.value}`]),i;s?(i=r.rootNode.getChild(s),t.deletes.push(e),e.nodeNameOrRef.linksTo=i,i?.labels.forEach(o=>{r.labelsUsedCache.delete(o.label.value)}),i?.linkedRefLabels.push(e.nodeNameOrRef),i?.parent?.deleteNode(i.name,e,i.address),e.parentNode instanceof Be&&!e.parentNode.pathName&&r.globalDeletes.push(e)):(r.unlinkedDeletes.push(e),this._issues.push(A(3,e.nodeNameOrRef,Zi.DiagnosticSeverity.Error,[],[],[e.nodeNameOrRef.value])))}else if(e.nodeNameOrRef instanceof Fn&&e.nodeNameOrRef.path&&!e.nodeNameOrRef.path.pathParts.some(s=>!s)){let s=["/",...e.nodeNameOrRef.path.pathParts.map(u=>u.toString())],i=r.rootNode,o=e.nodeNameOrRef.path.pathParts;for(let u=0;u<o.length&&o[u];u++){let d=o[u];if(d){let f=i?.getNode(d.name,d.address?.map(m=>m.address),!1);d.linksTo=f,f?.linkedNodeNamePaths.push(d),i=f}}let a=e.nodeNameOrRef.path.pathParts.every(u=>u),c=e.nodeNameOrRef.path.pathParts.find(u=>u&&!u.linksTo),l=e.nodeNameOrRef.path.pathParts.at(-1)?.linksTo;l||(r.unlinkedDeletes.push(e),c&&this._issues.push(A(8,c,Zi.DiagnosticSeverity.Error,[],[],[c.toString(),`${e.nodeNameOrRef.path.pathParts.filter(u=>u?.linksTo).map(u=>u?.toString()).join("/")}`]))),t.deletes.push(e),l?.labels.forEach(u=>{r.labelsUsedCache.delete(u.label.value)}),l?.parent?.deleteNode(l.name,e,l.address),e.parentNode instanceof Be&&!e.parentNode.pathName&&r.globalDeletes.push(e)}else r.unlinkedDeletes.push(e);e.children.forEach(s=>this.processChild(s,t,r))}processDeleteProperty(e,t,r){e.propertyName?.name&&!t.hasProperty(e.propertyName.name)?this._issues.push(A(1,e.propertyName)):e.propertyName?.name&&(t.deletes.push(e),t.deleteProperty(e.propertyName.name,e)),e.children.forEach(s=>this.processChild(s,t,r))}};var Et=G(X());var rE=require("fs"),to=require("path");function pM(n){if(!n||!(n.ast instanceof Vi))return[];let e=r=>r.flatMap(s=>(0,rE.readdirSync)(s,{withFileTypes:!0,recursive:!0}).filter(i=>i.name.toLowerCase().endsWith(".dtsi")||i.name.toLowerCase().endsWith(".h")).map(i=>({label:`${(0,to.join)((0,to.relative)(s,i.parentPath),i.name)}`,kind:Et.CompletionItemKind.File})));if(n.ast.relative)return e([(0,to.dirname)(n.ast.uri)]);let t=n.runtime.context.includePaths;return e(t)}var zu=(n,e)=>[...n.labels.filter(e),...n.deletedNodes.filter(t=>!e(t.by)).flatMap(t=>zu(t.node,e)),...n.nodes.flatMap(t=>zu(t,e))],am=(n,e)=>[...n.labels,...n.deletedNodes.filter(t=>!e(t.by)).flatMap(t=>am(t.node,e)),...n.nodes.flatMap(t=>am(t,e))];function mM(n,e){if(!n||!(n.item instanceof pt)||!(n.ast instanceof ke))return[];let t=r=>am(r,e);return Array.from(new Set(t(n.runtime.rootNode).map(r=>r.label.value))).map(r=>({label:`${r}`,kind:Et.CompletionItemKind.Method}))}function gM(n,e){if(!n||n.item!==null||!(n.ast instanceof ke)||!(n.ast.parentNode instanceof kt))return[];let t=r=>zu(r,e).filter(s=>e(s));return[...Array.from(new Set(t(n.runtime.rootNode).map(r=>r.label.value))).map(r=>({label:r,insertText:`${r} {
|
|
236
236
|
$1
|
|
237
237
|
};`,kind:Et.CompletionItemKind.Value,insertTextFormat:Et.InsertTextFormat.Snippet}))]}function yM(n,e){let t=s=>s?s.parentNode instanceof kt||s.parentNode instanceof Ht||s.parentNode instanceof we?!1:t(s.parentNode):!0;if(!n||n.item!==null||!bt(n.ast)||!t(n.ast))return[];let r=s=>zu(s,e).filter(i=>e(i));return n.ast instanceof mt?r(n.runtime.rootNode).length?[{label:"/delete-node/",insertText:"/delete-node/ $1;",kind:Et.CompletionItemKind.Keyword,insertTextFormat:Et.InsertTextFormat.Snippet,sortText:"~"}]:n.runtime.rootNode.nodes.length?[{label:"/delete-node/ &{}",insertText:"/delete-node/ {/$1};",kind:Et.CompletionItemKind.Keyword,insertTextFormat:Et.InsertTextFormat.Snippet,sortText:"~"}]:[]:Array.from(new Set(r(n.runtime.rootNode).map(s=>s.label.value))).map(s=>({label:`${s}`,kind:Et.CompletionItemKind.Variable}))}function bM(n,e){if(!n||!(n.item instanceof Ee)||n.item===null)return[];let t=r=>[...r.nodes,...r.deletedNodes.filter(s=>!e(s.by)).map(s=>s.node)].flatMap(s=>s.definitions.filter(i=>i instanceof we)).filter(s=>e(s));return n.ast instanceof Ie||n.ast instanceof kn?Array.from(new Set(t(n.item).map(r=>r.name?.toString()))).map(r=>({label:`${r}`,kind:Et.CompletionItemKind.Variable})):t(n.item).length?[{label:"/delete-node/",insertText:"/delete-node/$1;",kind:Et.CompletionItemKind.Keyword,insertTextFormat:Et.InsertTextFormat.Snippet,sortText:"~"}]:[]}function vM(n,e){if(!n||!(n.item instanceof Ee))return[];let t=r=>[...r.property,...r.deletedProperties.filter(s=>!e(s.by)).map(s=>s.property)].flatMap(s=>[s,...s.allReplaced]).filter(s=>e(s.ast));return n.ast instanceof Fe||n.ast instanceof He?Array.from(new Set(t(n.item).map(r=>r.name))).map(r=>({label:`${r}`,kind:Et.CompletionItemKind.Variable})):t(n.item).length?[{label:"/delete-property/",insertText:"/delete-property/$1;",kind:Et.CompletionItemKind.Keyword,sortText:"~",insertTextFormat:Et.InsertTextFormat.Snippet}]:[]}function TM(n,e){let t=n?.ast instanceof Cr?n.ast:n?.ast.parentNode;if(!n||!t||!(t instanceof Cr))return[];let r=t.pathParts.slice(0,-1);if(r.some(o=>!o))return[];let s=r.map(o=>o.toString());return(()=>{let o=n.runtime.rootNode.getChildFromScope(["/",...s],e);return[...o?.nodes.filter(a=>!bt(n.ast)||a.definitions.some(e))??[],...o?.deletedNodes.filter(a=>!e(a.by)).map(a=>a.node)??[]].map(a=>a.fullName)??[]})().map(o=>({label:`/${[...s,o].join("/")}`,kind:Et.CompletionItemKind.Variable}))}async function sE(n,e,t){return Ot(n,e,(r,s)=>[...vM(r,s),...bM(r,s),...yM(r,s),...TM(r,s),...gM(r,s),...mM(r,s),...pM(r)],t)}var Us=G(X());function _M(n){if(!n||n.item===null||!(n.ast instanceof Fe))return[];let e=r=>r.replacedBy?e(r.replacedBy):r,t=r=>[r.ast,...r.allReplaced.map(s=>s.ast),r.parent.deletedProperties.find(s=>s.property=r)?.by??[]].map(s=>{if(s instanceof Qe)return Us.Location.create(`file://${s.uri}`,oe(s.propertyName??s));if(s instanceof He)return Us.Location.create(`file://${s.uri}`,oe(s.propertyName??s))}).filter(s=>s);if(n.item instanceof pt&&n.ast instanceof Fe)return t(e(n.item));if(n.item instanceof Ee&&n.ast instanceof Fe&&n.ast.parentNode instanceof He){let r=n.item.deletedProperties.find(s=>s.by===n.ast.parentNode)?.property;if(r)return t(r)}return[]}function SM(n){if(!n||!(n.ast instanceof Ie)&&!(n.ast instanceof ht))return[];let e=t=>[...t.linkedRefLabels,...t.linkedNodeNamePaths,...t.definitions].map(r=>{if(r instanceof we)return Us.Location.create(`file://${r.uri}`,oe(r.name??r));if(r instanceof Ie)return Us.Location.create(`file://${r.uri}`,oe(r));if(r instanceof ke)return Us.Location.create(`file://${r.uri}`,oe(r.label??r))}).filter(r=>r);return n.item instanceof Ee&&!bt(n.ast)?e(n.item):n.ast instanceof ht&&n.ast.parentNode instanceof ke&&n.ast.parentNode.linksTo?e(n.ast.parentNode.linksTo):n.ast instanceof Ie&&n.ast.linksTo?bt(n.ast)?[...e(n.ast.linksTo),Us.Location.create(`file://${n.ast.uri}`,oe(n.ast))]:e(n.ast.linksTo):[]}async function iE(n,e,t){return Ot(n,e,r=>[...SM(r),..._M(r)],t)}var is=G(X());function oE(n){if(!n||n.item===null||!(n.ast instanceof Fe))return[];let e=r=>r.replacedBy?e(r.replacedBy):r,t=r=>[r.ast,...r.allReplaced.map(s=>s.ast),r.parent.deletedProperties.find(s=>s.property=r)?.by??[]].map(s=>{if((s instanceof Qe||s instanceof He)&&s.propertyName)return is.Location.create(`file://${s.uri}`,oe(s.propertyName))}).filter(s=>s);if(n.item instanceof pt&&n.ast instanceof Fe)return t(e(n.item));if(n.item instanceof Ee&&n.ast instanceof Fe&&n.ast.parentNode instanceof He){let r=n.item.deletedProperties.find(s=>s.by===n.ast.parentNode)?.property;if(r)return t(r)}return[]}function aE(n,e){if(!e||!(e.ast instanceof ht))return[];"newName"in n&&(e.ast.parentNode instanceof ke&&n.newName.startsWith("&")?n.newName=n.newName.slice(1):e.ast.parentNode instanceof rs&&n.newName.endsWith(":")&&(n.newName=n.newName.slice(0,-1)));let t=e.ast.value,r=s=>[...s.definitions.filter(i=>i instanceof we).flatMap(i=>i.labels.map(o=>o.label)),...s.linkedRefLabels.map(i=>i.label)].filter(i=>i?.value===t).map(i=>{if(i)return is.Location.create(`file://${i.uri}`,oe(i))}).filter(i=>i);return e.item instanceof Ee&&!bt(e.ast)?r(e.item):e.ast instanceof ht&&e.ast.parentNode instanceof ke&&e.ast.parentNode.linksTo?r(e.ast.parentNode.linksTo):[]}function cE(n){if(!n||!(n.ast instanceof Ie))return[];let e=t=>[...t.linkedNodeNamePaths,...t.definitions].map(r=>{if(r instanceof we&&r.name)return is.Location.create(`file://${r.uri}`,oe(r.name));if(r instanceof Ie)return is.Location.create(`file://${r.uri}`,oe(r))}).filter(r=>r);return n.item instanceof Ee&&!bt(n.ast)?e(n.item):n.ast instanceof Ie&&n.ast.linksTo?bt(n.ast)?[...e(n.ast.linksTo),is.Location.create(`file://${n.ast.uri}`,oe(n.ast))]:e(n.ast.linksTo):[]}async function lE(n,e,t){let r={};return(await Ot(n,e,i=>[...cE(i),...aE(n,i),...oE(i)],t)).forEach(i=>{r[i.uri]??=[],r[i.uri].push(is.TextEdit.replace(i.range,n.newName))}),{changes:r}}async function uE(n,e,t,r){let s=await Ot(n,e,i=>[...cE(i),...aE(n,i),...oE(i)],r);if(s.some(i=>t.some(o=>i.uri.replace("file://","").startsWith(o))))throw new Error('Path is locked by user setting "lockRenameEdits"');return{defaultBehavior:!!s.length}}var Gu=G(X());function wM(n){if(!n||n.item===null||!(n.ast instanceof Fe))return[];let e=r=>r.replacedBy?e(r.replacedBy):r,t=r=>[r.ast,...r.allReplaced.map(s=>s.ast)].map(s=>{if(s instanceof Qe)return Gu.Location.create(`file://${s.uri}`,oe(s.propertyName??s))}).filter(s=>s);if(n.item instanceof pt&&n.ast instanceof Fe)return t(e(n.item));if(n.item instanceof Ee&&n.ast instanceof Fe&&n.ast.parentNode instanceof He){let r=n.item.deletedProperties.find(s=>s.by===n.ast.parentNode)?.property;if(r)return t(r)}return[]}function kM(n){if(!n||!(n.ast instanceof Ie)&&!(n.ast instanceof ht))return[];let e=t=>[...t.definitions,...t.referencedBy].map(r=>{if(r instanceof we)return Gu.Location.create(`file://${r.uri}`,oe(r));if(r instanceof kt)return Gu.Location.create(`file://${r.uri}`,oe(r))}).filter(r=>r);return n.item instanceof Ee&&!bt(n.ast)?e(n.item):n.ast instanceof ht&&n.ast.parentNode instanceof ke&&n.ast.parentNode.linksTo?e(n.ast.parentNode.linksTo):n.ast instanceof Ie&&n.ast.linksTo?e(n.ast.linksTo):[]}async function dE(n,e,t){return Ot(n,e,r=>[...kM(r),...wM(r)],t)}var cm=G(X());function EM(n){if(!n||n.item===null||!(n.ast instanceof Fe))return;let e=r=>r.replaces?e(r.replaces):r,t=r=>cm.Location.create(`file://${r.ast.uri}`,oe(r.ast.propertyName??r.ast));if(n.item instanceof pt&&n.ast instanceof Fe)return t(e(n.item));if(n.item instanceof Ee&&n.ast instanceof Fe&&n.ast.parentNode instanceof He){let r=n.item.deletedProperties.find(s=>s.by===n.ast.parentNode)?.property;if(r)return t(e(r))}}function NM(n){if(!n||!(n.ast instanceof Ie)&&!(n.ast instanceof ht))return;let e=t=>{let r=t.definitions.at(0);return r?cm.Location.create(`file://${r.uri}`,oe(r)):void 0};if(n.item instanceof Ee&&!bt(n.ast))return e(n.item);if(n.ast instanceof ht&&n.ast.parentNode instanceof ke&&n.ast.parentNode.linksTo)return e(n.ast.parentNode.linksTo);if(n.ast instanceof Ie&&n.ast.linksTo)return e(n.ast.linksTo)}async function fE(n,e,t){return(await Ot(n,e,r=>[NM(r)||EM(r)],t)).at(0)}var ee=G(X());var PM=(n,e,t,r,s)=>{switch(t){case 1:return[{title:"Add semicolon",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),";")]}}}];case 2:return[{title:"Add open curly",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character)," {")]}}}];case 29:return[{title:"Remove white space",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.replace(ee.Range.create(ee.Position.create(r.range.start.line,n.pos.col+n.pos.len),ee.Position.create(r.range.end.line,e.pos.col)),"")]}}}];case 3:return[{title:"Add close curly",diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),"}")]}}}];case 19:return[{title:"Add '/'",diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),"/")]}}}];case 28:return[{title:"Add comma",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),",")]}}}];case 21:return[{title:"Add '/'",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),"/")]}}}];case 23:return[{title:"Remove ';'",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.del(r.range)]}}}];case 34:return[{title:"Complete Keyword '/delete-node/",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.replace(r.range,"/delete-node/")]}}}];case 35:return[{title:"Complete Keyword '/delete-property/",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.replace(r.range,"/delete-property/")]}}}];case 25:return[{title:"Complete Keyword '/delete-property/",diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.replace(r.range,"/delete-property/")]}}},{title:"Complete Keyword '/delete-node/",diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.replace(r.range,"/delete-node/")]}}}];case 12:return[{title:"Add '>'",diagnostics:[r],kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[s]:[ee.TextEdit.insert(ee.Position.create(r.range.end.line,r.range.end.character),">")]}}}];default:return}},RM=(n,e,t,r,s,i,o)=>{if(!i)return[];switch(t){case 0:return[{title:o??`Add Property "${i.newText.split("=",1)[0].replace(";","").trim()}"`,diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[i]}}}];case 26:return i?[{title:o??"TODO",diagnostics:[r],kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[s]:[i]}}}]:[];default:return}};function hE(n){let e=n.context.diagnostics.flatMap(a=>{let c=a.data;switch(c?.issues.type){case"SyntaxIssue":return c?.issues.items.flatMap(l=>PM(c.firstToken,c.lastToken,l,a,n.textDocument.uri));case"StandardTypeIssue":return c?.issues.items.flatMap(l=>RM(c.firstToken,c.lastToken,l,a,n.textDocument.uri,c.issues.edit,c.issues.codeActionTitle))}}).filter(a=>!!a),t=e.filter(a=>a.kind===ee.CodeActionKind.SourceFixAll),r=e.filter(a=>a.title.startsWith("Add Property")),s=e.filter(a=>a.kind!==ee.CodeActionKind.SourceFixAll),i=t.flatMap(a=>a.edit?.changes?.[n.textDocument.uri]??[]),o=new Map;return r.forEach(a=>{let c=a.edit.changes[n.textDocument.uri][0],l=c.range.start.line,u=c.range.start.character;o.has(`${l}:${u}`)||o.set(`${l}:${u}`,[]),o.get(`${l}:${u}`)?.push(c)}),[...s,...t.map(a=>({...a,kind:ee.CodeActionKind.QuickFix})),...i.length?[{title:"Fix All",kind:ee.CodeActionKind.SourceFixAll,isPreferred:!0,edit:{changes:{[n.textDocument.uri]:i}}}]:[],...Array.from(o.values()).flatMap(a=>a.length>1?{title:"Add All Missing Properties",kind:ee.CodeActionKind.QuickFix,isPreferred:!0,edit:{changes:{[n.textDocument.uri]:a}}}:[])]}function DM(n){if(!n||!(n.item instanceof pt)||!(n.ast instanceof Qe&&(n.ast.values||n.ast.values===null)))return[];let e=n.item.parent.nodeType;return e instanceof Ki?e.properties.find(t=>t.name===n.item?.name)?.getPropertyCompletionItems(n.item)??[]:[]}function CM(n){if(!n||!(n.item instanceof pt&&n.ast instanceof Fe&&n.item.ast.values==null||n.item instanceof Ee)||bt(n.ast))return[];let e=t=>t.nodeType?.getPropertyListCompletionItems(t)??[];return n.item instanceof pt?e(n.item.parent):e(n.item)}async function pE(n,e,t){return Ot(n,e,r=>[...DM(r),...CM(r)],t)}function OM(n){if(n?.item instanceof Ee)return{contents:n.item.toMarkupContent(),range:oe(n.ast)};if(n?.ast instanceof Ie){let e=n.ast.linksTo;if(e)return{contents:e.toMarkupContent(),range:oe(n.ast)}}if(n?.ast.parentNode instanceof ke){let e=n.ast.parentNode.linksTo;if(e)return{contents:e.toMarkupContent(),range:oe(n.ast)}}}function AM(n){if(n?.item instanceof pt&&n.ast instanceof Fe){let e=n.item.parent.nodeType?.getOnPropertyHover(n.item.name);if(e)return{contents:e,range:oe(n.ast)}}}function mE(n,e,t){return Ot(n,e,r=>[OM(r)||AM(r)],t)}var cv=G(Vg());var w0=G(m0(),1);var Ua=n=>{if(typeof n!="string")throw new TypeError("invalid pattern");if(n.length>65536)throw new TypeError("pattern is too long")};var uq={"[:alnum:]":["\\p{L}\\p{Nl}\\p{Nd}",!0],"[:alpha:]":["\\p{L}\\p{Nl}",!0],"[:ascii:]":["\\x00-\\x7f",!1],"[:blank:]":["\\p{Zs}\\t",!0],"[:cntrl:]":["\\p{Cc}",!0],"[:digit:]":["\\p{Nd}",!0],"[:graph:]":["\\p{Z}\\p{C}",!0,!0],"[:lower:]":["\\p{Ll}",!0],"[:print:]":["\\p{C}",!0],"[:punct:]":["\\p{P}",!0],"[:space:]":["\\p{Z}\\t\\r\\n\\v\\f",!0],"[:upper:]":["\\p{Lu}",!0],"[:word:]":["\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}",!0],"[:xdigit:]":["A-Fa-f0-9",!1]},Va=n=>n.replace(/[[\]\\-]/g,"\\$&"),dq=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),g0=n=>n.join(""),y0=(n,e)=>{let t=e;if(n.charAt(t)!=="[")throw new Error("not in a brace expression");let r=[],s=[],i=t+1,o=!1,a=!1,c=!1,l=!1,u=t,d="";e:for(;i<n.length;){let g=n.charAt(i);if((g==="!"||g==="^")&&i===t+1){l=!0,i++;continue}if(g==="]"&&o&&!c){u=i+1;break}if(o=!0,g==="\\"&&!c){c=!0,i++;continue}if(g==="["&&!c){for(let[S,[k,v,b]]of Object.entries(uq))if(n.startsWith(S,i)){if(d)return["$.",!1,n.length-t,!0];i+=S.length,b?s.push(k):r.push(k),a=a||v;continue e}}if(c=!1,d){g>d?r.push(Va(d)+"-"+Va(g)):g===d&&r.push(Va(g)),d="",i++;continue}if(n.startsWith("-]",i+1)){r.push(Va(g+"-")),i+=2;continue}if(n.startsWith("-",i+1)){d=g,i+=2;continue}r.push(Va(g)),i++}if(u<i)return["",!1,0,!1];if(!r.length&&!s.length)return["$.",!1,n.length-t,!0];if(s.length===0&&r.length===1&&/^\\?.$/.test(r[0])&&!l){let g=r[0].length===2?r[0].slice(-1):r[0];return[dq(g),!1,u-t,!1]}let f="["+(l?"^":"")+g0(r)+"]",m="["+(l?"":"^")+g0(s)+"]";return[r.length&&s.length?"("+f+"|"+m+")":r.length?f:m,a,u-t,!0]};var Kn=(n,{windowsPathsNoEscape:e=!1}={})=>e?n.replace(/\[([^\/\\])\]/g,"$1"):n.replace(/((?!\\).|^)\[([^\/\\])\]/g,"$1$2").replace(/\\([^\/])/g,"$1");var fq=new Set(["!","?","+","*","@"]),b0=n=>fq.has(n),hq="(?!(?:^|/)\\.\\.?(?:$|/))",Kd="(?!\\.)",pq=new Set(["[","."]),mq=new Set(["..","."]),gq=new Set("().*{}+?[]^$\\!"),yq=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),Kg="[^/]",v0=Kg+"*?",T0=Kg+"+?",ho=class n{type;#e;#t;#i=!1;#r=[];#o;#T;#l;#d=!1;#a;#c;#s=!1;constructor(e,t,r={}){this.type=e,e&&(this.#t=!0),this.#o=t,this.#e=this.#o?this.#o.#e:this,this.#a=this.#e===this?r:this.#e.#a,this.#l=this.#e===this?[]:this.#e.#l,e==="!"&&!this.#e.#d&&this.#l.push(this),this.#T=this.#o?this.#o.#r.length:0}get hasMagic(){if(this.#t!==void 0)return this.#t;for(let e of this.#r)if(typeof e!="string"&&(e.type||e.hasMagic))return this.#t=!0;return this.#t}toString(){return this.#c!==void 0?this.#c:this.type?this.#c=this.type+"("+this.#r.map(e=>String(e)).join("|")+")":this.#c=this.#r.map(e=>String(e)).join("")}#g(){if(this!==this.#e)throw new Error("should only call on root");if(this.#d)return this;this.toString(),this.#d=!0;let e;for(;e=this.#l.pop();){if(e.type!=="!")continue;let t=e,r=t.#o;for(;r;){for(let s=t.#T+1;!r.type&&s<r.#r.length;s++)for(let i of e.#r){if(typeof i=="string")throw new Error("string part in extglob AST??");i.copyIn(r.#r[s])}t=r,r=t.#o}}return this}push(...e){for(let t of e)if(t!==""){if(typeof t!="string"&&!(t instanceof n&&t.#o===this))throw new Error("invalid part: "+t);this.#r.push(t)}}toJSON(){let e=this.type===null?this.#r.slice().map(t=>typeof t=="string"?t:t.toJSON()):[this.type,...this.#r.map(t=>t.toJSON())];return this.isStart()&&!this.type&&e.unshift([]),this.isEnd()&&(this===this.#e||this.#e.#d&&this.#o?.type==="!")&&e.push({}),e}isStart(){if(this.#e===this)return!0;if(!this.#o?.isStart())return!1;if(this.#T===0)return!0;let e=this.#o;for(let t=0;t<this.#T;t++){let r=e.#r[t];if(!(r instanceof n&&r.type==="!"))return!1}return!0}isEnd(){if(this.#e===this||this.#o?.type==="!")return!0;if(!this.#o?.isEnd())return!1;if(!this.type)return this.#o?.isEnd();let e=this.#o?this.#o.#r.length:0;return this.#T===e-1}copyIn(e){typeof e=="string"?this.push(e):this.push(e.clone(this))}clone(e){let t=new n(this.type,e);for(let r of this.#r)t.copyIn(r);return t}static#y(e,t,r,s){let i=!1,o=!1,a=-1,c=!1;if(t.type===null){let m=r,T="";for(;m<e.length;){let g=e.charAt(m++);if(i||g==="\\"){i=!i,T+=g;continue}if(o){m===a+1?(g==="^"||g==="!")&&(c=!0):g==="]"&&!(m===a+2&&c)&&(o=!1),T+=g;continue}else if(g==="["){o=!0,a=m,c=!1,T+=g;continue}if(!s.noext&&b0(g)&&e.charAt(m)==="("){t.push(T),T="";let S=new n(g,t);m=n.#y(e,S,m,s),t.push(S);continue}T+=g}return t.push(T),m}let l=r+1,u=new n(null,t),d=[],f="";for(;l<e.length;){let m=e.charAt(l++);if(i||m==="\\"){i=!i,f+=m;continue}if(o){l===a+1?(m==="^"||m==="!")&&(c=!0):m==="]"&&!(l===a+2&&c)&&(o=!1),f+=m;continue}else if(m==="["){o=!0,a=l,c=!1,f+=m;continue}if(b0(m)&&e.charAt(l)==="("){u.push(f),f="";let T=new n(m,u);u.push(T),l=n.#y(e,T,l,s);continue}if(m==="|"){u.push(f),f="",d.push(u),u=new n(null,t);continue}if(m===")")return f===""&&t.#r.length===0&&(t.#s=!0),u.push(f),f="",t.push(...d,u),l;f+=m}return t.type=null,t.#t=void 0,t.#r=[e.substring(r-1)],l}static fromGlob(e,t={}){let r=new n(null,void 0,t);return n.#y(e,r,0,t),r}toMMPattern(){if(this!==this.#e)return this.#e.toMMPattern();let e=this.toString(),[t,r,s,i]=this.toRegExpSource();if(!(s||this.#t||this.#a.nocase&&!this.#a.nocaseMagicOnly&&e.toUpperCase()!==e.toLowerCase()))return r;let a=(this.#a.nocase?"i":"")+(i?"u":"");return Object.assign(new RegExp(`^${t}$`,a),{_src:t,_glob:e})}get options(){return this.#a}toRegExpSource(e){let t=e??!!this.#a.dot;if(this.#e===this&&this.#g(),!this.type){let c=this.isStart()&&this.isEnd(),l=this.#r.map(m=>{let[T,g,S,k]=typeof m=="string"?n.#f(m,this.#t,c):m.toRegExpSource(e);return this.#t=this.#t||S,this.#i=this.#i||k,T}).join(""),u="";if(this.isStart()&&typeof this.#r[0]=="string"&&!(this.#r.length===1&&mq.has(this.#r[0]))){let T=pq,g=t&&T.has(l.charAt(0))||l.startsWith("\\.")&&T.has(l.charAt(2))||l.startsWith("\\.\\.")&&T.has(l.charAt(4)),S=!t&&!e&&T.has(l.charAt(0));u=g?hq:S?Kd:""}let d="";return this.isEnd()&&this.#e.#d&&this.#o?.type==="!"&&(d="(?:$|\\/)"),[u+l+d,Kn(l),this.#t=!!this.#t,this.#i]}let r=this.type==="*"||this.type==="+",s=this.type==="!"?"(?:(?!(?:":"(?:",i=this.#h(t);if(this.isStart()&&this.isEnd()&&!i&&this.type!=="!"){let c=this.toString();return this.#r=[c],this.type=null,this.#t=void 0,[c,Kn(this.toString()),!1,!1]}let o=!r||e||t||!Kd?"":this.#h(!0);o===i&&(o=""),o&&(i=`(?:${i})(?:${o})*?`);let a="";if(this.type==="!"&&this.#s)a=(this.isStart()&&!t?Kd:"")+T0;else{let c=this.type==="!"?"))"+(this.isStart()&&!t&&!e?Kd:"")+v0+")":this.type==="@"?")":this.type==="?"?")?":this.type==="+"&&o?")":this.type==="*"&&o?")?":`)${this.type}`;a=s+i+c}return[a,Kn(i),this.#t=!!this.#t,this.#i]}#h(e){return this.#r.map(t=>{if(typeof t=="string")throw new Error("string type in extglob ast??");let[r,s,i,o]=t.toRegExpSource(e);return this.#i=this.#i||o,r}).filter(t=>!(this.isStart()&&this.isEnd())||!!t).join("|")}static#f(e,t,r=!1){let s=!1,i="",o=!1;for(let a=0;a<e.length;a++){let c=e.charAt(a);if(s){s=!1,i+=(gq.has(c)?"\\":"")+c;continue}if(c==="\\"){a===e.length-1?i+="\\\\":s=!0;continue}if(c==="["){let[l,u,d,f]=y0(e,a);if(d){i+=l,o=o||u,a+=d-1,t=t||f;continue}}if(c==="*"){r&&e==="*"?i+=T0:i+=v0,t=!0;continue}if(c==="?"){i+=Kg,t=!0;continue}i+=yq(c)}return[i,Kn(e),!!t,o]}};var po=(n,{windowsPathsNoEscape:e=!1}={})=>e?n.replace(/[?*()[\]]/g,"[$&]"):n.replace(/[?*()[\]\\]/g,"\\$&");var zt=(n,e,t={})=>(Ua(e),!t.nocomment&&e.charAt(0)==="#"?!1:new mn(e,t).match(n)),bq=/^\*+([^+@!?\*\[\(]*)$/,vq=n=>e=>!e.startsWith(".")&&e.endsWith(n),Tq=n=>e=>e.endsWith(n),_q=n=>(n=n.toLowerCase(),e=>!e.startsWith(".")&&e.toLowerCase().endsWith(n)),Sq=n=>(n=n.toLowerCase(),e=>e.toLowerCase().endsWith(n)),wq=/^\*+\.\*+$/,kq=n=>!n.startsWith(".")&&n.includes("."),Eq=n=>n!=="."&&n!==".."&&n.includes("."),Nq=/^\.\*+$/,Pq=n=>n!=="."&&n!==".."&&n.startsWith("."),Rq=/^\*+$/,Dq=n=>n.length!==0&&!n.startsWith("."),Cq=n=>n.length!==0&&n!=="."&&n!=="..",Oq=/^\?+([^+@!?\*\[\(]*)?$/,Aq=([n,e=""])=>{let t=k0([n]);return e?(e=e.toLowerCase(),r=>t(r)&&r.toLowerCase().endsWith(e)):t},Iq=([n,e=""])=>{let t=E0([n]);return e?(e=e.toLowerCase(),r=>t(r)&&r.toLowerCase().endsWith(e)):t},Mq=([n,e=""])=>{let t=E0([n]);return e?r=>t(r)&&r.endsWith(e):t},$q=([n,e=""])=>{let t=k0([n]);return e?r=>t(r)&&r.endsWith(e):t},k0=([n])=>{let e=n.length;return t=>t.length===e&&!t.startsWith(".")},E0=([n])=>{let e=n.length;return t=>t.length===e&&t!=="."&&t!==".."},N0=typeof process=="object"&&process?typeof process.env=="object"&&process.env&&process.env.__MINIMATCH_TESTING_PLATFORM__||process.platform:"posix",_0={win32:{sep:"\\"},posix:{sep:"/"}},Lq=N0==="win32"?_0.win32.sep:_0.posix.sep;zt.sep=Lq;var It=Symbol("globstar **");zt.GLOBSTAR=It;var xq="[^/]",qq=xq+"*?",jq="(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?",Fq="(?:(?!(?:\\/|^)\\.).)*?",Bq=(n,e={})=>t=>zt(t,n,e);zt.filter=Bq;var Nn=(n,e={})=>Object.assign({},n,e),Uq=n=>{if(!n||typeof n!="object"||!Object.keys(n).length)return zt;let e=zt;return Object.assign((r,s,i={})=>e(r,s,Nn(n,i)),{Minimatch:class extends e.Minimatch{constructor(s,i={}){super(s,Nn(n,i))}static defaults(s){return e.defaults(Nn(n,s)).Minimatch}},AST:class extends e.AST{constructor(s,i,o={}){super(s,i,Nn(n,o))}static fromGlob(s,i={}){return e.AST.fromGlob(s,Nn(n,i))}},unescape:(r,s={})=>e.unescape(r,Nn(n,s)),escape:(r,s={})=>e.escape(r,Nn(n,s)),filter:(r,s={})=>e.filter(r,Nn(n,s)),defaults:r=>e.defaults(Nn(n,r)),makeRe:(r,s={})=>e.makeRe(r,Nn(n,s)),braceExpand:(r,s={})=>e.braceExpand(r,Nn(n,s)),match:(r,s,i={})=>e.match(r,s,Nn(n,i)),sep:e.sep,GLOBSTAR:It})};zt.defaults=Uq;var P0=(n,e={})=>(Ua(n),e.nobrace||!/\{(?:(?!\{).)*\}/.test(n)?[n]:(0,w0.default)(n));zt.braceExpand=P0;var Vq=(n,e={})=>new mn(n,e).makeRe();zt.makeRe=Vq;var Wq=(n,e,t={})=>{let r=new mn(e,t);return n=n.filter(s=>r.match(s)),r.options.nonull&&!n.length&&n.push(e),n};zt.match=Wq;var S0=/[?*]|[+@!]\(.*?\)|\[|\]/,Hq=n=>n.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"),mn=class{options;set;pattern;windowsPathsNoEscape;nonegate;negate;comment;empty;preserveMultipleSlashes;partial;globSet;globParts;nocase;isWindows;platform;windowsNoMagicRoot;regexp;constructor(e,t={}){Ua(e),t=t||{},this.options=t,this.pattern=e,this.platform=t.platform||N0,this.isWindows=this.platform==="win32",this.windowsPathsNoEscape=!!t.windowsPathsNoEscape||t.allowWindowsEscape===!1,this.windowsPathsNoEscape&&(this.pattern=this.pattern.replace(/\\/g,"/")),this.preserveMultipleSlashes=!!t.preserveMultipleSlashes,this.regexp=null,this.negate=!1,this.nonegate=!!t.nonegate,this.comment=!1,this.empty=!1,this.partial=!!t.partial,this.nocase=!!this.options.nocase,this.windowsNoMagicRoot=t.windowsNoMagicRoot!==void 0?t.windowsNoMagicRoot:!!(this.isWindows&&this.nocase),this.globSet=[],this.globParts=[],this.set=[],this.make()}hasMagic(){if(this.options.magicalBraces&&this.set.length>1)return!0;for(let e of this.set)for(let t of e)if(typeof t!="string")return!0;return!1}debug(...e){}make(){let e=this.pattern,t=this.options;if(!t.nocomment&&e.charAt(0)==="#"){this.comment=!0;return}if(!e){this.empty=!0;return}this.parseNegate(),this.globSet=[...new Set(this.braceExpand())],t.debug&&(this.debug=(...i)=>console.error(...i)),this.debug(this.pattern,this.globSet);let r=this.globSet.map(i=>this.slashSplit(i));this.globParts=this.preprocess(r),this.debug(this.pattern,this.globParts);let s=this.globParts.map((i,o,a)=>{if(this.isWindows&&this.windowsNoMagicRoot){let c=i[0]===""&&i[1]===""&&(i[2]==="?"||!S0.test(i[2]))&&!S0.test(i[3]),l=/^[a-z]:/i.test(i[0]);if(c)return[...i.slice(0,4),...i.slice(4).map(u=>this.parse(u))];if(l)return[i[0],...i.slice(1).map(u=>this.parse(u))]}return i.map(c=>this.parse(c))});if(this.debug(this.pattern,s),this.set=s.filter(i=>i.indexOf(!1)===-1),this.isWindows)for(let i=0;i<this.set.length;i++){let o=this.set[i];o[0]===""&&o[1]===""&&this.globParts[i][2]==="?"&&typeof o[3]=="string"&&/^[a-z]:$/i.test(o[3])&&(o[2]="?")}this.debug(this.pattern,this.set)}preprocess(e){if(this.options.noglobstar)for(let r=0;r<e.length;r++)for(let s=0;s<e[r].length;s++)e[r][s]==="**"&&(e[r][s]="*");let{optimizationLevel:t=1}=this.options;return t>=2?(e=this.firstPhasePreProcess(e),e=this.secondPhasePreProcess(e)):t>=1?e=this.levelOneOptimize(e):e=this.adjascentGlobstarOptimize(e),e}adjascentGlobstarOptimize(e){return e.map(t=>{let r=-1;for(;(r=t.indexOf("**",r+1))!==-1;){let s=r;for(;t[s+1]==="**";)s++;s!==r&&t.splice(r,s-r)}return t})}levelOneOptimize(e){return e.map(t=>(t=t.reduce((r,s)=>{let i=r[r.length-1];return s==="**"&&i==="**"?r:s===".."&&i&&i!==".."&&i!=="."&&i!=="**"?(r.pop(),r):(r.push(s),r)},[]),t.length===0?[""]:t))}levelTwoFileOptimize(e){Array.isArray(e)||(e=this.slashSplit(e));let t=!1;do{if(t=!1,!this.preserveMultipleSlashes){for(let s=1;s<e.length-1;s++){let i=e[s];s===1&&i===""&&e[0]===""||(i==="."||i==="")&&(t=!0,e.splice(s,1),s--)}e[0]==="."&&e.length===2&&(e[1]==="."||e[1]==="")&&(t=!0,e.pop())}let r=0;for(;(r=e.indexOf("..",r+1))!==-1;){let s=e[r-1];s&&s!=="."&&s!==".."&&s!=="**"&&(t=!0,e.splice(r-1,2),r-=2)}}while(t);return e.length===0?[""]:e}firstPhasePreProcess(e){let t=!1;do{t=!1;for(let r of e){let s=-1;for(;(s=r.indexOf("**",s+1))!==-1;){let o=s;for(;r[o+1]==="**";)o++;o>s&&r.splice(s+1,o-s);let a=r[s+1],c=r[s+2],l=r[s+3];if(a!==".."||!c||c==="."||c===".."||!l||l==="."||l==="..")continue;t=!0,r.splice(s,1);let u=r.slice(0);u[s]="**",e.push(u),s--}if(!this.preserveMultipleSlashes){for(let o=1;o<r.length-1;o++){let a=r[o];o===1&&a===""&&r[0]===""||(a==="."||a==="")&&(t=!0,r.splice(o,1),o--)}r[0]==="."&&r.length===2&&(r[1]==="."||r[1]==="")&&(t=!0,r.pop())}let i=0;for(;(i=r.indexOf("..",i+1))!==-1;){let o=r[i-1];if(o&&o!=="."&&o!==".."&&o!=="**"){t=!0;let c=i===1&&r[i+1]==="**"?["."]:[];r.splice(i-1,2,...c),r.length===0&&r.push(""),i-=2}}}}while(t);return e}secondPhasePreProcess(e){for(let t=0;t<e.length-1;t++)for(let r=t+1;r<e.length;r++){let s=this.partsMatch(e[t],e[r],!this.preserveMultipleSlashes);if(s){e[t]=[],e[r]=s;break}}return e.filter(t=>t.length)}partsMatch(e,t,r=!1){let s=0,i=0,o=[],a="";for(;s<e.length&&i<t.length;)if(e[s]===t[i])o.push(a==="b"?t[i]:e[s]),s++,i++;else if(r&&e[s]==="**"&&t[i]===e[s+1])o.push(e[s]),s++;else if(r&&t[i]==="**"&&e[s]===t[i+1])o.push(t[i]),i++;else if(e[s]==="*"&&t[i]&&(this.options.dot||!t[i].startsWith("."))&&t[i]!=="**"){if(a==="b")return!1;a="a",o.push(e[s]),s++,i++}else if(t[i]==="*"&&e[s]&&(this.options.dot||!e[s].startsWith("."))&&e[s]!=="**"){if(a==="a")return!1;a="b",o.push(t[i]),s++,i++}else return!1;return e.length===t.length&&o}parseNegate(){if(this.nonegate)return;let e=this.pattern,t=!1,r=0;for(let s=0;s<e.length&&e.charAt(s)==="!";s++)t=!t,r++;r&&(this.pattern=e.slice(r)),this.negate=t}matchOne(e,t,r=!1){let s=this.options;if(this.isWindows){let g=typeof e[0]=="string"&&/^[a-z]:$/i.test(e[0]),S=!g&&e[0]===""&&e[1]===""&&e[2]==="?"&&/^[a-z]:$/i.test(e[3]),k=typeof t[0]=="string"&&/^[a-z]:$/i.test(t[0]),v=!k&&t[0]===""&&t[1]===""&&t[2]==="?"&&typeof t[3]=="string"&&/^[a-z]:$/i.test(t[3]),b=S?3:g?0:void 0,R=v?3:k?0:void 0;if(typeof b=="number"&&typeof R=="number"){let[O,L]=[e[b],t[R]];O.toLowerCase()===L.toLowerCase()&&(t[R]=O,R>b?t=t.slice(R):b>R&&(e=e.slice(b)))}}let{optimizationLevel:i=1}=this.options;i>=2&&(e=this.levelTwoFileOptimize(e)),this.debug("matchOne",this,{file:e,pattern:t}),this.debug("matchOne",e.length,t.length);for(var o=0,a=0,c=e.length,l=t.length;o<c&&a<l;o++,a++){this.debug("matchOne loop");var u=t[a],d=e[o];if(this.debug(t,u,d),u===!1)return!1;if(u===It){this.debug("GLOBSTAR",[t,u,d]);var f=o,m=a+1;if(m===l){for(this.debug("** at the end");o<c;o++)if(e[o]==="."||e[o]===".."||!s.dot&&e[o].charAt(0)===".")return!1;return!0}for(;f<c;){var T=e[f];if(this.debug(`
|
|
238
238
|
globstar while`,e,f,t,m,T),this.matchOne(e.slice(f),t.slice(m),r))return this.debug("globstar found match!",f,c,T),!0;if(T==="."||T===".."||!s.dot&&T.charAt(0)==="."){this.debug("dot detected!",e,f,t,m);break}this.debug("globstar swallow a segment, and continue"),f++}return!!(r&&(this.debug(`
|