@dbml/parse 7.1.0 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
11
11
  `;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()||!zu(this.peek()))return this.errors.push(new N(M.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`,_l.create(x.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]}}};let Fv=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var Iv=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===Fv.ListExpression&&(this.numberOfNestedLBrackets+=1),e===Fv.GroupExpression&&(this.numberOfNestedLParens+=1),e===Fv.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===Fv.ListExpression&&--this.numberOfNestedLBrackets,e===Fv.GroupExpression&&--this.numberOfNestedLParens,e===Fv.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return y(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 x.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[Fv.GroupExpression,Fv.ListExpression].includes(e));break;case x.RPAREN:if(this.isWithinGroupExpressionContext())return Fv.GroupExpression;break;case x.RBRACE:if(this.isWithinBlockExpressionContext())return Fv.BlockExpression;break;case x.RBRACKET:if(this.isWithinListExpressionContext())return Fv.ListExpression;break;default:break}}},Lv=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},Y=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Rv=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Iv,this.synchronizeProgram=()=>{let e=this.peek();e.kind===x.EOF?this.logError(e,M.UNEXPECTED_EOF,`Unexpected EOF`):k(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Wl(e)||this.check(x.COLON,x.LBRACE,x.LBRACKET))break;k(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COLON,x.LBRACE,x.LBRACKET))break;k(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Fv.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(E,e);try{this.consume(`Expect an opening brace '{'`,x.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(x.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof Y))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,x.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(x.RBRACE))for(k(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(x.RBRACE)||yl(this.previous(),e))break;k(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Fv.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Pl,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(Ml,e);try{this.consume(`Expect an opening parenthesis '('`,x.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(x.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(x.RPAREN);)try{this.consume(`Expect a comma ','`,x.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof Y))throw t;if(t.partialNode instanceof S&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new Y(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,x.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(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(x.RPAREN,x.COMMA))break;k(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Fv.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(D,e);try{this.consume(`Expect an opening bracket '['`,x.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(x.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(x.RBRACKET);)try{this.consume(`Expect a comma ','`,x.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(n.partialNode instanceof S&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,x.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET))break;k(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET,x.COLON))break;k(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET))break;k(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Lv(n,r)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===x.EOF}advance(){return this.isAtEnd()?y(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?y(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(),M.UNEXPECTED_TOKEN,e),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(k(this.peek()),this.logError(this.advance(),M.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)k(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(),n=this.nodeFactory.create(Tl,{body:e,eof:t,source:this.source});return this.gatherInvalid(),new P({ast:n,tokens:this.tokens},this.errors)}program(){let e=[];for(;!this.isAtEnd();)try{let t=this.elementDeclaration();e.push(t)}catch(t){if(!(t instanceof Y))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof Y?new Y(e.token,t(),e.handlerContext):e}if(!this.check(x.COLON,x.LBRACE,x.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Wl(this.peek()))if(e.as=this.advance(),this.check(x.COLON,x.LBRACE,x.LBRACKET))this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(x.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof Y?(e.attributeList=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,x.LBRACE,x.COLON))return t();try{if(this.match(x.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof w?(k(t),this.logError(t,M.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 Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof Y?(e.type=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,x.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof Y?(e.bodyColon=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof w?this.errors.push(new N(M.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}expression(){let e={args:[]},t=()=>Ul(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(T,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof Y?(e.callee=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){bl(this.previous())||this.logError(n,M.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof Y?(n=r.partialNode,e.args.push(n),new Y(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||vl(this.previous()))return!0;let e=this.peek().kind;return[x.RBRACE,x.RBRACKET,x.RPAREN,x.COMMA,x.COLON].includes(e)}commaExpression(){let e=this.check(x.COMMA)?this.nodeFactory.create(zl,{prevToken:this.previous()}):this.normalExpression();if(!this.check(x.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));break}if(this.check(x.COMMA)){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof Y?(e.partialNode&&t.elementList.push(e.partialNode),new Y(e.token,this.nodeFactory.create(Nl,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(x.COMMA));return this.nodeFactory.create(Nl,t)}shouldStopCommaExpression(){if(this.isAtEnd()||vl(this.previous()))return!0;let e=this.peek().kind;return[x.RBRACE,x.LBRACE,x.RBRACKET,x.LBRACKET,x.RPAREN,x.LPAREN,x.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===x.LPAREN){let{left:r}=Wv(n);if(r<e||yl(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(O,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(O,{callee:t,argumentList:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(n.kind===x.LBRACKET){if(bl(this.previous()))break;try{t=this.nodeFactory.create(Bl,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(Bl,{expression:t,indexer:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(gl(n)){let r=n,i=Wv(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Al,{expression:t,op:r})}else{let n=Bv(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(gl(this.peek())){let t={};t.op=this.peek();let n=Hv(t.op);if(n.right===null)throw this.logError(t.op,M.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new Y(t.op,this.nodeFactory.create(zl,{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 Y?(t.expression=e.partialNode,new Y(e.token,this.nodeFactory.create(Ol,t),e.handlerContext)):e}e=this.nodeFactory.create(Ol,t)}else if(e=this.extractOperand(),e instanceof zl)throw new Y(this.peek(),this.nodeFactory.create(zl,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(x.WILDCARD)?(this.advance(),this.nodeFactory.create(Il,{token:this.previous()})):this.check(x.NUMERIC_LITERAL,x.STRING_LITERAL,x.COLOR_LITERAL,x.QUOTED_STRING,x.IDENTIFIER)?this.primaryExpression():this.check(x.FUNCTION_EXPRESSION)?this.functionExpression():this.check(x.LBRACKET)?this.listExpression():this.check(x.LBRACE)?this.blockExpression():this.check(x.LPAREN)?this.tupleExpression():(this.peek().kind===x.EOF?this.logError(this.peek(),M.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),M.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(zl,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,x.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(jl,e),t.handlerContext):t}return this.nodeFactory.create(jl,e)}canBeField(){return this.peek().kind===x.IDENTIFIER&&this.peek(1).kind===x.COLON}primaryExpression(){if(this.match(x.COLOR_LITERAL,x.STRING_LITERAL,x.NUMERIC_LITERAL))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Fl,{literal:this.previous()})});if(this.match(x.QUOTED_STRING,x.IDENTIFIER))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Ll,{variable:this.previous()})});throw this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect a variable or literal`),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(x.COLON,x.RBRACKET,x.COMMA)){let t=this.peek();this.logError(t,M.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(El,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof Y))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new Y(t.token,this.nodeFactory.create(Dl,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(x.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(Dl,e)}attributeValue(){let e;try{e=this.peek().kind===x.IDENTIFIER&&this.peek(1).kind===x.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof Y)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==x.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(x.COLON,x.COMMA,x.RBRACKET);)try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(El,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(El,{identifiers:e})}logError(e,t,n){this.errors.push(new N(t,n,e))}},zv={"+":{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:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Bv(e){return zv[e.value]||{left:null,right:null}}var Vv={"+":{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 Hv(e){return Vv[e.value]||{left:null,right:null}}var Uv={"(":{left:14,right:null}};function Wv(e){return Uv[e.value]||{left:null,right:null}}function Gv(e,t){return e.getOffsetAt(t)}var Kv=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(!e?.referee)continue;let t;if(e.referee?.declaration&&[C.PRIMARY_EXPRESSION,C.VARIABLE].includes(e?.kind)&&({declaration:t}=e.referee),t){let{startPos:e,endPos:r}=t;return[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:r.column+1,endLineNumber:r.line+1},uri:n}]}}return[]}};let X=function(e){return e[e.Function=1]=`Function`,e[e.Constructor=2]=`Constructor`,e[e.Field=3]=`Field`,e[e.Variable=4]=`Variable`,e[e.Class=5]=`Class`,e[e.Struct=6]=`Struct`,e[e.Interface=7]=`Interface`,e[e.Module=8]=`Module`,e[e.Property=9]=`Property`,e[e.Event=10]=`Event`,e[e.Operator=11]=`Operator`,e[e.Unit=12]=`Unit`,e[e.Value=13]=`Value`,e[e.Constant=14]=`Constant`,e[e.Enum=15]=`Enum`,e[e.EnumMember=16]=`EnumMember`,e[e.Keyword=17]=`Keyword`,e[e.Text=18]=`Text`,e[e.Color=19]=`Color`,e[e.File=20]=`File`,e[e.Reference=21]=`Reference`,e[e.Customcolor=22]=`Customcolor`,e[e.Folder=23]=`Folder`,e[e.TypeParameter=24]=`TypeParameter`,e[e.User=25]=`User`,e[e.Issue=26]=`Issue`,e[e.Snippet=27]=`Snippet`,e}({}),Z=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),qv=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});var Jv=class{constructor(e){this.compiler=e}provideDiagnostics(){let e=[],t=this.compiler.parse._(),n=t.getErrors();for(let t of n)e.push(this.createDiagnostic(t,`error`));let r=t.getWarnings();for(let t of r)e.push(this.createDiagnostic(t,`warning`));return e}provideErrors(){return this.compiler.parse._().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(){return this.compiler.parse._().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(){return this.provideDiagnostics().map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code}}getSeverityValue(e){return e===`error`?qv.Error:qv.Warning}},Yv=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[C.ELEMENT_DECLARATION,C.FUNCTION_APPLICATION,C.PRIMARY_EXPRESSION].includes(e?.kind)){let{symbol:t}=e;if(t?.references.length)return t.references.map(({startPos:e,endPos:t})=>({range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}))}}return[]}};function Xv(e,t){return e>=t.start&&e<t.end}function Zv(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function Qv(e){return Zv(e)?e:`"${ey(e)}"`}function $v(e){let t=``,n=0,r={n:`
12
12
  `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function ey(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
13
13
  `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function ty(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${ey(e)}'`;let{value:t,type:n}=e;if(t==null||xf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(xf(n)){let e=q_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(bf(n)){let e=U_(t);return e===null?`\`${t}\``:String(e)}if(wf(n)){let e=$_(t);return e===null?`\`${t}\``:`'${ey(e)}'`}let r=Y_(t);return r===null?`\`${t}\``:`'${ey(r)}'`}function ny(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?$v(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function ry(e){switch(e){case F.Schema:return X.Module;case F.Table:case F.TablePartial:return X.Class;case F.Column:case F.TableGroupField:return X.Field;case F.Enum:return X.Enum;case F.EnumField:return X.EnumMember;case F.TableGroup:return X.Struct;default:return X.Text}}function iy(e,t){if(!e||bl(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===x.NEWLINE&&n.end<=t)return!1}return!0}function Q(){return{suggestions:[]}}function ay(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function oy(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Qv(e.insertText??``),quoted:!0}))}}function sy(e,t=`, `){let n=e.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label).join(t);return n?{...e,suggestions:[{label:`* (all)`,insertText:n,insertTextRules:Z.KeepWhitespace,kind:X.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function cy(e,t){return e<t.start||e>t.end?!1:t.body?e<t.body.start||e>t.body.end:!0}function ly(e){return e.commaList.length+e.elementList.length===0}function uy(e){let t=[];for(let[n,r]of e.symbolTable.entries()){let e=_u(n);if(e===void 0||e.kind!==F.Column||!(r instanceof wu||r instanceof ku))continue;let i=dy(r,e.name);i&&t.push(i)}return t}function dy(e,t){let n=ou(t),r=e instanceof ku?e.tablePartialSymbol.symbolTable.get(n)?.declaration:e.declaration;if(!(r instanceof T))return null;let i=R(r.callee)??null,a=R(r.args[0])??null;return i===null||a===null?null:{name:i,type:a}}function fy(e,t,n,r){let i=e.container.element(r);return!(i instanceof w)||!i.isKind(g.Records)||!(i.body instanceof E)||!i.body||!Xv(r,i.body)||t.getLineContent(n.lineNumber).trim()!==``?null:i.parent instanceof Tl?py(e,i):my(e,i)}function py(e,t){if(!(t.name instanceof O))return Q();let n=t.name.argumentList?.elementList||[],r=n.map(e=>vd(e));if(!r||r.length===0)return Q();let i=n.map((e,t)=>{let n=r[t];if(!n||!(n instanceof wu||n instanceof ku))return null;let i=R(e);return i?dy(n,i):null}).filter(e=>e!==null);return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function my(e,t){let n=t.parent;if(!(n instanceof w))return Q();let r=n.symbol;if(!(r instanceof Cu))return Q();let i;if(t.name instanceof Ml){let e=t.name.elementList,n=e.map(e=>vd(e)).filter(e=>e!==void 0);i=e.map((e,t)=>{let r=n[t];if(!r||!(r instanceof wu||r instanceof ku))return null;let i=R(e);return i===void 0?null:dy(r,i)}).filter(e=>e!==null)}else{let e=uy(r);if(!e)return Q();i=e}return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}var hy=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Gv(e,t),r=fy(this.compiler,e,t,n);if(r!==null)return r;let i=this.compiler.token.flatStream(),{token:a,index:o}=this.compiler.container.token(n),s=o===void 0?i[0]:i[o+1];if([...a?.trailingTrivia||[],...a?.leadingTrivia||[],...s?.leadingTrivia||[]].find(e=>Cl(e)&&Xv(n,e)))return Q();if(o===void 0)return Dy();if([x.STRING_LITERAL,x.QUOTED_STRING].includes(a.kind)&&Xv(n,a))return Q();let c=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||c instanceof w&&c.type&&c.type.start<=n&&c.type.end>=n)return Dy();let l=[...this.compiler.container.stack(n)].reverse();for(let e of l)if(e instanceof Ol)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`~`:return gy(this.compiler,n);default:}else if(e instanceof kl)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`.`:return Ty(this.compiler,n,e);default:}else if(e instanceof Dl)return Sy(this.compiler,n,e);else if(e instanceof D)return Sy(this.compiler,n,e);else if(e instanceof Ml)return by(this.compiler,n,e);else if(e instanceof Nl)return xy(this.compiler,n);else if(e instanceof O)return Ny(this.compiler,n,e);else if(e instanceof T)return Ey(this.compiler,n,e);else if(e instanceof w){if(cy(n,e))return My(this.compiler,n,e);if(e.bodyColon&&n>=e.bodyColon.end||e.body&&Xv(n,e.body))return Ey(this.compiler,n,void 0)}return Q()}};function gy(e,t){return yy(e,t,e.parse.ast(),[F.TablePartial])}function _y(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=yy(e,t,e.container.element(t),[F.Table,F.Schema,F.Column]);return iy(n.op,t)?ay(r):r}return Q()}function vy(e,t,n){return oy({suggestions:e.symbol.members(t).filter(({kind:e})=>n.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:ry(t),sortText:ry(t).toString().padStart(2,`0`),range:void 0}))})}function yy(e,t,n,r){if(n===void 0)return Q();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...vy(e,t,r).suggestions)}i=i instanceof w?i.parent:void 0}return oy(a)}function by(e,t,n){let r=e.container.scopeKind(t),i=e.container.element(t),a=[...e.container.stack(t)];for(let r of a)if(r instanceof O&&r.argumentList===n)return Ny(e,t,r);if(i instanceof w&&i.isKind(g.Records)&&!(i.name instanceof O)&&cy(t,i)){let t=i.parent?.symbol||i.name?.referee;if(t){let r=vy(e,t,[F.Column]);return ly(n)?sy(r):r}}switch(r){case $.INDEXES:return zy(e,t);case $.REF:for(;a.length>0;){let n=a.pop();if(n instanceof kl&&n.op?.value===`.`)return Ty(e,t,n)}return jy(e,t);default:break}return Q()}function xy(e,t){return e.container.scopeKind(t)===$.RECORDS?yy(e,t,e.container.element(t),[F.Schema,F.Enum,F.EnumField]):Q()}function Sy(e,t,n){let{token:r}=e.container.token(t);if([x.COMMA,x.LBRACKET].includes(r?.kind)){let n=Cy(e,t);return r?.kind===x.COMMA&&iy(r,t)?ay(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return Cy(e,t);if(n.name instanceof El){let i=wy(e,t,tu(n.name)??``);return r?.kind===x.COLON&&iy(r,t)?ay(i):i}return Q()}function Cy(e,t){let n=e.container.element(t);if(n instanceof Tl)return Q();let r=e.container.scopeKind(t);if(n.body&&!Xv(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[_.HeaderColor,_.Note];break;case $.TABLEGROUP:e=[_.Color,_.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Z.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[_.PK,_.PrimaryKey,_.Null,_.NotNull,_.Increment,_.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[_.Ref,_.Default,_.Note,_.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[_.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[_.Unique,_.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[_.Note,_.Name,_.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[_.Update,_.Delete,_.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[_.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function wy(e,t,n){switch(n?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`default`:return yy(e,t,e.container.element(t),[F.Schema,F.Enum]);default:break}return Q()}function Ty(e,t,n){let r=md(n)??[];if(r.pop(),r.some(e=>!j(e)))return Q();let i=r.map(e=>R(e));return oy({suggestions:e.symbol.ofName(i,e.container.element(t)).flatMap(({symbol:t})=>e.symbol.members(t)).map(({kind:e,name:t})=>({label:t,insertText:t,kind:ry(e),range:void 0}))})}function Ey(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return ky(e,t,n);case $.PROJECT:return Ay(e,t,n);case $.INDEXES:return Ly(e,t);case $.ENUM:return Oy(e,t,n);case $.REF:{let n=jy(e,t);return e.container.token(t).token?.kind===x.COLON&&iy(e.container.token(t).token,t)?ay(n):n}case $.TABLEGROUP:return Py(e);case $.DIAGRAMVIEW:return Fy();case $.CUSTOM:{let n=e.container.element(t);return n instanceof w&&n.parent instanceof w&&n.parent.isKind(g.DiagramView)?Iy(e,t):Q()}default:return Q()}}function Dy(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function Oy(e,t,n){return n?.callee&&By(t,n)===1?yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column]):Q()}function ky(e,t,n){let r=[`Note`,`indexes`,`checks`,`Records`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=By(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?Ry(e,t):Q()}function Ay(e,t,n){return!n?.callee||By(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Q()}function jy(e,t){return yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column])}function My(e,t,n){return n.isKind(g.Records)?yy(e,t,n.parent,[F.Schema,F.Table]):Q()}function Ny(e,t,n){let r=e.container.element(t),i=n.callee&&Xv(t,n.callee),a=n.argumentList&&Xv(t,n.argumentList);if(r instanceof w&&r.isKind(g.Records)&&cy(t,r)){if(i)return yy(e,t,r.parent,[F.Schema,F.Table]);if(!a)return Q();let o=n.callee;if(!o)return Q();let s=md(o)??[o],c=s[s.length-1]?.referee;if(!c)return Q();let l=vy(e,c,[F.Column]),{argumentList:u}=n;return!u||!ly(u)?l:sy(l)}let o=[...e.container.stack(t)];for(let r of o){if(!a||!(r instanceof T)||r.callee!==n||Bu(g,R(n.callee)??``)!==g.Records)continue;let i=e.container.element(t).symbol;if(!i)return Q();let o=vy(e,i,[F.Column]),{argumentList:s}=n;return!s||!ly(s)?o:sy(o)}return Q()}function Py(e){return{suggestions:[...oy({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==F.Table&&n!==F.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:ry(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function Fy(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0})),{label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}]}}function Iy(e,t){let n=e.container.element(t);if(!(n instanceof w))return Q();let r=n.type?.value.toLowerCase(),i={label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0};switch(r){case`tables`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.Table,F.Schema]).suggestions]};case`tablegroups`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.TableGroup]).suggestions]};case`schemas`:return{suggestions:[i,{label:se,insertText:se,insertTextRules:Z.KeepWhitespace,kind:X.Module,range:void 0},...yy(e,t,e.parse.ast(),[F.Schema]).suggestions]};case`notes`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.StickyNote]).suggestions]};default:return Q()}}function Ly(e,t){return zy(e,t)}function Ry(e,t){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...yy(e,t,e.container.element(t),[F.Enum,F.Schema]).suggestions]}}function zy(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Cu))return Q();let{symbolTable:r}=n.symbol;return oy({suggestions:[...r.entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:ry(F.Column),range:void 0}})})}function By(e,t){if(!t.callee)return-1;let n=[t.callee,...t.args],r=n.findIndex(t=>e<=t.end);return r===-1?n.length:r}var Vy={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`check`,`tables`,`tablegroups`,`notes`,`schemas`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}},Hy=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>hy,DBMLDefinitionProvider:()=>Kv,DBMLDiagnosticsProvider:()=>Jv,DBMLReferencesProvider:()=>Yv,MarkerSeverity:()=>qv,dbmlMonarchTokensProvider:()=>Vy},1);function Uy(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:Pc(t,e=>!e.isInvalid,n);if(i===-1)return[this.parse.ast()];let a=t[i].start,o=this.parse.ast(),s=[o];for(;;){let e=Yl(o).find(e=>Xv(a,e));if(e===void 0||e instanceof _l)break;s.push(e),o=e}if(r?.kind===x.COLON)return s;for(;s.length>0;){let t=!1,n=y(s);if(n instanceof T){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
14
- `&&(s.pop(),t=!0)}else n instanceof Ol||n instanceof kl?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof D?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof Ml?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof Nl?n.end<=e&&(s.pop(),t=!0):n instanceof E?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof El||n.end<e&&(s.pop(),t=!0);if(t){let t=y(s);t instanceof w&&t.end<=e&&s.pop()}if(!t)break}return s}function Wy(e){let t=this.token.flatStream().findIndex(t=>t.start>=e);return t===void 0||t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function Gy(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof w)return t[e];return this.parse.ast()}function Ky(e){return this.container.element(e)?.symbol?.symbolTable}let $=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function qy(e){let t=this.container.element(e);if(t instanceof Tl)return $.TOPLEVEL;switch(t.type?.value.toLowerCase()){case`table`:return $.TABLE;case`enum`:return $.ENUM;case`ref`:return $.REF;case`tablegroup`:return $.TABLEGROUP;case`indexes`:return $.INDEXES;case`note`:return $.NOTE;case`project`:return $.PROJECT;case`tablepartial`:return $.TABLEPARTIAL;case`checks`:return $.CHECKS;case`records`:return $.RECORDS;case`diagramview`:return $.DIAGRAMVIEW;default:return $.CUSTOM}}function Jy(){return this.parse._().getValue().ast}function Yy(){return this.parse._().getErrors()}function Xy(){return this.parse._().getWarnings()}function Zy(){return this.parse._().getValue().tokens}function Qy(){return this.parse._().getValue().rawDb}function $y(){return this.parse._().getValue().ast.symbol.symbolTable}function eb(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({..._u(e),symbol:t})):[]}function tb(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof w?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>Pu(t).flatMap(t=>{let n=e.get(t),r=_u(t);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function nb(e,t){return`${e.join(`.`)}@${t.id}`}function rb(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function ib(){return this.parse.tokens().filter(ql)}function ab(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 ob(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=ny(e);if(t.length===0)return{schema:se,table:``};if(t.length===1)return{schema:se,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 sb(e,t,n){let r=au(n);if(t===`public`){let t=e.get(r);return t instanceof Cu?t:null}let i=iu(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Cu?o:null}function cb(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function lb(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function ub(e,t){if(!e.declaration)return!1;let n=e.declaration;if(!n.name)return!1;let r=n.name;return t.substring(r.start,r.end).includes(`"`)}function db(e,t,n){let r=!lb(t),i=!lb(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 fb(e,t,n,r,i){let a=au(i),o;if(r===`public`)o=e.get(a);else{let t=iu(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function pb(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 cb(n.substring(i,a))===t?{start:i,end:e.end}:null}function mb(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=pb(o,t,r)??{start:o.start,end:o.end},s=`${e.start}-${e.end}`;if(a.has(s))continue;a.add(s);let c=n.schema===`public`?n.formattedTable:`${n.formattedSchema}.${n.formattedTable}`;i.push({start:e.start,end:e.end,newText:c})}return i}function hb(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=ob(e),a=ob(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=sb(r,o,s);if(!u||fb(r,o,s,c,l))return n;let d=db(c,l,ub(u,n)),f=[];if(u.declaration){let e=u.declaration;e.name&&f.push(e.name)}for(let e of u.references)n.substring(e.start,e.end).replace(/"/g,``)===s&&f.push(e);return ab(n,mb(f,o,d,n))}function gb(e){let t=[],n=new Pv(e,ce).lex();if(n.getErrors().length>0)return t;let r=new Rv(e,n.getValue(),new wl,ce).parse();if(r.getErrors().length>0)return t;let i=r.getValue().ast;for(let e of i.body)if(e.isKind(g.DiagramView)){let n=e.name?L(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function _b(e,t){let n=t.map(e=>e.schemaName===`public`?e.name:`${e.schemaName}.${e.name}`);e.push(` Tables {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function vb(e,t){e.push(` TableGroups {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function yb(e,t){e.push(` Schemas {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function bb(e,t){e.push(` Notes {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function xb(e,t){let n=`DiagramView ${Qv(e)} {`;if(!t)return`${n}\n}`;let{tables:r,tableGroups:i,schemas:a,stickyNotes:o}=t,s=r===null,c=i===null,l=a===null;if(s&&c&&l&&o===null)return`${n}\n}`;if(s||c||l){let e=!s&&r.length>0,t=!c&&i.length>0,u=!l&&a.length>0;if(!(e||t||u)){if(o&&o.length>0){let e=[n];return bb(e,o),e.push(`}`),e.join(`
14
+ `&&(s.pop(),t=!0)}else n instanceof Ol||n instanceof kl?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof D?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof Ml?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof Nl?n.end<=e&&(s.pop(),t=!0):n instanceof E?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof El||n.end<e&&(s.pop(),t=!0);if(t){let t=y(s);t instanceof w&&t.end<=e&&s.pop()}if(!t)break}return s}function Wy(e){let t=this.token.flatStream().findIndex(t=>t.start>=e);return t===void 0||t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function Gy(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof w)return t[e];return this.parse.ast()}function Ky(e){return this.container.element(e)?.symbol?.symbolTable}let $=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function qy(e){let t=this.container.element(e);if(t instanceof Tl)return $.TOPLEVEL;switch(t.type?.value.toLowerCase()){case`table`:return $.TABLE;case`enum`:return $.ENUM;case`ref`:return $.REF;case`tablegroup`:return $.TABLEGROUP;case`indexes`:return $.INDEXES;case`note`:return $.NOTE;case`project`:return $.PROJECT;case`tablepartial`:return $.TABLEPARTIAL;case`checks`:return $.CHECKS;case`records`:return $.RECORDS;case`diagramview`:return $.DIAGRAMVIEW;default:return $.CUSTOM}}function Jy(){return this.parse._().getValue().ast}function Yy(){return this.parse._().getErrors()}function Xy(){return this.parse._().getWarnings()}function Zy(){return this.parse._().getValue().tokens}function Qy(){return this.parse._().getValue().rawDb}function $y(){return this.parse._().getValue().ast.symbol.symbolTable}function eb(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({..._u(e),symbol:t})):[]}function tb(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof w?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>Pu(t).flatMap(t=>{let n=e.get(t),r=_u(t);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function nb(e,t){return`${e.join(`.`)}@${t.id}`}function rb(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function ib(){return this.parse.tokens().filter(ql)}function ab(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 ob(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=ny(e);if(t.length===0)return{schema:se,table:``};if(t.length===1)return{schema:se,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 sb(e,t,n){let r=au(n);if(t===`public`){let t=e.get(r);return t instanceof Cu?t:null}let i=iu(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Cu?o:null}function cb(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function lb(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function ub(e,t){if(!e.declaration)return!1;let n=e.declaration;if(!n.name)return!1;let r=n.name;return t.substring(r.start,r.end).includes(`"`)}function db(e,t,n){let r=!lb(t),i=!lb(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 fb(e,t,n,r,i){let a=au(i),o;if(r===`public`)o=e.get(a);else{let t=iu(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function pb(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 cb(n.substring(i,a))===t?{start:i,end:e.end}:null}function mb(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=pb(o,t,r)??{start:o.start,end:o.end},s=`${e.start}-${e.end}`;if(a.has(s))continue;a.add(s);let c=n.schema===`public`?n.formattedTable:`${n.formattedSchema}.${n.formattedTable}`;i.push({start:e.start,end:e.end,newText:c})}return i}function hb(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=ob(e),a=ob(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=sb(r,o,s);if(!u||fb(r,o,s,c,l))return n;let d=db(c,l,ub(u,n)),f=[];if(u.declaration){let e=u.declaration;e.name&&f.push(e.name)}for(let e of u.references)n.substring(e.start,e.end).replace(/"/g,``)===s&&f.push(e);return ab(n,mb(f,o,d,n))}function gb(e){let t=[],n=new Pv(e,ce).lex();if(n.getErrors().length>0)return t;let r=new Rv(e,n.getValue(),new wl,ce).parse();if(r.getErrors().length>0)return t;let i=r.getValue().ast;for(let e of i.body)if(e.isKind(g.DiagramView)){let n=e.name?L(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function _b(e,t){let n=t.map(e=>{let t=Qv(e.name);return e.schemaName===`public`?t:`${Qv(e.schemaName)}.${t}`});e.push(` Tables {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function vb(e,t){e.push(` TableGroups {`),t.forEach(t=>e.push(` ${Qv(t.name)}`)),e.push(` }`)}function yb(e,t){e.push(` Schemas {`),t.forEach(t=>e.push(` ${Qv(t.name)}`)),e.push(` }`)}function bb(e,t){e.push(` Notes {`),t.forEach(t=>e.push(` ${Qv(t.name)}`)),e.push(` }`)}function xb(e,t){let n=`DiagramView ${Qv(e)} {`;if(!t)return`${n}\n}`;let{tables:r,tableGroups:i,schemas:a,stickyNotes:o}=t,s=r===null,c=i===null,l=a===null;if(s&&c&&l&&o===null)return`${n}\n}`;if(s||c||l){let e=!s&&r.length>0,t=!c&&i.length>0,u=!l&&a.length>0;if(!(e||t||u)){if(o&&o.length>0){let e=[n];return bb(e,o),e.push(`}`),e.join(`
15
15
  `)}return`${n}\n Notes { * }\n}`}let d=[n];return e&&_b(d,r),t&&vb(d,i),u&&yb(d,a),o&&o.length>0&&bb(d,o),d.push(`}`),d.join(`
16
16
  `)}let u=r,d=i,f=a,p=u.length===0&&d.length===0&&f.length===0,m=o!=null&&o.length>0;if(p){if(m){let e=[n,` Tables { * }`];return bb(e,o),e.push(`}`),e.join(`
17
17
  `)}return`${n}\n *\n}`}let h=[n];return u.length>0&&_b(h,u),d.length>0&&vb(h,d),f.length>0&&yb(h,f),m&&bb(h,o),h.push(`}`),h.join(`
@@ -10952,17 +10952,20 @@ function findDiagramViewBlocks(r) {
10952
10952
  return j;
10953
10953
  }
10954
10954
  function emitTablesBlock(r, j) {
10955
- let M = j.map((r) => r.schemaName === "public" ? r.name : `${r.schemaName}.${r.name}`);
10955
+ let M = j.map((r) => {
10956
+ let j = addDoubleQuoteIfNeeded(r.name);
10957
+ return r.schemaName === "public" ? j : `${addDoubleQuoteIfNeeded(r.schemaName)}.${j}`;
10958
+ });
10956
10959
  r.push(" Tables {"), M.forEach((j) => r.push(` ${j}`)), r.push(" }");
10957
10960
  }
10958
10961
  function emitTableGroupsBlock(r, j) {
10959
- r.push(" TableGroups {"), j.forEach((j) => r.push(` ${j.name}`)), r.push(" }");
10962
+ r.push(" TableGroups {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
10960
10963
  }
10961
10964
  function emitSchemasBlock(r, j) {
10962
- r.push(" Schemas {"), j.forEach((j) => r.push(` ${j.name}`)), r.push(" }");
10965
+ r.push(" Schemas {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
10963
10966
  }
10964
10967
  function emitNotesBlock(r, j) {
10965
- r.push(" Notes {"), j.forEach((j) => r.push(` ${j.name}`)), r.push(" }");
10968
+ r.push(" Notes {"), j.forEach((j) => r.push(` ${addDoubleQuoteIfNeeded(j.name)}`)), r.push(" }");
10966
10969
  }
10967
10970
  function generateDiagramViewBlock(r, j) {
10968
10971
  let M = `DiagramView ${addDoubleQuoteIfNeeded(r)} {`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@dbml/parse",
4
- "version": "7.1.0",
4
+ "version": "7.1.2",
5
5
  "description": "DBML parser v2",
6
6
  "author": "Holistics <dev@holistics.io>",
7
7
  "license": "Apache-2.0",
@@ -39,11 +39,11 @@
39
39
  "monaco-editor-core": "^0.44.0"
40
40
  },
41
41
  "dependencies": {
42
- "lodash-es": "^4.17.21",
42
+ "lodash-es": "^4.18.1",
43
43
  "luxon": "^3.7.2"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18"
47
47
  },
48
- "gitHead": "ff4e35e824dfebc5237678dc03c983b409fbddc9"
48
+ "gitHead": "2260a23bc20e384be97722ab716c23a5ae047443"
49
49
  }