@dbml/parse 9.0.0-alpha.11 → 9.0.0-alpha.12

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.
@@ -18,15 +18,21 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Symbol(
18
18
  `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(v.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`,`-`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`-`:this.peek()===`>`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(v.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(v.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=+!!t,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Oo(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Oo(this.peek());)this.advance();if(this.isAtEnd()||!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(v.NUMERIC_LITERAL);if(!t&&!Ao(this.peek()))return this.addToken(v.NUMERIC_LITERAL);if(!t&&!Oo(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||Ao(this.peek()));)this.advance();let e=this.createToken(v.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new x(b.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();let e=this.createToken(v.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&Ao(this.peek());)this.advance();this.addToken(v.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
19
19
  `)&&this.advance(),``;case`
20
20
  `:return``;case`t`:return` `;case`n`:return`
21
- `;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Ao(this.peek()))return this.errors.push(new x(b.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Mb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Nb=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Pb=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Fb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Nb,this.useSpecifierList=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(Xs,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof Ys&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Xa(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),b.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Xa(e)||Ua(this.previous(),e))break;U(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,b.UNEXPECTED_EOF,`Unexpected EOF`):U(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;U(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Mb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(nc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ec,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof N&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.RPAREN,v.COMMA))break;U(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Mb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(V,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof N&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;U(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Pb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(U(this.peek()),this.logError(this.advance(),b.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)U(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(P,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){jc(e).forEach(t=>{t instanceof N&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Za(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Js&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(Js,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(ic,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Xs&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof ic?`'*'`:`specifier list`;return Xa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(Ys,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof N&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof F?(U(t),this.logError(t,b.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof F?this.errors.push(new x(b.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}expression(){let e={args:[]},t=()=>Dc(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(z,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,b.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(sc,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(tc,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(tc,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=Vb(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(H,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(H,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(cc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(cc,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Vb(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Qs,{expression:t,op:r})}else{let n=Lb(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=zb(t.op);if(n.right===null)throw this.logError(t.op,b.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(sc,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(L,t),e.handlerContext)):e}e=this.nodeFactory.create(L,t)}else if(e=this.extractOperand(),e instanceof sc)throw new $(this.peek(),this.nodeFactory.create(sc,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),b.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),b.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(sc,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create($s,e),t.handlerContext):t}return this.nodeFactory.create($s,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(ic,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(rc,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(ac,{variable:this.previous()})});throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,b.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(I,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(I,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new x(t,n,e))}},Ib={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"->":{left:7,right:8},"<-":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Lb(e){return Ib[e.value]||{left:null,right:null}}var Rb={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"->":{left:null,right:15},"<-":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function zb(e){return Rb[e.value]||{left:null,right:null}}var Bb={"(":{left:14,right:null}};function Vb(e){return Bb[e.value]||{left:null,right:null}}function Hb(e){let t=this.getSource(e);return new jb(t??``,e).lex().chain(n=>new Fb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Ub(){let e=Sg(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function Wb(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Ws?Yh.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function Gb(e,n,r){let i;if(e instanceof Ts)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Ts))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function Kb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Us&&n.originalSymbol===t&&n!==e))}function qb(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(w(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ec&&T(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ns(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of jc(e))t instanceof N&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Es&&t.isKind(M.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function Jb(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Yb(e){return this.resolutionIndex().references.get(e.intern())??[]}function Xb(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Zb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Ws&&n.originalSymbol===t&&n!==e))}function Qb(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function $b(e,t){if((e.schemaName&&e.schemaName.length>0?e.schemaName:`public`)!==(t.schemaName&&t.schemaName.length>0?t.schemaName:`public`)||e.tableName!==t.tableName)return!1;let n=e.fieldNames??[],r=t.fieldNames??[];return n.length===r.length?n.every((e,t)=>e===r[t]):!1}function ex(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=xg(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function tx(e,n,r,i,a=M.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,M.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function nx(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function rx(e,t){if(!e||!(e instanceof F))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function ix(e,t,n){let r=!gg(t),i=!gg(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function ax(e,t,n,r,i,a){return n===i&&r===a?!1:tx(e,t,i,a)!==void 0}function ox(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return nx(n.substring(i,a))===t?{start:i,end:e.end}:null}function sx(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function cx(e,t,n,r,i){let a=[],o=new Set,s=sx(r);for(let r of e){if(nx(i.substring(r.start,r.end))!==n)continue;let e=ox(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function lx(e,n,r){let i=ex(n),a=ex(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=tx(this,e,o,s);if(!u||u instanceof Us||ax(this,e,o,s,c,l))return new Map;if(u instanceof Ws&&u.useSpecifierDeclaration instanceof Ys&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return ux(this,e,n,u,c,l)}return dx(this,u,o,s,c,l)}function ux(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=ix(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,Qb(o,c)]])}function dx(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof F))return new Map;let c=s.filepath;if(!c)return new Map;let l=ix(i,a,rx(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:sx(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of cx([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,Qb(r,n))}return m}function fx(e,t){let n=gx(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof I?hs(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof F){let n=_x(e,t);if(n)return{kind:`body`,declaration:n}}}function px(e,t){let n=gx(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof F){let n=e.body;if(n&&!(n instanceof z))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function mx(e,t,n,r){if(n===null)return hx(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=fx(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return px(e,i)}function hx(e,t,n){let r=fx(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function gx(e){if(e instanceof z)return e.args.find(e=>e instanceof V);if(e instanceof F){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof z)return t.args.find(e=>e instanceof V)}}function _x(e,t){let n=e.body;if(!(!n||Po(e)||n instanceof z)){for(let e of n.body)if(e instanceof F&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function vx(e,t){let n=xx(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:wg(t)}}function yx(e){let t=xx(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function bx(e,t){if(xx(e)||!(e instanceof F))return;let n=Sx(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${wg(t)}\n`};let r=e.body;if(r instanceof z){let n=r.args.find(e=>e instanceof V);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${wg(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${wg(t)}]`}}}function xx(e){if(!(e instanceof F))return;let t=e.body;if(t&&!(t instanceof z))for(let e of t.body){if(!(e instanceof F)||!e.isKind(r.Note))continue;let t=Cx(e);if(t)return{kind:qs.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof z?t.args.find(e=>e instanceof V):void 0);if(n)return wx(n)}function Sx(e){let t=e.body;if(!(!t||t instanceof z)&&t.blockCloseBrace)return t.blockCloseBrace.start}function Cx(e){let t=e.body;if(t instanceof z)return t.callee??void 0;if(t instanceof B&&t.body[0]instanceof z)return t.body[0].callee??void 0}function wx(e){let t=S(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:qs.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function Tx(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations){if(!(e instanceof F)||!e.isKind(r.Dep))continue;let n=[],i=e.body;if(i instanceof z){if(i.callee instanceof R){let e=Nx(i.callee);e&&n.push(e)}}else if(i){for(let e of i.body)if(e instanceof z&&e.callee instanceof R){let t=Nx(e.callee);t&&n.push(t)}}t.push({startIndex:e.start,endIndex:e.end,declaration:e,edges:n})}return t}function Ex(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let a=new Fb(e,n.getValue(),new Ks,To).parse();if(a.getErrors().length>0)return t;let o=a.getValue().ast;for(let n of o.declarations){if(!(n instanceof F)||!n.isKind(r.Table))continue;let a=n.name?O(n.name)??[]:[];if(a.length===0)continue;let o=a[a.length-1],s=a.length>1?a[a.length-2]:void 0,c=n.body;if(!(!c||c instanceof z))for(let n of c.body){if(!(n instanceof z)||!n.callee)continue;let r=O(n.callee)?.at(-1);if(!r)continue;let a={schemaName:s,tableName:o,fieldNames:[r]},c=hx(n,i.Dep,e);if(c)for(let e of Bx(n,a))t.push({edge:e,stripStart:c.start,stripEnd:c.end})}}return t}function Dx(e,t){return`Dep [color: ${t}] {\n ${Fx(e.upstream)} -> ${Fx(e.downstream)}\n}`}function Ox(e,t,n){let r=this.getSource(e)??``,i=n??Tx(r),a=Ex(r),o=[];for(let e of t)o.push(...Vx(r,e,i,a));return o.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,o,!0),edits:o}}function kx(e){return e&&e.length>0?e:y}function Ax(e,t){if(e.length===0)return;if(!t){let t=e[e.length-1];return{schemaName:e.length>1?e[e.length-2]:null,tableName:t,fieldNames:[]}}let n=[e[e.length-1]],r=e[e.length-2];return{schemaName:e.length>2?e[e.length-3]:null,tableName:r,fieldNames:n}}function jx(e,t){return $b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)}function Mx(e,t){return e.edges.some(e=>jx(e,t))}function Nx(e){let t=e.op?.value;if(t!==`->`&&t!==`<-`)return;let n=e.leftExpression,r=e.rightExpression;if(!n||!r)return;let i=t===`<-`?r:n,a=t===`<-`?n:r,o=O(i),s=O(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=Ax(o,c),u=Ax(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function Px(e){if(e.name instanceof Zs)return as(e.name)?.toLowerCase()}function Fx(e){let t=kx(e.schemaName),n=[];t!==`public`&&n.push(_g(t)),n.push(_g(e.tableName));for(let t of e.fieldNames??[])n.push(_g(t));return n.join(`.`)}function Ix(e,t){return e.find(e=>Mx(e,t))}function Lx(e,t,n){let r=[];if(e.color!==void 0){let a=mx(t.declaration,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=yx(t.declaration);e&&r.push(e)}else if(e.note!==void 0){let n=vx(t.declaration,e.note)??bx(t.declaration,e.note);n&&r.push(n)}return r}function Rx(e,t,n,r){let i=Ix(n,t.edge);if(i)return Lx(t,i,e);let a=Dx(t.edge,t.color??``),o={start:e.length,end:e.length,newText:`
21
+ `;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!Ao(this.peek()))return this.errors.push(new x(b.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Va.create(v.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}},Mb=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({}),Nb=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===0&&(this.numberOfNestedLBrackets+=1),e===1&&(this.numberOfNestedLParens+=1),e===2&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===0&&--this.numberOfNestedLBrackets,e===1&&--this.numberOfNestedLParens,e===2&&--this.numberOfNestedLBraces,e}top(){return g(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case v.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[1,0].includes(e));break;case v.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case v.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case v.RBRACKET:if(this.isWithinListExpressionContext())return 0;break;default:break}}},Pb=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},$=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Fb=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Nb,this.useSpecifierList=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={specifiers:[]},t=()=>this.nodeFactory.create(Xs,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.openBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);){try{e.specifiers.push(this.useSpecifier())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof Ys&&e.specifiers.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeUseSpecifierList()}if(this.check(v.IDENTIFIER)&&Xa(this.peek()))break;!Ha(this.previous())&&!this.check(v.RBRACE)&&this.logError(this.peek(),b.MISSING_SPACES,`Expect a newline between use specifiers`)}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.closeBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeUseSpecifierList()}return t()}),this.synchronizeUseSpecifierList=()=>{if(!this.check(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||this.check(v.STRING_LITERAL)||this.check(v.IDENTIFIER)&&Xa(e)||Ua(this.previous(),e))break;U(e),this.advance()}},this.synchronizeProgram=()=>{let e=this.peek();e.kind===v.EOF?this.logError(e,b.UNEXPECTED_EOF,`Unexpected EOF`):U(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Ja(e)||this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COLON,v.LBRACE,v.LBRACKET))break;U(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Mb.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(B,e);try{this.consume(`Expect an opening brace '{'`,v.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(v.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof $))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,v.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(v.RBRACE))for(U(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(v.RBRACE)||Ua(this.previous(),e))break;U(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Mb.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(nc,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(ec,e);try{this.consume(`Expect an opening parenthesis '('`,v.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(v.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(v.RPAREN);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof $))throw t;if(t.partialNode instanceof N&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new $(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,v.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.RPAREN,v.COMMA))break;U(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Mb.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(V,e);try{this.consume(`Expect an opening bracket '['`,v.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(v.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(v.RBRACKET);)try{this.consume(`Expect a comma ','`,v.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof $))throw n;if(n.partialNode instanceof N&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,v.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET,v.COLON))break;U(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(v.COMMA,v.RBRACKET))break;U(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Pb(n,r),this.filepath=r}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===v.EOF}advance(){return this.isAtEnd()?g(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?g(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,e),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(U(this.peek()),this.logError(this.advance(),b.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)U(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),r=this.nodeFactory.create(P,{body:e,eof:t,source:this.source});return this.gatherInvalid(),this.assignParents(r),new n({ast:r,tokens:this.tokens},this.errors)}assignParents(e){jc(e).forEach(t=>{t instanceof N&&(t.parentNode=e,this.assignParents(t))})}program(){let e=[];for(;!this.isAtEnd();)if(Ya(this.peek())||Za(this.peek()))try{e.push(this.useDeclaration())}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Js&&e.push(t.partialNode),this.synchronizeProgram()}else try{e.push(this.elementDeclaration())}catch(t){if(!(t instanceof $))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}useDeclaration(){let e={},t=()=>this.nodeFactory.create(Js,e);if(this.advance(),e.useKeyword=this.previous(),this.peek().kind===v.WILDCARD)this.advance(),e.specifiers=this.nodeFactory.create(ic,{token:this.previous()});else try{e.specifiers=this.useSpecifierList()}catch(t){if(!(t instanceof $))throw t;t.partialNode instanceof Xs&&(e.specifiers=t.partialNode)}let n=e.specifiers instanceof ic?`'*'`:`specifier list`;return Xa(this.peek())?e.fromKeyword=this.advance():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect 'from' after ${n}`),this.match(v.STRING_LITERAL)?e.importPath=this.previous():this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a string literal path`),t()}useSpecifier(){let e={},t=()=>this.nodeFactory.create(Ys,e);try{this.consume(`Expect an import kind specifier (e.g. table, enum)`,v.IDENTIFIER),e.importKind=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(this.check(v.IDENTIFIER,v.QUOTED_STRING))try{e.name=this.normalExpression()}catch(n){throw n instanceof $?(n.partialNode instanceof N&&(e.name=n.partialNode),new $(n.token,t(),n.handlerContext)):n}else e.importKind&&this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an element name`);if(Ja(this.peek())){e.asKeyword=this.advance();try{if(!this.check(v.IDENTIFIER,v.QUOTED_STRING))throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias name after 'as'`),new $(this.peek(),t(),this.contextStack.findHandlerContext(this.tokens,this.current));e.alias=this.normalExpression()}catch(e){if(!(e instanceof $))throw e;if(!this.canHandle(e))throw new $(e.token,t(),e.handlerContext)}}return t()}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof $?new $(e.token,t(),e.handlerContext):e}if(!this.check(v.COLON,v.LBRACE,v.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Ja(this.peek()))if(e.as=this.advance(),this.check(v.COLON,v.LBRACE,v.LBRACKET))this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof $))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new $(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(v.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof $?(e.attributeList=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,v.LBRACE,v.COLON))return t();try{if(this.match(v.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof F?(U(t),this.logError(t,b.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(F,e);try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof $?(e.type=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,v.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof $?(e.bodyColon=n.partialNode,new $(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof F?this.errors.push(new x(b.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof $?(e.body=n.partialNode,new $(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(F,e)}expression(){let e={args:[]},t=()=>Dc(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(z,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof $?(e.callee=n.partialNode,new $(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){Wa(this.previous())||this.logError(n,b.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof $?(n=r.partialNode,e.args.push(n),new $(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.RBRACKET,v.RPAREN,v.COMMA,v.COLON].includes(e)}commaExpression(){let e=this.check(v.COMMA)?this.nodeFactory.create(sc,{prevToken:this.previous()}):this.normalExpression();if(!this.check(v.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));break}if(this.check(v.COMMA)){t.elementList.push(this.nodeFactory.create(sc,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof $?(e.partialNode&&t.elementList.push(e.partialNode),new $(e.token,this.nodeFactory.create(tc,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(v.COMMA));return this.nodeFactory.create(tc,t)}shouldStopCommaExpression(){if(this.isAtEnd()||Ha(this.previous()))return!0;let e=this.peek().kind;return[v.RBRACE,v.LBRACE,v.RBRACKET,v.LBRACKET,v.RPAREN,v.LPAREN,v.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===v.LPAREN){let{left:r}=Vb(n);if(r<e||Ua(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(H,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(H,{callee:t,argumentList:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(n.kind===v.LBRACKET){if(Wa(this.previous()))break;try{t=this.nodeFactory.create(cc,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(cc,{expression:t,indexer:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}else if(Ba(n)){let r=n,i=Vb(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Qs,{expression:t,op:r})}else{let n=Lb(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof $?(t=this.nodeFactory.create(R,{leftExpression:t,op:r,rightExpression:e.partialNode}),new $(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(Ba(this.peek())){let t={};t.op=this.peek();let n=zb(t.op);if(n.right===null)throw this.logError(t.op,b.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new $(t.op,this.nodeFactory.create(sc,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof $?(t.expression=e.partialNode,new $(e.token,this.nodeFactory.create(L,t),e.handlerContext)):e}e=this.nodeFactory.create(L,t)}else if(e=this.extractOperand(),e instanceof sc)throw new $(this.peek(),this.nodeFactory.create(sc,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(v.WILDCARD)?this.wildcardExpression():this.check(v.NUMERIC_LITERAL,v.STRING_LITERAL,v.COLOR_LITERAL,v.QUOTED_STRING,v.IDENTIFIER)?this.primaryExpression():this.check(v.FUNCTION_EXPRESSION)?this.functionExpression():this.check(v.LBRACKET)?this.listExpression():this.check(v.LBRACE)?this.blockExpression():this.check(v.LPAREN)?this.tupleExpression():(this.peek().kind===v.EOF?this.logError(this.peek(),b.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),b.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(sc,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,v.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create($s,e),t.handlerContext):t}return this.nodeFactory.create($s,e)}wildcardExpression(){return this.advance(),this.nodeFactory.create(ic,{token:this.previous()})}canBeField(){return this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.COLON}primaryExpression(){if(this.match(v.COLOR_LITERAL,v.STRING_LITERAL,v.NUMERIC_LITERAL))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(rc,{literal:this.previous()})});if(this.match(v.QUOTED_STRING,v.IDENTIFIER))return this.nodeFactory.create(oc,{expression:this.nodeFactory.create(ac,{variable:this.previous()})});throw this.logError(this.peek(),b.UNEXPECTED_TOKEN,`Expect a variable or literal`),new $(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(v.COLON,v.RBRACKET,v.COMMA)){let t=this.peek();this.logError(t,b.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(Zs,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof $))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new $(t.token,this.nodeFactory.create(I,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(v.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(I,e)}attributeValue(){let e;try{e=this.peek().kind===v.IDENTIFIER&&this.peek(1).kind===v.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof $)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==v.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(v.COLON,v.COMMA,v.RBRACKET);)try{this.consume(`Expect an identifier`,v.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof $?new $(t.token,this.nodeFactory.create(Zs,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(Zs,{identifiers:e})}logError(e,t,n){this.errors.push(new x(t,n,e))}},Ib={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"->":{left:7,right:8},"<-":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Lb(e){return Ib[e.value]||{left:null,right:null}}var Rb={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"->":{left:null,right:15},"<-":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function zb(e){return Rb[e.value]||{left:null,right:null}}var Bb={"(":{left:14,right:null}};function Vb(e){return Bb[e.value]||{left:null,right:null}}function Hb(e){let t=this.getSource(e);return new jb(t??``,e).lex().chain(n=>new Fb(t??``,n,this.nodeIdGenerator,e).parse()).map(({ast:t,tokens:n})=>({ast:t,tokens:n,path:e}))}function Ub(){let e=Sg(this,this.layout.getEntrypoints()),t=new Map;for(let n of e){let e=this.parseFile(n);t.set(n.absolute,e)}return t}function Wb(e){let n=this.symbolMembers(e).getFiltered(t),r=new Map;if(n)for(let e of n){let t=e instanceof Ws?Yh.visibleName(this,e)?.at(-1):e.name;if(t===void 0)continue;let n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}return r}function Gb(e,n,r){let i;if(e instanceof Ts)i=e;else{let n=this.nodeSymbol(e).getFiltered(t);if(!(n instanceof Ts))return;i=n}let a=Array.isArray(n)?n:[n],o=this.symbolMembersLookupMap(i).get(r);if(o)return o.find(e=>!(a.length===1&&e.kind!==a[0]||a.length>1&&!a.includes(e.kind)))}function Kb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Us&&n.originalSymbol===t&&n!==e))}function qb(){let e=new Map,n=new Map,r=this.parseProject();this.bindProject();let i=new Set,a=(t,n)=>{if(i.has(n))return;i.add(n);let r=t.intern(),a=e.get(r);a||(a=[],e.set(r,a)),a.push(n);let o=t.originalSymbol;if(o!==t){let t=o.intern(),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}},o=e=>{for(let t of e.owners(this)){let r=t.intern(),i=n.get(r);i||(i=[],n.set(r,i)),i.push(e)}};for(let e of r.values()){let n=e.getValue().ast,r=e=>{if(w(e)){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e);return}if(e instanceof ec&&T(e.parentNode)&&e.parentNode.rightExpression===e){let n=e.parentNode.leftExpression;if(n){let e=ns(n);if(e){let n=this.nodeReferee(e).getFiltered(t);n&&a(n,e)}}}let n=this.nodeMetadata(e).getFiltered(t);n&&o(n);for(let t of jc(e))t instanceof N&&r(t)};r(n)}let s=new Map,c=new Set;function l(e,n){let r=n.intern();if(c.has(r))return;c.add(r);let i=e.symbolMembers(n).getFiltered(t);if(i)for(let t of i){let r=t.intern(),i=s.get(r);i||(i=[],s.set(r,i)),i.push(n),t instanceof Es&&t.isKind(M.Schema)&&l(e,t)}}for(let e of r.values()){let n=e.getValue().ast,r=this.nodeSymbol(n).getFiltered(t);r&&l(this,r)}return{references:e,metadata:n,parents:s}}function Jb(e){return this.resolutionIndex().parents.get(e.intern())??[]}function Yb(e){return this.resolutionIndex().references.get(e.intern())??[]}function Xb(e){return this.resolutionIndex().metadata.get(e.intern())??[]}function Zb(e){let t=e.originalSymbol;return Cg(this).map(n=>n.filter(n=>n instanceof Ws&&n.originalSymbol===t&&n!==e))}function Qb(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function $b(e,t){let n=rx(e);if(n){let e=n.elementList??[],r=e.findIndex(e=>e instanceof I?hs(e)?.toLowerCase()===t.toLowerCase():!1);if(r!==-1)return{kind:`attribute`,settingsList:n,settingNode:e[r],settingIndex:r}}if(e instanceof F){let n=ix(e,t);if(n)return{kind:`body`,declaration:n}}}function ex(e,t){let n=rx(e);if(n){let e=n.end-1;return{start:e,end:e,newText:`, ${t}`}}if(e instanceof F){let n=e.body;if(n&&!(n instanceof z))return{start:n.start,end:n.start,newText:`[${t}] `}}return{start:e.end,end:e.end,newText:` [${t}]`}}function tx(e,t,n,r){if(n===null)return nx(e,t,r);let i=n===void 0?t:`${t}: ${n}`,a=$b(e,t);if(a){let e=a.kind===`attribute`?a.settingNode:a.declaration;return{start:e.start,end:e.end,newText:i}}return ex(e,i)}function nx(e,t,n){let r=$b(e,t);if(!r)return;if(r.kind===`body`)return{start:r.declaration.start,end:r.declaration.end,newText:``};let{settingsList:i,settingIndex:a}=r,o=i.elementList??[];if(o.length===1){let e=i.start;for(;e>0&&n[e-1]===` `;)e--;return{start:e,end:i.end,newText:``}}let s=o[a];if(a===0){let e=o[a+1];return{start:s.start,end:e.start,newText:``}}return{start:o[a-1].end,end:s.end,newText:``}}function rx(e){if(e instanceof z)return e.args.find(e=>e instanceof V);if(e instanceof F){if(e.attributeList)return e.attributeList;let t=e.body;if(t instanceof z)return t.args.find(e=>e instanceof V)}}function ix(e,t){let n=e.body;if(!(!n||Po(e)||n instanceof z)){for(let e of n.body)if(e instanceof F&&e.type?.value?.toLowerCase()===t.toLowerCase())return e}}function ax(e,n,r){let a=e.parseFile(n).getValue().ast,o=e.nodeSymbol(a).getFiltered(t);if(!o)return;let s=e.getSource(n)??``;for(let t of e.symbolMetadata(o))if(t instanceof pc&&sx(e,t,r)){if(t.declaration instanceof I){let n=t.op(e);if(!n)continue;let r=t.declaration.parentOfKind(z);if(!r)continue;let a=nx(r,i.Ref,s);if(!a)continue;return{kind:`inline`,op:n,fullStart:a.start,fullEnd:a.end}}if(t.declaration instanceof F){let e=cs(t.declaration)[0];if(e instanceof z)return{kind:`standalone`,node:e}}}}function ox(e,t,n){if(!e?.name||e.name!==n.tableName)return!1;let r=n.fieldNames??[];return r.length===0?!0:t.length===r.length?t.every((e,t)=>e.name===r[t]):!1}function sx(e,t,n){let r=t.leftTable(e),i=t.leftColumns(e),a=t.rightTable(e),o=t.rightColumns(e),[s,c]=n.endpoints;return ox(r,i,s)&&ox(a,o,c)||ox(r,i,c)&&ox(a,o,s)}function cx(e){return e&&e.length>0?e:y}function lx(e,t){if(cx(e.schemaName)!==cx(t.schemaName)||e.tableName!==t.tableName)return!1;let n=e.fieldNames??[],r=t.fieldNames??[];return n.length===r.length?n.every((e,t)=>e===r[t]):!1}function ux(e,t){if(cx(e.schemaName)!==cx(t.schemaName)||e.tableName!==t.tableName)return!1;let n=t.fieldNames??[];if(n.length===0)return!0;let r=e.fieldNames??[];return r.length===n.length?r.every((e,t)=>e===n[t]):!1}function dx(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=xg(e);if(t.length===0)return{schema:y,table:``};if(t.length===1)return{schema:y,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function fx(e,n,r,i,a=M.Table){let o=e.parseFile(n).getValue().ast,s=e.nodeSymbol(o).getFiltered(t);if(!s)return;if(r===`public`)return e.lookupMembers(s,a,i)??void 0;let c=e.lookupMembers(s,M.Schema,r);if(c)return e.lookupMembers(c,a,i)??void 0}function px(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function mx(e){let t=[];e.schemaName&&e.schemaName!==`public`&&t.push(_g(e.schemaName)),t.push(_g(e.tableName));for(let n of e.fieldNames??[])t.push(_g(n));return t.join(`.`)}function hx(e,t){return t===void 0?e:t===null?``:`${e}: ${t}`}function gx(e,t){if(!e||!(e instanceof F))return!1;let n=e.name;return n?t.substring(n.start,n.end).includes(`"`):!1}function _x(e,t,n){let r=!gg(t),i=!gg(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function vx(e,t,n,r,i,a){return n===i&&r===a?!1:fx(e,t,i,a)!==void 0}function yx(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return px(n.substring(i,a))===t?{start:i,end:e.end}:null}function bx(e){return e.schema===`public`?e.formattedTable:`${e.formattedSchema}.${e.formattedTable}`}function xx(e,t,n,r,i){let a=[],o=new Set,s=bx(r);for(let r of e){if(px(i.substring(r.start,r.end))!==n)continue;let e=yx(r,t,i)??{start:r.start,end:r.end},c=`${e.start}-${e.end}`;o.has(c)||(o.add(c),a.push({start:e.start,end:e.end,newText:s}))}return a}function Sx(e,n,r){let i=dx(n),a=dx(r),o=i.schema,s=i.table,c=a.schema,l=a.table,u=fx(this,e,o,s);if(!u||u instanceof Us||vx(this,e,o,s,c,l))return new Map;if(u instanceof Ws&&u.useSpecifierDeclaration instanceof Ys&&u.useSpecifierDeclaration.alias){let n=u.useSpecifierDeclaration;if(this.nodeAlias(n).getFiltered(t)===s)return Cx(this,e,n,u,c,l)}return wx(this,u,o,s,c,l)}function Cx(e,t,n,r,i,a){let o=e.getSource(t)??``;if(!n.alias)return new Map;let s=_x(i,a,o.substring(n.alias.start,n.alias.end).includes(`"`)),c=[];c.push({start:n.alias.start,end:n.alias.end,newText:s.formattedTable});let l=e.symbolReferences(r);for(let e of l)e.filepath.absolute===t.absolute&&e!==n.alias&&c.push({start:e.start,end:e.end,newText:s.formattedTable});return new Map([[t.absolute,Qb(o,c)]])}function wx(e,t,n,r,i,a){let o=t.originalSymbol,s=o.declaration;if(!s||!(s instanceof F))return new Map;let c=s.filepath;if(!c)return new Map;let l=_x(i,a,gx(s,e.getSource(c)??``)),u=new Map,d=(e,t)=>{let n=e.absolute,r=u.get(n);r||(r={fp:e,edits:[]},u.set(n,r)),r.edits.push(t)},f=s.name;f&&d(c,{start:f.start,end:f.end,newText:bx(l)});let p=e.symbolReferences(o);for(let t of p){if(t===f)continue;let i=t.filepath,a=e.getSource(i)??``;for(let e of xx([t],n,r,l,a))d(i,e)}let m=new Map;for(let{fp:t,edits:n}of u.values()){let r=e.getSource(t)??``;m.set(t.absolute,Qb(r,n))}return m}function Tx(e,t){let n=Ox(e);if(n)return{start:n.noteValueStart,end:n.noteValueEnd,newText:wg(t)}}function Ex(e){let t=Ox(e);if(t)return{start:t.fullNoteStart,end:t.fullNoteEnd,newText:``}}function Dx(e,t){if(Ox(e)||!(e instanceof F))return;let n=kx(e);if(n!==void 0)return{start:n,end:n,newText:` note: ${wg(t)}\n`};let r=e.body;if(r instanceof z){let n=r.args.find(e=>e instanceof V);if(n&&n.listCloseBracket){let e=n.elementList.length===0?``:`, `;return{start:n.listCloseBracket.start,end:n.listCloseBracket.start,newText:`${e}note: ${wg(t)}`}}return{start:e.end,end:e.end,newText:` [note: ${wg(t)}]`}}}function Ox(e){if(!(e instanceof F))return;let t=e.body;if(t&&!(t instanceof z))for(let e of t.body){if(!(e instanceof F)||!e.isKind(r.Note))continue;let t=Ax(e);if(t)return{kind:qs.ELEMENT_DECLARATION,noteValueStart:t.start,noteValueEnd:t.end,fullNoteStart:e.start,fullNoteEnd:e.end}}let n=e.attributeList??(t instanceof z?t.args.find(e=>e instanceof V):void 0);if(n)return jx(n)}function kx(e){let t=e.body;if(!(!t||t instanceof z)&&t.blockCloseBrace)return t.blockCloseBrace.start}function Ax(e){let t=e.body;if(t instanceof z)return t.callee??void 0;if(t instanceof B&&t.body[0]instanceof z)return t.body[0].callee??void 0}function jx(e){let t=S(e).getValue()[i.Note];if(!t?.length)return;let n=t[0];if(!n.value)return;let r=e.elementList,a=r.indexOf(n),o=n.start,s=n.end;return r.length===1?(o=e.start,s=e.end):a<r.length-1?s=r[a+1].start:o=r[a-1].end,{kind:qs.ATTRIBUTE,noteValueStart:n.value.start,noteValueEnd:n.value.end,fullNoteStart:o,fullNoteEnd:s}}function Mx(e){let t=Fx(e);return t?Nx(t):[]}function Nx(e){let t=[];for(let n of e.declarations){if(!(n instanceof F)||!n.isKind(r.Dep))continue;let e=[],i=n.body;if(i instanceof z){if(i.callee instanceof R){let t=Vx(i.callee);t&&e.push(t)}}else if(i){for(let t of i.body)if(t instanceof z&&t.callee instanceof R){let n=Vx(t.callee);n&&e.push(n)}}t.push({startIndex:n.start,endIndex:n.end,declaration:n,edges:e})}return t}function Px(e,t){let n=[];for(let a of t.declarations){if(!(a instanceof F)||!a.isKind(r.Table))continue;let t=a.name?O(a.name)??[]:[];if(t.length===0)continue;let o=t[t.length-1],s=t.length>1?t[t.length-2]:void 0,c=a.body;if(!(!c||c instanceof z))for(let t of c.body){if(!(t instanceof z)||!t.callee)continue;let r=O(t.callee)?.at(-1);if(!r)continue;let a={schemaName:s,tableName:o,fieldNames:[r]},c=nx(t,i.Dep,e);if(c)for(let e of qx(t,a))n.push({edge:e,stripStart:c.start,stripEnd:c.end})}}return n}function Fx(e){let t=new jb(e,To).lex();if(t.getErrors().length>0)return;let n=new Fb(e,t.getValue(),new Ks,To).parse();if(!(n.getErrors().length>0))return n.getValue().ast}function Ix(e,t){return`Dep [color: ${t}] {\n ${mx(e.upstream)} -> ${mx(e.downstream)}\n}`}function Lx(e,t,n){let r=this.getSource(e)??``,i=this.parseFile(e).getValue().ast,a=n??Nx(i),o=Px(r,i),s=[];for(let e of t)s.push(...Jx(r,e,a,o));return s.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,s,!0),edits:s}}function Rx(e,t){if(e.length===0)return;if(!t){let t=e[e.length-1];return{schemaName:e.length>1?e[e.length-2]:null,tableName:t,fieldNames:[]}}let n=[e[e.length-1]],r=e[e.length-2];return{schemaName:e.length>2?e[e.length-3]:null,tableName:r,fieldNames:n}}function zx(e,t){return lx(e.upstream,t.upstream)&&lx(e.downstream,t.downstream)}function Bx(e,t){return e.edges.some(e=>zx(e,t))}function Vx(e){let t=e.op?.value;if(t!==`->`&&t!==`<-`)return;let n=e.leftExpression,r=e.rightExpression;if(!n||!r)return;let i=t===`<-`?r:n,a=t===`<-`?n:r,o=O(i),s=O(a);if(!o||!s)return;let c=o.length>1&&s.length>1,l=Rx(o,c),u=Rx(s,c);if(!(!l||!u))return{upstream:l,downstream:u}}function Hx(e){if(e.name instanceof Zs)return as(e.name)?.toLowerCase()}function Ux(e,t){return e.find(e=>Bx(e,t))}function Wx(e,t,n){let r=[];if(e.color!==void 0){let a=tx(t.declaration,i.Color,e.color,n);a&&r.push(a)}if(e.note===null){let e=Ex(t.declaration);e&&r.push(e)}else if(e.note!==void 0){let n=Tx(t.declaration,e.note)??Dx(t.declaration,e.note);n&&r.push(n)}return r}function Gx(e,t,n,r){let i=Ux(n,t.edge);if(i)return Wx(t,i,e);let a=Ix(t.edge,t.color??``),o={start:e.length,end:e.length,newText:`
22
22
 
23
23
  `+a+`
24
- `},s=r.find(e=>jx(e.edge,t.edge));return s?[{start:s.stripStart,end:s.stripEnd,newText:``},o]:[o]}function zx(e,t,n){let r=e.color===void 0&&e.note===void 0;return Lx({...e,color:r?null:e.color},t,n)}function Bx(e,t){let n=e.args.find(e=>e instanceof V);if(!n)return[];let r=[];for(let e of n.elementList){if(Px(e)!==i.Dep)continue;let n=e.value;if(!(n instanceof L)||!n.expression)continue;let a=n.op?.value;if(a!==`->`&&a!==`<-`)continue;let o=O(n.expression);if(!o)continue;let s=Ax(o,o.length>1);s&&r.push(a===`->`?{upstream:t,downstream:s}:{upstream:s,downstream:t})}return r}function Vx(e,t,n,r){switch(t.operation){case`create`:return Rx(e,t,n,r);case`update`:{let r=Ix(n,t.edge);return r?Lx(t,r,e):[]}case`remove`:{let r=Ix(n,t.edge);return r?zx(t,r,e):[]}default:return[]}}function Hx(e,t,n,r){let i=this.getSource(e)??``;if(t.kind===`dep`)return Wx(i,t,n,r);if(t.kind===`ref`)return Gx(i,t,n,r);let a=Ux(this,e,t);if(!a)return i;let o=mx(a,n,r,i);return o?Qb(i,[o]):i}function Ux(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case M.Column:{let i=tx(e,t,r,n.table,M.Table);return i?e.lookupMembers(i,M.Column,n.column)?.declaration:void 0}case M.Table:return tx(e,t,r,n.table)?.declaration;case M.Enum:case M.StickyNote:case M.TableGroup:return tx(e,t,r,n.name,n.kind)?.declaration;case M.Schema:return tx(e,t,n.schema,``,M.Schema)?.declaration;default:return}}function Wx(e,t,n,r){let i=Tx(e).find(e=>e.edges.some(e=>$b(e.upstream,t.upstream)&&$b(e.downstream,t.downstream)));if(!i)return e;let{declaration:a}=i,{body:o}=a;if(o instanceof z){let t=mx(a,n,r,e);if(t)return Qb(e,[t]);let i=mx(o,n,r,e);return i?Qb(e,[i]):e}let s=mx(a,n,r,e);return s?Qb(e,[s]):e}function Gx(e,t,n,r){let i=Jx(e,t);if(!i)return e;let a=mx(i,n,r,e);return a?Qb(e,[a]):e}function Kx(e){if(e.length!==0)return e.length===1?{tableName:e[0]}:e.length===2?{tableName:e[0],fieldNames:[e[1]]}:{schemaName:e[0],tableName:e[1],fieldNames:e.slice(2)}}function qx(e,t){let n=e.leftExpression?O(e.leftExpression):null,r=e.rightExpression?O(e.rightExpression):null;if(!n||!r)return!1;let i=Kx(n),a=Kx(r);if(!i||!a)return!1;let[o,s]=t.endpoints;return $b(i,o)&&$b(a,s)||$b(i,s)&&$b(a,o)}function Jx(e,t){let n=new jb(e,To).lex();if(n.getErrors().length>0)return;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return;let a=i.getValue().ast;for(let e of a.declarations){if(!(e instanceof F)||!e.isKind(r.Ref))continue;let n=e.body;if(n instanceof z&&n.callee instanceof R){if(qx(n.callee,t))return n;continue}if(n&&!(n instanceof z)){for(let e of n.body)if(e instanceof z&&e.callee instanceof R&&qx(e.callee,t))return e}}}function Yx(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?O(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function Xx(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function Zx(e,t){e.push(` ${t} { * }`)}function Qx(e){return e==null?`null`:e.length===0?`empty`:`items`}function $x(e,t){let n=`DiagramView ${_g(e)} {`,r=e=>_g(e.name),i=t?.tables?.map(e=>{let t=_g(e.name);return e.schemaName===`public`?t:`${_g(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:Qx(t.tables),tableGroups:Qx(t.tableGroups),schemas:Qx(t.schemas),stickyNotes:Qx(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&Xx(d,`Tables`,i),c.tableGroups===`items`&&Xx(d,`TableGroups`,a),c.schemas===`items`&&Xx(d,`Schemas`,o)):u&&Zx(d,`Tables`),c.stickyNotes===`items`?Xx(d,`Notes`,s):c.stickyNotes===`empty`&&Zx(d,`Notes`),d.push(`}`),d.join(`
25
- `)}function eS(e,t,n){let r=this.getSource(e)??``,i=n??Yx(r),a=[];for(let e of t){let t=tS(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,a,!0),edits:a}}function tS(e,t,n){switch(t.operation){case`create`:return nS(e,t,n);case`update`:return rS(e,t,n);case`delete`:return iS(e,t,n);default:return[]}}function nS(e,t,n){if(n.find(e=>e.name===t.name))return rS(e,t,n);let r=`
24
+ `},s=r.find(e=>zx(e.edge,t.edge));return s?[{start:s.stripStart,end:s.stripEnd,newText:``},o]:[o]}function Kx(e,t,n){let r=e.color===void 0&&e.note===void 0;return Wx({...e,color:r?null:e.color},t,n)}function qx(e,t){let n=e.args.find(e=>e instanceof V);if(!n)return[];let r=[];for(let e of n.elementList){if(Hx(e)!==i.Dep)continue;let n=e.value;if(!(n instanceof L)||!n.expression)continue;let a=n.op?.value;if(a!==`->`&&a!==`<-`)continue;let o=O(n.expression);if(!o)continue;let s=Rx(o,o.length>1);s&&r.push(a===`->`?{upstream:t,downstream:s}:{upstream:s,downstream:t})}return r}function Jx(e,t,n,r){switch(t.operation){case`create`:return Gx(e,t,n,r);case`update`:{let r=Ux(n,t.edge);return r?Wx(t,r,e):[]}case`remove`:{let r=Ux(n,t.edge);return r?Kx(t,r,e):[]}default:return[]}}function Yx(e,t,n,r){if(t.kind===`dep`)return Qx(this,e,t,n,r);if(t.kind===`ref`)return $x(this,e,t,n,r);let i=Zx(this,e,t);if(!i)return[];let a=tx(i,n,r,this.getSource(e)??``);return a?[a]:[]}function Xx(e,t,n,r){let i=this.getSource(e)??``,a=this.updateElementSettingEdit(e,t,n,r);return a.length===0?i:Qb(i,a)}function Zx(e,t,n){let r=(`schema`in n?n.schema:void 0)??`public`;switch(n.kind){case M.Column:{let i=fx(e,t,r,n.table,M.Table);return i?e.lookupMembers(i,M.Column,n.column)?.declaration:void 0}case M.Table:return fx(e,t,r,n.table)?.declaration;case M.Enum:case M.StickyNote:case M.TableGroup:return fx(e,t,r,n.name,n.kind)?.declaration;case M.Schema:return fx(e,t,n.schema,``,M.Schema)?.declaration;default:return}}function Qx(e,t,n,r,i){let a=e.getSource(t)??``,o=e.parseFile(t).getValue().ast,s=Nx(o).find(e=>e.edges.some(e=>lx(e.upstream,n.upstream)&&lx(e.downstream,n.downstream)));if(!s){if(i===null)return[];let e=Px(a,o).find(e=>ux(e.edge.upstream,n.upstream)&&ux(e.edge.downstream,n.downstream));if(!e)return[];let t=mx(n.upstream),s=mx(n.downstream),c=hx(r,i),l=c?`Dep [${c}] {\n ${t} -> ${s}\n}`:`Dep {\n ${t} -> ${s}\n}`;return[{start:e.stripStart,end:e.stripEnd,newText:``},{start:a.length,end:a.length,newText:`
26
25
 
27
- `+$x(t.name,t.visibleEntities)+`
28
- `;return[{start:e.length,end:e.length,newText:r}]}function rS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=$x(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function iS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
26
+ `+l+`
27
+ `}]}let{declaration:c}=s,{body:l}=c;if(l instanceof z){let e=tx(c,r,i,a);if(e)return[e];let t=tx(l,r,i,a);return t?[t]:[]}let u=tx(c,r,i,a);return u?[u]:[]}function $x(e,t,n,r,i){let a=e.getSource(t)??``,o=ax(e,t,n);if(!o)return[];if(o.kind===`inline`){if(i===null)return[];let e=mx(n.endpoints[0]),t=mx(n.endpoints[1]),s=hx(r,i),c=s?`Ref: ${e} ${o.op} ${t} [${s}]`:`Ref: ${e} ${o.op} ${t}`;return[{start:o.fullStart,end:o.fullEnd,newText:``},{start:a.length,end:a.length,newText:`
28
+
29
+ `+c+`
30
+ `}]}let s=tx(o.node,r,i,a);return s?[s]:[]}function eS(e){let t=[],n=new jb(e,To).lex();if(n.getErrors().length>0)return t;let i=new Fb(e,n.getValue(),new Ks,To).parse();if(i.getErrors().length>0)return t;let a=i.getValue().ast;for(let e of a.declarations)if(e.isKind(r.DiagramView)){let n=e.name?O(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function tS(e,t,n){e.push(` ${t} {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function nS(e,t){e.push(` ${t} { * }`)}function rS(e){return e==null?`null`:e.length===0?`empty`:`items`}function iS(e,t){let n=`DiagramView ${_g(e)} {`,r=e=>_g(e.name),i=t?.tables?.map(e=>{let t=_g(e.name);return e.schemaName===`public`?t:`${_g(e.schemaName)}.${t}`})??[],a=t?.tableGroups?.map(r)??[],o=t?.schemas?.map(r)??[],s=t?.stickyNotes?.map(r)??[];if(!t)return`${n}\n}`;let c={tables:rS(t.tables),tableGroups:rS(t.tableGroups),schemas:rS(t.schemas),stickyNotes:rS(t.stickyNotes)};if(Object.values(c).every(e=>e===`null`))return`${n}\n}`;if(Object.values(c).every(e=>e===`empty`))return`${n}\n *\n}`;let l=c.tables===`items`||c.tableGroups===`items`||c.schemas===`items`,u=c.tables===`empty`&&c.tableGroups===`empty`&&c.schemas===`empty`,d=[n];return l?(c.tables===`items`&&tS(d,`Tables`,i),c.tableGroups===`items`&&tS(d,`TableGroups`,a),c.schemas===`items`&&tS(d,`Schemas`,o)):u&&nS(d,`Tables`),c.stickyNotes===`items`?tS(d,`Notes`,s):c.stickyNotes===`empty`&&nS(d,`Notes`),d.push(`}`),d.join(`
31
+ `)}function aS(e,t,n){let r=this.getSource(e)??``,i=n??eS(r),a=[];for(let e of t){let t=oS(r,e,i);a.push(...t)}return a.sort((e,t)=>t.start-e.start),{newDbml:Qb(r,a,!0),edits:a}}function oS(e,t,n){switch(t.operation){case`create`:return sS(e,t,n);case`update`:return cS(e,t,n);case`delete`:return lS(e,t,n);default:return[]}}function sS(e,t,n){if(n.find(e=>e.name===t.name))return cS(e,t,n);let r=`
32
+
33
+ `+iS(t.name,t.visibleEntities)+`
34
+ `;return[{start:e.length,end:e.length,newText:r}]}function cS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=iS(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function lS(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
29
35
  `;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
30
36
  `,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
31
37
  `&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
32
- `&&a++,[{start:i,end:a,newText:``}]}var aS=Symbol(`COMPUTING`),oS=class{constructor(e){this.layout=e,this.nodeIdGenerator=new Ks,this.symbolIdGenerator=new ws,this.symbolFactory=new $a(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(Hb),this.parseProject=this.globalQuery(Ub),this.validateNode=this.localQuery(U_),this.validateFile=this.localQuery(Ab),this.nodeFullname=this.localQuery(G_),this.nodeAlias=this.localQuery(K_),this.nodeSettings=this.localQuery(W_),this.canonicalName=this.globalQuery(db),this.bindNode=this.globalQuery($g),this.bindFile=this.globalQuery(Eb),this.bindProject=this.globalQuery(Db),this.interpretSymbol=this.globalQuery(t_),this.interpretMetadata=this.globalQuery(n_),this.interpretFile=this.globalQuery(Ob),this.interpretProject=this.globalQuery(kb),this.nodeSymbol=this.globalQuery(Xg),this.nodeMetadata=this.globalQuery(e_),this.symbolMembers=this.globalQuery(Zg),this.symbolMembersLookupMap=this.globalQuery(Wb),this.lookupMembers=this.globalQuery(Gb),this.nodeReferee=this.globalQuery(Qg),this.resolutionIndex=this.globalQuery(qb),this.symbolReferences=this.globalQuery(Yb),this.symbolParent=this.globalQuery(Jb),this.symbolMetadata=this.globalQuery(Xb),this.symbolAliases=this.globalQuery(Kb),this.symbolUses=this.globalQuery(Zb),this.fileDependencies=this.localQuery(mb),this.reachableFiles=this.globalQuery(gb),this.usableMembers=this.globalQuery(Qh),this.nodeAtPosition=this.localQuery(Tb),this.renameTable=lx.bind(this),this.updateElementSetting=Hx.bind(this),this.syncDiagramView=eS.bind(this),this.syncDep=Ox.bind(this),this.token={invalidStream:this.localQuery(wb),flatStream:this.localQuery(Cb)},this.parse={source:e=>this.getSource(e)||``,ast:(e=To)=>_b.call(this,e),errors:(e=To)=>vb.call(this,e),warnings:(e=To)=>yb.call(this,e),tokens:(e=To)=>bb.call(this,e),rawDb:(e=To)=>xb.call(this,e),publicSymbolTable:(e=To)=>Sb.call(this,e)},this.container={stack:this.localQuery(ob),token:this.localQuery(sb),element:this.localQuery(cb),scope:this.localQuery(lb),scopeKind:this.localQuery(ub)}}getSource(e){return this.layout.getSource(e)}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);r===void 0?this.sourceSnapshot.set(n,t):r!==t&&(this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t))}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of hb(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?Ec(n[0]):n.map(e=>Ec(e)).join(`\0`),a=r.get(i);if(a){if(a===aS)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,aS);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof N?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?Ec(n[0]):n.map(e=>Ec(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===aS)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,aS);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new ty(this),referenceProvider:new ry(this),autocompletionProvider:new Ay(this,{triggerCharacters:t}),diagnosticsProvider:new ny(this)}}},sS=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(yo.from)}getEntrypoints(){return[...this.files.keys()].map(yo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=cc,exports.AttributeNode=I,exports.BlockExpressionNode=B,exports.CallExpressionNode=H,exports.CommaExpressionNode=tc,exports.CompileError=x,exports.CompileErrorCode=b,exports.Compiler=oS,exports.CompletionItemInsertTextRule=X,exports.CompletionItemKind=Y,exports.DBMLCompletionItemProvider=Ay,exports.DBMLDefinitionProvider=ty,exports.DBMLDiagnosticsProvider=ny,exports.DBMLReferencesProvider=ry,exports.DEFAULT_ENTRY=To,exports.ElementDeclarationNode=F,exports.ElementKind=r,exports.EmptyNode=sc,exports.FALSY_VALUES=Qm,exports.Filepath=yo,exports.FunctionApplicationNode=z,exports.FunctionExpressionNode=$s,exports.GroupExpressionNode=nc,exports.IdentifierStreamNode=Zs,exports.InfixExpressionNode=R,exports.ListExpressionNode=V,exports.LiteralNode=rc,exports.MarkerSeverity=Qv,exports.MemoryProjectLayout=sS,exports.MetadataKind=dc,exports.PostfixExpressionNode=Qs,exports.PrefixExpressionNode=L,exports.PrimaryExpressionNode=oc,exports.ProgramNode=P,exports.ScopeKind=Q,exports.SymbolKind=M,exports.SyntaxNode=N,exports.SyntaxNodeIdGenerator=Ks,exports.SyntaxNodeKind=qs,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=Zm,exports.TupleExpressionNode=ec,exports.UNHANDLED=t,exports.Uri=Vv,exports.UseDeclarationNode=Js,exports.UseSpecifierListNode=Xs,exports.UseSpecifierNode=Ys,exports.VariableNode=ac,exports.WildcardNode=ic,exports.addDoubleQuoteIfNeeded=_g,exports.dbmlLanguageConfig=ib,exports.dbmlMonarchTokensProvider=ab,exports.escapeString=yg,exports.extractNumericLiteral=fs,exports.extractSignedNumber=Jm,exports.findDepBlocks=Tx,exports.findDiagramViewBlocks=Yx,exports.formatRecordValue=bg,exports.getRecordValueType=Al,exports.isBinaryType=Dl,exports.isBooleanType=Tl,exports.isDateTimeType=Ol,exports.isEmptyStringLiteral=Km,exports.isFloatType=Cl,exports.isFunctionExpression=qm,exports.isIntegerType=Sl,exports.isNullish=Gm,exports.isNumericType=wl,exports.isOp=za,exports.isOpToken=Ba,exports.isSerialType=kl,exports.isStringType=El,exports.isTriviaToken=Ra,exports.isValidIdentifier=gg,exports.normalizeTypeName=xl,exports.splitQualifiedIdentifier=xg,exports.tryExtractBoolean=$m,exports.tryExtractDateTime=ah,exports.tryExtractEnum=eh,exports.tryExtractInteger=Xm,exports.tryExtractNumeric=Ym,exports.tryExtractString=th,exports.unescapeString=vg,exports.validateForeignKeys=Oh,exports.validatePrimaryKey=_h,exports.validateUnique=wh;
38
+ `&&a++,[{start:i,end:a,newText:``}]}var uS=Symbol(`COMPUTING`),dS=class{constructor(e){this.layout=e,this.nodeIdGenerator=new Ks,this.symbolIdGenerator=new ws,this.symbolFactory=new $a(this.symbolIdGenerator),this.sourceSnapshot=new Map,this.globalCache=new Map,this.globallyQuerying=!1,this.localCache=new Map,this.parseFile=this.localQuery(Hb),this.parseProject=this.globalQuery(Ub),this.validateNode=this.localQuery(U_),this.validateFile=this.localQuery(Ab),this.nodeFullname=this.localQuery(G_),this.nodeAlias=this.localQuery(K_),this.nodeSettings=this.localQuery(W_),this.canonicalName=this.globalQuery(db),this.bindNode=this.globalQuery($g),this.bindFile=this.globalQuery(Eb),this.bindProject=this.globalQuery(Db),this.interpretSymbol=this.globalQuery(t_),this.interpretMetadata=this.globalQuery(n_),this.interpretFile=this.globalQuery(Ob),this.interpretProject=this.globalQuery(kb),this.nodeSymbol=this.globalQuery(Xg),this.nodeMetadata=this.globalQuery(e_),this.symbolMembers=this.globalQuery(Zg),this.symbolMembersLookupMap=this.globalQuery(Wb),this.lookupMembers=this.globalQuery(Gb),this.nodeReferee=this.globalQuery(Qg),this.resolutionIndex=this.globalQuery(qb),this.symbolReferences=this.globalQuery(Yb),this.symbolParent=this.globalQuery(Jb),this.symbolMetadata=this.globalQuery(Xb),this.symbolAliases=this.globalQuery(Kb),this.symbolUses=this.globalQuery(Zb),this.fileDependencies=this.localQuery(mb),this.reachableFiles=this.globalQuery(gb),this.usableMembers=this.globalQuery(Qh),this.nodeAtPosition=this.localQuery(Tb),this.renameTable=Sx.bind(this),this.updateElementSetting=Xx.bind(this),this.updateElementSettingEdit=Yx.bind(this),this.syncDiagramView=aS.bind(this),this.syncDep=Lx.bind(this),this.token={invalidStream:this.localQuery(wb),flatStream:this.localQuery(Cb)},this.parse={source:e=>this.getSource(e)||``,ast:(e=To)=>_b.call(this,e),errors:(e=To)=>vb.call(this,e),warnings:(e=To)=>yb.call(this,e),tokens:(e=To)=>bb.call(this,e),rawDb:(e=To)=>xb.call(this,e),publicSymbolTable:(e=To)=>Sb.call(this,e)},this.container={stack:this.localQuery(ob),token:this.localQuery(sb),element:this.localQuery(cb),scope:this.localQuery(lb),scopeKind:this.localQuery(ub)}}getSource(e){return this.layout.getSource(e)}cleanStaleLocalCache(e){let t=this.layout.getSource(e),n=e.absolute,r=this.sourceSnapshot.get(n);r===void 0?this.sourceSnapshot.set(n,t):r!==t&&(this.localCache.delete(e.intern()),this.globalCache.clear(),this.sourceSnapshot.set(n,t))}cleanStaleGlobalCache(){let e=this.layout.getEntrypoints(),t=!1;this.entrypointsSnapshot!==void 0&&(this.entrypointsSnapshot.length!==e.length||this.entrypointsSnapshot.some((t,n)=>t.absolute!==e[n].absolute))&&(t=!0),this.entrypointsSnapshot=e;for(let t of hb(this,e))this.cleanStaleLocalCache(t);t&&this.globalCache.clear()}globalQuery(e){let t=Symbol();return((...n)=>{let r=!this.globallyQuerying;r&&(this.globallyQuerying=!0,this.cleanStaleGlobalCache());try{let r=this.globalCache.get(t);r||(r=new Map,this.globalCache.set(t,r));let i=n.length===0?``:n.length===1?Ec(n[0]):n.map(e=>Ec(e)).join(`\0`),a=r.get(i);if(a){if(a===uS)throw Error(`Cycle detected in query: ${e.name}(${i})`);return a}r.set(i,uS);try{let t=e.apply(this,n);return r.set(i,t),t}catch(e){throw r.delete(i),e}}finally{r&&(this.globallyQuerying=!1)}})}localQuery(e){let t=Symbol();return((...n)=>{let[r]=n,i=r instanceof N?r.filepath:r;this.cleanStaleLocalCache(i);let a=i.intern(),o=n.length===0?``:n.length===1?Ec(n[0]):n.map(e=>Ec(e)).join(`\0`),s=this.localCache.get(a);s||(s=new Map,this.localCache.set(a,s));let c=s.get(t);if(c||(c=new Map,s.set(t,c)),c.has(o)){let t=c.get(o);if(t===uS)throw Error(`Cycle detected in query: ${e.name}(${a}, ${o})`);return t}c.set(o,uS);try{let t=e.apply(this,n);return c.set(o,t),t}catch(e){throw c.delete(o),e}})}initMonacoServices(e){let t=e?.autocompletion?.triggerCharacters??[];return{definitionProvider:new ty(this),referenceProvider:new ry(this),autocompletionProvider:new Ay(this,{triggerCharacters:t}),diagnosticsProvider:new ny(this)}}},fS=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(yo.from)}getEntrypoints(){return[...this.files.keys()].map(yo.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};exports.ArrayNode=cc,exports.AttributeNode=I,exports.BlockExpressionNode=B,exports.CallExpressionNode=H,exports.CommaExpressionNode=tc,exports.CompileError=x,exports.CompileErrorCode=b,exports.Compiler=dS,exports.CompletionItemInsertTextRule=X,exports.CompletionItemKind=Y,exports.DBMLCompletionItemProvider=Ay,exports.DBMLDefinitionProvider=ty,exports.DBMLDiagnosticsProvider=ny,exports.DBMLReferencesProvider=ry,exports.DEFAULT_ENTRY=To,exports.ElementDeclarationNode=F,exports.ElementKind=r,exports.EmptyNode=sc,exports.FALSY_VALUES=Qm,exports.Filepath=yo,exports.FunctionApplicationNode=z,exports.FunctionExpressionNode=$s,exports.GroupExpressionNode=nc,exports.IdentifierStreamNode=Zs,exports.InfixExpressionNode=R,exports.ListExpressionNode=V,exports.LiteralNode=rc,exports.MarkerSeverity=Qv,exports.MemoryProjectLayout=fS,exports.MetadataKind=dc,exports.PostfixExpressionNode=Qs,exports.PrefixExpressionNode=L,exports.PrimaryExpressionNode=oc,exports.ProgramNode=P,exports.ScopeKind=Q,exports.SymbolKind=M,exports.SyntaxNode=N,exports.SyntaxNodeIdGenerator=Ks,exports.SyntaxNodeKind=qs,exports.SyntaxToken=Va,exports.SyntaxTokenKind=v,exports.TRUTHY_VALUES=Zm,exports.TupleExpressionNode=ec,exports.UNHANDLED=t,exports.Uri=Vv,exports.UseDeclarationNode=Js,exports.UseSpecifierListNode=Xs,exports.UseSpecifierNode=Ys,exports.VariableNode=ac,exports.WildcardNode=ic,exports.addDoubleQuoteIfNeeded=_g,exports.dbmlLanguageConfig=ib,exports.dbmlMonarchTokensProvider=ab,exports.escapeString=yg,exports.extractNumericLiteral=fs,exports.extractSignedNumber=Jm,exports.findDepBlocks=Mx,exports.findDiagramViewBlocks=eS,exports.formatRecordValue=bg,exports.getRecordValueType=Al,exports.isBinaryType=Dl,exports.isBooleanType=Tl,exports.isDateTimeType=Ol,exports.isEmptyStringLiteral=Km,exports.isFloatType=Cl,exports.isFunctionExpression=qm,exports.isIntegerType=Sl,exports.isNullish=Gm,exports.isNumericType=wl,exports.isOp=za,exports.isOpToken=Ba,exports.isSerialType=kl,exports.isStringType=El,exports.isTriviaToken=Ra,exports.isValidIdentifier=gg,exports.normalizeTypeName=xl,exports.splitQualifiedIdentifier=xg,exports.tryExtractBoolean=$m,exports.tryExtractDateTime=ah,exports.tryExtractEnum=eh,exports.tryExtractInteger=Xm,exports.tryExtractNumeric=Ym,exports.tryExtractString=th,exports.unescapeString=vg,exports.validateForeignKeys=Oh,exports.validatePrimaryKey=_h,exports.validateUnique=wh;