@dbml/parse 5.4.0 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/dist/{tests → __tests__/examples}/binder/binder.test.d.ts +0 -0
- package/dist/{tests → __tests__/examples}/compiler/applyTextEdits.test.d.ts +0 -0
- package/dist/{tests → __tests__/examples}/compiler/renameTable.test.d.ts +0 -0
- package/dist/{tests → __tests__/examples}/interpreter/interpreter.test.d.ts +0 -0
- package/dist/{tests → __tests__/examples}/lexer/lexer.test.d.ts +0 -0
- package/dist/{tests → __tests__/examples}/parser/parser.test.d.ts +0 -0
- package/dist/{tests/NaN_errors/interpreter_NaN.test.d.ts → __tests__/examples/services/definition.test.d.ts} +0 -0
- package/dist/{tests/validator/validator.test.d.ts → __tests__/examples/services/references.test.d.ts} +0 -0
- package/dist/__tests__/examples/services/service_utils.test.d.ts +1 -0
- package/dist/__tests__/examples/services/suggestions.test.d.ts +1 -0
- package/dist/__tests__/examples/validator/validator.test.d.ts +1 -0
- package/dist/__tests__/fuzz/interpreter.test.d.ts +1 -0
- package/dist/__tests__/fuzz/parser.test.d.ts +1 -0
- package/dist/__tests__/fuzz/services.test.d.ts +1 -0
- package/dist/__tests__/properties/lexer.test.d.ts +1 -0
- package/dist/__tests__/properties/parser.test.d.ts +1 -0
- package/dist/__tests__/snapshots/nan/nan.test.d.ts +1 -0
- package/dist/__tests__/utils/arbitraries/grammars.d.ts +100 -0
- package/dist/__tests__/utils/arbitraries/index.d.ts +3 -0
- package/dist/__tests__/utils/arbitraries/tokens.d.ts +20 -0
- package/dist/__tests__/utils/arbitraries/utils.d.ts +59 -0
- package/dist/__tests__/utils/compiler.d.ts +13 -0
- package/dist/__tests__/utils/index.d.ts +3 -0
- package/dist/__tests__/utils/mocks.d.ts +16 -0
- package/dist/__tests__/utils/testHelpers.d.ts +16 -0
- package/dist/dbml-parse.js +9 -9
- package/dist/dbml-parse.mjs +2066 -2117
- package/dist/src/compiler/index.d.ts +0 -0
- package/dist/src/compiler/queries/container/element.d.ts +0 -0
- package/dist/src/compiler/queries/container/index.d.ts +0 -0
- package/dist/src/compiler/queries/container/scope.d.ts +0 -0
- package/dist/src/compiler/queries/container/scopeKind.d.ts +0 -0
- package/dist/src/compiler/queries/container/stack.d.ts +0 -0
- package/dist/src/compiler/queries/container/token.d.ts +0 -0
- package/dist/src/compiler/queries/parse.d.ts +0 -0
- package/dist/src/compiler/queries/symbol.d.ts +0 -0
- package/dist/src/compiler/queries/token.d.ts +0 -0
- package/dist/src/compiler/queries/transform/applyTextEdits.d.ts +0 -0
- package/dist/src/compiler/queries/transform/index.d.ts +0 -0
- package/dist/src/compiler/queries/transform/renameTable.d.ts +0 -0
- package/dist/src/compiler/types.d.ts +0 -0
- package/dist/src/constants.d.ts +0 -0
- package/dist/src/core/analyzer/analyzer.d.ts +0 -0
- package/dist/src/core/analyzer/binder/binder.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/checks.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/custom.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/elementBinder.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/enum.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/indexes.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/note.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/project.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/ref.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/table.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/tableGroup.d.ts +0 -0
- package/dist/src/core/analyzer/binder/elementBinder/tablePartial.d.ts +0 -0
- package/dist/src/core/analyzer/binder/types.d.ts +0 -0
- package/dist/src/core/analyzer/binder/utils.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/factory.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/symbolIndex.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/symbolTable.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/symbols.d.ts +0 -0
- package/dist/src/core/analyzer/symbol/utils.d.ts +0 -0
- package/dist/src/core/analyzer/types.d.ts +0 -0
- package/dist/src/core/analyzer/utils.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/checks.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/custom.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/enum.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/indexes.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/note.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/project.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/ref.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/table.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/tableGroup.d.ts +0 -0
- package/dist/src/core/analyzer/validator/elementValidators/tablePartial.d.ts +0 -0
- package/dist/src/core/analyzer/validator/types.d.ts +0 -0
- package/dist/src/core/analyzer/validator/utils.d.ts +0 -0
- package/dist/src/core/analyzer/validator/validator.d.ts +0 -0
- package/dist/src/core/errors.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/enum.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/project.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/ref.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/sticky_note.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/table.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/tableGroup.d.ts +0 -0
- package/dist/src/core/interpreter/elementInterpreter/tablePartial.d.ts +0 -0
- package/dist/src/core/interpreter/interpreter.d.ts +0 -0
- package/dist/src/core/interpreter/types.d.ts +0 -0
- package/dist/src/core/interpreter/utils.d.ts +0 -0
- package/dist/src/core/lexer/lexer.d.ts +0 -0
- package/dist/src/core/lexer/tokens.d.ts +0 -0
- package/dist/src/core/lexer/utils.d.ts +0 -0
- package/dist/src/core/option.d.ts +0 -0
- package/dist/src/core/parser/contextStack.d.ts +0 -0
- package/dist/src/core/parser/factory.d.ts +0 -0
- package/dist/src/core/parser/nodes.d.ts +1 -0
- package/dist/src/core/parser/parser.d.ts +0 -0
- package/dist/src/core/parser/utils.d.ts +0 -0
- package/dist/src/core/report.d.ts +0 -0
- package/dist/src/core/serialization/serialize.d.ts +0 -0
- package/dist/src/core/types.d.ts +0 -0
- package/dist/src/core/utils.d.ts +0 -0
- package/dist/src/index.d.ts +0 -0
- package/dist/src/services/definition/provider.d.ts +0 -0
- package/dist/src/services/index.d.ts +0 -0
- package/dist/src/services/references/provider.d.ts +0 -0
- package/dist/src/services/suggestions/provider.d.ts +0 -0
- package/dist/src/services/suggestions/utils.d.ts +0 -0
- package/dist/src/services/types.d.ts +1 -1
- package/dist/src/services/utils.d.ts +0 -0
- package/package.json +4 -5
- package/dist/tests/jestHelpers.d.ts +0 -1
package/dist/dbml-parse.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Qn=typeof global=="object"&&global&&global.Object===Object&&global,Zs=typeof self=="object"&&self&&self.Object===Object&&self,Ae=Qn||Zs||Function("return this")(),Ne=Ae.Symbol,Jn=Object.prototype,er=Jn.hasOwnProperty,tr=Jn.toString,Je=Ne?Ne.toStringTag:void 0;function nr(e){var t=er.call(e,Je),n=e[Je];try{e[Je]=void 0;var s=!0}catch{}var r=tr.call(e);return s&&(t?e[Je]=n:delete e[Je]),r}var sr=Object.prototype,rr=sr.toString;function ir(e){return rr.call(e)}var ar="[object Null]",or="[object Undefined]",ln=Ne?Ne.toStringTag:void 0;function Ke(e){return e==null?e===void 0?or:ar:ln&&ln in Object(e)?nr(e):ir(e)}function Re(e){return e!=null&&typeof e=="object"}var lr="[object Symbol]";function bt(e){return typeof e=="symbol"||Re(e)&&Ke(e)==lr}function Zn(e,t){for(var n=-1,s=e==null?0:e.length,r=Array(s);++n<s;)r[n]=t(e[n],n,e);return r}var pe=Array.isArray,cn=Ne?Ne.prototype:void 0,un=cn?cn.toString:void 0;function es(e){if(typeof e=="string")return e;if(pe(e))return Zn(e,es)+"";if(bt(e))return un?un.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}var cr=/\s/;function ur(e){for(var t=e.length;t--&&cr.test(e.charAt(t)););return t}var hr=/^\s+/;function fr(e){return e&&e.slice(0,ur(e)+1).replace(hr,"")}function Xe(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var hn=NaN,pr=/^[-+]0x[0-9a-f]+$/i,dr=/^0b[01]+$/i,Er=/^0o[0-7]+$/i,Nr=parseInt;function Tr(e){if(typeof e=="number")return e;if(bt(e))return hn;if(Xe(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Xe(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=fr(e);var n=dr.test(e);return n||Er.test(e)?Nr(e.slice(2),n?2:8):pr.test(e)?hn:+e}var fn=1/0,mr=17976931348623157e292;function br(e){if(!e)return e===0?e:0;if(e=Tr(e),e===fn||e===-fn){var t=e<0?-1:1;return t*mr}return e===e?e:0}function Ir(e){var t=br(e),n=t%1;return t===t?n?t-n:t:0}function It(e){return e}var gr="[object AsyncFunction]",_r="[object Function]",Ar="[object GeneratorFunction]",Lr="[object Proxy]";function ts(e){if(!Xe(e))return!1;var t=Ke(e);return t==_r||t==Ar||t==gr||t==Lr}var xt=Ae["__core-js_shared__"],pn=function(){var e=/[^.]+$/.exec(xt&&xt.keys&&xt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function vr(e){return!!pn&&pn in e}var yr=Function.prototype,wr=yr.toString;function Ce(e){if(e!=null){try{return wr.call(e)}catch{}try{return e+""}catch{}}return""}var Sr=/[\\^$.*+?()[\]{}|]/g,Pr=/^\[object .+?Constructor\]$/,Or=Function.prototype,xr=Object.prototype,kr=Or.toString,Dr=xr.hasOwnProperty,Rr=RegExp("^"+kr.call(Dr).replace(Sr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Ur(e){if(!Xe(e)||vr(e))return!1;var t=ts(e)?Rr:Pr;return t.test(Ce(e))}function Mr(e,t){return e==null?void 0:e[t]}function Ve(e,t){var n=Mr(e,t);return Ur(n)?n:void 0}var Rt=Ve(Ae,"WeakMap");function Fr(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Br=800,Cr=16,Vr=Date.now;function Gr(e){var t=0,n=0;return function(){var s=Vr(),r=Cr-(s-n);if(n=s,r>0){if(++t>=Br)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function $r(e){return function(){return e}}var dn=function(){try{var e=Ve(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Xr=dn?function(e,t){return dn(e,"toString",{configurable:!0,enumerable:!1,value:$r(t),writable:!0})}:It,jr=Gr(Xr);function Wr(e,t,n,s){e.length;for(var r=n+1;r--;)if(t(e[r],r,e))return r;return-1}var Hr=9007199254740991,Kr=/^(?:0|[1-9]\d*)$/;function ns(e,t){var n=typeof e;return t=t??Hr,!!t&&(n=="number"||n!="symbol"&&Kr.test(e))&&e>-1&&e%1==0&&e<t}function ss(e,t){return e===t||e!==e&&t!==t}var En=Math.max;function qr(e,t,n){return t=En(t===void 0?e.length-1:t,0),function(){for(var s=arguments,r=-1,i=En(s.length-t,0),a=Array(i);++r<i;)a[r]=s[t+r];r=-1;for(var o=Array(t+1);++r<t;)o[r]=s[r];return o[t]=n(a),Fr(e,this,o)}}function zr(e,t){return jr(qr(e,t,It),e+"")}var Yr=9007199254740991;function Xt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Yr}function gt(e){return e!=null&&Xt(e.length)&&!ts(e)}var Qr=Object.prototype;function rs(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Qr;return e===n}function is(e,t){for(var n=-1,s=Array(e);++n<e;)s[n]=t(n);return s}var Jr="[object Arguments]";function Nn(e){return Re(e)&&Ke(e)==Jr}var as=Object.prototype,Zr=as.hasOwnProperty,ei=as.propertyIsEnumerable,jt=Nn(function(){return arguments}())?Nn:function(e){return Re(e)&&Zr.call(e,"callee")&&!ei.call(e,"callee")};function ti(){return!1}var os=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Tn=os&&typeof module=="object"&&module&&!module.nodeType&&module,ni=Tn&&Tn.exports===os,mn=ni?Ae.Buffer:void 0,si=mn?mn.isBuffer:void 0,Ut=si||ti,ri="[object Arguments]",ii="[object Array]",ai="[object Boolean]",oi="[object Date]",li="[object Error]",ci="[object Function]",ui="[object Map]",hi="[object Number]",fi="[object Object]",pi="[object RegExp]",di="[object Set]",Ei="[object String]",Ni="[object WeakMap]",Ti="[object ArrayBuffer]",mi="[object DataView]",bi="[object Float32Array]",Ii="[object Float64Array]",gi="[object Int8Array]",_i="[object Int16Array]",Ai="[object Int32Array]",Li="[object Uint8Array]",vi="[object Uint8ClampedArray]",yi="[object Uint16Array]",wi="[object Uint32Array]",k={};k[bi]=k[Ii]=k[gi]=k[_i]=k[Ai]=k[Li]=k[vi]=k[yi]=k[wi]=!0;k[ri]=k[ii]=k[Ti]=k[ai]=k[mi]=k[oi]=k[li]=k[ci]=k[ui]=k[hi]=k[fi]=k[pi]=k[di]=k[Ei]=k[Ni]=!1;function Si(e){return Re(e)&&Xt(e.length)&&!!k[Ke(e)]}function Pi(e){return function(t){return e(t)}}var ls=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Ze=ls&&typeof module=="object"&&module&&!module.nodeType&&module,Oi=Ze&&Ze.exports===ls,kt=Oi&&Qn.process,bn=function(){try{var e=Ze&&Ze.require&&Ze.require("util").types;return e||kt&&kt.binding&&kt.binding("util")}catch{}}(),In=bn&&bn.isTypedArray,cs=In?Pi(In):Si,xi=Object.prototype,ki=xi.hasOwnProperty;function us(e,t){var n=pe(e),s=!n&&jt(e),r=!n&&!s&&Ut(e),i=!n&&!s&&!r&&cs(e),a=n||s||r||i,o=a?is(e.length,String):[],u=o.length;for(var h in e)(t||ki.call(e,h))&&!(a&&(h=="length"||r&&(h=="offset"||h=="parent")||i&&(h=="buffer"||h=="byteLength"||h=="byteOffset")||ns(h,u)))&&o.push(h);return o}function Di(e,t){return function(n){return e(t(n))}}var Ri=Di(Object.keys,Object),Ui=Object.prototype,Mi=Ui.hasOwnProperty;function Fi(e){if(!rs(e))return Ri(e);var t=[];for(var n in Object(e))Mi.call(e,n)&&n!="constructor"&&t.push(n);return t}function Wt(e){return gt(e)?us(e):Fi(e)}function Bi(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Ci=Object.prototype,Vi=Ci.hasOwnProperty;function Gi(e){if(!Xe(e))return Bi(e);var t=rs(e),n=[];for(var s in e)s=="constructor"&&(t||!Vi.call(e,s))||n.push(s);return n}function $i(e){return gt(e)?us(e,!0):Gi(e)}var Xi=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ji=/^\w*$/;function Ht(e,t){if(pe(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||bt(e)?!0:ji.test(e)||!Xi.test(e)||t!=null&&e in Object(t)}var tt=Ve(Object,"create");function Wi(){this.__data__=tt?tt(null):{},this.size=0}function Hi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Ki="__lodash_hash_undefined__",qi=Object.prototype,zi=qi.hasOwnProperty;function Yi(e){var t=this.__data__;if(tt){var n=t[e];return n===Ki?void 0:n}return zi.call(t,e)?t[e]:void 0}var Qi=Object.prototype,Ji=Qi.hasOwnProperty;function Zi(e){var t=this.__data__;return tt?t[e]!==void 0:Ji.call(t,e)}var ea="__lodash_hash_undefined__";function ta(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=tt&&t===void 0?ea:t,this}function Ue(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Ue.prototype.clear=Wi;Ue.prototype.delete=Hi;Ue.prototype.get=Yi;Ue.prototype.has=Zi;Ue.prototype.set=ta;function na(){this.__data__=[],this.size=0}function _t(e,t){for(var n=e.length;n--;)if(ss(e[n][0],t))return n;return-1}var sa=Array.prototype,ra=sa.splice;function ia(e){var t=this.__data__,n=_t(t,e);if(n<0)return!1;var s=t.length-1;return n==s?t.pop():ra.call(t,n,1),--this.size,!0}function aa(e){var t=this.__data__,n=_t(t,e);return n<0?void 0:t[n][1]}function oa(e){return _t(this.__data__,e)>-1}function la(e,t){var n=this.__data__,s=_t(n,e);return s<0?(++this.size,n.push([e,t])):n[s][1]=t,this}function Le(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Le.prototype.clear=na;Le.prototype.delete=ia;Le.prototype.get=aa;Le.prototype.has=oa;Le.prototype.set=la;var nt=Ve(Ae,"Map");function ca(){this.size=0,this.__data__={hash:new Ue,map:new(nt||Le),string:new Ue}}function ua(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function At(e,t){var n=e.__data__;return ua(t)?n[typeof t=="string"?"string":"hash"]:n.map}function ha(e){var t=At(this,e).delete(e);return this.size-=t?1:0,t}function fa(e){return At(this,e).get(e)}function pa(e){return At(this,e).has(e)}function da(e,t){var n=At(this,e),s=n.size;return n.set(e,t),this.size+=n.size==s?0:1,this}function ve(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}ve.prototype.clear=ca;ve.prototype.delete=ha;ve.prototype.get=fa;ve.prototype.has=pa;ve.prototype.set=da;var Ea="Expected a function";function Kt(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(Ea);var n=function(){var s=arguments,r=t?t.apply(this,s):s[0],i=n.cache;if(i.has(r))return i.get(r);var a=e.apply(this,s);return n.cache=i.set(r,a)||i,a};return n.cache=new(Kt.Cache||ve),n}Kt.Cache=ve;var Na=500;function Ta(e){var t=Kt(e,function(s){return n.size===Na&&n.clear(),s}),n=t.cache;return t}var ma=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ba=/\\(\\)?/g,Ia=Ta(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(ma,function(n,s,r,i){t.push(r?i.replace(ba,"$1"):s||n)}),t});function ga(e){return e==null?"":es(e)}function hs(e,t){return pe(e)?e:Ht(e,t)?[e]:Ia(ga(e))}function Lt(e){if(typeof e=="string"||bt(e))return e;var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function fs(e,t){t=hs(t,e);for(var n=0,s=t.length;e!=null&&n<s;)e=e[Lt(t[n++])];return n&&n==s?e:void 0}function ps(e,t,n){var s=e==null?void 0:fs(e,t);return s===void 0?n:s}function ds(e,t){for(var n=-1,s=t.length,r=e.length;++n<s;)e[r+n]=t[n];return e}var gn=Ne?Ne.isConcatSpreadable:void 0;function _a(e){return pe(e)||jt(e)||!!(gn&&e&&e[gn])}function Aa(e,t,n,s,r){var i=-1,a=e.length;for(n||(n=_a),r||(r=[]);++i<a;){var o=e[i];n(o)?ds(r,o):r[r.length]=o}return r}function _n(e){var t=e==null?0:e.length;return t?Aa(e):[]}function La(){this.__data__=new Le,this.size=0}function va(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function ya(e){return this.__data__.get(e)}function wa(e){return this.__data__.has(e)}var Sa=200;function Pa(e,t){var n=this.__data__;if(n instanceof Le){var s=n.__data__;if(!nt||s.length<Sa-1)return s.push([e,t]),this.size=++n.size,this;n=this.__data__=new ve(s)}return n.set(e,t),this.size=n.size,this}function ge(e){var t=this.__data__=new Le(e);this.size=t.size}ge.prototype.clear=La;ge.prototype.delete=va;ge.prototype.get=ya;ge.prototype.has=wa;ge.prototype.set=Pa;function Es(e,t){for(var n=-1,s=e==null?0:e.length,r=0,i=[];++n<s;){var a=e[n];t(a,n,e)&&(i[r++]=a)}return i}function Oa(){return[]}var xa=Object.prototype,ka=xa.propertyIsEnumerable,An=Object.getOwnPropertySymbols,Da=An?function(e){return e==null?[]:(e=Object(e),Es(An(e),function(t){return ka.call(e,t)}))}:Oa;function Ra(e,t,n){var s=t(e);return pe(e)?s:ds(s,n(e))}function Ln(e){return Ra(e,Wt,Da)}var Mt=Ve(Ae,"DataView"),Ft=Ve(Ae,"Promise"),Bt=Ve(Ae,"Set"),vn="[object Map]",Ua="[object Object]",yn="[object Promise]",wn="[object Set]",Sn="[object WeakMap]",Pn="[object DataView]",Ma=Ce(Mt),Fa=Ce(nt),Ba=Ce(Ft),Ca=Ce(Bt),Va=Ce(Rt),Pe=Ke;(Mt&&Pe(new Mt(new ArrayBuffer(1)))!=Pn||nt&&Pe(new nt)!=vn||Ft&&Pe(Ft.resolve())!=yn||Bt&&Pe(new Bt)!=wn||Rt&&Pe(new Rt)!=Sn)&&(Pe=function(e){var t=Ke(e),n=t==Ua?e.constructor:void 0,s=n?Ce(n):"";if(s)switch(s){case Ma:return Pn;case Fa:return vn;case Ba:return yn;case Ca:return wn;case Va:return Sn}return t});var On=Ae.Uint8Array,Ga="__lodash_hash_undefined__";function $a(e){return this.__data__.set(e,Ga),this}function Xa(e){return this.__data__.has(e)}function pt(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new ve;++t<n;)this.add(e[t])}pt.prototype.add=pt.prototype.push=$a;pt.prototype.has=Xa;function ja(e,t){for(var n=-1,s=e==null?0:e.length;++n<s;)if(t(e[n],n,e))return!0;return!1}function Wa(e,t){return e.has(t)}var Ha=1,Ka=2;function Ns(e,t,n,s,r,i){var a=n&Ha,o=e.length,u=t.length;if(o!=u&&!(a&&u>o))return!1;var h=i.get(e),f=i.get(t);if(h&&f)return h==t&&f==e;var d=-1,N=!0,m=n&Ka?new pt:void 0;for(i.set(e,t),i.set(t,e);++d<o;){var A=e[d],b=t[d];if(s)var y=a?s(b,A,d,t,e,i):s(A,b,d,e,t,i);if(y!==void 0){if(y)continue;N=!1;break}if(m){if(!ja(t,function(j,q){if(!Wa(m,q)&&(A===j||r(A,j,n,s,i)))return m.push(q)})){N=!1;break}}else if(!(A===b||r(A,b,n,s,i))){N=!1;break}}return i.delete(e),i.delete(t),N}function qa(e){var t=-1,n=Array(e.size);return e.forEach(function(s,r){n[++t]=[r,s]}),n}function za(e){var t=-1,n=Array(e.size);return e.forEach(function(s){n[++t]=s}),n}var Ya=1,Qa=2,Ja="[object Boolean]",Za="[object Date]",eo="[object Error]",to="[object Map]",no="[object Number]",so="[object RegExp]",ro="[object Set]",io="[object String]",ao="[object Symbol]",oo="[object ArrayBuffer]",lo="[object DataView]",xn=Ne?Ne.prototype:void 0,Dt=xn?xn.valueOf:void 0;function co(e,t,n,s,r,i,a){switch(n){case lo:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case oo:return!(e.byteLength!=t.byteLength||!i(new On(e),new On(t)));case Ja:case Za:case no:return ss(+e,+t);case eo:return e.name==t.name&&e.message==t.message;case so:case io:return e==t+"";case to:var o=qa;case ro:var u=s&Ya;if(o||(o=za),e.size!=t.size&&!u)return!1;var h=a.get(e);if(h)return h==t;s|=Qa,a.set(e,t);var f=Ns(o(e),o(t),s,r,i,a);return a.delete(e),f;case ao:if(Dt)return Dt.call(e)==Dt.call(t)}return!1}var uo=1,ho=Object.prototype,fo=ho.hasOwnProperty;function po(e,t,n,s,r,i){var a=n&uo,o=Ln(e),u=o.length,h=Ln(t),f=h.length;if(u!=f&&!a)return!1;for(var d=u;d--;){var N=o[d];if(!(a?N in t:fo.call(t,N)))return!1}var m=i.get(e),A=i.get(t);if(m&&A)return m==t&&A==e;var b=!0;i.set(e,t),i.set(t,e);for(var y=a;++d<u;){N=o[d];var j=e[N],q=t[N];if(s)var S=a?s(q,j,N,t,e,i):s(j,q,N,e,t,i);if(!(S===void 0?j===q||r(j,q,n,s,i):S)){b=!1;break}y||(y=N=="constructor")}if(b&&!y){var ee=e.constructor,G=t.constructor;ee!=G&&"constructor"in e&&"constructor"in t&&!(typeof ee=="function"&&ee instanceof ee&&typeof G=="function"&&G instanceof G)&&(b=!1)}return i.delete(e),i.delete(t),b}var Eo=1,kn="[object Arguments]",Dn="[object Array]",ct="[object Object]",No=Object.prototype,Rn=No.hasOwnProperty;function To(e,t,n,s,r,i){var a=pe(e),o=pe(t),u=a?Dn:Pe(e),h=o?Dn:Pe(t);u=u==kn?ct:u,h=h==kn?ct:h;var f=u==ct,d=h==ct,N=u==h;if(N&&Ut(e)){if(!Ut(t))return!1;a=!0,f=!1}if(N&&!f)return i||(i=new ge),a||cs(e)?Ns(e,t,n,s,r,i):co(e,t,u,n,s,r,i);if(!(n&Eo)){var m=f&&Rn.call(e,"__wrapped__"),A=d&&Rn.call(t,"__wrapped__");if(m||A){var b=m?e.value():e,y=A?t.value():t;return i||(i=new ge),r(b,y,n,s,i)}}return N?(i||(i=new ge),po(e,t,n,s,r,i)):!1}function qt(e,t,n,s,r){return e===t?!0:e==null||t==null||!Re(e)&&!Re(t)?e!==e&&t!==t:To(e,t,n,s,qt,r)}var mo=1,bo=2;function Io(e,t,n,s){var r=n.length,i=r;if(e==null)return!i;for(e=Object(e);r--;){var a=n[r];if(a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++r<i;){a=n[r];var o=a[0],u=e[o],h=a[1];if(a[2]){if(u===void 0&&!(o in e))return!1}else{var f=new ge,d;if(!(d===void 0?qt(h,u,mo|bo,s,f):d))return!1}}return!0}function Ts(e){return e===e&&!Xe(e)}function go(e){for(var t=Wt(e),n=t.length;n--;){var s=t[n],r=e[s];t[n]=[s,r,Ts(r)]}return t}function ms(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function _o(e){var t=go(e);return t.length==1&&t[0][2]?ms(t[0][0],t[0][1]):function(n){return n===e||Io(n,e,t)}}function Ao(e,t){return e!=null&&t in Object(e)}function Lo(e,t,n){t=hs(t,e);for(var s=-1,r=t.length,i=!1;++s<r;){var a=Lt(t[s]);if(!(i=e!=null&&n(e,a)))break;e=e[a]}return i||++s!=r?i:(r=e==null?0:e.length,!!r&&Xt(r)&&ns(a,r)&&(pe(e)||jt(e)))}function vo(e,t){return e!=null&&Lo(e,t,Ao)}var yo=1,wo=2;function So(e,t){return Ht(e)&&Ts(t)?ms(Lt(e),t):function(n){var s=ps(n,e);return s===void 0&&s===t?vo(n,e):qt(t,s,yo|wo)}}function bs(e){return function(t){return t==null?void 0:t[e]}}function Po(e){return function(t){return fs(t,e)}}function Oo(e){return Ht(e)?bs(Lt(e)):Po(e)}function Is(e){return typeof e=="function"?e:e==null?It:typeof e=="object"?pe(e)?So(e[0],e[1]):_o(e):Oo(e)}function xo(e,t,n,s){for(var r=-1,i=e==null?0:e.length;++r<i;){var a=e[r];t(s,a,n(a),e)}return s}function ko(e){return function(t,n,s){for(var r=-1,i=Object(t),a=s(t),o=a.length;o--;){var u=a[++r];if(n(i[u],u,i)===!1)break}return t}}var gs=ko();function Do(e,t){return e&&gs(e,t,Wt)}function Ro(e,t){return function(n,s){if(n==null)return n;if(!gt(n))return e(n,s);for(var r=n.length,i=-1,a=Object(n);++i<r&&s(a[i],i,a)!==!1;);return n}}var Uo=Ro(Do);function Mo(e,t,n,s){return Uo(e,function(r,i,a){t(s,r,n(r),a)}),s}function Fo(e,t){return function(n,s){var r=pe(n)?xo:Mo,i=t?t():{};return r(n,e,Is(s),i)}}function Bo(e){return Re(e)&>(e)}function U(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function Co(e){return typeof e=="function"?e:It}var Vo=Math.max,Go=Math.min;function $o(e,t,n){var s=e==null?0:e.length;if(!s)return-1;var r=s-1;return n!==void 0&&(r=Ir(n),r=n<0?Vo(s+r,0):Go(r,s-1)),Wr(e,Is(t),r)}function Xo(e){return e&&e.length?e[0]:void 0}function st(e,t){return e==null?e:gs(e,Co(t),$i)}var oe=Fo(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),jo=Math.max;function Wo(e){if(!(e&&e.length))return[];var t=0;return e=Es(e,function(n){if(Bo(n))return t=jo(n.length,t),!0}),is(t,function(n){return Zn(e,bs(n))})}var Ct=zr(Wo),p=(e=>(e.SPACE="<space>",e.TAB="<tab>",e.NEWLINE="<newline>",e.COMMA="<comma>",e.LPAREN="<lparen>",e.RPAREN="<rparen>",e.LBRACE="<lbrace>",e.RBRACE="<rbrace>",e.LBRACKET="<lbracket>",e.RBRACKET="<rbracket>",e.LANGLE="<langle>",e.RANGLE="<rangle>",e.OP="<op>",e.EOF="<eof>",e.NUMERIC_LITERAL="<number>",e.STRING_LITERAL="<string>",e.COLOR_LITERAL="<color>",e.FUNCTION_EXPRESSION="<function-expression>",e.QUOTED_STRING="<variable>",e.IDENTIFIER="<identifier>",e.SEMICOLON="<semicolon>",e.COLON="<colon>",e.TILDE="<tilde>",e.SINGLE_LINE_COMMENT="<single-line-comment>",e.MULTILINE_COMMENT="<multiline-comment>",e))(p||{});function Ho(e){switch(e.kind){case"<newline>":case"<space>":case"<tab>":case"<single-line-comment>":case"<multiline-comment>":return!0;default:return!1}}function Ko(e){if(!e)return!1;switch(e){case"+":case"-":case"*":case"/":case"%":case"<":case">":case"=":case"!":case".":case"&":case"|":return!0;default:return!1}}function Un(e){return e!==void 0&&e.kind==="<op>"}class Q{constructor(t,n,s,r,i){this.kind=t,this.startPos=n,this.endPos=s,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=n.offset,this.end=s.offset}static create(t,n,s,r,i){return new Q(t,n,s,r,i)}}function _s(e){return e.trailingTrivia.find(({kind:t})=>t===p.NEWLINE)!==void 0}function Mn(e,t){return t.leadingTrivia.find(({kind:s})=>s===p.NEWLINE)!==void 0||_s(e)}function Vt(e){return e.trailingTrivia.find(({kind:t})=>[p.SPACE,p.TAB].includes(t))!==void 0}function As(e){return e.trailingTrivia.length===0?e.end:As(U(e.trailingTrivia))}function Ls(e){return e.leadingTrivia.length===0?e.start:Ls(e.leadingTrivia[0])}function qo(e){return[p.SINGLE_LINE_COMMENT,p.MULTILINE_COMMENT].includes(e.kind)}class zo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class D{constructor(t,n,s){this.id=t,this.kind=n;const r=s.find(a=>a!==void 0&&!Number.isNaN(a.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof Q?Ls(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);const i=[...s].reverse().find(a=>a!==void 0&&!Number.isNaN(a.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof Q?As(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}}var Oe=(e=>(e.PROGRAM="<program>",e.ELEMENT_DECLARATION="<element-declaration>",e.ATTRIBUTE="<attribute>",e.IDENTIFIER_STREAM="<identifer-stream>",e.LITERAL="<literal>",e.VARIABLE="<variable>",e.PREFIX_EXPRESSION="<prefix-expression>",e.INFIX_EXPRESSION="<infix-expression>",e.POSTFIX_EXPRESSION="<postfix-expression>",e.FUNCTION_EXPRESSION="<function-expression>",e.FUNCTION_APPLICATION="<function-application>",e.BLOCK_EXPRESSION="<block-expression>",e.LIST_EXPRESSION="<list-expression>",e.TUPLE_EXPRESSION="<tuple-expression>",e.CALL_EXPRESSION="<call-expression>",e.PRIMARY_EXPRESSION="<primary-expression>",e.GROUP_EXPRESSION="<group-expression>",e.DUMMY="<dummy>",e.ARRAY="<array>",e.PARTIAL_INJECTION="<partial-injection>",e))(Oe||{});class J extends D{constructor({body:t=[],eof:n},s){super(s,"<program>",[...t,n]),this.body=t,this.eof=n}}class P extends D{constructor({type:t,name:n,as:s,alias:r,attributeList:i,bodyColon:a,body:o},u){if(super(u,"<element-declaration>",[t,n,s,r,i,a,o]),o&&a&&!(o instanceof w||o instanceof P))throw new Error("If an element has a simple body, it must be a function application node");this.type=t,this.name=n,this.as=s,this.alias=r,this.attributeList=i,this.bodyColon=a,this.body=o}}class ce extends D{constructor({identifiers:t=[]},n){super(n,"<identifer-stream>",t||[]),this.identifiers=t}}class ue extends D{constructor({name:t,colon:n,value:s},r){super(r,"<attribute>",[t,n,s]),this.name=t,this.value=s,this.colon=n}}class re extends D{constructor({op:t,expression:n},s){super(s,"<prefix-expression>",[t,n]),this.op=t,this.expression=n}}class Te extends D{constructor({op:t,leftExpression:n,rightExpression:s},r){super(r,"<infix-expression>",[n,t,s]),this.op=t,this.leftExpression=n,this.rightExpression=s}}class vt extends D{constructor({op:t,expression:n},s){super(s,"<postfix-expression>",[n,t]),this.op=t,this.expression=n}}class ie extends D{constructor({value:t},n){super(n,"<function-expression>",[t]),this.value=t}}class w extends D{constructor({callee:t,args:n=[]},s){super(s,"<function-application>",[t,...n]),this.callee=t,this.args=n}}class Ee extends D{constructor({blockOpenBrace:t,body:n=[],blockCloseBrace:s},r){super(r,"<block-expression>",[t,...n,s]),this.blockOpenBrace=t,this.body=n,this.blockCloseBrace=s}}class Me extends D{constructor({op:t,partial:n},s){super(s,"<partial-injection>",[t,n]),this.partial=n}}class R extends D{constructor({listOpenBracket:t,elementList:n=[],commaList:s=[],listCloseBracket:r},i){super(i,"<list-expression>",[t,...vs(n,s),r]),this.listOpenBracket=t,this.elementList=n,this.commaList=s,this.listCloseBracket=r}}class me extends D{constructor({tupleOpenParen:t,elementList:n=[],commaList:s=[],tupleCloseParen:r},i){super(i,"<tuple-expression>",[t,...vs(n,s),r]),this.tupleOpenParen=t,this.elementList=n,this.commaList=s,this.tupleCloseParen=r}}class zt extends me{constructor({groupOpenParen:t,expression:n,groupCloseParen:s},r){super({tupleOpenParen:t,elementList:n&&[n],commaList:[],tupleCloseParen:s},r),this.kind="<group-expression>"}}class ae extends D{constructor({callee:t,argumentList:n},s){super(s,"<call-expression>",[t,n]),this.callee=t,this.argumentList=n}}class qe extends D{constructor({literal:t},n){super(n,"<literal>",[t]),this.literal=t}}class de extends D{constructor({variable:t},n){super(n,"<variable>",[t]),this.variable=t}}class Y extends D{constructor({expression:t},n){super(n,"<primary-expression>",[t]),this.expression=t}}class ut extends D{constructor({pre:t},n){const s=Q.create(p.SPACE,t.endPos,t.endPos," ",!1);super(n,"<dummy>",[s])}}class Fe extends D{constructor({expression:t,indexer:n},s){super(s,"<array>",[t,n]),this.array=t,this.indexer=n}}function vs(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];const[n]=e,[s]=t;return(n.start<s.start?_n(Ct(e,t)):_n(Ct(t,e))).filter(r=>r!==null)}function Yo(e,t=!1){return JSON.stringify(e,function(n,s){var r;return!(this instanceof J)&&n==="symbol"?s==null?void 0:s.id:n==="symbol"?{symbolTable:s==null?void 0:s.symbolTable,id:s==null?void 0:s.id,references:s==null?void 0:s.references.map(i=>i.id),declaration:(r=s==null?void 0:s.declaration)==null?void 0:r.id}:n==="referee"||n==="parent"||n==="declaration"?s==null?void 0:s.id:n==="symbolTable"?Object.fromEntries(s.table):s},t?2:0)}class Qo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class ys{constructor({symbolTable:t},n){this.references=[],this.id=n,this.symbolTable=t}}class Jo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Zo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class dt{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Yt{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class el{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class tl{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class nl{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class sl{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class rl{constructor({injectorFieldSymbol:t,injectorDeclaration:n},s){this.references=[],this.id=s,this.injectorDeclaration=n,this.injectorFieldSymbol=t}}var l=(e=>(e[e.UNKNOWN_SYMBOL=1e3]="UNKNOWN_SYMBOL",e[e.UNEXPECTED_SYMBOL=1001]="UNEXPECTED_SYMBOL",e[e.UNEXPECTED_EOF=1002]="UNEXPECTED_EOF",e[e.UNEXPECTED_NEWLINE=1003]="UNEXPECTED_NEWLINE",e[e.UNKNOWN_TOKEN=1004]="UNKNOWN_TOKEN",e[e.UNEXPECTED_TOKEN=1005]="UNEXPECTED_TOKEN",e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]="UNEXPECTED_ELEMENT_DECLARATION",e[e.MISSING_SPACES=1007]="MISSING_SPACES",e[e.UNKNOWN_PREFIX_OP=1008]="UNKNOWN_PREFIX_OP",e[e.INVALID_OPERAND=1009]="INVALID_OPERAND",e[e.EMPTY_ATTRIBUTE_NAME=1010]="EMPTY_ATTRIBUTE_NAME",e[e.INVALID_ESCAPE_SEQUENCE=1011]="INVALID_ESCAPE_SEQUENCE",e[e.INVALID_NAME=3e3]="INVALID_NAME",e[e.UNEXPECTED_NAME=3001]="UNEXPECTED_NAME",e[e.NAME_NOT_FOUND=3002]="NAME_NOT_FOUND",e[e.DUPLICATE_NAME=3003]="DUPLICATE_NAME",e[e.INVALID_ALIAS=3004]="INVALID_ALIAS",e[e.UNEXPECTED_ALIAS=3005]="UNEXPECTED_ALIAS",e[e.UNEXPECTED_SETTINGS=3006]="UNEXPECTED_SETTINGS",e[e.INVALID_SETTINGS=3007]="INVALID_SETTINGS",e[e.UNEXPECTED_SIMPLE_BODY=3008]="UNEXPECTED_SIMPLE_BODY",e[e.UNEXPECTED_COMPLEX_BODY=3009]="UNEXPECTED_COMPLEX_BODY",e[e.INVALID_TABLE_CONTEXT=3010]="INVALID_TABLE_CONTEXT",e[e.UNKNOWN_TABLE_SETTING=3011]="UNKNOWN_TABLE_SETTING",e[e.DUPLICATE_TABLE_SETTING=3012]="DUPLICATE_TABLE_SETTING",e[e.INVALID_TABLEGROUP_CONTEXT=3013]="INVALID_TABLEGROUP_CONTEXT",e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]="INVALID_TABLEGROUP_ELEMENT_NAME",e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]="DUPLICATE_TABLEGROUP_ELEMENT_NAME",e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]="DUPLICATE_TABLEGROUP_FIELD_NAME",e[e.INVALID_TABLEGROUP_FIELD=3017]="INVALID_TABLEGROUP_FIELD",e[e.EMPTY_TABLE=3018]="EMPTY_TABLE",e[e.INVALID_COLUMN=3019]="INVALID_COLUMN",e[e.INVALID_COLUMN_NAME=3020]="INVALID_COLUMN_NAME",e[e.UNKNOWN_COLUMN_SETTING=3021]="UNKNOWN_COLUMN_SETTING",e[e.INVALID_COLUMN_TYPE=3022]="INVALID_COLUMN_TYPE",e[e.DUPLICATE_COLUMN_NAME=3023]="DUPLICATE_COLUMN_NAME",e[e.DUPLICATE_COLUMN_SETTING=3024]="DUPLICATE_COLUMN_SETTING",e[e.INVALID_COLUMN_SETTING_VALUE=3025]="INVALID_COLUMN_SETTING_VALUE",e[e.INVALID_ENUM_CONTEXT=3026]="INVALID_ENUM_CONTEXT",e[e.INVALID_ENUM_ELEMENT_NAME=3027]="INVALID_ENUM_ELEMENT_NAME",e[e.INVALID_ENUM_ELEMENT=3028]="INVALID_ENUM_ELEMENT",e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]="DUPLICATE_ENUM_ELEMENT_NAME",e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]="UNKNOWN_ENUM_ELEMENT_SETTING",e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]="DUPLICATE_ENUM_ELEMENT_SETTING",e[e.INVALID_ENUM_ELEMENT_SETTING=3032]="INVALID_ENUM_ELEMENT_SETTING",e[e.EMPTY_ENUM=3033]="EMPTY_ENUM",e[e.INVALID_REF_CONTEXT=3034]="INVALID_REF_CONTEXT",e[e.UNKNOWN_REF_SETTING=3035]="UNKNOWN_REF_SETTING",e[e.DUPLICATE_REF_SETTING=3036]="DUPLICATE_REF_SETTING",e[e.INVALID_REF_SETTING_VALUE=3037]="INVALID_REF_SETTING_VALUE",e[e.INVALID_REF_RELATIONSHIP=3038]="INVALID_REF_RELATIONSHIP",e[e.INVALID_REF_FIELD=3039]="INVALID_REF_FIELD",e[e.EMPTY_REF=3040]="EMPTY_REF",e[e.REF_REDEFINED=3041]="REF_REDEFINED",e[e.INVALID_NOTE_CONTEXT=3042]="INVALID_NOTE_CONTEXT",e[e.INVALID_NOTE=3043]="INVALID_NOTE",e[e.NOTE_REDEFINED=3044]="NOTE_REDEFINED",e[e.NOTE_CONTENT_REDEFINED=3045]="NOTE_CONTENT_REDEFINED",e[e.EMPTY_NOTE=3046]="EMPTY_NOTE",e[e.INVALID_INDEXES_CONTEXT=3047]="INVALID_INDEXES_CONTEXT",e[e.INVALID_INDEXES_FIELD=3048]="INVALID_INDEXES_FIELD",e[e.INVALID_INDEX=3049]="INVALID_INDEX",e[e.UNKNOWN_INDEX_SETTING=3050]="UNKNOWN_INDEX_SETTING",e[e.DUPLICATE_INDEX_SETTING=3051]="DUPLICATE_INDEX_SETTING",e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]="UNEXPECTED_INDEX_SETTING_VALUE",e[e.INVALID_INDEX_SETTING_VALUE=3053]="INVALID_INDEX_SETTING_VALUE",e[e.INVALID_PROJECT_CONTEXT=3054]="INVALID_PROJECT_CONTEXT",e[e.PROJECT_REDEFINED=3055]="PROJECT_REDEFINED",e[e.INVALID_PROJECT_FIELD=3056]="INVALID_PROJECT_FIELD",e[e.INVALID_CUSTOM_CONTEXT=3057]="INVALID_CUSTOM_CONTEXT",e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]="INVALID_CUSTOM_ELEMENT_VALUE",e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]="INVALID_ELEMENT_IN_SIMPLE_BODY",e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]="INVALID_TABLE_PARTIAL_CONTEXT",e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]="INVALID_TABLE_PARTIAL_ELEMENT_NAME",e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]="INVALID_TABLE_PARTIAL_SETTING_VALUE",e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]="DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME",e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]="DUPLICATE_TABLE_PARTIAL_SETTING",e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]="INVALID_TABLE_PARTIAL_INJECTION",e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]="INVALID_TABLE_PARTIAL_INJECTION_OP",e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]="INVALID_TABLE_PARTIAL_INJECTION_NAME",e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]="DUPLICATE_TABLE_PARTIAL_INJECTION_NAME",e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]="UNKNOWN_TABLE_PARTIAL_SETTING",e[e.INVALID_TABLE_SETTING_VALUE=3070]="INVALID_TABLE_SETTING_VALUE",e[e.INVALID_CHECKS_CONTEXT=3071]="INVALID_CHECKS_CONTEXT",e[e.INVALID_CHECKS_FIELD=3072]="INVALID_CHECKS_FIELD",e[e.INVALID_CHECK=3073]="INVALID_CHECK",e[e.UNKNOWN_CHECK_SETTING=3074]="UNKNOWN_CHECK_SETTING",e[e.DUPLICATE_CHECK_SETTING=3075]="DUPLICATE_CHECK_SETTING",e[e.INVALID_CHECK_SETTING_VALUE=3076]="INVALID_CHECK_SETTING_VALUE",e[e.BINDING_ERROR=4e3]="BINDING_ERROR",e[e.UNSUPPORTED=5e3]="UNSUPPORTED",e[e.CIRCULAR_REF=5001]="CIRCULAR_REF",e[e.SAME_ENDPOINT=5002]="SAME_ENDPOINT",e[e.UNEQUAL_FIELDS_BINARY_REF=5003]="UNEQUAL_FIELDS_BINARY_REF",e[e.CONFLICTING_SETTING=5004]="CONFLICTING_SETTING",e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]="TABLE_REAPPEAR_IN_TABLEGROUP",e))(l||{});class c extends Error{constructor(t,n,s){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=s,this.start=s.start,this.end=s.end,this.name=this.constructor.name,Object.setPrototypeOf(this,c.prototype)}}class se{constructor(t,n){this.value=t,this.errors=n===void 0?[]:n}getValue(){return this.value}getErrors(){return this.errors}chain(t){const n=t(this.value),s=[...this.errors,...n.errors];return new se(n.value,s)}map(t){return new se(t(this.value),this.errors)}}function at(e){return!!e.match(new RegExp("(\\p{L}|_|\\p{M})","gu"))}function je(e){if(!e)return!1;const t=e[0];return t>="0"&&t<="9"}function il(e){const[t]=e;return je(t)||at(t)&&t.toLowerCase()>="a"&&t.toLowerCase()<="f"}function De(e){return at(e)||je(e)}function al(e){return e.split("").every(De)?e:`"${e}"`}function Fn(e,t){const n=[],s=Math.min(e.length,t.length);for(let r=0;r<s;r+=1)n.push(e[r],t[r]);return n.push(...e.slice(s),...t.slice(s)),n}function et(e,t){return e>=t.start&&e<t.end}function ws(e){var t;return e instanceof re?`${(t=e.op)==null?void 0:t.value}${ws(e.expression)}`:e.expression.literal.value}function Gt(e){var t;return e instanceof re?((t=e.op)==null?void 0:t.value)==="-"?-Gt(e.expression):Gt(e.expression):Number.parseFloat(e.expression.literal.value)}class B{constructor(t){this.value=t}unwrap(){return this.value}unwrap_or(t){return this.value}and_then(t){return t(this.value)}map(t){return new B(t(this.value))}isOk(){return!0}}class x{constructor(){this.value=void 0}unwrap(){throw new Error("Trying to unwrap a None value")}unwrap_or(t){return t}and_then(t){return new x}map(t){return new x}isOk(){return!1}}function ol(e,t,n){if(!e||!xe(e)||t.length===0)return new x;const s=[...t],r=Bn(e).unwrap(),i=s.pop();if(!(i instanceof Ee))return new x;const a=U(s)instanceof R?s.pop():void 0;if(s.length===3){const o=Bn(s[1]).value;return!o||!$t(o)?new x:new B(n.create(P,{type:r,name:s[0],as:o,alias:s[2],attributeList:a,body:i}))}return s.length===1?new B(n.create(P,{type:r,name:s[0],attributeList:a,body:i})):s.length===0?new B(n.create(P,{type:r,attributeList:a,body:i})):new x}function $t(e){return(e==null?void 0:e.kind)===p.IDENTIFIER&&e.value==="as"}function _(e){e&&(e instanceof Q?ll(e):cl(e))}function ll(e){e.kind!==p.EOF&&(e.isInvalid=!0)}function cl(e){if(e instanceof P)_(e.type),_(e.name),_(e.as),_(e.alias),_(e.bodyColon),_(e.attributeList),_(e.body);else if(e instanceof ce)e.identifiers.forEach(_);else if(e instanceof ue)_(e.name),_(e.colon),_(e.value);else if(e instanceof re)_(e.op),_(e.expression);else if(e instanceof Te)_(e.leftExpression),_(e.op),_(e.rightExpression);else if(e instanceof vt)_(e.op),_(e.expression);else if(e instanceof Ee)_(e.blockOpenBrace),e.body.forEach(_),_(e.blockCloseBrace);else if(e instanceof R)_(e.listOpenBracket),e.commaList.forEach(_),e.elementList.forEach(_),_(e.listCloseBracket);else if(e instanceof me)_(e.tupleOpenParen),e.commaList.forEach(_),e.elementList.forEach(_),_(e.tupleCloseParen);else if(e instanceof ae)_(e.callee),_(e.argumentList);else if(e instanceof w)_(e.callee),e.args.forEach(_);else if(e instanceof Y)_(e.expression);else if(e instanceof ie)_(e.value);else if(e instanceof de)_(e.variable);else if(e instanceof qe)_(e.literal);else throw e instanceof zt?new Error("This case is handled by the TupleExpressionNode case"):new Error("Unreachable case in markInvalidNode")}function Ss(e){return!!(e!=null&&e.isInvalid)}function W(...e){return e.filter(t=>t!==void 0)}function ul(e){if(e instanceof J)return W(...e.body,e.eof);if(e instanceof P)return W(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof ue)return W(e.name,e.colon,e.value);if(e instanceof ce)return e.identifiers;if(e instanceof qe)return e.literal?[e.literal]:[];if(e instanceof de)return W(e.variable);if(e instanceof re)return W(e.op,e.expression);if(e instanceof Te)return W(e.leftExpression,e.op,e.rightExpression);if(e instanceof vt)return W(e.expression,e.op);if(e instanceof ie)return W(e.value);if(e instanceof w)return W(e.callee,...e.args);if(e instanceof Ee)return W(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof R)return W(e.listOpenBracket,...Fn(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof me)return W(e.tupleOpenParen,...Fn(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof ae)return W(e.callee,e.argumentList);if(e instanceof Y)return W(e.expression);if(e instanceof Fe)return W(e.array,e.indexer);if(e instanceof Me)return W(e.partial);throw e instanceof zt?new Error("This case is already handled by TupleExpressionNode"):new Error("Unreachable - no other possible cases")}function Bn(e){return V(e)?new B(e.expression.variable):new x}function K(e){var t;return e instanceof Y&&(e.expression instanceof de&&e.expression.variable instanceof Q&&e.expression.variable.kind===p.QUOTED_STRING||e.expression instanceof qe&&((t=e.expression.literal)==null?void 0:t.kind)===p.STRING_LITERAL)}function V(e){return e instanceof Y&&e.expression instanceof de&&e.expression.variable instanceof Q}function xe(e){var t;return e instanceof Y&&e.expression instanceof de&&((t=e.expression.variable)==null?void 0:t.kind)===p.IDENTIFIER}function yt(e){var t;return e instanceof Te&&e.leftExpression instanceof D&&e.rightExpression instanceof D&&((t=e.op)==null?void 0:t.value)==="."}function Qt(e){return V(e)?!0:yt(e)&&V(e.rightExpression)&&Qt(e.leftExpression)}function We(e){if(e===void 0)return new x;const t=e.identifiers.map(n=>n.value).join(" ");return t===""?new x:new B(t)}class hl{constructor(t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){const t=this.peek();return this.current={...this.current},t===`
|
|
2
|
-
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,t}peek(t=0){if(!(this.current.offset+t>=this.text.length))return this.text[this.current.offset+t]}check(t){for(let n=0;n<t.length;n+=1)if(t[n]!==this.peek(n))return!1;return!0}match(t){return this.check(t)?(t.split("").forEach(()=>this.advance()),!0):!1}addToken(t,n=!1){this.tokens.push(this.createToken(t,n))}createToken(t,n=!1){return
|
|
3
|
-
`:this.addToken(p.NEWLINE);break;case" ":this.addToken(p.TAB);break;case",":this.addToken(p.COMMA);break;case"(":this.addToken(p.LPAREN);break;case")":this.addToken(p.RPAREN);break;case"[":this.addToken(p.LBRACKET);break;case"]":this.addToken(p.RBRACKET);break;case"{":this.addToken(p.LBRACE);break;case"}":this.addToken(p.RBRACE);break;case";":this.addToken(p.SEMICOLON);break;case":":this.addToken(p.COLON);break;case"~":this.addToken(p.TILDE);break;case"'":this.match("''")?this.multilineStringLiteral():this.singleLineStringLiteral();break;case'"':this.quotedVariable();break;case"`":this.functionExpression();break;case"#":this.colorLiteral();break;case"/":this.match("/")?this.singleLineComment():this.match("*")?this.multilineComment():this.operator(t);break;default:if(
|
|
4
|
-
`))&&!this.check(n);)this.peek()==="\\"&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){const
|
|
5
|
-
`)&&!s){const
|
|
6
|
-
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(p.MULTILINE_COMMENT,"*/",{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var Kn=typeof global=="object"&&global&&global.Object===Object&&global,Ks=typeof self=="object"&&self&&self.Object===Object&&self,me=Kn||Ks||Function("return this")(),he=me.Symbol,qn=Object.prototype,qs=qn.hasOwnProperty,zs=qn.toString,je=he?he.toStringTag:void 0;function Ys(e){var t=qs.call(e,je),n=e[je];try{e[je]=void 0;var s=!0}catch{}var r=zs.call(e);return s&&(t?e[je]=n:delete e[je]),r}var Qs=Object.prototype,Js=Qs.toString;function Zs(e){return Js.call(e)}var er="[object Null]",tr="[object Undefined]",sn=he?he.toStringTag:void 0;function Ce(e){return e==null?e===void 0?tr:er:sn&&sn in Object(e)?Ys(e):Zs(e)}function Pe(e){return e!=null&&typeof e=="object"}var nr="[object Symbol]";function pt(e){return typeof e=="symbol"||Pe(e)&&Ce(e)==nr}function zn(e,t){for(var n=-1,s=e==null?0:e.length,r=Array(s);++n<s;)r[n]=t(e[n],n,e);return r}var ae=Array.isArray,rn=he?he.prototype:void 0,an=rn?rn.toString:void 0;function Yn(e){if(typeof e=="string")return e;if(ae(e))return zn(e,Yn)+"";if(pt(e))return an?an.call(e):"";var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}var sr=/\s/;function rr(e){for(var t=e.length;t--&&sr.test(e.charAt(t)););return t}var ir=/^\s+/;function ar(e){return e&&e.slice(0,rr(e)+1).replace(ir,"")}function Ue(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}var on=NaN,or=/^[-+]0x[0-9a-f]+$/i,lr=/^0b[01]+$/i,cr=/^0o[0-7]+$/i,ur=parseInt;function hr(e){if(typeof e=="number")return e;if(pt(e))return on;if(Ue(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Ue(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=ar(e);var n=lr.test(e);return n||cr.test(e)?ur(e.slice(2),n?2:8):or.test(e)?on:+e}var ln=1/0,fr=17976931348623157e292;function pr(e){if(!e)return e===0?e:0;if(e=hr(e),e===ln||e===-ln){var t=e<0?-1:1;return t*fr}return e===e?e:0}function dr(e){var t=pr(e),n=t%1;return t===t?n?t-n:t:0}function dt(e){return e}var Er="[object AsyncFunction]",Nr="[object Function]",Tr="[object GeneratorFunction]",mr="[object Proxy]";function Qn(e){if(!Ue(e))return!1;var t=Ce(e);return t==Nr||t==Tr||t==Er||t==mr}var vt=me["__core-js_shared__"],cn=function(){var e=/[^.]+$/.exec(vt&&vt.keys&&vt.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function br(e){return!!cn&&cn in e}var Ir=Function.prototype,gr=Ir.toString;function xe(e){if(e!=null){try{return gr.call(e)}catch{}try{return e+""}catch{}}return""}var _r=/[\\^$.*+?()[\]{}|]/g,Ar=/^\[object .+?Constructor\]$/,Lr=Function.prototype,vr=Object.prototype,yr=Lr.toString,wr=vr.hasOwnProperty,Sr=RegExp("^"+yr.call(wr).replace(_r,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function Pr(e){if(!Ue(e)||br(e))return!1;var t=Qn(e)?Sr:Ar;return t.test(xe(e))}function Or(e,t){return e?.[t]}function ke(e,t){var n=Or(e,t);return Pr(n)?n:void 0}var St=ke(me,"WeakMap");function xr(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var kr=800,Dr=16,Rr=Date.now;function Ur(e){var t=0,n=0;return function(){var s=Rr(),r=Dr-(s-n);if(n=s,r>0){if(++t>=kr)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}function Mr(e){return function(){return e}}var un=function(){try{var e=ke(Object,"defineProperty");return e({},"",{}),e}catch{}}(),Fr=un?function(e,t){return un(e,"toString",{configurable:!0,enumerable:!1,value:Mr(t),writable:!0})}:dt,Br=Ur(Fr);function Cr(e,t,n,s){e.length;for(var r=n+1;r--;)if(t(e[r],r,e))return r;return-1}var Vr=9007199254740991,Gr=/^(?:0|[1-9]\d*)$/;function Jn(e,t){var n=typeof e;return t=t??Vr,!!t&&(n=="number"||n!="symbol"&&Gr.test(e))&&e>-1&&e%1==0&&e<t}function Zn(e,t){return e===t||e!==e&&t!==t}var hn=Math.max;function $r(e,t,n){return t=hn(t===void 0?e.length-1:t,0),function(){for(var s=arguments,r=-1,i=hn(s.length-t,0),a=Array(i);++r<i;)a[r]=s[t+r];r=-1;for(var o=Array(t+1);++r<t;)o[r]=s[r];return o[t]=n(a),xr(e,this,o)}}function Xr(e,t){return Br($r(e,t,dt),e+"")}var jr=9007199254740991;function Ct(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=jr}function Et(e){return e!=null&&Ct(e.length)&&!Qn(e)}var Wr=Object.prototype;function es(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Wr;return e===n}function ts(e,t){for(var n=-1,s=Array(e);++n<e;)s[n]=t(n);return s}var Hr="[object Arguments]";function fn(e){return Pe(e)&&Ce(e)==Hr}var ns=Object.prototype,Kr=ns.hasOwnProperty,qr=ns.propertyIsEnumerable,Vt=fn(function(){return arguments}())?fn:function(e){return Pe(e)&&Kr.call(e,"callee")&&!qr.call(e,"callee")};function zr(){return!1}var ss=typeof exports=="object"&&exports&&!exports.nodeType&&exports,pn=ss&&typeof module=="object"&&module&&!module.nodeType&&module,Yr=pn&&pn.exports===ss,dn=Yr?me.Buffer:void 0,Qr=dn?dn.isBuffer:void 0,Pt=Qr||zr,Jr="[object Arguments]",Zr="[object Array]",ei="[object Boolean]",ti="[object Date]",ni="[object Error]",si="[object Function]",ri="[object Map]",ii="[object Number]",ai="[object Object]",oi="[object RegExp]",li="[object Set]",ci="[object String]",ui="[object WeakMap]",hi="[object ArrayBuffer]",fi="[object DataView]",pi="[object Float32Array]",di="[object Float64Array]",Ei="[object Int8Array]",Ni="[object Int16Array]",Ti="[object Int32Array]",mi="[object Uint8Array]",bi="[object Uint8ClampedArray]",Ii="[object Uint16Array]",gi="[object Uint32Array]",O={};O[pi]=O[di]=O[Ei]=O[Ni]=O[Ti]=O[mi]=O[bi]=O[Ii]=O[gi]=!0;O[Jr]=O[Zr]=O[hi]=O[ei]=O[fi]=O[ti]=O[ni]=O[si]=O[ri]=O[ii]=O[ai]=O[oi]=O[li]=O[ci]=O[ui]=!1;function _i(e){return Pe(e)&&Ct(e.length)&&!!O[Ce(e)]}function Ai(e){return function(t){return e(t)}}var rs=typeof exports=="object"&&exports&&!exports.nodeType&&exports,He=rs&&typeof module=="object"&&module&&!module.nodeType&&module,Li=He&&He.exports===rs,yt=Li&&Kn.process,En=function(){try{var e=He&&He.require&&He.require("util").types;return e||yt&&yt.binding&&yt.binding("util")}catch{}}(),Nn=En&&En.isTypedArray,is=Nn?Ai(Nn):_i,vi=Object.prototype,yi=vi.hasOwnProperty;function as(e,t){var n=ae(e),s=!n&&Vt(e),r=!n&&!s&&Pt(e),i=!n&&!s&&!r&&is(e),a=n||s||r||i,o=a?ts(e.length,String):[],h=o.length;for(var f in e)(t||yi.call(e,f))&&!(a&&(f=="length"||r&&(f=="offset"||f=="parent")||i&&(f=="buffer"||f=="byteLength"||f=="byteOffset")||Jn(f,h)))&&o.push(f);return o}function wi(e,t){return function(n){return e(t(n))}}var Si=wi(Object.keys,Object),Pi=Object.prototype,Oi=Pi.hasOwnProperty;function xi(e){if(!es(e))return Si(e);var t=[];for(var n in Object(e))Oi.call(e,n)&&n!="constructor"&&t.push(n);return t}function Gt(e){return Et(e)?as(e):xi(e)}function ki(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Di=Object.prototype,Ri=Di.hasOwnProperty;function Ui(e){if(!Ue(e))return ki(e);var t=es(e),n=[];for(var s in e)s=="constructor"&&(t||!Ri.call(e,s))||n.push(s);return n}function Mi(e){return Et(e)?as(e,!0):Ui(e)}var Fi=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Bi=/^\w*$/;function $t(e,t){if(ae(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||pt(e)?!0:Bi.test(e)||!Fi.test(e)||t!=null&&e in Object(t)}var qe=ke(Object,"create");function Ci(){this.__data__=qe?qe(null):{},this.size=0}function Vi(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Gi="__lodash_hash_undefined__",$i=Object.prototype,Xi=$i.hasOwnProperty;function ji(e){var t=this.__data__;if(qe){var n=t[e];return n===Gi?void 0:n}return Xi.call(t,e)?t[e]:void 0}var Wi=Object.prototype,Hi=Wi.hasOwnProperty;function Ki(e){var t=this.__data__;return qe?t[e]!==void 0:Hi.call(t,e)}var qi="__lodash_hash_undefined__";function zi(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=qe&&t===void 0?qi:t,this}function Oe(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Oe.prototype.clear=Ci;Oe.prototype.delete=Vi;Oe.prototype.get=ji;Oe.prototype.has=Ki;Oe.prototype.set=zi;function Yi(){this.__data__=[],this.size=0}function Nt(e,t){for(var n=e.length;n--;)if(Zn(e[n][0],t))return n;return-1}var Qi=Array.prototype,Ji=Qi.splice;function Zi(e){var t=this.__data__,n=Nt(t,e);if(n<0)return!1;var s=t.length-1;return n==s?t.pop():Ji.call(t,n,1),--this.size,!0}function ea(e){var t=this.__data__,n=Nt(t,e);return n<0?void 0:t[n][1]}function ta(e){return Nt(this.__data__,e)>-1}function na(e,t){var n=this.__data__,s=Nt(n,e);return s<0?(++this.size,n.push([e,t])):n[s][1]=t,this}function be(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}be.prototype.clear=Yi;be.prototype.delete=Zi;be.prototype.get=ea;be.prototype.has=ta;be.prototype.set=na;var ze=ke(me,"Map");function sa(){this.size=0,this.__data__={hash:new Oe,map:new(ze||be),string:new Oe}}function ra(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function Tt(e,t){var n=e.__data__;return ra(t)?n[typeof t=="string"?"string":"hash"]:n.map}function ia(e){var t=Tt(this,e).delete(e);return this.size-=t?1:0,t}function aa(e){return Tt(this,e).get(e)}function oa(e){return Tt(this,e).has(e)}function la(e,t){var n=Tt(this,e),s=n.size;return n.set(e,t),this.size+=n.size==s?0:1,this}function Ie(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var s=e[t];this.set(s[0],s[1])}}Ie.prototype.clear=sa;Ie.prototype.delete=ia;Ie.prototype.get=aa;Ie.prototype.has=oa;Ie.prototype.set=la;var ca="Expected a function";function Xt(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(ca);var n=function(){var s=arguments,r=t?t.apply(this,s):s[0],i=n.cache;if(i.has(r))return i.get(r);var a=e.apply(this,s);return n.cache=i.set(r,a)||i,a};return n.cache=new(Xt.Cache||Ie),n}Xt.Cache=Ie;var ua=500;function ha(e){var t=Xt(e,function(s){return n.size===ua&&n.clear(),s}),n=t.cache;return t}var fa=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,pa=/\\(\\)?/g,da=ha(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(fa,function(n,s,r,i){t.push(r?i.replace(pa,"$1"):s||n)}),t});function Ea(e){return e==null?"":Yn(e)}function os(e,t){return ae(e)?e:$t(e,t)?[e]:da(Ea(e))}function mt(e){if(typeof e=="string"||pt(e))return e;var t=e+"";return t=="0"&&1/e==-1/0?"-0":t}function ls(e,t){t=os(t,e);for(var n=0,s=t.length;e!=null&&n<s;)e=e[mt(t[n++])];return n&&n==s?e:void 0}function cs(e,t,n){var s=e==null?void 0:ls(e,t);return s===void 0?n:s}function us(e,t){for(var n=-1,s=t.length,r=e.length;++n<s;)e[r+n]=t[n];return e}var Tn=he?he.isConcatSpreadable:void 0;function Na(e){return ae(e)||Vt(e)||!!(Tn&&e&&e[Tn])}function Ta(e,t,n,s,r){var i=-1,a=e.length;for(n||(n=Na),r||(r=[]);++i<a;){var o=e[i];n(o)?us(r,o):r[r.length]=o}return r}function mn(e){var t=e==null?0:e.length;return t?Ta(e):[]}function ma(){this.__data__=new be,this.size=0}function ba(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}function Ia(e){return this.__data__.get(e)}function ga(e){return this.__data__.has(e)}var _a=200;function Aa(e,t){var n=this.__data__;if(n instanceof be){var s=n.__data__;if(!ze||s.length<_a-1)return s.push([e,t]),this.size=++n.size,this;n=this.__data__=new Ie(s)}return n.set(e,t),this.size=n.size,this}function Ne(e){var t=this.__data__=new be(e);this.size=t.size}Ne.prototype.clear=ma;Ne.prototype.delete=ba;Ne.prototype.get=Ia;Ne.prototype.has=ga;Ne.prototype.set=Aa;function hs(e,t){for(var n=-1,s=e==null?0:e.length,r=0,i=[];++n<s;){var a=e[n];t(a,n,e)&&(i[r++]=a)}return i}function La(){return[]}var va=Object.prototype,ya=va.propertyIsEnumerable,bn=Object.getOwnPropertySymbols,wa=bn?function(e){return e==null?[]:(e=Object(e),hs(bn(e),function(t){return ya.call(e,t)}))}:La;function Sa(e,t,n){var s=t(e);return ae(e)?s:us(s,n(e))}function In(e){return Sa(e,Gt,wa)}var Ot=ke(me,"DataView"),xt=ke(me,"Promise"),kt=ke(me,"Set"),gn="[object Map]",Pa="[object Object]",_n="[object Promise]",An="[object Set]",Ln="[object WeakMap]",vn="[object DataView]",Oa=xe(Ot),xa=xe(ze),ka=xe(xt),Da=xe(kt),Ra=xe(St),_e=Ce;(Ot&&_e(new Ot(new ArrayBuffer(1)))!=vn||ze&&_e(new ze)!=gn||xt&&_e(xt.resolve())!=_n||kt&&_e(new kt)!=An||St&&_e(new St)!=Ln)&&(_e=function(e){var t=Ce(e),n=t==Pa?e.constructor:void 0,s=n?xe(n):"";if(s)switch(s){case Oa:return vn;case xa:return gn;case ka:return _n;case Da:return An;case Ra:return Ln}return t});var yn=me.Uint8Array,Ua="__lodash_hash_undefined__";function Ma(e){return this.__data__.set(e,Ua),this}function Fa(e){return this.__data__.has(e)}function ot(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Ie;++t<n;)this.add(e[t])}ot.prototype.add=ot.prototype.push=Ma;ot.prototype.has=Fa;function Ba(e,t){for(var n=-1,s=e==null?0:e.length;++n<s;)if(t(e[n],n,e))return!0;return!1}function Ca(e,t){return e.has(t)}var Va=1,Ga=2;function fs(e,t,n,s,r,i){var a=n&Va,o=e.length,h=t.length;if(o!=h&&!(a&&h>o))return!1;var f=i.get(e),u=i.get(t);if(f&&u)return f==t&&u==e;var d=-1,I=!0,_=n&Ga?new ot:void 0;for(i.set(e,t),i.set(t,e);++d<o;){var v=e[d],w=t[d];if(s)var k=a?s(w,v,d,t,e,i):s(v,w,d,e,t,i);if(k!==void 0){if(k)continue;I=!1;break}if(_){if(!Ba(t,function(V,ce){if(!Ca(_,ce)&&(v===V||r(v,V,n,s,i)))return _.push(ce)})){I=!1;break}}else if(!(v===w||r(v,w,n,s,i))){I=!1;break}}return i.delete(e),i.delete(t),I}function $a(e){var t=-1,n=Array(e.size);return e.forEach(function(s,r){n[++t]=[r,s]}),n}function Xa(e){var t=-1,n=Array(e.size);return e.forEach(function(s){n[++t]=s}),n}var ja=1,Wa=2,Ha="[object Boolean]",Ka="[object Date]",qa="[object Error]",za="[object Map]",Ya="[object Number]",Qa="[object RegExp]",Ja="[object Set]",Za="[object String]",eo="[object Symbol]",to="[object ArrayBuffer]",no="[object DataView]",wn=he?he.prototype:void 0,wt=wn?wn.valueOf:void 0;function so(e,t,n,s,r,i,a){switch(n){case no:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case to:return!(e.byteLength!=t.byteLength||!i(new yn(e),new yn(t)));case Ha:case Ka:case Ya:return Zn(+e,+t);case qa:return e.name==t.name&&e.message==t.message;case Qa:case Za:return e==t+"";case za:var o=$a;case Ja:var h=s&ja;if(o||(o=Xa),e.size!=t.size&&!h)return!1;var f=a.get(e);if(f)return f==t;s|=Wa,a.set(e,t);var u=fs(o(e),o(t),s,r,i,a);return a.delete(e),u;case eo:if(wt)return wt.call(e)==wt.call(t)}return!1}var ro=1,io=Object.prototype,ao=io.hasOwnProperty;function oo(e,t,n,s,r,i){var a=n&ro,o=In(e),h=o.length,f=In(t),u=f.length;if(h!=u&&!a)return!1;for(var d=h;d--;){var I=o[d];if(!(a?I in t:ao.call(t,I)))return!1}var _=i.get(e),v=i.get(t);if(_&&v)return _==t&&v==e;var w=!0;i.set(e,t),i.set(t,e);for(var k=a;++d<h;){I=o[d];var V=e[I],ce=t[I];if(s)var nn=a?s(ce,V,I,t,e,i):s(V,ce,I,e,t,i);if(!(nn===void 0?V===ce||r(V,ce,n,s,i):nn)){w=!1;break}k||(k=I=="constructor")}if(w&&!k){var nt=e.constructor,st=t.constructor;nt!=st&&"constructor"in e&&"constructor"in t&&!(typeof nt=="function"&&nt instanceof nt&&typeof st=="function"&&st instanceof st)&&(w=!1)}return i.delete(e),i.delete(t),w}var lo=1,Sn="[object Arguments]",Pn="[object Array]",rt="[object Object]",co=Object.prototype,On=co.hasOwnProperty;function uo(e,t,n,s,r,i){var a=ae(e),o=ae(t),h=a?Pn:_e(e),f=o?Pn:_e(t);h=h==Sn?rt:h,f=f==Sn?rt:f;var u=h==rt,d=f==rt,I=h==f;if(I&&Pt(e)){if(!Pt(t))return!1;a=!0,u=!1}if(I&&!u)return i||(i=new Ne),a||is(e)?fs(e,t,n,s,r,i):so(e,t,h,n,s,r,i);if(!(n&lo)){var _=u&&On.call(e,"__wrapped__"),v=d&&On.call(t,"__wrapped__");if(_||v){var w=_?e.value():e,k=v?t.value():t;return i||(i=new Ne),r(w,k,n,s,i)}}return I?(i||(i=new Ne),oo(e,t,n,s,r,i)):!1}function jt(e,t,n,s,r){return e===t?!0:e==null||t==null||!Pe(e)&&!Pe(t)?e!==e&&t!==t:uo(e,t,n,s,jt,r)}var ho=1,fo=2;function po(e,t,n,s){var r=n.length,i=r;if(e==null)return!i;for(e=Object(e);r--;){var a=n[r];if(a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++r<i;){a=n[r];var o=a[0],h=e[o],f=a[1];if(a[2]){if(h===void 0&&!(o in e))return!1}else{var u=new Ne,d;if(!(d===void 0?jt(f,h,ho|fo,s,u):d))return!1}}return!0}function ps(e){return e===e&&!Ue(e)}function Eo(e){for(var t=Gt(e),n=t.length;n--;){var s=t[n],r=e[s];t[n]=[s,r,ps(r)]}return t}function ds(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}function No(e){var t=Eo(e);return t.length==1&&t[0][2]?ds(t[0][0],t[0][1]):function(n){return n===e||po(n,e,t)}}function To(e,t){return e!=null&&t in Object(e)}function mo(e,t,n){t=os(t,e);for(var s=-1,r=t.length,i=!1;++s<r;){var a=mt(t[s]);if(!(i=e!=null&&n(e,a)))break;e=e[a]}return i||++s!=r?i:(r=e==null?0:e.length,!!r&&Ct(r)&&Jn(a,r)&&(ae(e)||Vt(e)))}function bo(e,t){return e!=null&&mo(e,t,To)}var Io=1,go=2;function _o(e,t){return $t(e)&&ps(t)?ds(mt(e),t):function(n){var s=cs(n,e);return s===void 0&&s===t?bo(n,e):jt(t,s,Io|go)}}function Es(e){return function(t){return t?.[e]}}function Ao(e){return function(t){return ls(t,e)}}function Lo(e){return $t(e)?Es(mt(e)):Ao(e)}function Ns(e){return typeof e=="function"?e:e==null?dt:typeof e=="object"?ae(e)?_o(e[0],e[1]):No(e):Lo(e)}function vo(e,t,n,s){for(var r=-1,i=e==null?0:e.length;++r<i;){var a=e[r];t(s,a,n(a),e)}return s}function yo(e){return function(t,n,s){for(var r=-1,i=Object(t),a=s(t),o=a.length;o--;){var h=a[++r];if(n(i[h],h,i)===!1)break}return t}}var Ts=yo();function wo(e,t){return e&&Ts(e,t,Gt)}function So(e,t){return function(n,s){if(n==null)return n;if(!Et(n))return e(n,s);for(var r=n.length,i=-1,a=Object(n);++i<r&&s(a[i],i,a)!==!1;);return n}}var Po=So(wo);function Oo(e,t,n,s){return Po(e,function(r,i,a){t(s,r,n(r),a)}),s}function xo(e,t){return function(n,s){var r=ae(n)?vo:Oo,i=t?t():{};return r(n,e,Ns(s),i)}}function ko(e){return Pe(e)&&Et(e)}function R(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function Do(e){return typeof e=="function"?e:dt}var Ro=Math.max,Uo=Math.min;function Mo(e,t,n){var s=e==null?0:e.length;if(!s)return-1;var r=s-1;return n!==void 0&&(r=dr(n),r=n<0?Ro(s+r,0):Uo(r,s-1)),Cr(e,Ns(t),r)}function Fo(e){return e&&e.length?e[0]:void 0}function Ye(e,t){return e==null?e:Ts(e,Do(t),Mi)}var te=xo(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),Bo=Math.max;function Co(e){if(!(e&&e.length))return[];var t=0;return e=hs(e,function(n){if(ko(n))return t=Bo(n.length,t),!0}),ts(t,function(n){return zn(e,Es(n))})}var Dt=Xr(Co),p=(e=>(e.SPACE="<space>",e.TAB="<tab>",e.NEWLINE="<newline>",e.COMMA="<comma>",e.LPAREN="<lparen>",e.RPAREN="<rparen>",e.LBRACE="<lbrace>",e.RBRACE="<rbrace>",e.LBRACKET="<lbracket>",e.RBRACKET="<rbracket>",e.LANGLE="<langle>",e.RANGLE="<rangle>",e.OP="<op>",e.EOF="<eof>",e.NUMERIC_LITERAL="<number>",e.STRING_LITERAL="<string>",e.COLOR_LITERAL="<color>",e.FUNCTION_EXPRESSION="<function-expression>",e.QUOTED_STRING="<variable>",e.IDENTIFIER="<identifier>",e.SEMICOLON="<semicolon>",e.COLON="<colon>",e.TILDE="<tilde>",e.SINGLE_LINE_COMMENT="<single-line-comment>",e.MULTILINE_COMMENT="<multiline-comment>",e))(p||{});function Vo(e){switch(e.kind){case"<newline>":case"<space>":case"<tab>":case"<single-line-comment>":case"<multiline-comment>":return!0;default:return!1}}function Go(e){if(!e)return!1;switch(e){case"+":case"-":case"*":case"/":case"%":case"<":case">":case"=":case"!":case".":case"&":case"|":return!0;default:return!1}}function xn(e){return e!==void 0&&e.kind==="<op>"}class z{constructor(t,n,s,r,i){this.kind=t,this.startPos=n,this.endPos=s,this.value=r,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=i,this.start=n.offset,this.end=s.offset}static create(t,n,s,r,i){return new z(t,n,s,r,i)}}function ms(e){return e.trailingTrivia.find(({kind:t})=>t===p.NEWLINE)!==void 0}function kn(e,t){return t.leadingTrivia.find(({kind:s})=>s===p.NEWLINE)!==void 0||ms(e)}function Rt(e){return e.trailingTrivia.find(({kind:t})=>[p.SPACE,p.TAB].includes(t))!==void 0}function bs(e){return e.trailingTrivia.length===0?e.end:bs(R(e.trailingTrivia))}function Is(e){return e.leadingTrivia.length===0?e.start:Is(e.leadingTrivia[0])}function $o(e){return[p.SINGLE_LINE_COMMENT,p.MULTILINE_COMMENT].includes(e.kind)}class Xo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class x{constructor(t,n,s){this.id=t,this.kind=n;const r=s.find(a=>a!==void 0&&!Number.isNaN(a.start));r?(this.startPos=r.startPos,this.fullStart=r instanceof z?Is(r):r.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);const i=[...s].reverse().find(a=>a!==void 0&&!Number.isNaN(a.end));i?(this.endPos=i.endPos,this.fullEnd=i instanceof z?bs(i):i.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}}var Ae=(e=>(e.PROGRAM="<program>",e.ELEMENT_DECLARATION="<element-declaration>",e.ATTRIBUTE="<attribute>",e.IDENTIFIER_STREAM="<identifer-stream>",e.LITERAL="<literal>",e.VARIABLE="<variable>",e.PREFIX_EXPRESSION="<prefix-expression>",e.INFIX_EXPRESSION="<infix-expression>",e.POSTFIX_EXPRESSION="<postfix-expression>",e.FUNCTION_EXPRESSION="<function-expression>",e.FUNCTION_APPLICATION="<function-application>",e.BLOCK_EXPRESSION="<block-expression>",e.LIST_EXPRESSION="<list-expression>",e.TUPLE_EXPRESSION="<tuple-expression>",e.CALL_EXPRESSION="<call-expression>",e.PRIMARY_EXPRESSION="<primary-expression>",e.GROUP_EXPRESSION="<group-expression>",e.DUMMY="<dummy>",e.ARRAY="<array>",e.PARTIAL_INJECTION="<partial-injection>",e))(Ae||{});class K extends x{constructor({body:t=[],eof:n},s){super(s,"<program>",[...t,n]),this.body=t,this.eof=n}}class y extends x{constructor({type:t,name:n,as:s,alias:r,attributeList:i,bodyColon:a,body:o},h){if(super(h,"<element-declaration>",[t,n,s,r,i,a,o]),o&&a&&!(o instanceof L||o instanceof y))throw new Error("If an element has a simple body, it must be a function application node");this.type=t,this.name=n,this.as=s,this.alias=r,this.attributeList=i,this.bodyColon=a,this.body=o}}class ne extends x{constructor({identifiers:t=[]},n){super(n,"<identifer-stream>",t||[]),this.identifiers=t}}class se extends x{constructor({name:t,colon:n,value:s},r){super(r,"<attribute>",[t,n,s]),this.name=t,this.value=s,this.colon=n}}class Z extends x{constructor({op:t,expression:n},s){super(s,"<prefix-expression>",[t,n]),this.op=t,this.expression=n}}class fe extends x{constructor({op:t,leftExpression:n,rightExpression:s},r){super(r,"<infix-expression>",[n,t,s]),this.op=t,this.leftExpression=n,this.rightExpression=s}}class bt extends x{constructor({op:t,expression:n},s){super(s,"<postfix-expression>",[n,t]),this.op=t,this.expression=n}}class ee extends x{constructor({value:t},n){super(n,"<function-expression>",[t]),this.value=t}}class L extends x{constructor({callee:t,args:n=[]},s){super(s,"<function-application>",[t,...n]),this.callee=t,this.args=n}}class le extends x{constructor({blockOpenBrace:t,body:n=[],blockCloseBrace:s},r){super(r,"<block-expression>",[t,...n,s]),this.blockOpenBrace=t,this.body=n,this.blockCloseBrace=s}}class Le extends x{constructor({op:t,partial:n},s){super(s,"<partial-injection>",[t,n]),this.op=t,this.partial=n}}class D extends x{constructor({listOpenBracket:t,elementList:n=[],commaList:s=[],listCloseBracket:r},i){super(i,"<list-expression>",[t,...gs(n,s),r]),this.listOpenBracket=t,this.elementList=n,this.commaList=s,this.listCloseBracket=r}}class pe extends x{constructor({tupleOpenParen:t,elementList:n=[],commaList:s=[],tupleCloseParen:r},i){super(i,"<tuple-expression>",[t,...gs(n,s),r]),this.tupleOpenParen=t,this.elementList=n,this.commaList=s,this.tupleCloseParen=r}}class Wt extends pe{constructor({groupOpenParen:t,expression:n,groupCloseParen:s},r){super({tupleOpenParen:t,elementList:n&&[n],commaList:[],tupleCloseParen:s},r),this.kind="<group-expression>"}}class H extends x{constructor({callee:t,argumentList:n},s){super(s,"<call-expression>",[t,n]),this.callee=t,this.argumentList=n}}class Ve extends x{constructor({literal:t},n){super(n,"<literal>",[t]),this.literal=t}}class oe extends x{constructor({variable:t},n){super(n,"<variable>",[t]),this.variable=t}}class q extends x{constructor({expression:t},n){super(n,"<primary-expression>",[t]),this.expression=t}}class We extends x{constructor({pre:t},n){const s=z.create(p.SPACE,t.endPos,t.endPos," ",!1);super(n,"<dummy>",[s])}}class ue extends x{constructor({expression:t,indexer:n},s){super(s,"<array>",[t,n]),this.array=t,this.indexer=n}}function gs(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];const[n]=e,[s]=t;return(n.start<s.start?mn(Dt(e,t)):mn(Dt(t,e))).filter(r=>r!==null)}function jo(e,t=!1){return JSON.stringify(e,function(n,s){return!(this instanceof K)&&n==="symbol"?s?.id:n==="symbol"?{symbolTable:s?.symbolTable,id:s?.id,references:s?.references.map(r=>r.id),declaration:s?.declaration?.id}:n==="referee"||n==="parent"||n==="declaration"?s?.id:n==="symbolTable"?Object.fromEntries(s.table):s},t?2:0)}class Wo{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}}class _s{constructor({symbolTable:t},n){this.references=[],this.id=n,this.symbolTable=t}}class Ho{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Ko{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class lt{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Ht{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class qo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class zo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class Yo{constructor({symbolTable:t,declaration:n},s){this.references=[],this.id=s,this.symbolTable=t,this.declaration=n}}class Qo{constructor({declaration:t},n){this.references=[],this.id=n,this.declaration=t}}class Jo{constructor({injectorFieldSymbol:t,injectorDeclaration:n},s){this.references=[],this.id=s,this.injectorDeclaration=n,this.injectorFieldSymbol=t}}var l=(e=>(e[e.UNKNOWN_SYMBOL=1e3]="UNKNOWN_SYMBOL",e[e.UNEXPECTED_SYMBOL=1001]="UNEXPECTED_SYMBOL",e[e.UNEXPECTED_EOF=1002]="UNEXPECTED_EOF",e[e.UNEXPECTED_NEWLINE=1003]="UNEXPECTED_NEWLINE",e[e.UNKNOWN_TOKEN=1004]="UNKNOWN_TOKEN",e[e.UNEXPECTED_TOKEN=1005]="UNEXPECTED_TOKEN",e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]="UNEXPECTED_ELEMENT_DECLARATION",e[e.MISSING_SPACES=1007]="MISSING_SPACES",e[e.UNKNOWN_PREFIX_OP=1008]="UNKNOWN_PREFIX_OP",e[e.INVALID_OPERAND=1009]="INVALID_OPERAND",e[e.EMPTY_ATTRIBUTE_NAME=1010]="EMPTY_ATTRIBUTE_NAME",e[e.INVALID_ESCAPE_SEQUENCE=1011]="INVALID_ESCAPE_SEQUENCE",e[e.INVALID_NAME=3e3]="INVALID_NAME",e[e.UNEXPECTED_NAME=3001]="UNEXPECTED_NAME",e[e.NAME_NOT_FOUND=3002]="NAME_NOT_FOUND",e[e.DUPLICATE_NAME=3003]="DUPLICATE_NAME",e[e.INVALID_ALIAS=3004]="INVALID_ALIAS",e[e.UNEXPECTED_ALIAS=3005]="UNEXPECTED_ALIAS",e[e.UNEXPECTED_SETTINGS=3006]="UNEXPECTED_SETTINGS",e[e.INVALID_SETTINGS=3007]="INVALID_SETTINGS",e[e.UNEXPECTED_SIMPLE_BODY=3008]="UNEXPECTED_SIMPLE_BODY",e[e.UNEXPECTED_COMPLEX_BODY=3009]="UNEXPECTED_COMPLEX_BODY",e[e.INVALID_TABLE_CONTEXT=3010]="INVALID_TABLE_CONTEXT",e[e.UNKNOWN_TABLE_SETTING=3011]="UNKNOWN_TABLE_SETTING",e[e.DUPLICATE_TABLE_SETTING=3012]="DUPLICATE_TABLE_SETTING",e[e.INVALID_TABLEGROUP_CONTEXT=3013]="INVALID_TABLEGROUP_CONTEXT",e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]="INVALID_TABLEGROUP_ELEMENT_NAME",e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]="DUPLICATE_TABLEGROUP_ELEMENT_NAME",e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]="DUPLICATE_TABLEGROUP_FIELD_NAME",e[e.INVALID_TABLEGROUP_FIELD=3017]="INVALID_TABLEGROUP_FIELD",e[e.EMPTY_TABLE=3018]="EMPTY_TABLE",e[e.INVALID_COLUMN=3019]="INVALID_COLUMN",e[e.INVALID_COLUMN_NAME=3020]="INVALID_COLUMN_NAME",e[e.UNKNOWN_COLUMN_SETTING=3021]="UNKNOWN_COLUMN_SETTING",e[e.INVALID_COLUMN_TYPE=3022]="INVALID_COLUMN_TYPE",e[e.DUPLICATE_COLUMN_NAME=3023]="DUPLICATE_COLUMN_NAME",e[e.DUPLICATE_COLUMN_SETTING=3024]="DUPLICATE_COLUMN_SETTING",e[e.INVALID_COLUMN_SETTING_VALUE=3025]="INVALID_COLUMN_SETTING_VALUE",e[e.INVALID_ENUM_CONTEXT=3026]="INVALID_ENUM_CONTEXT",e[e.INVALID_ENUM_ELEMENT_NAME=3027]="INVALID_ENUM_ELEMENT_NAME",e[e.INVALID_ENUM_ELEMENT=3028]="INVALID_ENUM_ELEMENT",e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]="DUPLICATE_ENUM_ELEMENT_NAME",e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]="UNKNOWN_ENUM_ELEMENT_SETTING",e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]="DUPLICATE_ENUM_ELEMENT_SETTING",e[e.INVALID_ENUM_ELEMENT_SETTING=3032]="INVALID_ENUM_ELEMENT_SETTING",e[e.EMPTY_ENUM=3033]="EMPTY_ENUM",e[e.INVALID_REF_CONTEXT=3034]="INVALID_REF_CONTEXT",e[e.UNKNOWN_REF_SETTING=3035]="UNKNOWN_REF_SETTING",e[e.DUPLICATE_REF_SETTING=3036]="DUPLICATE_REF_SETTING",e[e.INVALID_REF_SETTING_VALUE=3037]="INVALID_REF_SETTING_VALUE",e[e.INVALID_REF_RELATIONSHIP=3038]="INVALID_REF_RELATIONSHIP",e[e.INVALID_REF_FIELD=3039]="INVALID_REF_FIELD",e[e.EMPTY_REF=3040]="EMPTY_REF",e[e.REF_REDEFINED=3041]="REF_REDEFINED",e[e.INVALID_NOTE_CONTEXT=3042]="INVALID_NOTE_CONTEXT",e[e.INVALID_NOTE=3043]="INVALID_NOTE",e[e.NOTE_REDEFINED=3044]="NOTE_REDEFINED",e[e.NOTE_CONTENT_REDEFINED=3045]="NOTE_CONTENT_REDEFINED",e[e.EMPTY_NOTE=3046]="EMPTY_NOTE",e[e.INVALID_INDEXES_CONTEXT=3047]="INVALID_INDEXES_CONTEXT",e[e.INVALID_INDEXES_FIELD=3048]="INVALID_INDEXES_FIELD",e[e.INVALID_INDEX=3049]="INVALID_INDEX",e[e.UNKNOWN_INDEX_SETTING=3050]="UNKNOWN_INDEX_SETTING",e[e.DUPLICATE_INDEX_SETTING=3051]="DUPLICATE_INDEX_SETTING",e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]="UNEXPECTED_INDEX_SETTING_VALUE",e[e.INVALID_INDEX_SETTING_VALUE=3053]="INVALID_INDEX_SETTING_VALUE",e[e.INVALID_PROJECT_CONTEXT=3054]="INVALID_PROJECT_CONTEXT",e[e.PROJECT_REDEFINED=3055]="PROJECT_REDEFINED",e[e.INVALID_PROJECT_FIELD=3056]="INVALID_PROJECT_FIELD",e[e.INVALID_CUSTOM_CONTEXT=3057]="INVALID_CUSTOM_CONTEXT",e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]="INVALID_CUSTOM_ELEMENT_VALUE",e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]="INVALID_ELEMENT_IN_SIMPLE_BODY",e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]="INVALID_TABLE_PARTIAL_CONTEXT",e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]="INVALID_TABLE_PARTIAL_ELEMENT_NAME",e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]="INVALID_TABLE_PARTIAL_SETTING_VALUE",e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]="DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME",e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]="DUPLICATE_TABLE_PARTIAL_SETTING",e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]="INVALID_TABLE_PARTIAL_INJECTION",e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]="INVALID_TABLE_PARTIAL_INJECTION_OP",e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]="INVALID_TABLE_PARTIAL_INJECTION_NAME",e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]="DUPLICATE_TABLE_PARTIAL_INJECTION_NAME",e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]="UNKNOWN_TABLE_PARTIAL_SETTING",e[e.INVALID_TABLE_SETTING_VALUE=3070]="INVALID_TABLE_SETTING_VALUE",e[e.INVALID_CHECKS_CONTEXT=3071]="INVALID_CHECKS_CONTEXT",e[e.INVALID_CHECKS_FIELD=3072]="INVALID_CHECKS_FIELD",e[e.INVALID_CHECK=3073]="INVALID_CHECK",e[e.UNKNOWN_CHECK_SETTING=3074]="UNKNOWN_CHECK_SETTING",e[e.DUPLICATE_CHECK_SETTING=3075]="DUPLICATE_CHECK_SETTING",e[e.INVALID_CHECK_SETTING_VALUE=3076]="INVALID_CHECK_SETTING_VALUE",e[e.BINDING_ERROR=4e3]="BINDING_ERROR",e[e.UNSUPPORTED=5e3]="UNSUPPORTED",e[e.CIRCULAR_REF=5001]="CIRCULAR_REF",e[e.SAME_ENDPOINT=5002]="SAME_ENDPOINT",e[e.UNEQUAL_FIELDS_BINARY_REF=5003]="UNEQUAL_FIELDS_BINARY_REF",e[e.CONFLICTING_SETTING=5004]="CONFLICTING_SETTING",e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]="TABLE_REAPPEAR_IN_TABLEGROUP",e))(l||{});class c extends Error{constructor(t,n,s){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=s,this.start=s.start,this.end=s.end,this.name=this.constructor.name,Object.setPrototypeOf(this,c.prototype)}}class J{constructor(t,n){this.value=t,this.errors=n===void 0?[]:n}getValue(){return this.value}getErrors(){return this.errors}chain(t){const n=t(this.value),s=[...this.errors,...n.errors];return new J(n.value,s)}map(t){return new J(t(this.value),this.errors)}}function Ze(e){return!!e.match(new RegExp("(\\p{L}|_|\\p{M})","gu"))}function Me(e){if(!e)return!1;const t=e[0];return t>="0"&&t<="9"}function Zo(e){const[t]=e;return Me(t)||Ze(t)&&t.toLowerCase()>="a"&&t.toLowerCase()<="f"}function Se(e){return Ze(e)||Me(e)}function el(e){return e.split("").every(Se)?e:`"${e}"`}function Dn(e,t){const n=[],s=Math.min(e.length,t.length);for(let r=0;r<s;r+=1)n.push(e[r],t[r]);return n.push(...e.slice(s),...t.slice(s)),n}function Ke(e,t){return e>=t.start&&e<t.end}function Ut(e){return e instanceof Z?`${e.op?.value}${Ut(e.expression)}`:e.expression.literal.value}function Mt(e){return e instanceof Z?e.op?.value==="-"?-Mt(e.expression):Mt(e.expression):Number.parseFloat(e.expression.literal.value)}class F{constructor(t){this.value=t}unwrap(){return this.value}unwrap_or(t){return this.value}and_then(t){return t(this.value)}map(t){return new F(t(this.value))}isOk(){return!0}}class P{constructor(){this.value=void 0}unwrap(){throw new Error("Trying to unwrap a None value")}unwrap_or(t){return t}and_then(t){return new P}map(t){return new P}isOk(){return!1}}function tl(e,t,n){if(!e||!ve(e)||t.length===0)return new P;const s=[...t],r=Rn(e).unwrap(),i=s.pop();if(!(i instanceof le))return new P;const a=R(s)instanceof D?s.pop():void 0;if(s.length===3){const o=Rn(s[1]).value;return!o||!Ft(o)?new P:new F(n.create(y,{type:r,name:s[0],as:o,alias:s[2],attributeList:a,body:i}))}return s.length===1?new F(n.create(y,{type:r,name:s[0],attributeList:a,body:i})):s.length===0?new F(n.create(y,{type:r,attributeList:a,body:i})):new P}function Ft(e){return e?.kind===p.IDENTIFIER&&e.value.toLowerCase()==="as"}function m(e){e&&(e instanceof z?nl(e):sl(e))}function nl(e){e.kind!==p.EOF&&(e.isInvalid=!0)}function sl(e){if(e instanceof y)m(e.type),m(e.name),m(e.as),m(e.alias),m(e.bodyColon),m(e.attributeList),m(e.body);else if(e instanceof ne)e.identifiers.forEach(m);else if(e instanceof se)m(e.name),m(e.colon),m(e.value);else if(e instanceof Z)m(e.op),m(e.expression);else if(e instanceof fe)m(e.leftExpression),m(e.op),m(e.rightExpression);else if(e instanceof bt)m(e.op),m(e.expression);else if(e instanceof le)m(e.blockOpenBrace),e.body.forEach(m),m(e.blockCloseBrace);else if(e instanceof D)m(e.listOpenBracket),e.commaList.forEach(m),e.elementList.forEach(m),m(e.listCloseBracket);else if(e instanceof pe)m(e.tupleOpenParen),e.commaList.forEach(m),e.elementList.forEach(m),m(e.tupleCloseParen);else if(e instanceof H)m(e.callee),m(e.argumentList);else if(e instanceof L)m(e.callee),e.args.forEach(m);else if(e instanceof q)m(e.expression);else if(e instanceof ee)m(e.value);else if(e instanceof oe)m(e.variable);else if(e instanceof Ve)m(e.literal);else{if(e instanceof Wt)throw new Error("This case is handled by the TupleExpressionNode case");if(e instanceof ue)m(e.array),m(e.indexer);else if(e instanceof K)e.body.forEach(m),m(e.eof);else if(e instanceof Le)m(e.op),m(e.partial);else if(!(e instanceof We))throw new Error("Unreachable case in markInvalidNode")}}function Bt(e){return!!e?.isInvalid}function X(...e){return e.filter(t=>t!==void 0)}function rl(e){if(e instanceof K)return X(...e.body,e.eof);if(e instanceof y)return X(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof se)return X(e.name,e.colon,e.value);if(e instanceof ne)return e.identifiers;if(e instanceof Ve)return e.literal?[e.literal]:[];if(e instanceof oe)return X(e.variable);if(e instanceof Z)return X(e.op,e.expression);if(e instanceof fe)return X(e.leftExpression,e.op,e.rightExpression);if(e instanceof bt)return X(e.expression,e.op);if(e instanceof ee)return X(e.value);if(e instanceof L)return X(e.callee,...e.args);if(e instanceof le)return X(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof D)return X(e.listOpenBracket,...Dn(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof pe)return X(e.tupleOpenParen,...Dn(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof H)return X(e.callee,e.argumentList);if(e instanceof q)return X(e.expression);if(e instanceof ue)return X(e.array,e.indexer);if(e instanceof Le)return X(e.op,e.partial);throw e instanceof Wt?new Error("This case is already handled by TupleExpressionNode"):new Error("Unreachable - no other possible cases")}function Rn(e){return C(e)?new F(e.expression.variable):new P}function $(e){return e instanceof q&&(e.expression instanceof oe&&e.expression.variable instanceof z&&e.expression.variable.kind===p.QUOTED_STRING||e.expression instanceof Ve&&e.expression.literal?.kind===p.STRING_LITERAL)}function C(e){return e instanceof q&&e.expression instanceof oe&&e.expression.variable instanceof z}function ve(e){return e instanceof q&&e.expression instanceof oe&&e.expression.variable?.kind===p.IDENTIFIER}function It(e){return e instanceof fe&&e.leftExpression instanceof x&&e.rightExpression instanceof x&&e.op?.value==="."}function Kt(e){return C(e)?!0:It(e)&&C(e.rightExpression)&&Kt(e.leftExpression)}function Fe(e){if(e===void 0)return new P;const t=e.identifiers.map(n=>n.value).join(" ");return t===""?new P:new F(t)}class il{constructor(t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){const t=this.peek();return this.current={...this.current},t===`
|
|
2
|
+
`?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,t}peek(t=0){if(!(this.current.offset+t>=this.text.length))return this.text[this.current.offset+t]}check(t){for(let n=0;n<t.length;n+=1)if(t[n]!==this.peek(n))return!1;return!0}match(t){return this.check(t)?(t.split("").forEach(()=>this.advance()),!0):!1}addToken(t,n=!1){this.tokens.push(this.createToken(t,n))}createToken(t,n=!1){return z.create(t,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),n)}lex(){return this.scanTokens(),this.tokens.push(z.create(p.EOF,this.start,this.current,"",!1)),this.gatherTrivia(),this.gatherInvalid(),new J(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){const t=this.advance();switch(t){case" ":this.addToken(p.SPACE);break;case"\r":break;case`
|
|
3
|
+
`:this.addToken(p.NEWLINE);break;case" ":this.addToken(p.TAB);break;case",":this.addToken(p.COMMA);break;case"(":this.addToken(p.LPAREN);break;case")":this.addToken(p.RPAREN);break;case"[":this.addToken(p.LBRACKET);break;case"]":this.addToken(p.RBRACKET);break;case"{":this.addToken(p.LBRACE);break;case"}":this.addToken(p.RBRACE);break;case";":this.addToken(p.SEMICOLON);break;case":":this.addToken(p.COLON);break;case"~":this.addToken(p.TILDE);break;case"'":this.match("''")?this.multilineStringLiteral():this.singleLineStringLiteral();break;case'"':this.quotedVariable();break;case"`":this.functionExpression();break;case"#":this.colorLiteral();break;case"/":this.match("/")?this.singleLineComment():this.match("*")?this.multilineComment():this.operator(t);break;default:if(Go(t)){this.operator(t);break}if(Ze(t)){this.identifier();break}if(Me(t)){this.numericLiteralOrIdentifier();break}this.addToken(p.OP,!0),this.errors.push(new c(l.UNKNOWN_SYMBOL,`Unexpected token '${t}'`,this.createToken(p.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let t=!0,n=[],s;const r=[];for(const i of this.tokens)Vo(i)?(n.push(i),i.kind===p.NEWLINE&&s&&(s.trailingTrivia=n,t=!0,s=void 0,n=[])):(t?i.leadingTrivia=n:s.trailingTrivia=n,r.push(i),n=[],s=i,t=!1);this.tokens=r}gatherInvalid(){let t;const n=[],s=[];for(t=0;t<this.tokens.length&&Bt(this.tokens[t]);t+=1)s.push(this.tokens[t]);let r=this.tokens[t];for(r.leadingInvalid=[...s,...r.leadingInvalid];t<this.tokens.length;t+=1){const i=this.tokens[t];Bt(i)?r.trailingInvalid.push(i):(r=i,n.push(i))}this.tokens=n}consumeUntil(t,n,{allowNewline:s,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o="";for(;!this.isAtEnd()&&(s||!this.check(`
|
|
4
|
+
`))&&!this.check(n);)this.peek()==="\\"&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){const h=this.createToken(t,!0);this.tokens.push(h),this.errors.push(new c(l.UNEXPECTED_EOF,"EOF reached while parsing",h));return}if(this.check(`
|
|
5
|
+
`)&&!s){const h=this.createToken(t,!0);this.tokens.push(h),this.errors.push(new c(l.UNEXPECTED_NEWLINE,"Invalid newline encountered while parsing",h));return}a&&this.match(n),this.tokens.push(z.create(t,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(p.STRING_LITERAL,"'",{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(p.STRING_LITERAL,"'''",{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(p.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(p.QUOTED_STRING,'"',{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(p.SINGLE_LINE_COMMENT,`
|
|
6
|
+
`,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(p.MULTILINE_COMMENT,"*/",{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&Se(this.peek());)this.advance();this.addToken(p.IDENTIFIER)}operator(t){switch(t){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}this.addToken(p.OP)}numericLiteralOrIdentifier(){let t=0;if(this.isAtEnd())return this.addToken(p.NUMERIC_LITERAL);for(;!this.isAtEnd();){const n=this.check(".");if(t+=n?1:0,t>1)break;if(!n&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(p.NUMERIC_LITERAL);if(!n&&!Se(this.peek()))return this.addToken(p.NUMERIC_LITERAL);if(!n&&!Me(this.peek()))break;this.advance()}if(t>0){for(;!this.isAtEnd()&&(this.check(".")||Se(this.peek()));)this.advance();const n=this.createToken(p.NUMERIC_LITERAL,!0);this.tokens.push(n),this.errors.push(new c(l.UNKNOWN_TOKEN,"Invalid number",n))}else{for(;!this.isAtEnd()&&Se(this.peek());)this.advance();const n=this.createToken(p.IDENTIFIER,!1);this.tokens.push(n)}}colorLiteral(){for(;!this.isAtEnd()&&Se(this.peek());)this.advance();this.addToken(p.COLOR_LITERAL)}escapedString(){const t={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(`
|
|
7
7
|
`)&&this.advance(),"";case`
|
|
8
8
|
`:return"";case"t":return" ";case"n":return`
|
|
9
|
-
`;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 n="";for(let s=0;s<=3;s+=1){if(this.isAtEnd()||!De(this.peek()))return this.errors.push(new c(l.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${n}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,Q.create(p.STRING_LITERAL,t,this.current,`\\u${n}`,!0))),`\\u${n}`;n+=this.advance()}return String.fromCharCode(parseInt(n,16))}default:return this.text[this.current.offset-1]}}}var ht=(e=>(e[e.ListExpression=0]="ListExpression",e[e.GroupExpression=1]="GroupExpression",e[e.BlockExpression=2]="BlockExpression",e))(ht||{});class fl{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(t){this.stack.push(t),t===0&&(this.numberOfNestedLBrackets+=1),t===1&&(this.numberOfNestedLParens+=1),t===2&&(this.numberOfNestedLBraces+=1)}pop(){const t=this.stack.pop();return t===0&&(this.numberOfNestedLBrackets-=1),t===1&&(this.numberOfNestedLParens-=1),t===2&&(this.numberOfNestedLBraces-=1),t}top(){return U(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(t,n){return()=>{this.push(t);try{return n()}finally{this.pop()}}}findHandlerContext(t,n){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let s=n;s<t.length-1;s+=1)switch(t[s].kind){case p.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(i=>[1,0].includes(i));break;case p.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case p.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case p.RBRACKET:if(this.isWithinListExpressionContext())return 0;break}}}class pl{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class T{constructor(t,n,s){this.token=t,this.partialNode=n,this.handlerContext=s}}class dl{constructor(t,n){this.current=0,this.errors=[],this.contextStack=new fl,this.synchronizeProgram=()=>{const s=this.peek();s.kind!==p.EOF?_(this.advance()):(_(this.peek()),this.logError(s,l.UNEXPECTED_EOF,"Unexpected EOF"))},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){const s=this.peek();if($t(s)||this.check(p.COLON,p.LBRACE,p.LBRACKET))break;_(s),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COLON,p.LBRACE,p.LBRACKET))break;_(s),this.advance()}},this.blockExpression=this.contextStack.withContextDo(ht.BlockExpression,()=>{const s={body:[]},r=()=>this.nodeFactory.create(Ee,s);try{this.consume("Expect an opening brace '{'",p.LBRACE),s.blockOpenBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockOpenBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(p.RBRACE);)try{if(this.match(p.TILDE)){const i=this.previous(),a=this.variable(),o=this.nodeFactory.create(Me,{op:i,partial:a});s.body.push(o)}else s.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(i){if(!(i instanceof T))throw i;if(s.body.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}try{this.consume("Expect a closing brace '}'",p.RBRACE),s.blockCloseBrace=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.blockCloseBrace=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeBlock()}return r()}),this.synchronizeBlock=()=>{if(!this.check(p.RBRACE))for(_(this.advance());!this.isAtEnd();){const s=this.peek();if(this.check(p.RBRACE)||Mn(this.previous(),s))break;_(s),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(ht.GroupExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(zt,{groupOpenParen:s.tupleOpenParen,groupCloseParen:s.tupleCloseParen,expression:s.elementList[0]}),i=()=>this.nodeFactory.create(me,s);try{this.consume("Expect an opening parenthesis '('",p.LPAREN),s.tupleOpenParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleOpenParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(p.RPAREN))try{s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,r(),a.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(p.RPAREN);)try{this.consume("Expect a comma ','",p.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof T))throw a;if(a.partialNode instanceof D&&s.elementList.push(a.partialNode),!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}try{this.consume("Expect a closing parenthesis ')'",p.RPAREN),s.tupleCloseParen=this.previous()}catch(a){if(!(a instanceof T))throw a;if(s.tupleCloseParen=a.partialNode,!this.canHandle(a))throw new T(a.token,i(),a.handlerContext);this.synchronizeTuple()}return s.elementList.length===1?r():i()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.RPAREN,p.COMMA))break;_(s),this.advance()}},this.listExpression=this.contextStack.withContextDo(ht.ListExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(R,s);try{this.consume("Expect an opening bracket '['",p.LBRACKET),s.listOpenBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listOpenBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(p.RBRACKET))try{s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(p.RBRACKET);)try{this.consume("Expect a comma ','",p.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.attribute())}catch(i){if(!(i instanceof T))throw i;if(i.partialNode instanceof D&&s.elementList.push(i.partialNode),!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}try{this.consume("Expect a closing bracket ']'",p.RBRACKET),s.listCloseBracket=this.previous()}catch(i){if(!(i instanceof T))throw i;if(s.listCloseBracket=i.partialNode,!this.canHandle(i))throw new T(i.token,r(),i.handlerContext);this.synchronizeList()}return r()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET))break;_(s),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET,p.COLON))break;_(s),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET))break;_(s),this.advance()}},this.tokens=t,this.nodeFactory=new pl(n)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===p.EOF}advance(){return this.isAtEnd()?U(this.tokens):this.tokens[this.current++]}peek(t=0){return t+this.current>=this.tokens.length?U(this.tokens):this.tokens[this.current+t]}match(...t){const n=this.check(...t);return n&&this.advance(),n}check(...t){const n=this.peek();return t.includes(n.kind)}previous(){return this.tokens[this.current-1]}canHandle(t){return t.handlerContext===void 0||t.handlerContext===this.contextStack.top()}consume(t,...n){if(!this.match(...n))throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,t),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(t,...n){if(this.isAtEnd()||!this.check(...n)){for(_(this.peek()),this.logError(this.advance(),l.UNEXPECTED_TOKEN,t);!this.isAtEnd()&&!this.check(...n);)_(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){const t=[],n=[];let s,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)n.push(this.tokens[r]);for(s=this.tokens[r],s.leadingInvalid=n,t.push(s),r+=1;r<this.tokens.length;r+=1){const i=this.tokens[r];i.isInvalid?s.trailingInvalid.push(i):(s=i,t.push(s))}this.tokens=t}parse(){const t=this.program(),n=this.advance(),s=this.nodeFactory.create(J,{body:t,eof:n});return this.gatherInvalid(),new se({ast:s,tokens:this.tokens},this.errors)}program(){const t=[];for(;!this.isAtEnd();)try{const n=this.elementDeclaration();t.push(n)}catch(n){if(!(n instanceof T))throw n;t.push(n.partialNode),this.synchronizeProgram()}return t}elementDeclaration(){const t={},n=()=>this.nodeFactory.create(P,t);try{this.consume("Expect an identifier",p.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.check(p.COLON,p.LBRACE,p.LBRACKET))try{t.name=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.name=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationName()}if($t(this.peek()))if(t.as=this.advance(),this.check(p.COLON,p.LBRACE,p.LBRACKET))this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect an alias");else try{t.alias=this.normalExpression()}catch(s){if(!(s instanceof T))throw s;if(t.alias=s.partialNode,!this.canHandle(s))throw new T(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationAlias()}try{t.attributeList=this.check(p.LBRACKET)?this.listExpression():void 0}catch(s){throw s instanceof T?(t.attributeList=s.partialNode,new T(s.token,n(),s.handlerContext)):s}if(!this.discardUntil("Expect an opening brace '{' or a colon ':'",p.LBRACE,p.COLON))return n();try{if(this.match(p.COLON)){t.bodyColon=this.previous();const s=this.expression();s instanceof P?(_(s),this.logError(s,l.UNEXPECTED_ELEMENT_DECLARATION,"An element's simple body must not be an element declaration")):t.body=s}else t.body=this.blockExpression()}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(P,t)}fieldDeclaration(){const t={},n=()=>this.nodeFactory.create(P,t);try{this.consume("Expect an identifier",p.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof T?(t.type=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{this.consume("Expect a colon ':'",p.COLON),t.bodyColon=this.previous()}catch(s){throw s instanceof T?(t.bodyColon=s.partialNode,new T(s.token,n(),s.handlerContext)):s}try{const s=this.expression();s instanceof P?this.errors.push(new c(l.INVALID_ELEMENT_IN_SIMPLE_BODY,"Simple body cannot be an element declaration",s)):t.body=s}catch(s){throw s instanceof T?(t.body=s.partialNode,new T(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(P,t)}expression(){const t={args:[]},n=()=>ol(t.callee,t.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(w,t));try{t.callee=this.normalExpression()}catch(r){throw r instanceof T?(t.callee=r.partialNode,new T(r.token,n(),r.handlerContext)):r}if(this.shouldStopExpression())return n();let s=t.callee;for(;!this.shouldStopExpression();){Vt(this.previous())||this.logError(s,l.MISSING_SPACES,"Expect a following space");try{s=this.normalExpression(),t.args.push(s)}catch(r){throw r instanceof T?(s=r.partialNode,t.args.push(s),new T(r.token,n(),r.handlerContext)):r}}return n()}shouldStopExpression(){if(this.isAtEnd()||_s(this.previous()))return!0;const t=this.peek().kind;return t===p.RBRACE||t===p.RBRACKET||t===p.RPAREN||t===p.COMMA||t===p.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(t){let n=this.leftExpression_bp();for(;!this.isAtEnd();){const s=this.peek();if(s.kind===p.LPAREN){const{left:r}=Cn(s);if(r<t||Mn(this.previous(),s)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{n=this.nodeFactory.create(ae,{callee:n,argumentList:this.tupleExpression()})}catch(i){throw i instanceof T?(n=this.nodeFactory.create(ae,{callee:n,argumentList:i.partialNode}),new T(i.token,n,i.handlerContext)):i}}else if(s.kind===p.LBRACKET){if(Vt(this.previous()))break;try{n=this.nodeFactory.create(Fe,{expression:n,indexer:this.listExpression()})}catch(r){throw r instanceof T?(n=this.nodeFactory.create(Fe,{expression:n,indexer:r.partialNode}),new T(r.token,n,r.handlerContext)):r}}else if(Un(s)){const r=s,i=Cn(r);if(i.left!==null){if(i.left<=t)break;this.advance(),n=this.nodeFactory.create(vt,{expression:n,op:r})}else{const a=Nl(r);if(a.left===null||a.left<=t)break;this.advance();try{n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:r.value==="."?this.extractOperand():this.expression_bp(a.right)})}catch(o){throw o instanceof T?(n=this.nodeFactory.create(Te,{leftExpression:n,op:r,rightExpression:o.partialNode}),new T(o.token,n,o.handlerContext)):o}}}else break}return n}leftExpression_bp(){let t;if(Un(this.peek())){const n={};n.op=this.peek();const s=ml(n.op);if(s.right===null)throw this.logError(n.op,l.UNKNOWN_PREFIX_OP,`Unexpected '${n.op.value}' in an expression`),new T(n.op,this.nodeFactory.create(ut,{pre:n.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{n.expression=this.expression_bp(s.right)}catch(r){throw r instanceof T?(n.expression=r.partialNode,new T(r.token,this.nodeFactory.create(re,n),r.handlerContext)):r}t=this.nodeFactory.create(re,n)}else if(t=this.extractOperand(),t instanceof ut)throw new T(this.peek(),this.nodeFactory.create(ut,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return t}extractOperand(){return this.check(p.NUMERIC_LITERAL,p.STRING_LITERAL,p.COLOR_LITERAL,p.QUOTED_STRING,p.IDENTIFIER)?this.primaryExpression():this.check(p.FUNCTION_EXPRESSION)?this.functionExpression():this.check(p.LBRACKET)?this.listExpression():this.check(p.LBRACE)?this.blockExpression():this.check(p.LPAREN)?this.tupleExpression():(this.peek().kind===p.EOF?this.logError(this.peek(),l.UNEXPECTED_EOF,"Unexpected EOF"):this.logError(this.peek(),l.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(ut,{pre:this.previous()}))}functionExpression(){const t={};try{this.consume("Expect a function expression",p.FUNCTION_EXPRESSION),t.value=this.previous()}catch(n){throw n instanceof T?(t.value=n.partialNode,new T(n.token,this.nodeFactory.create(ie,t),n.handlerContext)):n}return this.nodeFactory.create(ie,t)}variable(){this.consume("Expect a variable",p.IDENTIFIER);const t=this.previous();return this.nodeFactory.create(de,{variable:t})}canBeField(){return this.peek().kind===p.IDENTIFIER&&this.peek(1).kind===p.COLON}primaryExpression(){if(this.match(p.COLOR_LITERAL,p.STRING_LITERAL,p.NUMERIC_LITERAL))return this.nodeFactory.create(Y,{expression:this.nodeFactory.create(qe,{literal:this.previous()})});if(this.match(p.QUOTED_STRING,p.IDENTIFIER))return this.nodeFactory.create(Y,{expression:this.nodeFactory.create(de,{variable:this.previous()})});throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect a variable or literal"),new T(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){const t={};if(this.check(p.COLON,p.RBRACKET,p.COMMA)){const n=this.peek();this.logError(n,l.EMPTY_ATTRIBUTE_NAME,"Expect a non-empty attribute name"),t.name=this.nodeFactory.create(ce,{identifiers:[]})}else try{t.name=this.attributeName()}catch(n){if(!(n instanceof T))throw n;if(t.name=n.partialNode,!this.canHandle(n))throw new T(n.token,this.nodeFactory.create(ue,t),n.handlerContext);this.synchronizeAttributeName()}return this.match(p.COLON)&&(t.colon=this.previous(),t.value=this.attributeValue()),this.nodeFactory.create(ue,t)}attributeValue(){let t;try{t=this.peek().kind===p.IDENTIFIER&&this.peek(1).kind===p.IDENTIFIER?this.attributeName():this.normalExpression()}catch(n){if(!(n instanceof T)||!this.canHandle(n))throw n;t=n.partialNode,this.synchronizeAttributeValue()}return t}attributeName(){const t=[];if(this.peek().kind!==p.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(p.COLON,p.COMMA,p.RBRACKET);)try{this.consume("Expect an identifier",p.IDENTIFIER),t.push(this.previous())}catch(n){throw n instanceof T?new T(n.token,this.nodeFactory.create(ce,{identifiers:t}),n.handlerContext):n}return this.nodeFactory.create(ce,{identifiers:t})}logError(t,n,s){this.errors.push(new c(n,s,t))}}const El={"+":{left:9,right:10},"*":{left:11,right:12},"-":{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 Nl(e){return El[e.value]||{left:null,right:null}}const Tl={"+":{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 ml(e){return Tl[e.value]||{left:null,right:null}}const bl={"(":{left:14,right:null}};function Cn(e){return bl[e.value]||{left:null,right:null}}const Il=["-","+"],_e="public";var I=(e=>(e.Schema="Schema",e.Table="Table",e.Column="Column",e.TableGroup="TableGroup",e.TableGroupField="TableGroup field",e.Enum="Enum",e.EnumField="Enum field",e.Note="Note",e.TablePartial="TablePartial",e.TablePartialInjection="TablePartialInjection",e))(I||{});function ot(e){return`Schema:${e}`}function He(e){return`Table:${e}`}function wt(e){return`Column:${e}`}function Jt(e){return`Enum:${e}`}function Zt(e){return`Enum field:${e}`}function en(e){return`TableGroup:${e}`}function tn(e){return`TableGroup field:${e}`}function gl(e){return`Note:${e}`}function nn(e){return`TablePartial:${e}`}function Ps(e){return`TablePartialInjection:${e}`}function ft(e,t){switch(t){case"Column":return wt(e);case"Enum":return Jt(e);case"Enum field":return Zt(e);case"Schema":return ot(e);case"Table":return He(e);case"TableGroup":return en(e);case"TableGroup field":return tn(e);case"TablePartial":return nn(e);default:throw new Error("Unreachable")}}function he(e){const[t,n]=e.split(":");return Object.values(I).includes(t)?new B({name:n,kind:t}):new x}function _l(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n,name:s}=t;return n==="Schema"&&s===_e}function Al(e){const t=he(e).unwrap_or(void 0);if(!t)return!1;const{kind:n}=t;return n==="TablePartialInjection"}function Ll(e){const t=he(e).unwrap_or(void 0);if(!t)return null;const{kind:n,name:s}=t;return n==="TablePartialInjection"?ft(s,"TablePartial"):null}var g=(e=>(e.Table="table",e.Enum="enum",e.Ref="ref",e.Note="note",e.Project="project",e.Indexes="indexes",e.TableGroup="tablegroup",e.TablePartial="tablepartial",e.Check="checks",e))(g||{}),E=(e=>(e.Color="color",e.HeaderColor="headercolor",e.Note="note",e.PK="pk",e.PrimaryKey="primary key",e.Unique="unique",e.Ref="ref",e.NotNull="not null",e.Null="null",e.Increment="increment",e.Default="default",e.Name="name",e.Type="type",e.Check="check",e.Update="update",e.Delete="delete",e))(E||{});function ke(e){var n;const t=(n=e==null?void 0:e.type)==null?void 0:n.value.toLowerCase();switch(t){case g.Enum:case g.Table:case g.Indexes:case g.Note:case g.Project:case g.Ref:case g.TableGroup:case g.TablePartial:case g.Check:return new B(t);default:return new x}}function ye(e){if(!e)return new x;if(!yt(e))return new B([e]);const t=ye(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new B(t)):new x}function Z(e){if(e===void 0)return new x;const t=ye(e).unwrap_or(void 0);if(!t)return new x;const n=[];for(const s of t){const r=z(s).unwrap_or(void 0);if(!r)return new x;n.push(r)}return new B(n)}function rt(e){if(e===void 0)return new x;const t=ye(e).unwrap_or(void 0);if(!t||t.length===0)return new x;const n=[];let s;if(!V(U(t))){const r=t.pop();if(Rs(r))s=r.elementList.map(i=>H(i).unwrap());else return new x}for(const r of t){const i=z(r).unwrap_or(void 0);if(!i)return new x;n.push(i)}return new B({variables:n,tupleElements:s})}function z(e){return V(e)?new B(e.expression.variable.value):new x}function Et(e){if(Vn(e))return e instanceof ie?new B({functional:[e],nonFunctional:[]}):new B({functional:[],nonFunctional:[e]});if(e instanceof me&&e.elementList.every(Vn)){const t=e.elementList.filter(s=>s instanceof ie),n=e.elementList.filter(V);return new B({functional:t,nonFunctional:n})}return new x}function H(e){var n;const t=(n=e==null?void 0:e.expression.variable)==null?void 0:n.value;return t===void 0?new x:new B(t)}function vl(e){var n,s;const t=(s=(n=e==null?void 0:e.partial)==null?void 0:n.variable)==null?void 0:s.value;return t===void 0?new x:new B(t)}function C(e){return K(e)?e.expression instanceof de?new B(e.expression.variable.value):new B(e.expression.literal.value):new x}function yl(e){var t;return!(e instanceof Te)||!xs((t=e.op)==null?void 0:t.value)?!1:rt(e.leftExpression).and_then(()=>rt(e.rightExpression)).unwrap_or(void 0)!==void 0}function wl(e){const t=rt(e.leftExpression),n=rt(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;const{tupleElements:s}=t.unwrap(),{tupleElements:r}=n.unwrap();return(s==null?void 0:s.length)===(r==null?void 0:r.length)}function Vn(e){return e instanceof Y&&e.expression instanceof de||e instanceof ie}function Gn(e,t){var r,i,a,o;let n=t;const s=_l(e);for(;n;){if((i=(r=n.symbol)==null?void 0:r.symbolTable)!=null&&i.has(e))return(a=n.symbol.symbolTable)==null?void 0:a.get(e);if(((o=n.symbol)==null?void 0:o.declaration)instanceof J&&s)return n.symbol;if(n instanceof J)return;n=n.parent}}class Sl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof J||ke(this.declarationNode.parent).unwrap_or(void 0)!==g.Project?[new c(l.INVALID_CUSTOM_CONTEXT,"A Custom element can only appear in a Project",this.declarationNode)]:[]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Custom element shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof Ee)return[new c(l.UNEXPECTED_COMPLEX_BODY,"A Custom element can only have an inline field",t)];const n=[];return K(t.callee)||n.push(new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",t)),t.args.length>0&&n.push(...t.args.map(s=>new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",s))),n}}class ze{constructor(){this.table=new Map}has(t){return this.table.has(t)}set(t,n){this.table.set(t,n)}get(t,n){return this.table.get(t)||n!==void 0&&this.set(t,n)||n}entries(){return this.table.entries()}forEach(t){return this.table.forEach(t)}}class Pl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new c(l.INVALID_PROJECT_CONTEXT,"An Enum can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?Os(t)?[]:[new c(l.INVALID_NAME,"An Enum name must be of the form <enum> or <schema>.<enum>",t)]:[new c(l.NAME_NOT_FOUND,"An Enum must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Enum shouldn't have an alias",t)]:[]}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(Jo,{declaration:this.declarationNode,symbolTable:new ze});const{name:n}=this.declarationNode,s=Z(n);if(s.isOk()){const r=s.unwrap(),i=r.pop(),a=St(r,this.publicSymbolTable,this.symbolFactory),o=Jt(i);a.has(o)&&t.push(new c(l.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(".")||_e}'`,n)),a.set(o,this.declarationNode.symbol)}return t}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Enum shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.length===0?[new c(l.EMPTY_ENUM,"An Enum must have at least one element",this.declarationNode)]:t.flatMap(n=>{const s=[];n.callee&&!V(n.callee)&&s.push(new c(l.INVALID_ENUM_ELEMENT_NAME,"An enum field must be an identifier or a quoted identifier",n.callee));const r=[...n.args];return U(r)instanceof R?(s.push(...this.validateFieldSettings(U(r))),r.pop()):r[0]instanceof R&&(s.push(...this.validateFieldSettings(r[0])),r.shift()),r.length>0&&s.push(...r.map(i=>new c(l.INVALID_ENUM_ELEMENT,"An Enum must have only a field and optionally a setting list",i))),s.push(...this.registerField(n)),s})}validateFieldSettings(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_ENUM_ELEMENT_SETTING,"'note' can only appear once",o))),a.forEach(o=>{K(o.value)||s.push(new c(l.INVALID_ENUM_ELEMENT_SETTING,"'note' must be a string",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}registerField(t){if(t.callee&&V(t.callee)){const n=H(t.callee).unwrap(),s=Zt(n),r=this.symbolFactory.create(Zo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,a.declaration)]}i.set(s,r)}return[]}}class Ol{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){const t=new c(l.INVALID_INDEXES_CONTEXT,"An Indexes can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=ke(this.declarationNode.parent).unwrap_or(void 0);return n&&[g.Table,g.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"An Indexes shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Indexes shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Indexes shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"An Indexes must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return U(r)instanceof R&&s.push(...this.validateFieldSetting(r.pop())),r.forEach(i=>{for(;i instanceof ae;)i.argumentList&&!Et(i.argumentList).isOk()&&s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i.argumentList)),i=i.callee;Et(i).isOk()||s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i))}),s})}validateFieldSetting(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{K(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must be a string`,o))});break;case"unique":case"pk":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{ne(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must not have a value`,o))});break;case"type":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,"'type' can only appear once",o))),a.forEach(o=>{V(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_INDEX_SETTING,`Unknown index setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class xl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return!(this.declarationNode.parent instanceof J)&&![g.Table,g.TableGroup,g.TablePartial,g.Project].includes(ke(this.declarationNode.parent).unwrap_or(void 0))?[new c(l.INVALID_NOTE_CONTEXT,"A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.",this.declarationNode)]:[]}validateName(t){if(!(this.declarationNode.parent instanceof J))return t?[new c(l.UNEXPECTED_NAME,"A Note shouldn't have a name",t)]:[];if(!t)return[new c(l.INVALID_NAME,"Sticky note must have a name",this.declarationNode)];const n=Z(t);if(!n.isOk())return[new c(l.INVALID_NAME,"Invalid name for sticky note ",this.declarationNode)];const r=n.unwrap().join("."),i=gl(r);return this.publicSymbolTable.has(i)?[new c(l.DUPLICATE_NAME,`Sticky note "${r}" has already been defined`,t)]:(this.publicSymbolTable.set(i,this.declarationNode.symbol),[])}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Note shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){const n=[];return t.length===0?[new c(l.EMPTY_NOTE,"A Note must have a content",this.declarationNode)]:(t.length>1&&t.slice(1).forEach(s=>n.push(new c(l.NOTE_CONTENT_REDEFINED,"A Note can only contain one string",s))),K(t[0].callee)||n.push(new c(l.INVALID_NOTE,"A Note content must be a quoted string",t[0])),t[0].args.length>0&&n.push(...t[0].args.map(s=>new c(l.INVALID_NOTE,"A Note can only contain one quoted string",s))),n)}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class kl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new c(l.INVALID_PROJECT_CONTEXT,"A Project can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?Ye(t)?[]:[new c(l.INVALID_NAME,"A Project's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Project shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Project shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Project's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof w);return[...n.map(r=>new c(l.INVALID_PROJECT_FIELD,"A Project can not have inline fields",r)),...this.validateSubElements(s)]}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class Dl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof J?[]:[new c(l.INVALID_REF_CONTEXT,"A Ref must appear top-level",this.declarationNode)]}validateName(t){return t?Ye(t)?[]:[new c(l.INVALID_NAME,"A Ref's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Ref shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return this.validateFields([t]);const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){if(t.length===0)return[new c(l.EMPTY_REF,"A Ref must have at least one field",this.declarationNode)];const n=[];return t.length>1&&n.push(...t.slice(1).map(s=>new c(l.REF_REDEFINED,"A Ref can only contain one binary relationship",s))),t.forEach(s=>{s.callee&&!yl(s.callee)&&n.push(new c(l.INVALID_REF_FIELD,"A Ref field must be a binary relationship",s.callee)),s.callee&&!wl(s.callee)&&n.push(new c(l.UNEQUAL_FIELDS_BINARY_REF,"Unequal fields in ref endpoints",s.callee));const r=[...s.args];if(U(r)instanceof R){const i=this.validateFieldSettings(U(r));n.push(...i),r.pop()}else r[0]instanceof R&&(n.push(...this.validateFieldSettings(r[0])),r.shift());r.length>0&&n.push(...r.map(i=>new c(l.INVALID_REF_FIELD,"A Ref field should only have a single binary relationship",i)))}),n}validateFieldSettings(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"delete":case"update":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_REF_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Rl(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,`'${i}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,o))});break;case"color":a.length>1&&s.push(...a.map(o=>new c(l.DUPLICATE_REF_SETTING,"'color' can only appear once",o))),a.forEach(o=>{Pt(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,"'color' must be a color literal",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_REF_SETTING,`Unknown ref setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function Rl(e){if(!(V(e)&&e.expression.variable.kind!==p.QUOTED_STRING)&&!(e instanceof ce))return!1;let t;if(e instanceof ce?t=We(e).unwrap_or(""):t=e.expression.variable.value,t)switch(t.toLowerCase()){case"cascade":case"no action":case"set null":case"set default":case"restrict":return!0;default:return!1}return!1}class Ul{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new c(l.INVALID_TABLE_CONTEXT,"Table must appear top-level",this.declarationNode)]:[]}validateName(t){return t?t instanceof Fe?[new c(l.INVALID_NAME,"Invalid array as Table name, maybe you forget to add a space between the name and the setting list?",t)]:Os(t)?[]:[new c(l.INVALID_NAME,"A Table name must be of the form <table> or <schema>.<table>",t)]:[new c(l.NAME_NOT_FOUND,"A Table must have a name",this.declarationNode)]}validateAlias(t){return t?Vl(t)?[]:[new c(l.INVALID_ALIAS,"Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes",t)]:[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return st(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'headercolor' can only appear once",o))),i.forEach(o=>{Pt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'headercolor' must be a color literal",o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.forEach(o=>{K(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(dt,{declaration:this.declarationNode,symbolTable:new ze});const{name:n,alias:s}=this.declarationNode,r=Z(n);if(r.isOk()){const i=[...r.unwrap()],a=i.pop(),o=St(i,this.publicSymbolTable,this.symbolFactory),u=He(a);o.has(u)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${a}' already exists in schema '${i.join(".")||_e}'`,n)),o.set(u,this.declarationNode.symbol)}if(s&&Ye(s)&&!Ml(s.expression.variable.value,r.unwrap_or([]))){const i=H(s).unwrap(),a=He(i);this.publicSymbolTable.has(a)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${i}' already exists`,n)),this.publicSymbolTable.set(a,this.declarationNode.symbol)}return t}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Table's body must be a block",t)];const[n,s,r]=t.body.reduce((i,a)=>(a instanceof w?i[0].push(a):a instanceof Me?i[1].push(a):a instanceof P&&i[2].push(a),i),[[],[],[]]);return[...this.validateFields(n),...this.validateInjections(s),...this.validateSubElements(r)]}validateInjections(t){return t.flatMap(n=>this.registerInjection(n))}registerInjection(t){var o,u,h;if(!((u=(o=t.partial)==null?void 0:o.variable)!=null&&u.value))return[];const n=(h=t.partial.variable)==null?void 0:h.value,s=Ps(n),r=this.symbolFactory.create(sl,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable,a=i.get(s);return a?[new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,t),new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,a.declaration)]:(i.set(s,r),[])}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),V(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Us(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r)),s.push(...this.registerField(n)),s})}registerField(t){if(t.callee&&V(t.callee)){const n=H(t.callee).unwrap(),s=wt(n),r=this.symbolFactory.create(Yt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}i.set(s,r)}return[]}validateFieldSetting(t){if(!t.slice(0,-1).every(xe)||!t.slice(-1).every(u=>xe(u)||u instanceof R))return[...t.map(u=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",u))];if(t.length===0)return[];let n;U(t)instanceof R&&(n=t.pop());const s=F(n),r=s.getErrors(),i=s.getValue();t.forEach(u=>{const h=H(u).unwrap_or("").toLowerCase();if(h!=="pk"&&h!=="unique"){r.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",u));return}i[h]===void 0?i[h]=[u]:i[h].push(u)});const a=i[E.PK]||[],o=i[E.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",u))),st(i,(u,h)=>{switch(h){case E.Note:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"note can only appear once",f))),u.forEach(f=>{K(f.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'note' must be a quoted string",f.value||f.name))});break;case E.Ref:u.forEach(f=>{Ds(f.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'ref' must be a valid unary relationship",f.value||f.name))});break;case E.PrimaryKey:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"primary key can only appear once",f))),u.forEach(f=>{ne(f.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'primary key' must not have a value",f.value||f.name))});break;case E.PK:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"'pk' can only appear once",f))),u.forEach(f=>{f instanceof ue&&!ne(f.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'pk' must not have a value",f.value||f.name))});break;case E.NotNull:{u.length>1&&r.push(...u.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,"'not null' can only appear once",d)));const f=i[E.Null]||[];u.length>=1&&f.length>=1&&r.push(...[...u,...f].map(d=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",d))),u.forEach(d=>{ne(d.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'not null' must not have a value",d.value||d.name))});break}case E.Null:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"'null' can only appear once",f))),u.forEach(f=>{ne(f.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'null' must not have a value",f.value||f.name))});break;case E.Unique:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"'unique' can only appear once",f))),u.forEach(f=>{f instanceof ue&&!ne(f.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'unique' must not have a value",f.value||f.name))});break;case E.Increment:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"'increment' can only appear once",f))),u.forEach(f=>{f instanceof ue&&!ne(f.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'increment' must not have a value",f.value||f.name))});break;case E.Default:u.length>1&&r.push(...u.map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"'default' can only appear once",f))),u.forEach(f=>{ks(f.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'default' must be an enum value, a string literal, number literal, function expression, true, false or null",f.value||f.name))});break;case E.Check:u.forEach(f=>{f.value instanceof ie||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",f.value||f.name))});break;default:u.forEach(f=>r.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${h}'`,f)))}}),r}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=be(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}function Ml(e,t){return t.length===1&&e===t[0]}class Fl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new c(l.INVALID_TABLEGROUP_CONTEXT,"TableGroup must appear top-level",this.declarationNode)]:[]}validateName(t){return t?Ye(t)?[]:[new c(l.INVALID_NAME,"A TableGroup name must be a single identifier",t)]:[new c(l.NAME_NOT_FOUND,"A TableGroup must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TableGroup shouldn't have an alias",t)]:[]}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(el,{declaration:this.declarationNode,symbolTable:new ze});const n=Z(t);if(n.isOk()){const s=n.unwrap(),r=s.pop(),i=St(s,this.publicSymbolTable,this.symbolFactory),a=en(r);if(i.has(a))return[new c(l.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,t)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return st(r,(i,a)=>{switch(a){case"color":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'color' can only appear once",o))),i.forEach(o=>{Pt(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'color' must be a color literal",o.value||o.name))});break;case"note":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.filter(o=>!K(o.value)).forEach(o=>{s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)));break}}),s}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TableGroup's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{const s=[];return n.callee&&!Z(n.callee).isOk()&&s.push(new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field must be of the form <table> or <schema>.<table>",n.callee)),this.registerField(n),n.args.length>0&&s.push(...n.args.map(r=>new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field should only have a single Table name",r))),s})}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=be(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())==="note"});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}registerField(t){if(t.callee&&V(t.callee)){const n=H(t.callee).unwrap(),s=tn(n),r=this.symbolFactory.create(tl,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,t),new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,a.declaration)]}i.set(s,r)}return[]}}class Bl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof P?[new c(l.INVALID_TABLE_PARTIAL_CONTEXT,"TablePartial must appear top-level",this.declarationNode)]:[]}validateName(t){return t?Ye(t)?[]:[new c(l.INVALID_NAME,"A TablePartial name must be an identifier or a quoted identifer",t)]:[new c(l.NAME_NOT_FOUND,"A TablePartial must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TablePartial shouldn't have an alias",t)]:[]}validateSettingList(t){const n=F(t),s=n.getErrors(),r=n.getValue();return st(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{Pt(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a color literal`,o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{K(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a string literal`,o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(nl,{declaration:this.declarationNode,symbolTable:new ze});const n=Z(t);if(!n.isOk())return[];const s=n.unwrap(),r=s.pop(),i=St(s,this.publicSymbolTable,this.symbolFactory),a=nn(r);return i.has(a)?[new c(l.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,t)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TablePartial's body must be a block",t)];const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),V(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Us(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r),...this.registerField(n)),s})}registerField(t){if(!t.callee||!V(t.callee))return[];const n=H(t.callee).unwrap(),s=wt(n),r=this.symbolFactory.create(Yt,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}return i.set(s,r),[]}validateFieldSetting(t){const n=U(t);if(!t.slice(0,-1).every(xe)||!(xe(n)||n instanceof R))return[...t.map(h=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",h))];if(t.length===0)return[];let s;U(t)instanceof R&&(s=t.pop());const r=F(s),i=r.getErrors(),a=r.getValue();t.forEach(h=>{const f=H(h).unwrap_or("").toLowerCase();if(f!==E.PK&&f!==E.Unique){i.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",h));return}a[f]===void 0?a[f]=[h]:a[f].push(h)});const o=a[E.PK]||[],u=a[E.PrimaryKey]||[];return o.length>=1&&u.length>=1&&i.push(...[...o,...u].map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",h))),st(a,(h,f)=>{switch(f){case E.Note:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{K(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must be a quoted string`,d.value||d.name))});break;case E.Ref:h.forEach(d=>{Ds(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must be a valid unary relationship`,d.value||d.name))});break;case E.PrimaryKey:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,d.value||d.name))});break;case E.PK:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,d.value||d.name))});break;case E.NotNull:{h.length>1&&i.push(...h.map(N=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,N)));const d=a[E.Null]||[];h.length>=1&&d.length>=1&&i.push(...[...h,...d].map(N=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",N))),h.forEach(N=>{ne(N.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,N.value||N.name))});break}case E.Null:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{ne(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,d.value||d.name))});break;case E.Unique:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,d.value||d.name))});break;case E.Increment:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{d instanceof ue&&!ne(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must not have a value`,d.value||d.name))});break;case E.Default:h.length>1&&i.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${f}' can only appear once`,d))),h.forEach(d=>{ks(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${f}' must be a string literal, number literal, function expression, true, false or null`,d.value||d.name))});break;case E.Check:h.forEach(d=>{d.value instanceof ie||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",d.value||d.name))});break;default:h.forEach(d=>i.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${f}'`,d)))}}),i}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=be(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>{var i;return((i=r.type)==null?void 0:i.value.toLowerCase())===g.Note});return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}class Cl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){const t=new c(l.INVALID_CHECKS_CONTEXT,"A Checks can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof J)return[t];const n=ke(this.declarationNode.parent).unwrap_or(void 0);return n&&[g.Table,g.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Checks shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Checks shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Checks shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof w)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Checks must have a complex body",t)];const[n,s]=oe(t.body,r=>r instanceof w);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return U(r)instanceof R&&s.push(...this.validateFieldSetting(r.pop())),(r.length>1||!(r[0]instanceof ie))&&s.push(new c(l.INVALID_CHECKS_FIELD,"A check field must be a function expression",n)),s})}validateFieldSetting(t){const n=F(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_CHECK_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{K(o.value)||s.push(new c(l.INVALID_CHECK_SETTING_VALUE,`'${i}' must be a string`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_CHECK_SETTING,`Unknown check setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=be(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function be(e){switch(e.type.value.toLowerCase()){case g.Enum:return Pl;case g.Table:return Ul;case g.TableGroup:return Fl;case g.Project:return kl;case g.Ref:return Dl;case g.Note:return xl;case g.Indexes:return Ol;case g.TablePartial:return Bl;case g.Check:return Cl;default:return Sl}}function Os(e){return!!Z(e).unwrap_or(!1)}function Vl(e){return Ye(e)}function Ye(e){return e instanceof Y&&e.expression instanceof de}function St(e,t,n){var r;e[0]===_e&&(e=e.slice(1));let s=t;for(const i of e){let a;const o=ot(i);if(s.has(o)){if(a=(r=s.get(o))==null?void 0:r.symbolTable,!a)throw new Error("Expect a symbol table in a schema symbol")}else{a=new ze;const u=n.create(ys,{symbolTable:a});s.set(o,u)}s=a}return s}function xs(e){return e==="-"||e==="<>"||e===">"||e==="<"}function Pt(e){var n;if(!(e instanceof Y)||!(e.expression instanceof qe)||((n=e.expression.literal)==null?void 0:n.kind)!==p.COLOR_LITERAL)return!1;const t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!=="#")return!1;for(let s=1;s<t.length;s+=1)if(!il(t[s]))return!1;return!0}function ne(e){return e===void 0}function ks(e){var n;if(K(e)||Be(e)||xe(e)&&["true","false","null"].includes(e.expression.variable.value.toLowerCase())||e instanceof re&&Il.includes((n=e.op)==null?void 0:n.value)&&Be(e.expression)||e instanceof ie)return!0;if(!e||!Qt(e))return!1;const t=ye(e).unwrap();return t.length===2||t.length===3}function Be(e){var t,n,s;return e instanceof re?((t=e.op)==null?void 0:t.value)!=="-"&&((n=e.op)==null?void 0:n.value)!=="+"?!1:Be(e.expression):e instanceof Y&&e.expression instanceof qe&&((s=e.expression.literal)==null?void 0:s.kind)===p.NUMERIC_LITERAL}function Ds(e){var n;if(!(e instanceof re)||!xs((n=e.op)==null?void 0:n.value))return!1;const t=Z(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Rs(e){return e instanceof me&&e.elementList.every(V)}function Us(e){if(!(e instanceof ae||yt(e)||e instanceof Y||e instanceof Fe))return!1;if(e instanceof ae){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(n=>Be(n)||K(n)||xe(n)))return!1;e=e.callee}for(;e instanceof Fe;){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(n=>!n.colon&&!n.value&&Be(n.name)))return!1;e=e.array}const t=Z(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function F(e){const t={},n=[];return e?(e.elementList.forEach(s=>{var i;if(!s.name)return;if(s.name instanceof Y){n.push(new c(l.INVALID_SETTINGS,"A setting name must be a stream of identifiers",s.name));return}const r=(i=We(s.name).unwrap_or(void 0))==null?void 0:i.toLowerCase();r&&(t[r]===void 0?t[r]=[s]:t[r].push(s))}),new se(t,n)):new se({})}class $n{constructor(t,n){this.ast=t,this.symbolFactory=n,this.publicSchemaSymbol=this.symbolFactory.create(ys,{symbolTable:new ze}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){const t=[];this.ast.body.forEach(s=>{if(s.parent=this.ast,s.type===void 0)return;const r=be(s),i=new r(s,this.publicSchemaSymbol.symbolTable,this.symbolFactory);t.push(...i.validate())});const n=this.ast.body.filter(s=>ke(s).unwrap_or(void 0)===g.Project);return n.length>1&&n.forEach(s=>t.push(new c(l.PROJECT_REDEFINED,"Only one project can exist",s))),new se(this.ast,t)}}function Gl(e){return[ot,He,Jt,en,wt,Zt,tn,nn,Ps].map(t=>t(e))}function $l(e){return e instanceof Yt?rl:null}class Ie{constructor(t,n){this.declarationNode=t,this.errors=n}bind(){this.bindSettingList(this.declarationNode.attributeList,this.settingList),this.bindBody()}bindSettingList(t,n){t&&t.elementList.forEach(s=>{if(s.name instanceof Y)return;const r=We(s.name).unwrap_or(void 0);if(!r)return;const i=n[r.toLowerCase()];i!=null&&i.shouldBind&&this.scanAndBind(s.value,i)})}bindBody(){const t=this.declarationNode;if(!t.body)return;const{body:n}=t;n instanceof Ee?n.body.forEach(s=>{if(s instanceof P){if(!s.type||ke(this.declarationNode).unwrap_or(null)===g.TablePartial&&ke(s).unwrap_or(null)===g.Indexes)return;const r=Ms(s);new r(s,this.errors).bind()}else s instanceof w?this.bindSubfield(s):this.bindPartialInjection(s)}):this.bindSubfield(n)}bindSubfield(t){const n=[t.callee,...t.args],s=U(n);s instanceof R&&(n.pop(),this.bindSettingList(s,this.subfield.settingList));const{argBinderRules:r}=this.subfield.arg;for(let i=0;i<Math.min(n.length,r.length);i+=1)r[i].shouldBind&&this.scanAndBind(n[i],r[i])}bindPartialInjection(t){var n;(n=this.injectionBinderRule)!=null&&n.shouldBind&&this.scanAndBind(t,this.injectionBinderRule)}scanAndBind(t,n){var s,r;if(t)if(t instanceof Y){if(t.expression instanceof de&&((r=n.keywords)!=null&&r.includes((s=t.expression.variable)==null?void 0:s.value.toLowerCase())))return;this.bindFragments([t],n)}else t instanceof Te?yt(t)?this.bindFragments(ye(t).unwrap_or([]),n):(this.scanAndBind(t.leftExpression,n),this.scanAndBind(t.rightExpression,n)):t instanceof re?this.scanAndBind(t.expression,n):t instanceof vt?this.scanAndBind(t.expression,n):t instanceof me?t.elementList.forEach(i=>this.scanAndBind(i,n)):t instanceof Me&&this.bindFragments([t],n)}bindFragments(t,n){if(t.length===0)return;const s=t.length===1&&t[0]instanceof Me,r=[...n.topSubnamesSymbolKind],i=s?-1:t.findIndex(N=>!V(N)),o=i!==-1&&Rs(t[i])?t[i]:void 0,u=i>=0?r.pop():void 0,h=t.slice(0,i===-1?void 0:i);if(h.length===0)return;const f=[];for(;r.length&&h.length;){const N=r.pop(),m=h.pop(),A=H(m).unwrap();f.unshift({index:ft(A,N),referrer:m})}for(;h.length;){const N=h.pop(),m=s?vl(N).unwrap():H(N).unwrap();f.unshift({index:ft(m,n.remainingSubnamesSymbolKind),referrer:N})}const d=K(t[0]);return o?o.elementList.forEach(N=>this.resolveIndexStack([...f,{index:ft(H(N).unwrap(),u),referrer:N}],n,d)):this.resolveIndexStack(f,n,d)}resolveIndexStack(t,n,s){if(t.length===0)throw new Error("Unreachable - An unresolved name must have at least one name component");const[r,...i]=t,a=Gn(r.index,this.declarationNode);if(a===void 0){const{kind:f,name:d}=he(r.index).unwrap();this.logError(r.referrer,`Can not find ${f} '${d}'`,n.ignoreNameNotFound||!!n.ignoreNameNotFoundForQuotedVariable&&s);return}a.references.push(r.referrer),r.referrer.referee=a;let o=a.symbolTable,{kind:u,name:h}=he(r.index).unwrap();for(const f of i){const{kind:d,name:N}=he(f.index).unwrap(),m=o.get(f.index);if(!m){this.logError(f.referrer,`${u} '${h}' does not have ${d} '${N}'`,n.ignoreNameNotFound);return}if(u=d,h=N,f.referrer.referee=m,m.references.push(f.referrer),!m.symbolTable)break;o=m.symbolTable}}logError(t,n,s){s||this.errors.push(new c(l.BINDING_ERROR,n,t))}resolveInjections(t){var r;const n=(r=this.declarationNode.symbol)==null?void 0:r.symbolTable;if(!n)return;const s=new Map;n.forEach((i,a)=>{var h,f;if(!Al(a))return;const o=Gn(Ll(a),this.declarationNode),u=(f=(h=o==null?void 0:o.declaration)==null?void 0:h.symbol)==null?void 0:f.symbolTable;u&&u.forEach((d,N)=>{n.has(N)||s.set(N,{injectorFieldSymbol:d,injectorDeclaration:i.declaration})})}),s.forEach((i,a)=>{const o=$l(i.injectorFieldSymbol);if(!o)return;const u=t.create(o,i);n.set(a,u)})}}class Xl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class jl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Wl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Hl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class Kl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class ql extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class zl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class Yl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Enum],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!0,ignoreNameNotFoundForQuotedVariable:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},default:{shouldBind:!0,topSubnamesSymbolKind:[I.Enum,I.EnumField],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,keywords:["false","true","null"],ignoreNameNotFoundForQuotedVariable:!0},check:{shouldBind:!1}}},this.settingList={},this.injectionBinderRule={shouldBind:!0,topSubnamesSymbolKind:[],remainingSubnamesSymbolKind:I.TablePartial,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}}}class Ql extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[I.Table],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class Jl extends Ie{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[I.Enum],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!0,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[I.Table,I.Column],remainingSubnamesSymbolKind:I.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},default:{shouldBind:!1},check:{shouldBind:!1}}},this.settingList={}}}function Ms(e){switch(e.type.value.toLowerCase()){case g.Enum:return Wl;case g.Table:return Yl;case g.TableGroup:return Ql;case g.Project:return ql;case g.Ref:return zl;case g.Note:return Kl;case g.Indexes:return Hl;case g.TablePartial:return Jl;case g.Check:return Xl;default:return jl}}class Zl{constructor(t){this.ast=t,this.errors=[]}resolve(t){return this.ast.body.map(n=>{if(!n.type)return null;const s=Ms(n),r=new s(n,this.errors);return r.resolveInjections(t),r}).forEach(n=>n==null?void 0:n.bind()),new se(this.ast,this.errors)}}class ec{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class tc{constructor(t,n){this.ast=t,this.symbolFactory=new ec(n)}analyze(){return new $n(this.ast,this.symbolFactory).validate().chain(n=>new Zl(n).resolve(this.symbolFactory))}validate(){return new $n(this.ast,this.symbolFactory).validate().chain(n=>new se(n,[]))}}function Xn(e,t){const{variables:n,tupleElements:s}=rt(e).unwrap();return s?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:s}:{tableName:n.pop(),schemaName:n.pop()||null,fieldNames:s}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[n[0]]}:{fieldNames:[n.pop()],tableName:n.pop(),schemaName:n.pop()||null}}function Fs(e){switch(e){case"<":return["1","*"];case"<>":return["*","*"];case">":return["*","1"];case"-":return["1","1"];default:throw new Error("Invalid relation op")}}function L(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1}}}function Nt(e){var n;const t=(n=ye(e).unwrap_or(void 0))==null?void 0:n.pop();return t instanceof me?t.elementList.map(s=>s.referee):[t.referee]}function Ge(e){const t=Z(e).unwrap();return{name:t.pop(),schemaName:t}}function lt(e){return e.expression.literal.value}function Bs(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort().join(","),i=t.map(({id:a})=>a).sort().join(",");return r<i?`${r}-${i}`:`${i}-${r}`}const n=e.id.toString(),s=t.id.toString();return n<s?`${n}-${s}`:`${s}-${n}`}function sn(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort(),i=t.map(({id:a})=>a).sort();return Ct(r,i).every(([a,o])=>a===o)}const n=e.id,s=t.id;return n===s}function fe(e){const t=e.split(`
|
|
9
|
+
`;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 n="";for(let s=0;s<=3;s+=1){if(this.isAtEnd()||!Se(this.peek()))return this.errors.push(new c(l.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${n}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,z.create(p.STRING_LITERAL,t,this.current,`\\u${n}`,!0))),`\\u${n}`;n+=this.advance()}return String.fromCharCode(parseInt(n,16))}default:return this.text[this.current.offset-1]}}}var it=(e=>(e[e.ListExpression=0]="ListExpression",e[e.GroupExpression=1]="GroupExpression",e[e.BlockExpression=2]="BlockExpression",e))(it||{});class al{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(t){this.stack.push(t),t===0&&(this.numberOfNestedLBrackets+=1),t===1&&(this.numberOfNestedLParens+=1),t===2&&(this.numberOfNestedLBraces+=1)}pop(){const t=this.stack.pop();return t===0&&(this.numberOfNestedLBrackets-=1),t===1&&(this.numberOfNestedLParens-=1),t===2&&(this.numberOfNestedLBraces-=1),t}top(){return R(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(t,n){return()=>{this.push(t);try{return n()}finally{this.pop()}}}findHandlerContext(t,n){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let s=n;s<t.length-1;s+=1)switch(t[s].kind){case p.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(i=>[1,0].includes(i));break;case p.RPAREN:if(this.isWithinGroupExpressionContext())return 1;break;case p.RBRACE:if(this.isWithinBlockExpressionContext())return 2;break;case p.RBRACKET:if(this.isWithinListExpressionContext())return 0;break}}}class ol{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class N{constructor(t,n,s){this.token=t,this.partialNode=n,this.handlerContext=s}}class ll{constructor(t,n){this.current=0,this.errors=[],this.contextStack=new al,this.synchronizeProgram=()=>{const s=this.peek();s.kind!==p.EOF?m(this.advance()):this.logError(s,l.UNEXPECTED_EOF,"Unexpected EOF")},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(Ft(s)||this.check(p.COLON,p.LBRACE,p.LBRACKET))break;m(s),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COLON,p.LBRACE,p.LBRACKET))break;m(s),this.advance()}},this.blockExpression=this.contextStack.withContextDo(it.BlockExpression,()=>{const s={body:[]},r=()=>this.nodeFactory.create(le,s);try{this.consume("Expect an opening brace '{'",p.LBRACE),s.blockOpenBrace=this.previous()}catch(i){if(!(i instanceof N))throw i;if(!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(p.RBRACE);)try{if(this.match(p.TILDE)){const i=this.previous(),a=this.variable(),o=this.nodeFactory.create(Le,{op:i,partial:a});s.body.push(o)}else s.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(i){if(!(i instanceof N))throw i;if(s.body.push(i.partialNode),!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeBlock()}try{this.consume("Expect a closing brace '}'",p.RBRACE),s.blockCloseBrace=this.previous()}catch(i){if(!(i instanceof N))throw i;if(!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeBlock()}return r()}),this.synchronizeBlock=()=>{if(!this.check(p.RBRACE))for(m(this.advance());!this.isAtEnd();){const s=this.peek();if(this.check(p.RBRACE)||kn(this.previous(),s))break;m(s),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(it.GroupExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(Wt,{groupOpenParen:s.tupleOpenParen,groupCloseParen:s.tupleCloseParen,expression:s.elementList[0]}),i=()=>this.nodeFactory.create(pe,s);try{this.consume("Expect an opening parenthesis '('",p.LPAREN),s.tupleOpenParen=this.previous()}catch(a){if(!(a instanceof N))throw a;if(!this.canHandle(a))throw new N(a.token,i(),a.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(p.RPAREN))try{s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof N))throw a;if(s.elementList.push(a.partialNode),!this.canHandle(a))throw new N(a.token,r(),a.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(p.RPAREN);)try{this.consume("Expect a comma ','",p.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.normalExpression())}catch(a){if(!(a instanceof N))throw a;if(a.partialNode instanceof x&&s.elementList.push(a.partialNode),!this.canHandle(a))throw new N(a.token,i(),a.handlerContext);this.synchronizeTuple()}try{this.consume("Expect a closing parenthesis ')'",p.RPAREN),s.tupleCloseParen=this.previous()}catch(a){if(!(a instanceof N))throw a;if(!this.canHandle(a))throw new N(a.token,i(),a.handlerContext);this.synchronizeTuple()}return s.elementList.length===1?r():i()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.RPAREN,p.COMMA))break;m(s),this.advance()}},this.listExpression=this.contextStack.withContextDo(it.ListExpression,()=>{const s={elementList:[],commaList:[]},r=()=>this.nodeFactory.create(D,s);try{this.consume("Expect an opening bracket '['",p.LBRACKET),s.listOpenBracket=this.previous()}catch(i){if(!(i instanceof N))throw i;if(!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(p.RBRACKET))try{s.elementList.push(this.attribute())}catch(i){if(!(i instanceof N))throw i;if(s.elementList.push(i.partialNode),!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(p.RBRACKET);)try{this.consume("Expect a comma ','",p.COMMA),s.commaList.push(this.previous()),s.elementList.push(this.attribute())}catch(i){if(!(i instanceof N))throw i;if(i.partialNode instanceof x&&s.elementList.push(i.partialNode),!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeList()}try{this.consume("Expect a closing bracket ']'",p.RBRACKET),s.listCloseBracket=this.previous()}catch(i){if(!(i instanceof N))throw i;if(!this.canHandle(i))throw new N(i.token,r(),i.handlerContext);this.synchronizeList()}return r()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET))break;m(s),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET,p.COLON))break;m(s),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){const s=this.peek();if(this.check(p.COMMA,p.RBRACKET))break;m(s),this.advance()}},this.tokens=t,this.nodeFactory=new ol(n)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===p.EOF}advance(){return this.isAtEnd()?R(this.tokens):this.tokens[this.current++]}peek(t=0){return t+this.current>=this.tokens.length?R(this.tokens):this.tokens[this.current+t]}match(...t){const n=this.check(...t);return n&&this.advance(),n}check(...t){const n=this.peek();return t.includes(n.kind)}previous(){return this.tokens[this.current-1]}canHandle(t){return t.handlerContext===void 0||t.handlerContext===this.contextStack.top()}consume(t,...n){if(!this.match(...n))throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,t),new N(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(t,...n){if(this.isAtEnd()||!this.check(...n)){for(m(this.peek()),this.logError(this.advance(),l.UNEXPECTED_TOKEN,t);!this.isAtEnd()&&!this.check(...n);)m(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){const t=[],n=[];let s,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)n.push(this.tokens[r]);for(s=this.tokens[r],s.leadingInvalid=[...n,...s.leadingInvalid],t.push(s),r+=1;r<this.tokens.length;r+=1){const i=this.tokens[r];i.isInvalid?s.trailingInvalid.push(i):(s=i,t.push(s))}this.tokens=t}parse(){const t=this.program(),n=this.advance(),s=this.nodeFactory.create(K,{body:t,eof:n});return this.gatherInvalid(),new J({ast:s,tokens:this.tokens},this.errors)}program(){const t=[];for(;!this.isAtEnd();)try{const n=this.elementDeclaration();t.push(n)}catch(n){if(!(n instanceof N))throw n;t.push(n.partialNode),this.synchronizeProgram()}return t}elementDeclaration(){const t={},n=()=>this.nodeFactory.create(y,t);try{this.consume("Expect an identifier",p.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof N?new N(s.token,n(),s.handlerContext):s}if(!this.check(p.COLON,p.LBRACE,p.LBRACKET))try{t.name=this.normalExpression()}catch(s){if(!(s instanceof N))throw s;if(t.name=s.partialNode,!this.canHandle(s))throw new N(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationName()}if(Ft(this.peek()))if(t.as=this.advance(),this.check(p.COLON,p.LBRACE,p.LBRACKET))this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect an alias");else try{t.alias=this.normalExpression()}catch(s){if(!(s instanceof N))throw s;if(t.alias=s.partialNode,!this.canHandle(s))throw new N(s.token,n(),s.handlerContext);this.synchronizeElementDeclarationAlias()}try{t.attributeList=this.check(p.LBRACKET)?this.listExpression():void 0}catch(s){throw s instanceof N?(t.attributeList=s.partialNode,new N(s.token,n(),s.handlerContext)):s}if(!this.discardUntil("Expect an opening brace '{' or a colon ':'",p.LBRACE,p.COLON))return n();try{if(this.match(p.COLON)){t.bodyColon=this.previous();const s=this.expression();s instanceof y?(m(s),this.logError(s,l.UNEXPECTED_ELEMENT_DECLARATION,"An element's simple body must not be an element declaration")):t.body=s}else t.body=this.blockExpression()}catch(s){throw s instanceof N?(t.body=s.partialNode,new N(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(y,t)}fieldDeclaration(){const t={},n=()=>this.nodeFactory.create(y,t);try{this.consume("Expect an identifier",p.IDENTIFIER),t.type=this.previous()}catch(s){throw s instanceof N?(t.type=s.partialNode,new N(s.token,n(),s.handlerContext)):s}try{this.consume("Expect a colon ':'",p.COLON),t.bodyColon=this.previous()}catch(s){throw s instanceof N?(t.bodyColon=s.partialNode,new N(s.token,n(),s.handlerContext)):s}try{const s=this.expression();s instanceof y?this.errors.push(new c(l.INVALID_ELEMENT_IN_SIMPLE_BODY,"Simple body cannot be an element declaration",s)):t.body=s}catch(s){throw s instanceof N?(t.body=s.partialNode,new N(s.token,n(),s.handlerContext)):s}return this.nodeFactory.create(y,t)}expression(){const t={args:[]},n=()=>tl(t.callee,t.args,this.nodeFactory).unwrap_or(this.nodeFactory.create(L,t));try{t.callee=this.normalExpression()}catch(r){throw r instanceof N?(t.callee=r.partialNode,new N(r.token,n(),r.handlerContext)):r}if(this.shouldStopExpression())return n();let s=t.callee;for(;!this.shouldStopExpression();){Rt(this.previous())||this.logError(s,l.MISSING_SPACES,"Expect a following space");try{s=this.normalExpression(),t.args.push(s)}catch(r){throw r instanceof N?(s=r.partialNode,t.args.push(s),new N(r.token,n(),r.handlerContext)):r}}return n()}shouldStopExpression(){if(this.isAtEnd()||ms(this.previous()))return!0;const t=this.peek().kind;return t===p.RBRACE||t===p.RBRACKET||t===p.RPAREN||t===p.COMMA||t===p.COLON}normalExpression(){return this.expression_bp(0)}expression_bp(t){let n=this.leftExpression_bp();for(;!this.isAtEnd();){const s=this.peek();if(s.kind===p.LPAREN){const{left:r}=Un(s);if(r<t||kn(this.previous(),s)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{n=this.nodeFactory.create(H,{callee:n,argumentList:this.tupleExpression()})}catch(i){throw i instanceof N?(n=this.nodeFactory.create(H,{callee:n,argumentList:i.partialNode}),new N(i.token,n,i.handlerContext)):i}}else if(s.kind===p.LBRACKET){if(Rt(this.previous()))break;try{n=this.nodeFactory.create(ue,{expression:n,indexer:this.listExpression()})}catch(r){throw r instanceof N?(n=this.nodeFactory.create(ue,{expression:n,indexer:r.partialNode}),new N(r.token,n,r.handlerContext)):r}}else if(xn(s)){const r=s,i=Un(r);if(i.left!==null){if(i.left<=t)break;this.advance(),n=this.nodeFactory.create(bt,{expression:n,op:r})}else{const a=ul(r);if(a.left===null||a.left<=t)break;this.advance();try{n=this.nodeFactory.create(fe,{leftExpression:n,op:r,rightExpression:r.value==="."?this.extractOperand():this.expression_bp(a.right)})}catch(o){throw o instanceof N?(n=this.nodeFactory.create(fe,{leftExpression:n,op:r,rightExpression:o.partialNode}),new N(o.token,n,o.handlerContext)):o}}}else break}return n}leftExpression_bp(){let t;if(xn(this.peek())){const n={};n.op=this.peek();const s=fl(n.op);if(s.right===null)throw this.logError(n.op,l.UNKNOWN_PREFIX_OP,`Unexpected '${n.op.value}' in an expression`),new N(n.op,this.nodeFactory.create(We,{pre:n.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{n.expression=this.expression_bp(s.right)}catch(r){throw r instanceof N?(n.expression=r.partialNode,new N(r.token,this.nodeFactory.create(Z,n),r.handlerContext)):r}t=this.nodeFactory.create(Z,n)}else if(t=this.extractOperand(),t instanceof We)throw new N(this.peek(),this.nodeFactory.create(We,{pre:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return t}extractOperand(){return this.check(p.NUMERIC_LITERAL,p.STRING_LITERAL,p.COLOR_LITERAL,p.QUOTED_STRING,p.IDENTIFIER)?this.primaryExpression():this.check(p.FUNCTION_EXPRESSION)?this.functionExpression():this.check(p.LBRACKET)?this.listExpression():this.check(p.LBRACE)?this.blockExpression():this.check(p.LPAREN)?this.tupleExpression():(this.peek().kind===p.EOF?this.logError(this.peek(),l.UNEXPECTED_EOF,"Unexpected EOF"):this.logError(this.peek(),l.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(We,{pre:this.previous()}))}functionExpression(){const t={};try{this.consume("Expect a function expression",p.FUNCTION_EXPRESSION),t.value=this.previous()}catch(n){throw n instanceof N?new N(n.token,this.nodeFactory.create(ee,t),n.handlerContext):n}return this.nodeFactory.create(ee,t)}variable(){this.consume("Expect a variable",p.IDENTIFIER);const t=this.previous();return this.nodeFactory.create(oe,{variable:t})}canBeField(){return this.peek().kind===p.IDENTIFIER&&this.peek(1).kind===p.COLON}primaryExpression(){if(this.match(p.COLOR_LITERAL,p.STRING_LITERAL,p.NUMERIC_LITERAL))return this.nodeFactory.create(q,{expression:this.nodeFactory.create(Ve,{literal:this.previous()})});if(this.match(p.QUOTED_STRING,p.IDENTIFIER))return this.nodeFactory.create(q,{expression:this.nodeFactory.create(oe,{variable:this.previous()})});throw this.logError(this.peek(),l.UNEXPECTED_TOKEN,"Expect a variable or literal"),new N(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){const t={};if(this.check(p.COLON,p.RBRACKET,p.COMMA)){const n=this.peek();this.logError(n,l.EMPTY_ATTRIBUTE_NAME,"Expect a non-empty attribute name"),t.name=this.nodeFactory.create(ne,{identifiers:[]})}else try{t.name=this.attributeName()}catch(n){if(!(n instanceof N))throw n;if(t.name=n.partialNode,!this.canHandle(n))throw new N(n.token,this.nodeFactory.create(se,t),n.handlerContext);this.synchronizeAttributeName()}return this.match(p.COLON)&&(t.colon=this.previous(),t.value=this.attributeValue()),this.nodeFactory.create(se,t)}attributeValue(){let t;try{t=this.peek().kind===p.IDENTIFIER&&this.peek(1).kind===p.IDENTIFIER?this.attributeName():this.normalExpression()}catch(n){if(!(n instanceof N)||!this.canHandle(n))throw n;t=n.partialNode,this.synchronizeAttributeValue()}return t}attributeName(){const t=[];if(this.peek().kind!==p.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(p.COLON,p.COMMA,p.RBRACKET);)try{this.consume("Expect an identifier",p.IDENTIFIER),t.push(this.previous())}catch(n){throw n instanceof N?new N(n.token,this.nodeFactory.create(ne,{identifiers:t}),n.handlerContext):n}return this.nodeFactory.create(ne,{identifiers:t})}logError(t,n,s){this.errors.push(new c(n,s,t))}}const cl={"+":{left:9,right:10},"*":{left:11,right:12},"-":{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 ul(e){return cl[e.value]||{left:null,right:null}}const hl={"+":{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 fl(e){return hl[e.value]||{left:null,right:null}}const pl={"(":{left:14,right:null}};function Un(e){return pl[e.value]||{left:null,right:null}}const dl=["-","+"],Te="public";var T=(e=>(e.Schema="Schema",e.Table="Table",e.Column="Column",e.TableGroup="TableGroup",e.TableGroupField="TableGroup field",e.Enum="Enum",e.EnumField="Enum field",e.Note="Note",e.TablePartial="TablePartial",e.TablePartialInjection="TablePartialInjection",e))(T||{});function et(e){return`Schema:${e}`}function Be(e){return`Table:${e}`}function gt(e){return`Column:${e}`}function qt(e){return`Enum:${e}`}function zt(e){return`Enum field:${e}`}function Yt(e){return`TableGroup:${e}`}function Qt(e){return`TableGroup field:${e}`}function El(e){return`Note:${e}`}function Jt(e){return`TablePartial:${e}`}function As(e){return`TablePartialInjection:${e}`}function at(e,t){switch(t){case"Column":return gt(e);case"Enum":return qt(e);case"Enum field":return zt(e);case"Schema":return et(e);case"Table":return Be(e);case"TableGroup":return Yt(e);case"TableGroup field":return Qt(e);case"TablePartial":return Jt(e);default:throw new Error("Unreachable")}}function re(e){const[t,n]=e.split(":");return Object.values(T).includes(t)?new F({name:n,kind:t}):new P}function Nl(e){const t=re(e).unwrap_or(void 0);if(!t)return!1;const{kind:n,name:s}=t;return n==="Schema"&&s===Te}function Tl(e){const t=re(e).unwrap_or(void 0);if(!t)return!1;const{kind:n}=t;return n==="TablePartialInjection"}function ml(e){const t=re(e).unwrap_or(void 0);if(!t)return null;const{kind:n,name:s}=t;return n==="TablePartialInjection"?at(s,"TablePartial"):null}var b=(e=>(e.Table="table",e.Enum="enum",e.Ref="ref",e.Note="note",e.Project="project",e.Indexes="indexes",e.TableGroup="tablegroup",e.TablePartial="tablepartial",e.Check="checks",e))(b||{}),E=(e=>(e.Color="color",e.HeaderColor="headercolor",e.Note="note",e.PK="pk",e.PrimaryKey="primary key",e.Unique="unique",e.Ref="ref",e.NotNull="not null",e.Null="null",e.Increment="increment",e.Default="default",e.Name="name",e.Type="type",e.Check="check",e.Update="update",e.Delete="delete",e))(E||{});function ye(e){const t=e?.type?.value.toLowerCase();switch(t){case b.Enum:case b.Table:case b.Indexes:case b.Note:case b.Project:case b.Ref:case b.TableGroup:case b.TablePartial:case b.Check:return new F(t);default:return new P}}function ge(e){if(!e)return new P;if(!It(e))return new F([e]);const t=ge(e.leftExpression).unwrap_or(void 0);return t?(t.push(e.rightExpression),new F(t)):new P}function Y(e){if(e===void 0)return new P;const t=ge(e).unwrap_or(void 0);if(!t)return new P;const n=[];for(const s of t){const r=j(s).unwrap_or(void 0);if(typeof r!="string")return new P;n.push(r)}return new F(n)}function Qe(e){if(e===void 0)return new P;const t=ge(e).unwrap_or(void 0);if(!t||t.length===0)return new P;const n=[];let s;if(!C(R(t))){const r=t.pop();if(Ss(r))s=r.elementList.map(i=>W(i).unwrap());else return new P}for(const r of t){const i=j(r).unwrap_or(void 0);if(typeof i!="string")return new P;n.push(i)}return new F({variables:n,tupleElements:s})}function j(e){return C(e)?new F(e.expression.variable.value):new P}function ct(e){if(Mn(e))return e instanceof ee?new F({functional:[e],nonFunctional:[]}):new F({functional:[],nonFunctional:[e]});if(e instanceof pe&&e.elementList.every(Mn)){const t=e.elementList.filter(s=>s instanceof ee),n=e.elementList.filter(C);return new F({functional:t,nonFunctional:n})}return new P}function W(e){const t=e?.expression.variable?.value;return t===void 0?new P:new F(t)}function bl(e){const t=e?.partial?.variable?.value;return t===void 0?new P:new F(t)}function B(e){return $(e)?e.expression instanceof oe?new F(e.expression.variable.value):new F(e.expression.literal.value):new P}function Il(e){return!(e instanceof fe)||!vs(e.op?.value)?!1:Qe(e.leftExpression).and_then(()=>Qe(e.rightExpression)).unwrap_or(void 0)!==void 0}function gl(e){const t=Qe(e.leftExpression),n=Qe(e.rightExpression);if(!t.isOk()||!n.isOk())return!1;const{tupleElements:s}=t.unwrap(),{tupleElements:r}=n.unwrap();return s?.length===r?.length}function Mn(e){return e instanceof q&&e.expression instanceof oe||e instanceof ee}function Fn(e,t){let n=t;const s=Nl(e);for(;n;){if(n.symbol?.symbolTable?.has(e))return n.symbol.symbolTable?.get(e);if(n.symbol?.declaration instanceof K&&s)return n.symbol;if(n instanceof K)return;n=n.parent}}class _l{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof K||ye(this.declarationNode.parent).unwrap_or(void 0)!==b.Project?[new c(l.INVALID_CUSTOM_CONTEXT,"A Custom element can only appear in a Project",this.declarationNode)]:[]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_NAME,"A Custom element shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Custom element shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof le)return[new c(l.UNEXPECTED_COMPLEX_BODY,"A Custom element can only have an inline field",t)];const n=[];return $(t.callee)||n.push(new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",t)),t.args.length>0&&n.push(...t.args.map(s=>new c(l.INVALID_CUSTOM_ELEMENT_VALUE,"A Custom element value can only be a string",s))),n}}class Ge{constructor(){this.table=new Map}has(t){return this.table.has(t)}set(t,n){this.table.set(t,n)}get(t,n){return this.table.get(t)||n!==void 0&&this.set(t,n)||n}entries(){return this.table.entries()}forEach(t){return this.table.forEach(t)}}class Al{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof y?[new c(l.INVALID_PROJECT_CONTEXT,"An Enum can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?Ls(t)?[]:[new c(l.INVALID_NAME,"An Enum name must be of the form <enum> or <schema>.<enum>",t)]:[new c(l.NAME_NOT_FOUND,"An Enum must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Enum shouldn't have an alias",t)]:[]}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(Ho,{declaration:this.declarationNode,symbolTable:new Ge});const{name:n}=this.declarationNode,s=Y(n);if(s.isOk()){const r=s.unwrap(),i=r.pop(),a=_t(r,this.publicSymbolTable,this.symbolFactory),o=qt(i);a.has(o)&&t.push(new c(l.DUPLICATE_NAME,`Enum name ${i} already exists in schema '${r.join(".")||Te}'`,n)),a.set(o,this.declarationNode.symbol)}return t}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Enum shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return this.validateFields([t]);const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.length===0?[new c(l.EMPTY_ENUM,"An Enum must have at least one element",this.declarationNode)]:t.flatMap(n=>{const s=[];n.callee&&!C(n.callee)&&s.push(new c(l.INVALID_ENUM_ELEMENT_NAME,"An enum field must be an identifier or a quoted identifier",n.callee));const r=[...n.args];return R(r)instanceof D?(s.push(...this.validateFieldSettings(R(r))),r.pop()):r[0]instanceof D&&(s.push(...this.validateFieldSettings(r[0])),r.shift()),r.length>0&&s.push(...r.map(i=>new c(l.INVALID_ENUM_ELEMENT,"An Enum must have only a field and optionally a setting list",i))),s.push(...this.registerField(n)),s})}validateFieldSettings(t){const n=M(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_ENUM_ELEMENT_SETTING,"'note' can only appear once",o))),a.forEach(o=>{$(o.value)||s.push(new c(l.INVALID_ENUM_ELEMENT_SETTING,"'note' must be a string",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}registerField(t){if(t.callee&&C(t.callee)){const n=W(t.callee).unwrap(),s=zt(n),r=this.symbolFactory.create(Ko,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${n}`,a.declaration)]}i.set(s,r)}return[]}}class Ll{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){const t=new c(l.INVALID_INDEXES_CONTEXT,"An Indexes can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof K)return[t];const n=ye(this.declarationNode.parent).unwrap_or(void 0);return n&&[b.Table,b.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"An Indexes shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"An Indexes shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"An Indexes shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"An Indexes must have a complex body",t)];const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return R(r)instanceof D&&s.push(...this.validateFieldSetting(r.pop())),r.forEach(i=>{for(;i instanceof H;)i.argumentList&&!ct(i.argumentList).isOk()&&s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i.argumentList)),i=i.callee;ct(i).isOk()||s.push(new c(l.INVALID_INDEXES_FIELD,"An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such",i))}),s})}validateFieldSetting(t){const n=M(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"note":case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{$(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must be a string`,o))});break;case"unique":case"pk":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Q(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'${i}' must not have a value`,o))});break;case"type":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_INDEX_SETTING,"'type' can only appear once",o))),a.forEach(o=>{C(o.value)||s.push(new c(l.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_INDEX_SETTING,`Unknown index setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class vl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return!(this.declarationNode.parent instanceof K)&&![b.Table,b.TableGroup,b.TablePartial,b.Project].includes(ye(this.declarationNode.parent).unwrap_or(void 0))?[new c(l.INVALID_NOTE_CONTEXT,"A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.",this.declarationNode)]:[]}validateName(t){if(!(this.declarationNode.parent instanceof K))return t?[new c(l.UNEXPECTED_NAME,"A Note shouldn't have a name",t)]:[];if(!t)return[new c(l.INVALID_NAME,"Sticky note must have a name",this.declarationNode)];const n=Y(t);if(!n.isOk())return[new c(l.INVALID_NAME,"Invalid name for sticky note ",this.declarationNode)];const r=n.unwrap().join("."),i=El(r);return this.publicSymbolTable.has(i)?[new c(l.DUPLICATE_NAME,`Sticky note "${r}" has already been defined`,t)]:(this.publicSymbolTable.set(i,this.declarationNode.symbol),[])}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Note shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return this.validateFields([t]);const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){const n=[];return t.length===0?[new c(l.EMPTY_NOTE,"A Note must have a content",this.declarationNode)]:(t.length>1&&t.slice(1).forEach(s=>n.push(new c(l.NOTE_CONTENT_REDEFINED,"A Note can only contain one string",s))),$(t[0].callee)||n.push(new c(l.INVALID_NOTE,"A Note content must be a quoted string",t[0])),t[0].args.length>0&&n.push(...t[0].args.map(s=>new c(l.INVALID_NOTE,"A Note can only contain one quoted string",s))),n)}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class yl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof y?[new c(l.INVALID_PROJECT_CONTEXT,"A Project can only appear top-level",this.declarationNode)]:[]}validateName(t){return t?$e(t)?[]:[new c(l.INVALID_NAME,"A Project's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Project shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Project shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Project's body must be a block",t)];const[n,s]=te(t.body,r=>r instanceof L);return[...n.map(r=>new c(l.INVALID_PROJECT_FIELD,"A Project can not have inline fields",r)),...this.validateSubElements(s)]}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}class wl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof K?[]:[new c(l.INVALID_REF_CONTEXT,"A Ref must appear top-level",this.declarationNode)]}validateName(t){return t?$e(t)?[]:[new c(l.INVALID_NAME,"A Ref's name is optional or must be an identifier or a quoted identifer",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Ref shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Ref shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return this.validateFields([t]);const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){if(t.length===0)return[new c(l.EMPTY_REF,"A Ref must have at least one field",this.declarationNode)];const n=[];return t.length>1&&n.push(...t.slice(1).map(s=>new c(l.REF_REDEFINED,"A Ref can only contain one binary relationship",s))),t.forEach(s=>{s.callee&&!Il(s.callee)&&n.push(new c(l.INVALID_REF_FIELD,"A Ref field must be a binary relationship",s.callee)),s.callee&&!gl(s.callee)&&n.push(new c(l.UNEQUAL_FIELDS_BINARY_REF,"Unequal fields in ref endpoints",s.callee));const r=[...s.args];if(R(r)instanceof D){const i=this.validateFieldSettings(R(r));n.push(...i),r.pop()}else r[0]instanceof D&&(n.push(...this.validateFieldSettings(r[0])),r.shift());r.length>0&&n.push(...r.map(i=>new c(l.INVALID_REF_FIELD,"A Ref field should only have a single binary relationship",i)))}),n}validateFieldSettings(t){const n=M(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"delete":case"update":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_REF_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{Sl(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,`'${i}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,o))});break;case"color":a.length>1&&s.push(...a.map(o=>new c(l.DUPLICATE_REF_SETTING,"'color' can only appear once",o))),a.forEach(o=>{At(o.value)||s.push(new c(l.INVALID_REF_SETTING_VALUE,"'color' must be a color literal",o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_REF_SETTING,`Unknown ref setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function Sl(e){if(!(C(e)&&e.expression.variable.kind!==p.QUOTED_STRING)&&!(e instanceof ne))return!1;let t;if(e instanceof ne?t=Fe(e).unwrap_or(""):t=e.expression.variable.value,t)switch(t.toLowerCase()){case"cascade":case"no action":case"set null":case"set default":case"restrict":return!0;default:return!1}return!1}class Pl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof y?[new c(l.INVALID_TABLE_CONTEXT,"Table must appear top-level",this.declarationNode)]:[]}validateName(t){return t?t instanceof ue?[new c(l.INVALID_NAME,"Invalid array as Table name, maybe you forget to add a space between the name and the setting list?",t)]:Ls(t)?[]:[new c(l.INVALID_NAME,"A Table name must be of the form <table> or <schema>.<table>",t)]:[new c(l.NAME_NOT_FOUND,"A Table must have a name",this.declarationNode)]}validateAlias(t){return t?Rl(t)?[]:[new c(l.INVALID_ALIAS,"Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes",t)]:[]}validateSettingList(t){const n=M(t),s=n.getErrors(),r=n.getValue();return Ye(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'headercolor' can only appear once",o))),i.forEach(o=>{At(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'headercolor' must be a color literal",o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.forEach(o=>{$(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const t=[];this.declarationNode.symbol=this.symbolFactory.create(lt,{declaration:this.declarationNode,symbolTable:new Ge});const{name:n,alias:s}=this.declarationNode,r=Y(n);if(r.isOk()){const i=[...r.unwrap()],a=i.pop(),o=_t(i,this.publicSymbolTable,this.symbolFactory),h=Be(a);o.has(h)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${a}' already exists in schema '${i.join(".")||Te}'`,n)),o.set(h,this.declarationNode.symbol)}if(s&&$e(s)&&!Ol(s.expression.variable.value,r.unwrap_or([]))){const i=W(s).unwrap(),a=Be(i);this.publicSymbolTable.has(a)&&t.push(new c(l.DUPLICATE_NAME,`Table name '${i}' already exists`,n)),this.publicSymbolTable.set(a,this.declarationNode.symbol)}return t}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Table's body must be a block",t)];const[n,s,r]=t.body.reduce((i,a)=>(a instanceof L?i[0].push(a):a instanceof Le?i[1].push(a):a instanceof y&&i[2].push(a),i),[[],[],[]]);return[...this.validateFields(n),...this.validateInjections(s),...this.validateSubElements(r)]}validateInjections(t){return t.flatMap(n=>this.registerInjection(n))}registerInjection(t){if(!t.partial?.variable?.value)return[];const n=t.partial.variable?.value,s=As(n),r=this.symbolFactory.create(Qo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable,a=i.get(s);return a?[new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,t),new c(l.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate injection ${n}`,a.declaration)]:(i.set(s,r),[])}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),C(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Ps(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r)),s.push(...this.registerField(n)),s})}registerField(t){if(t.callee&&C(t.callee)){const n=W(t.callee).unwrap(),s=gt(n),r=this.symbolFactory.create(Ht,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}i.set(s,r)}return[]}validateFieldSetting(t){if(!t.slice(0,-1).every(ve)||!t.slice(-1).every(h=>ve(h)||h instanceof D))return[...t.map(h=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",h))];if(t.length===0)return[];let n;R(t)instanceof D&&(n=t.pop());const s=M(n),r=s.getErrors(),i=s.getValue();t.forEach(h=>{const f=W(h).unwrap_or("").toLowerCase();if(f!=="pk"&&f!=="unique"){r.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",h));return}i[f]===void 0?i[f]=[h]:i[f].push(h)});const a=i[E.PK]||[],o=i[E.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(h=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",h))),Ye(i,(h,f)=>{switch(f){case E.Note:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"note can only appear once",u))),h.forEach(u=>{$(u.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'note' must be a quoted string",u.value||u.name))});break;case E.Ref:h.forEach(u=>{ws(u.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'ref' must be a valid unary relationship",u.value||u.name))});break;case E.PrimaryKey:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"primary key can only appear once",u))),h.forEach(u=>{Q(u.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'primary key' must not have a value",u.value||u.name))});break;case E.PK:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"'pk' can only appear once",u))),h.forEach(u=>{u instanceof se&&!Q(u.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'pk' must not have a value",u.value||u.name))});break;case E.NotNull:{h.length>1&&r.push(...h.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,"'not null' can only appear once",d)));const u=i[E.Null]||[];h.length>=1&&u.length>=1&&r.push(...[...h,...u].map(d=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",d))),h.forEach(d=>{Q(d.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'not null' must not have a value",d.value||d.name))});break}case E.Null:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"'null' can only appear once",u))),h.forEach(u=>{Q(u.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'null' must not have a value",u.value||u.name))});break;case E.Unique:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"'unique' can only appear once",u))),h.forEach(u=>{u instanceof se&&!Q(u.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'unique' must not have a value",u.value||u.name))});break;case E.Increment:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"'increment' can only appear once",u))),h.forEach(u=>{u instanceof se&&!Q(u.value)&&r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'increment' must not have a value",u.value||u.name))});break;case E.Default:h.length>1&&r.push(...h.map(u=>new c(l.DUPLICATE_COLUMN_SETTING,"'default' can only appear once",u))),h.forEach(u=>{ys(u.value)||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'default' must be an enum value, a string literal, number literal, function expression, true, false or null",u.value||u.name))});break;case E.Check:h.forEach(u=>{u.value instanceof ee||r.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",u.value||u.name))});break;default:h.forEach(u=>r.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${f}'`,u)))}}),r}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=de(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>r.type?.value.toLowerCase()==="note");return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}function Ol(e,t){return t.length===1&&e===t[0]}class xl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof y?[new c(l.INVALID_TABLEGROUP_CONTEXT,"TableGroup must appear top-level",this.declarationNode)]:[]}validateName(t){return t?$e(t)?[]:[new c(l.INVALID_NAME,"A TableGroup name must be a single identifier",t)]:[new c(l.NAME_NOT_FOUND,"A TableGroup must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TableGroup shouldn't have an alias",t)]:[]}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(qo,{declaration:this.declarationNode,symbolTable:new Ge});const n=Y(t);if(n.isOk()){const s=n.unwrap(),r=s.pop(),i=_t(s,this.publicSymbolTable,this.symbolFactory),a=Yt(r);if(i.has(a))return[new c(l.DUPLICATE_NAME,`TableGroup name '${r}' already exists`,t)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(t){const n=M(t),s=n.getErrors(),r=n.getValue();return Ye(r,(i,a)=>{switch(a){case"color":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'color' can only appear once",o))),i.forEach(o=>{At(o.value)||s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'color' must be a color literal",o.value||o.name))});break;case"note":i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_SETTING,"'note' can only appear once",o))),i.filter(o=>!$(o.value)).forEach(o=>{s.push(new c(l.INVALID_TABLE_SETTING_VALUE,"'note' must be a string literal",o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_SETTING,`Unknown '${a}' setting`,o)));break}}),s}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TableGroup's body must be a block",t)];const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{const s=[];return n.callee&&!Y(n.callee).isOk()&&s.push(new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field must be of the form <table> or <schema>.<table>",n.callee)),this.registerField(n),n.args.length>0&&s.push(...n.args.map(r=>new c(l.INVALID_TABLEGROUP_FIELD,"A TableGroup field should only have a single Table name",r))),s})}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=de(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>r.type?.value.toLowerCase()==="note");return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}registerField(t){if(t.callee&&C(t.callee)){const n=W(t.callee).unwrap(),s=Qt(n),r=this.symbolFactory.create(zo,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,t),new c(l.DUPLICATE_TABLEGROUP_FIELD_NAME,`${n} already exists in the group`,a.declaration)]}i.set(s,r)}return[]}}class kl{constructor(t,n,s){this.declarationNode=t,this.symbolFactory=s,this.publicSymbolTable=n}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof y?[new c(l.INVALID_TABLE_PARTIAL_CONTEXT,"TablePartial must appear top-level",this.declarationNode)]:[]}validateName(t){return t?$e(t)?[]:[new c(l.INVALID_NAME,"A TablePartial name must be an identifier or a quoted identifer",t)]:[new c(l.NAME_NOT_FOUND,"A TablePartial must have a name",this.declarationNode)]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A TablePartial shouldn't have an alias",t)]:[]}validateSettingList(t){const n=M(t),s=n.getErrors(),r=n.getValue();return Ye(r,(i,a)=>{switch(a){case E.HeaderColor:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{At(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a color literal`,o.value||o.name))});break;case E.Note:i.length>1&&s.push(...i.map(o=>new c(l.DUPLICATE_TABLE_PARTIAL_SETTING,`'${a}' can only appear once`,o))),i.forEach(o=>{$(o.value)||s.push(new c(l.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${a}' must be a string literal`,o.value||o.name))});break;default:s.push(...i.map(o=>new c(l.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${a}' setting`,o)))}}),s}registerElement(){const{name:t}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Yo,{declaration:this.declarationNode,symbolTable:new Ge});const n=Y(t);if(!n.isOk())return[];const s=n.unwrap(),r=s.pop(),i=_t(s,this.publicSymbolTable,this.symbolFactory),a=Jt(r);return i.has(a)?[new c(l.DUPLICATE_NAME,`TablePartial name '${r}' already exists`,t)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A TablePartial's body must be a block",t)];const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[];n.args.length===0&&s.push(new c(l.INVALID_COLUMN,"A column must have a type",n.callee)),C(n.callee)||s.push(new c(l.INVALID_COLUMN_NAME,"A column name must be an identifier or a quoted identifier",n.callee)),n.args[0]&&!Ps(n.args[0])&&s.push(new c(l.INVALID_COLUMN_TYPE,"Invalid column type",n.args[0]));const r=n.args.slice(1);return s.push(...this.validateFieldSetting(r),...this.registerField(n)),s})}registerField(t){if(!t.callee||!C(t.callee))return[];const n=W(t.callee).unwrap(),s=gt(n),r=this.symbolFactory.create(Ht,{declaration:t});t.symbol=r;const i=this.declarationNode.symbol.symbolTable;if(i.has(s)){const a=i.get(s);return[new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,t),new c(l.DUPLICATE_COLUMN_NAME,`Duplicate column ${n}`,a.declaration)]}return i.set(s,r),[]}validateFieldSetting(t){const n=R(t);if(!t.slice(0,-1).every(ve)||!(ve(n)||n instanceof D))return[...t.map(f=>new c(l.INVALID_COLUMN,"These fields must be some inline settings optionally ended with a setting list",f))];if(t.length===0)return[];let s;R(t)instanceof D&&(s=t.pop());const r=M(s),i=r.getErrors(),a=r.getValue();t.forEach(f=>{const u=W(f).unwrap_or("").toLowerCase();if(u!==E.PK&&u!==E.Unique){i.push(new c(l.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",f));return}a[u]===void 0?a[u]=[f]:a[u].push(f)});const o=a[E.PK]||[],h=a[E.PrimaryKey]||[];return o.length>=1&&h.length>=1&&i.push(...[...o,...h].map(f=>new c(l.DUPLICATE_COLUMN_SETTING,"Either one of 'primary key' and 'pk' can appear",f))),Ye(a,(f,u)=>{switch(u){case E.Note:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{$(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must be a quoted string`,d.value||d.name))});break;case E.Ref:f.forEach(d=>{ws(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must be a valid unary relationship`,d.value||d.name))});break;case E.PrimaryKey:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{Q(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,d.value||d.name))});break;case E.PK:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{d instanceof se&&!Q(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,d.value||d.name))});break;case E.NotNull:{f.length>1&&i.push(...f.map(I=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,I)));const d=a[E.Null]||[];f.length>=1&&d.length>=1&&i.push(...[...f,...d].map(I=>new c(l.CONFLICTING_SETTING,"'not null' and 'null' can not be set at the same time",I))),f.forEach(I=>{Q(I.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,I.value||I.name))});break}case E.Null:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{Q(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,d.value||d.name))});break;case E.Unique:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{d instanceof se&&!Q(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,d.value||d.name))});break;case E.Increment:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{d instanceof se&&!Q(d.value)&&i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must not have a value`,d.value||d.name))});break;case E.Default:f.length>1&&i.push(...f.map(d=>new c(l.DUPLICATE_COLUMN_SETTING,`'${u}' can only appear once`,d))),f.forEach(d=>{ys(d.value)||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,`'${u}' must be a string literal, number literal, function expression, true, false or null`,d.value||d.name))});break;case E.Check:f.forEach(d=>{d.value instanceof ee||i.push(new c(l.INVALID_COLUMN_SETTING_VALUE,"'check' must be a function expression",d.value||d.name))});break;default:f.forEach(d=>i.push(new c(l.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${u}'`,d)))}}),i}validateSubElements(t){const n=t.flatMap(r=>{if(r.parent=this.declarationNode,!r.type)return[];const i=de(r);return new i(r,this.publicSymbolTable,this.symbolFactory).validate()}),s=t.filter(r=>r.type?.value.toLowerCase()===b.Note);return s.length>1&&n.push(...s.map(r=>new c(l.NOTE_REDEFINED,"Duplicate notes are defined",r))),n}}class Dl{constructor(t,n,s){this.declarationNode=t,this.publicSymbolTable=n,this.symbolFactory=s}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){const t=new c(l.INVALID_CHECKS_CONTEXT,"A Checks can only appear inside a Table or a TablePartial",this.declarationNode);if(this.declarationNode.parent instanceof K)return[t];const n=ye(this.declarationNode.parent).unwrap_or(void 0);return n&&[b.Table,b.TablePartial].includes(n)?[]:[t]}validateName(t){return t?[new c(l.UNEXPECTED_NAME,"A Checks shouldn't have a name",t)]:[]}validateAlias(t){return t?[new c(l.UNEXPECTED_ALIAS,"A Checks shouldn't have an alias",t)]:[]}validateSettingList(t){return t?[new c(l.UNEXPECTED_SETTINGS,"A Checks shouldn't have a setting list",t)]:[]}validateBody(t){if(!t)return[];if(t instanceof L)return[new c(l.UNEXPECTED_SIMPLE_BODY,"A Checks must have a complex body",t)];const[n,s]=te(t.body,r=>r instanceof L);return[...this.validateFields(n),...this.validateSubElements(s)]}validateFields(t){return t.flatMap(n=>{if(!n.callee)return[];const s=[],r=[n.callee,...n.args];return R(r)instanceof D&&s.push(...this.validateFieldSetting(r.pop())),(r.length>1||!(r[0]instanceof ee))&&s.push(new c(l.INVALID_CHECKS_FIELD,"A check field must be a function expression",n)),s})}validateFieldSetting(t){const n=M(t),s=n.getErrors(),r=n.getValue();for(const i in r){const a=r[i];switch(i){case"name":a.length>1&&a.forEach(o=>s.push(new c(l.DUPLICATE_CHECK_SETTING,`'${i}' can only appear once`,o))),a.forEach(o=>{$(o.value)||s.push(new c(l.INVALID_CHECK_SETTING_VALUE,`'${i}' must be a string`,o))});break;default:a.forEach(o=>s.push(new c(l.UNKNOWN_CHECK_SETTING,`Unknown check setting '${i}'`,o)))}}return s}validateSubElements(t){return t.flatMap(n=>{if(n.parent=this.declarationNode,!n.type)return[];const s=de(n);return new s(n,this.publicSymbolTable,this.symbolFactory).validate()})}}function de(e){switch(e.type.value.toLowerCase()){case b.Enum:return Al;case b.Table:return Pl;case b.TableGroup:return xl;case b.Project:return yl;case b.Ref:return wl;case b.Note:return vl;case b.Indexes:return Ll;case b.TablePartial:return kl;case b.Check:return Dl;default:return _l}}function Ls(e){return!!Y(e).unwrap_or(!1)}function Rl(e){return $e(e)}function $e(e){return e instanceof q&&e.expression instanceof oe}function _t(e,t,n){e[0]===Te&&(e=e.slice(1));let s=t;for(const r of e){let i;const a=et(r);if(s.has(a)){if(i=s.get(a)?.symbolTable,!i)throw new Error("Expect a symbol table in a schema symbol")}else{i=new Ge;const o=n.create(_s,{symbolTable:i});s.set(a,o)}s=i}return s}function vs(e){return e==="-"||e==="<>"||e===">"||e==="<"}function At(e){if(!(e instanceof q)||!(e.expression instanceof Ve)||e.expression.literal?.kind!==p.COLOR_LITERAL)return!1;const t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!=="#")return!1;for(let n=1;n<t.length;n+=1)if(!Zo(t[n]))return!1;return!0}function Q(e){return e===void 0}function ys(e){if($(e)||we(e)||ve(e)&&["true","false","null"].includes(e.expression.variable.value.toLowerCase())||e instanceof Z&&dl.includes(e.op?.value)&&we(e.expression)||e instanceof ee)return!0;if(!e||!Kt(e))return!1;const t=ge(e).unwrap();return t.length===2||t.length===3}function we(e){return e instanceof Z?e.op?.value!=="-"&&e.op?.value!=="+"?!1:we(e.expression):e instanceof q&&e.expression instanceof Ve&&e.expression.literal?.kind===p.NUMERIC_LITERAL}function ws(e){if(!(e instanceof Z)||!vs(e.op?.value))return!1;const t=Y(e.expression).unwrap_or(void 0);return t!==void 0&&t.length>0}function Ss(e){return e instanceof pe&&e.elementList.every(C)}function Ps(e){if(!(e instanceof H||It(e)||e instanceof q||e instanceof ue))return!1;for(;e instanceof H||e instanceof ue;)if(e instanceof H){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(n=>we(n)||$(n)||ve(n)))return!1;e=e.callee}else if(e instanceof ue){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(n=>!n.colon&&!n.value&&we(n.name)))return!1;e=e.array}const t=Y(e).unwrap_or(void 0);return t!==void 0&&t.length>0}function M(e){const t={},n=[];return e?(e.elementList.forEach(s=>{if(!s.name)return;if(s.name instanceof q){n.push(new c(l.INVALID_SETTINGS,"A setting name must be a stream of identifiers",s.name));return}const r=Fe(s.name).unwrap_or(void 0)?.toLowerCase();r&&(t[r]===void 0?t[r]=[s]:t[r].push(s))}),new J(t,n)):new J({})}class Bn{constructor(t,n){this.ast=t,this.symbolFactory=n,this.publicSchemaSymbol=this.symbolFactory.create(_s,{symbolTable:new Ge}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){const t=[];this.ast.body.forEach(s=>{if(s.parent=this.ast,s.type===void 0)return;const r=de(s),i=new r(s,this.publicSchemaSymbol.symbolTable,this.symbolFactory);t.push(...i.validate())});const n=this.ast.body.filter(s=>ye(s).unwrap_or(void 0)===b.Project);return n.length>1&&n.forEach(s=>t.push(new c(l.PROJECT_REDEFINED,"Only one project can exist",s))),new J(this.ast,t)}}function Ul(e){return[et,Be,qt,Yt,gt,zt,Qt,Jt,As].map(t=>t(e))}function Ml(e){return e instanceof Ht?Jo:null}class Ee{constructor(t,n){this.declarationNode=t,this.errors=n}bind(){this.bindSettingList(this.declarationNode.attributeList,this.settingList),this.bindBody()}bindSettingList(t,n){t&&t.elementList.forEach(s=>{if(s.name instanceof q)return;const r=Fe(s.name).unwrap_or(void 0);if(!r)return;const i=n[r.toLowerCase()];i?.shouldBind&&this.scanAndBind(s.value,i)})}bindBody(){const t=this.declarationNode;if(!t.body)return;const{body:n}=t;n instanceof le?n.body.forEach(s=>{if(s instanceof y){if(!s.type||ye(this.declarationNode).unwrap_or(null)===b.TablePartial&&ye(s).unwrap_or(null)===b.Indexes)return;const r=Os(s);new r(s,this.errors).bind()}else s instanceof L?this.bindSubfield(s):this.bindPartialInjection(s)}):this.bindSubfield(n)}bindSubfield(t){const n=[t.callee,...t.args],s=R(n);s instanceof D&&(n.pop(),this.bindSettingList(s,this.subfield.settingList));const{argBinderRules:r}=this.subfield.arg;for(let i=0;i<Math.min(n.length,r.length);i+=1)r[i].shouldBind&&this.scanAndBind(n[i],r[i])}bindPartialInjection(t){this.injectionBinderRule?.shouldBind&&this.scanAndBind(t,this.injectionBinderRule)}scanAndBind(t,n){if(t)if(t instanceof q){if(t.expression instanceof oe&&n.keywords?.includes(t.expression.variable?.value.toLowerCase()))return;this.bindFragments([t],n)}else t instanceof fe?It(t)?this.bindFragments(ge(t).unwrap_or([]),n):(this.scanAndBind(t.leftExpression,n),this.scanAndBind(t.rightExpression,n)):t instanceof Z?this.scanAndBind(t.expression,n):t instanceof bt?this.scanAndBind(t.expression,n):t instanceof pe?t.elementList.forEach(s=>this.scanAndBind(s,n)):t instanceof Le&&this.bindFragments([t],n)}bindFragments(t,n){if(t.length===0)return;const s=t.length===1&&t[0]instanceof Le,r=[...n.topSubnamesSymbolKind],i=s?-1:t.findIndex(I=>!C(I)),o=i!==-1&&Ss(t[i])?t[i]:void 0,h=i>=0?r.pop():void 0,f=t.slice(0,i===-1?void 0:i);if(f.length===0)return;const u=[];for(;r.length&&f.length;){const I=r.pop(),_=f.pop(),v=W(_).unwrap();u.unshift({index:at(v,I),referrer:_})}for(;f.length;){const I=f.pop(),_=s?bl(I).unwrap():W(I).unwrap();u.unshift({index:at(_,n.remainingSubnamesSymbolKind),referrer:I})}const d=$(t[0]);return o?o.elementList.forEach(I=>this.resolveIndexStack([...u,{index:at(W(I).unwrap(),h),referrer:I}],n,d)):this.resolveIndexStack(u,n,d)}resolveIndexStack(t,n,s){if(t.length===0)throw new Error("Unreachable - An unresolved name must have at least one name component");const[r,...i]=t,a=Fn(r.index,this.declarationNode);if(a===void 0){const{kind:u,name:d}=re(r.index).unwrap();this.logError(r.referrer,`Can not find ${u} '${d}'`,n.ignoreNameNotFound||!!n.ignoreNameNotFoundForQuotedVariable&&s);return}a.references.push(r.referrer),r.referrer.referee=a;let o=a.symbolTable,{kind:h,name:f}=re(r.index).unwrap();for(const u of i){const{kind:d,name:I}=re(u.index).unwrap(),_=o.get(u.index);if(!_){this.logError(u.referrer,`${h} '${f}' does not have ${d} '${I}'`,n.ignoreNameNotFound);return}if(h=d,f=I,u.referrer.referee=_,_.references.push(u.referrer),!_.symbolTable)break;o=_.symbolTable}}logError(t,n,s){s||this.errors.push(new c(l.BINDING_ERROR,n,t))}resolveInjections(t){const n=this.declarationNode.symbol?.symbolTable;if(!n)return;const s=new Map;n.forEach((r,i)=>{if(!Tl(i))return;const o=Fn(ml(i),this.declarationNode)?.declaration?.symbol?.symbolTable;o&&o.forEach((h,f)=>{n.has(f)||s.set(f,{injectorFieldSymbol:h,injectorDeclaration:r.declaration})})}),s.forEach((r,i)=>{const a=Ml(r.injectorFieldSymbol);if(!a)return;const o=t.create(a,r);n.set(i,o)})}}class Fl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Bl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Cl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class Vl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class Gl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1}]},settingList:{}},this.settingList={}}}class $l extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[]},settingList:{}},this.settingList={}}}class Xl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class jl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[T.Enum],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!0,ignoreNameNotFoundForQuotedVariable:!0}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},default:{shouldBind:!0,topSubnamesSymbolKind:[T.Enum,T.EnumField],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,keywords:["false","true","null"],ignoreNameNotFoundForQuotedVariable:!0},check:{shouldBind:!1}}},this.settingList={},this.injectionBinderRule={shouldBind:!0,topSubnamesSymbolKind:[],remainingSubnamesSymbolKind:T.TablePartial,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}}}class Wl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!0,topSubnamesSymbolKind:[T.Table],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{}},this.settingList={}}}class Hl extends Ee{constructor(){super(...arguments),this.subfield={arg:{argBinderRules:[{shouldBind:!1},{shouldBind:!0,topSubnamesSymbolKind:[T.Enum],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!0,ignoreNameNotFoundForQuotedVariable:!1}]},settingList:{ref:{shouldBind:!0,topSubnamesSymbolKind:[T.Table,T.Column],remainingSubnamesSymbolKind:T.Schema,ignoreNameNotFound:!1,ignoreNameNotFoundForQuotedVariable:!1},default:{shouldBind:!1},check:{shouldBind:!1}}},this.settingList={}}}function Os(e){switch(e.type.value.toLowerCase()){case b.Enum:return Cl;case b.Table:return jl;case b.TableGroup:return Wl;case b.Project:return $l;case b.Ref:return Xl;case b.Note:return Gl;case b.Indexes:return Vl;case b.TablePartial:return Hl;case b.Check:return Fl;default:return Bl}}class Kl{constructor(t){this.ast=t,this.errors=[]}resolve(t){return this.ast.body.map(n=>{if(!n.type)return null;const s=Os(n),r=new s(n,this.errors);return r.resolveInjections(t),r}).forEach(n=>n?.bind()),new J(this.ast,this.errors)}}class ql{constructor(t){this.generator=t}create(t,n){return new t(n,this.generator.nextId())}}class zl{constructor(t,n){this.ast=t,this.symbolFactory=new ql(n)}analyze(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new Kl(n).resolve(this.symbolFactory))}validate(){return new Bn(this.ast,this.symbolFactory).validate().chain(n=>new J(n,[]))}}function Cn(e,t){const{variables:n,tupleElements:s}=Qe(e).unwrap();return s?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:s}:{tableName:n.pop(),schemaName:n.pop()||null,fieldNames:s}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[n[0]]}:{fieldNames:[n.pop()],tableName:n.pop(),schemaName:n.pop()||null}}function xs(e){switch(e){case"<":return["1","*"];case"<>":return["*","*"];case">":return["*","1"];case"-":return["1","1"];default:throw new Error("Invalid relation op")}}function g(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1}}}function ut(e){const t=ge(e).unwrap_or(void 0)?.pop();return t instanceof pe?t.elementList.map(n=>n.referee):[t.referee]}function De(e){const t=Y(e).unwrap();return{name:t.pop(),schemaName:t}}function tt(e){return e.expression.literal.value}function ks(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort().join(","),i=t.map(({id:a})=>a).sort().join(",");return r<i?`${r}-${i}`:`${i}-${r}`}const n=e.id.toString(),s=t.id.toString();return n<s?`${n}-${s}`:`${s}-${n}`}function Zt(e,t){if(Array.isArray(e)){const r=e.map(({id:a})=>a).sort(),i=t.map(({id:a})=>a).sort();return Dt(r,i).every(([a,o])=>a===o)}const n=e.id,s=t.id;return n===s}function ie(e){const t=e.split(`
|
|
10
10
|
`),n=t.slice(t.findIndex(i=>i.trimStart()!=="")),s=n.filter(i=>i.trimStart()),r=Math.min(...s.map(i=>i.length-i.trimStart().length));return n.map(i=>i.slice(r)).join(`
|
|
11
|
-
`)}function Cs(e){if(e){if(K(e))return{value:C(e).unwrap(),type:"string"};if(Be(e))return{type:"number",value:Gt(e)};if(xe(e))return{value:e.expression.variable.value.toLowerCase(),type:"boolean"};if(e instanceof ie&&e.value)return{value:e.value.value,type:"expression"};if(Qt(e))return{value:ye(e).map(U).and_then(z).unwrap(),type:"string"};throw new Error("Unreachable")}}function Vs(e){let t=null;e instanceof ae&&(t=e.argumentList.elementList.map(i=>Be(i)?ws(i):K(i)?C(i).unwrap():z(i).unwrap()).join(","),e=e.callee);let n="";for(;e instanceof Fe;)n=`[${e.indexer.elementList.map(i=>i.name.expression.literal.value).join(",")}]${n}`,e=e.array;const{name:s,schemaName:r}=Ge(e);return r.length>1?new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t},[new c(l.UNSUPPORTED,"Nested schema is not supported",e)]):new se({schemaName:r.length===0?null:r[0],type_name:`${s}${n}${t?`(${t})`:""}`,args:t})}class Gs{constructor(t,n){this.declarationNode=t,this.env=n,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=L(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);const t=[...this.interpretName(this.declarationNode.name),...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n,schemaName:s}=Ge(t);return s.length>1?(this.table.name=n,this.table.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.table.name=n,this.table.schemaName=s.length?s[0]:null,[])}interpretAlias(t){if(!t)return[];const n=H(t).unwrap_or(null);return n&&(this.env.aliases.push({name:n,kind:"table",value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=n),[]}interpretSettingList(t){var r,i,a;const n=F(t).getValue();this.table.headerColor=(r=n[E.HeaderColor])!=null&&r.length?lt((a=(i=n[E.HeaderColor])==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n[E.Note]||[];return this.table.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof w||r instanceof Me);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case g.Note:return this.table.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case g.Indexes:return this.interpretIndexes(n);case g.Check:return this.interpretChecks(n);default:return[]}})}interpretInjection(t,n){const s={order:n,token:L(t)};return s.name=t.partial.variable.value,this.table.partials.push(s),[]}interpretFields(t){var a;const r=((a=this.declarationNode.symbol)!=null&&a.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([o])=>{const u=he(o).unwrap_or(null);return(u==null?void 0:u.kind)===I.Column}).length?[]:[new c(l.EMPTY_TABLE,"A Table must have at least one column",this.declarationNode)],i=t.flatMap((o,u)=>o instanceof w?this.interpretColumn(o):this.interpretInjection(o,u));return[...r,...i]}interpretColumn(t){var a,o,u,h,f,d,N,m,A;const n=[],s={};s.name=H(t.callee).unwrap();const r=Vs(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(U(i)instanceof R){const b=F(i.pop()).getValue();s.pk=!!((a=b[E.PK])!=null&&a.length)||!!((o=b[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=b[E.Increment])!=null&&u.length),s.unique=!!((h=b[E.Unique])!=null&&h.length),s.not_null=(f=b[E.NotNull])!=null&&f.length?!0:(d=b[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=Cs((m=(N=b[E.Default])==null?void 0:N.at(0))==null?void 0:m.value);const y=(A=b[E.Note])==null?void 0:A.at(0);s.note=y&&{value:C(y.value).map(fe).unwrap(),token:L(y)};const j=b[E.Ref]||[];s.inline_refs=j.flatMap(S=>{const[ee]=Nt(S.value.expression);if(sn(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",S)),[];const G=S.value.op,$=Z(S.value.expression).unwrap();let le;if($.length===1){const[te]=$;le={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[te],relation:G.value,token:L(S)}}else if($.length===2){const[te,Se]=$;le={schemaName:null,tableName:te,fieldNames:[Se],relation:G.value,token:L(S)}}else if($.length===3){const[te,Se,on]=$;le={schemaName:te,tableName:Se,fieldNames:[on],relation:G.value,token:L(S)}}else{n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",S));const te=$.pop(),Se=$.pop();le={schemaName:$.join("."),tableName:Se,fieldNames:[te],relation:G.value,token:L(S)}}const we=this.registerInlineRefToEnv(t,ee,le,S);return n.push(...we),we.length===0?le:[]});const q=b[E.Check]||[];s.checks=q.map(S=>{const ee=L(S),G=S.value.value.value;return{token:ee,expression:G}})}return s.pk||(s.pk=i.some(b=>z(b).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(b=>z(b).unwrap().toLowerCase()==="unique")),this.table.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.table.indexes.push(...t.body.body.map(n=>{var a,o,u,h,f,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(U(i)instanceof R){const m=F(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length),s.unique=!!((o=m[E.Unique])!=null&&o.length),s.name=C((h=(u=m[E.Name])==null?void 0:u.at(0))==null?void 0:h.value).unwrap_or(void 0);const A=(f=m[E.Note])==null?void 0:f.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=z((N=(d=m[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(m=>{if(!(m instanceof ae))return m;const A=[];for(;m instanceof ae;)A.push(m.argumentList),m=m.callee;return A.push(m),A}).forEach(m=>{const{functional:A,nonFunctional:b}=Et(m).unwrap();s.columns.push(...A.map(y=>({value:y.value.value,type:"expression",token:L(y)})),...b.map(y=>({value:H(y).unwrap(),type:"column",token:L(y)})))}),s})),[]}interpretChecks(t){return this.table.checks.push(...t.body.body.map(n=>{var i,a;const s={},r=n;if(s.token=L(r),r.args[0]instanceof R){const o=F(r.args[0]).getValue();s.name=C((a=(i=o[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}registerInlineRefToEnv(t,n,s,r){const i=Bs(t.symbol,n);if(this.env.refIds[i])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",r),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[i])];const a=Fs(s.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:s.token,endpoints:[{...s,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[z(t.callee).unwrap()],token:L(t),relation:a[0]}]}),[]}}class nc{constructor(t,n){this.declarationNode=t,this.env=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=L(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n}=Ge(t);return this.note.name=n,[]}interpretSettingList(t){var s,r,i;const n=F(t).getValue();return this.note.headerColor=(s=n.headercolor)!=null&&s.length?lt((i=(r=n.headercolor)==null?void 0:r.at(0))==null?void 0:i.value):void 0,[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof w);return n.length!==1||s.length>0?[new c(l.INVALID_NOTE,"Invalid note syntax",t)]:[...this.interpretNote(n[0])]}interpretNote(t){const n=ps(t,"callee.expression.literal.value","");return this.note.content=fe(n),[]}}class $s{constructor(t,n){this.declarationNode=t,this.env=n,this.container=this.declarationNode.parent instanceof P?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=L(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const n=[],s=Z(this.declarationNode.name).unwrap_or([]);return this.ref.name=s.pop()||null,s.length>1&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name)),this.ref.schemaName=s.join(".")||null,n}interpretBody(t){return t instanceof w?this.interpretField(t):this.interpretField(t.body[0])}interpretField(t){var h,f,d,N,m,A,b;const n=t.callee.op.value,{leftExpression:s,rightExpression:r}=t.callee,i=Nt(s),a=Nt(r);if(sn(i,a))return[new c(l.SAME_ENDPOINT,"Two endpoints are the same",t)];const o=Bs(i,a);if(this.env.refIds[o])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",this.declarationNode),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[o])];if(t.args[0]){const y=F(t.args[0]).getValue(),j=(f=(h=y.delete)==null?void 0:h.at(0))==null?void 0:f.value;this.ref.onDelete=j instanceof ce?We(j).unwrap_or(void 0):z(j).unwrap_or(void 0);const q=(N=(d=y.update)==null?void 0:d.at(0))==null?void 0:N.value;this.ref.onUpdate=q instanceof ce?We(q).unwrap_or(void 0):z(q).unwrap_or(void 0),this.ref.color=(m=y.color)!=null&&m.length?lt((b=(A=y.color)==null?void 0:A.at(0))==null?void 0:b.value):void 0}const u=Fs(n);return this.ref.endpoints=[{...Xn(s,this.container),relation:u[0],token:L(s)},{...Xn(r,this.container),relation:u[1],token:L(r)}],this.env.refIds[o]=this.declarationNode,[]}}class Xs{constructor(t,n){this.declarationNode=t,this.env=n,this.tableGroup={tables:[]}}interpret(){const t=[];return this.tableGroup.token=L(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),t.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),t}interpretName(t){const n=[],{name:s,schemaName:r}=Ge(t);return r.length>=2&&(this.tableGroup.name=s,this.tableGroup.schemaName=r.join("."),n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name))),this.tableGroup.name=s,this.tableGroup.schemaName=r[0]||null,n}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof w);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case"note":this.tableGroup.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)};break}return[]})}interpretFields(t){const n=[];return this.tableGroup.tables=t.map(s=>{const r=Z(s.callee).unwrap();r.length>2&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",s));const i=ye(s.callee).unwrap().pop().referee.id;if(this.env.groupOfTable[i]){const a=this.env.groupOfTable[i],{schemaName:o,name:u}=this.env.tableGroups.get(a),h=o?`${o}.${u}`:u;n.push(new c(l.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r.join(".")}" already appears in group "${h}"`,s))}else this.env.groupOfTable[i]=this.declarationNode;return{name:r.pop(),schemaName:r.join(".")}}),n}interpretSettingList(t){var r,i,a;const n=F(t).getValue();this.tableGroup.color=(r=n.color)!=null&&r.length?lt((a=(i=n.color)==null?void 0:i.at(0))==null?void 0:a.value):void 0;const[s]=n.note||[];return this.tableGroup.note=s&&{value:C(s==null?void 0:s.value).map(fe).unwrap(),token:L(s)},[]}}class js{constructor(t,n){this.declarationNode=t,this.env=n,this.enum={values:[]}}interpret(){return this.enum.token=L(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n,schemaName:s}=Ge(t);return s.length>1?(this.enum.name=n,this.enum.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.enum.name=n,this.enum.schemaName=s.length?s[0]:null,[])}interpretBody(t){return t.body.flatMap(n=>{var o;const s=n,r={};r.token=L(s),r.name=z(s.callee).unwrap();const a=(o=F(s.args[0]).getValue().note)==null?void 0:o.at(0);return r.note=a&&{value:C(a.value).map(fe).unwrap(),token:L(a)},this.enum.values.push(r),[]})}}class Ws{constructor(t,n){this.declarationNode=t,this.env=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=L(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);const t=[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n}=Ge(t);return this.tablePartial.name=n,[]}interpretSettingList(t){const n=F(t).getValue(),s=Xo(n[E.HeaderColor]);this.tablePartial.headerColor=s?lt(s.value):void 0;const[r]=n[E.Note]||[];return this.tablePartial.note=r&&{value:C(r==null?void 0:r.value).map(fe).unwrap(),token:L(r)},[]}interpretBody(t){const[n,s]=oe(t.body,r=>r instanceof w);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{var s;switch((s=n.type)==null?void 0:s.value.toLowerCase()){case g.Note:return this.tablePartial.note={value:C(n.body instanceof Ee?n.body.body[0].callee:n.body.callee).map(fe).unwrap(),token:L(n)},[];case g.Indexes:return this.interpretIndexes(n);case g.Check:return this.interpretChecks(n);default:return[]}})}interpretFields(t){return t.flatMap(n=>this.interpretColumn(n))}interpretColumn(t){var a,o,u,h,f,d,N,m,A;const n=[],s={};s.name=H(t.callee).unwrap();const r=Vs(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=L(t),s.inline_refs=[];const i=t.args.slice(1);if(U(i)instanceof R){const b=F(i.pop()).getValue();s.pk=!!((a=b[E.PK])!=null&&a.length)||!!((o=b[E.PrimaryKey])!=null&&o.length),s.increment=!!((u=b[E.Increment])!=null&&u.length),s.unique=!!((h=b[E.Unique])!=null&&h.length),s.not_null=(f=b[E.NotNull])!=null&&f.length?!0:(d=b[E.Null])!=null&&d.length?!1:void 0,s.dbdefault=Cs((m=(N=b[E.Default])==null?void 0:N.at(0))==null?void 0:m.value);const y=(A=b[E.Note])==null?void 0:A.at(0);s.note=y&&{value:C(y.value).map(fe).unwrap(),token:L(y)};const j=b[E.Ref]||[];s.inline_refs=j.flatMap(S=>{const[ee]=Nt(S.value.expression);if(sn(ee,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",S)),[];const G=S.value.op,$=Z(S.value.expression).unwrap();let le;if($.length===2){const[we,te]=$;le={schemaName:null,tableName:we,fieldNames:[te],relation:G.value,token:L(S)}}else if($.length===3){const[we,te,Se]=$;le={schemaName:we,tableName:te,fieldNames:[Se],relation:G.value,token:L(S)}}else{n.push(new c(l.UNSUPPORTED,"Unsupported",S));const we=$.pop(),te=$.pop();le={schemaName:$.join("."),tableName:te,fieldNames:[we],relation:G.value,token:L(S)}}return le});const q=b[E.Check]||[];s.checks=q.map(S=>{const ee=L(S),G=S.value.value.value;return{token:ee,expression:G}})}return s.pk||(s.pk=i.some(b=>z(b).unwrap().toLowerCase()==="pk")),s.unique||(s.unique=i.some(b=>z(b).unwrap().toLowerCase()==="unique")),this.tablePartial.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.tablePartial.indexes.push(...t.body.body.map(n=>{var a,o,u,h,f,d,N;const s={columns:[]},r=n;s.token=L(r);const i=[r.callee,...r.args];if(U(i)instanceof R){const m=F(i.pop()).getValue();s.pk=!!((a=m[E.PK])!=null&&a.length),s.unique=!!((o=m[E.Unique])!=null&&o.length),s.name=C((h=(u=m[E.Name])==null?void 0:u.at(0))==null?void 0:h.value).unwrap_or(void 0);const A=(f=m[E.Note])==null?void 0:f.at(0);s.note=A&&{value:C(A.value).unwrap(),token:L(A)},s.type=z((N=(d=m[E.Type])==null?void 0:d.at(0))==null?void 0:N.value).unwrap_or(void 0)}return i.flatMap(m=>{if(!(m instanceof ae))return m;const A=[];let b=m;for(;b instanceof ae;)A.push(b.argumentList),b=b.callee;return A.push(b),A}).forEach(m=>{const{functional:A,nonFunctional:b}=Et(m).unwrap();s.columns.push(...A.map(y=>({value:y.value.value,type:"expression",token:L(y)})),...b.map(y=>({value:H(y).unwrap(),type:"column",token:L(y)})))}),s})),[]}interpretChecks(t){return this.tablePartial.checks.push(...t.body.body.map(n=>{var i,a;const s={},r=n;if(s.token=L(r),r.args[0]instanceof R){const o=F(r.args[0]).getValue();s.name=C((a=(i=o[E.Name])==null?void 0:i.at(0))==null?void 0:a.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}}class sc{constructor(t,n){this.declarationNode=t,this.env=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=L(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){if(!t)return this.project.name=null,[];const{name:n}=Ge(t);return this.project.name=n,[]}interpretBody(t){return t.body.flatMap(n=>{var r;const s=n;switch((r=s.type)==null?void 0:r.value.toLowerCase()){case"table":{const i=new Gs(s,this.env).interpret();return this.project.tables.push(this.env.tables.get(s)),i}case"ref":{const i=new $s(s,this.env).interpret();return this.project.refs.push(this.env.ref.get(s)),i}case"tablegroup":{const i=new Xs(s,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(s)),i}case"enum":{const i=new js(s,this.env).interpret();return this.project.enums.push(this.env.enums.get(s)),i}case"note":return this.project.note={value:C(s.body instanceof Ee?s.body.body[0].callee:s.body.callee).map(fe).unwrap(),token:L(s)},[];case"tablepartial":{const i=new Ws(s,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(s)),i}default:return this.project[s.type.value.toLowerCase()]=C(s.body.callee).unwrap(),[]}})}}function rc(e){return{schemas:[],tables:Array.from(e.tables.values()),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values())}}class ic{constructor(t){this.ast=t,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableGroups:new Map,groupOfTable:{},aliases:[],project:new Map,tablePartials:new Map}}interpret(){const t=this.ast.body.flatMap(n=>{switch(ke(n).unwrap_or(void 0)){case g.Table:return new Gs(n,this.env).interpret();case g.Note:return new nc(n,this.env).interpret();case g.Ref:return new $s(n,this.env).interpret();case g.TableGroup:return new Xs(n,this.env).interpret();case g.TablePartial:return new Ws(n,this.env).interpret();case g.Enum:return new js(n,this.env).interpret();case g.Project:return new sc(n,this.env).interpret();default:return[]}});return new se(rc(this.env),t)}}var O=(e=>(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))(O||{}),M=(e=>(e[e.None=0]="None",e[e.KeepWhitespace=1]="KeepWhitespace",e[e.InsertAsSnippet=4]="InsertAsSnippet",e))(M||{});function it(e){switch(e){case I.Schema:return O.Module;case I.Table:case I.TablePartial:return O.Class;case I.Column:case I.TableGroupField:return O.Field;case I.Enum:return O.Enum;case I.EnumField:return O.EnumMember;case I.TableGroup:return O.Struct;default:return O.Text}}function Tt(e,t){if(!e||Vt(e))return!1;for(const n of e.trailingTrivia){if(n.start>t)break;if(n.kind===p.NEWLINE&&n.end<=t)return!1}return!0}function X(){return{suggestions:[]}}function mt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:` ${t.insertText}`}))}}function Ot(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:t.insertText.split("").every(at)?t.insertText:`"${t.insertText}"`}))}}function rn(e,t){return e.getOffsetAt(t)}class Hs{constructor(t,n=[]){this.compiler=t,this.triggerCharacters=n}provideCompletionItems(t,n){var f,d;const s=rn(t,n),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(s),o=a===void 0?r[0]:r[a+1];if([...(i==null?void 0:i.trailingTrivia)||[],...(i==null?void 0:i.leadingTrivia)||[],...(o==null?void 0:o.leadingTrivia)||[]].find(N=>qo(N)&&et(s,N)))return X();if(a===void 0)return qn();if([p.STRING_LITERAL,p.QUOTED_STRING].includes(i.kind)&&et(s,i))return X();const u=this.compiler.container.element(s);if(this.compiler.container.scopeKind(s)===v.TOPLEVEL||u instanceof P&&u.type&&u.type.start<=s&&u.type.end>=s)return qn();const h=[...this.compiler.container.stack(s)].reverse();for(const N of h)if(N instanceof re)switch((f=N.op)==null?void 0:f.value){case">":case"<":case"<>":case"-":return jn(this.compiler,s,N)}else if(N instanceof Te)switch((d=N.op)==null?void 0:d.value){case">":case"<":case"<>":case"-":return jn(this.compiler,s,N);case".":return Ks(this.compiler,s,N)}else{if(N instanceof ue)return Wn(this.compiler,s,N);if(N instanceof R)return Wn(this.compiler,s,N);if(N instanceof me)return oc(this.compiler,s);if(N instanceof Me)return ac(this.compiler,s);if(N instanceof w)return Kn(this.compiler,s,N);if(N instanceof P&&(N.bodyColon&&s>=N.bodyColon.end||N.body&&et(s,N.body)))return Kn(this.compiler,s,void 0)}return X()}}function ac(e,t){const n=e.container.element(t);return Qe(e,t,n,[I.TablePartial])}function jn(e,t,n){const s=e.container.scopeKind(t);if([v.REF,v.TABLE,v.TABLEPARTIAL].includes(s)){const r=Qe(e,t,e.container.element(t),[I.Table,I.Schema,I.Column]);return Tt(n.op,t)?mt(r):r}return X()}function Qe(e,t,n,s){var a;if(n===void 0)return X();let r=n;const i={suggestions:[]};for(;r;){if((a=r==null?void 0:r.symbol)!=null&&a.symbolTable){const{symbol:o}=r;i.suggestions.push(...e.symbol.members(o).filter(({kind:u})=>s.includes(u)).map(({name:u,kind:h})=>({label:u,insertText:u,insertTextRules:M.KeepWhitespace,kind:it(h),sortText:it(h).toString().padStart(2,"0"),range:void 0})))}r=r instanceof P?r.parent:void 0}return Ot(i)}function oc(e,t){var s;switch(e.container.scopeKind(t)){case v.INDEXES:return zs(e,t);case v.REF:{const r=[...e.container.stack(t)];for(;r.length>0;){const i=r.pop();if(i instanceof Te&&((s=i.op)==null?void 0:s.value)===".")return Ks(e,t,i)}}return qs(e,t)}return X()}function Wn(e,t,n){const{token:s}=e.container.token(t);if([p.COMMA,p.LBRACKET].includes(s==null?void 0:s.kind)){const r=Hn(e,t);return(s==null?void 0:s.kind)===p.COMMA&&Tt(s,t)?mt(r):r}if(n.name&&n.name.start<=t&&n.name.end>=t)return Hn(e,t);if(n.name instanceof ce){const r=lc(e,t,We(n.name).unwrap_or(""));return(s==null?void 0:s.kind)===p.COLON&&Tt(s,t)?mt(r):r}return X()}function Hn(e,t){const n=e.container.element(t);if(n instanceof J)return X();const s=e.container.scopeKind(t);if(n.body&&!et(t,n.body)){let r;switch(s){case v.TABLE:case v.TABLEPARTIAL:r=[E.HeaderColor,E.Note];break;case v.TABLEGROUP:r=[E.Color,E.Note];break;default:r=[]}return{suggestions:r.map(i=>({label:i,insertText:`${i}: `,kind:O.Field,insertTextRules:M.KeepWhitespace,range:void 0}))}}switch(s){case v.TABLE:case v.TABLEPARTIAL:return{suggestions:[...[E.PK,E.PrimaryKey,E.Null,E.NotNull,E.Increment,E.Unique].map(r=>({label:r,insertText:r,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0})),...[E.Ref,E.Default,E.Note,E.Check].map(r=>({label:r,insertText:`${r}: `,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case v.ENUM:return{suggestions:[...[E.Note].map(r=>({label:r,insertText:`${r}: `,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case v.INDEXES:return{suggestions:[...[E.Unique,E.PK].map(r=>({label:r,insertText:r,insertTextRules:M.KeepWhitespace,kind:O.Property,range:void 0})),...[E.Note,E.Name,E.Type].map(r=>({label:r,insertText:`${r}: `,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0}))]};case v.REF:return{suggestions:[E.Update,E.Delete,E.Color].map(r=>({label:r,insertText:`${r}: `,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0}))};case v.CHECKS:return{suggestions:[E.Name].map(r=>({label:r,insertText:`${r}: `,kind:O.Property,insertTextRules:M.KeepWhitespace,range:void 0}))}}return X()}function lc(e,t,n){switch(n==null?void 0:n.toLowerCase()){case"update":case"delete":return{suggestions:["cascade","set default","set null","restrict"].map(s=>({label:s,insertText:s,kind:O.Value,insertTextRules:M.KeepWhitespace,range:void 0}))};case"type":return{suggestions:["btree","hash"].map(s=>({label:s,insertText:`${s}`,kind:O.Value,insertTextRules:M.KeepWhitespace,range:void 0}))};case"default":return Qe(e,t,e.container.element(t),[I.Schema,I.Enum])}return X()}function Ks(e,t,n){const s=ye(n).unwrap_or([]);if(s.pop(),s.some(i=>!V(i)))return X();const r=s.map(i=>z(i).unwrap());return Ot({suggestions:e.symbol.ofName(r,e.container.element(t)).flatMap(({symbol:i})=>e.symbol.members(i)).map(({kind:i,name:a})=>({label:a,insertText:a,kind:it(i),range:void 0}))})}function Kn(e,t,n){var r;switch(e.container.scopeKind(t)){case v.TABLE:case v.TABLEPARTIAL:return uc(e,t,n);case v.PROJECT:return hc(e,t,n);case v.INDEXES:return pc(e,t);case v.ENUM:return cc(e,t,n);case v.REF:{const i=qs(e,t);return((r=e.container.token(t).token)==null?void 0:r.kind)===p.COLON&&Tt(e.container.token(t).token,t)?mt(i):i}case v.TABLEGROUP:return fc(e);default:return X()}}function qn(){return{suggestions:["Table","TableGroup","Enum","Project","Ref","TablePartial"].map(e=>({label:e,insertText:e,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))}}function cc(e,t,n){return n!=null&&n.callee&&an(t,n)===1?Qe(e,t,e.container.element(t),[I.Schema,I.Table,I.Column]):X()}function uc(e,t,n){const s=["Note","indexes","checks"];if(!(n!=null&&n.callee))return{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))};const r=an(t,n);return r===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))}:r===1?dc(e,t):X()}function hc(e,t,n){const s=["Table","TableGroup","Enum","Note","Ref","TablePartial"];return n!=null&&n.callee?an(t,n)===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))}:X():{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))}}function qs(e,t){return Qe(e,t,e.container.element(t),[I.Schema,I.Table,I.Column])}function fc(e){return{suggestions:[...Ot({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([t])=>{const n=he(t).unwrap_or(void 0);if(n===void 0)return[];const{kind:s,name:r}=n;return s!==I.Table&&s!==I.Schema?[]:{label:r,insertText:r,insertTextRules:M.KeepWhitespace,kind:it(s),range:void 0}})}).suggestions,...["Note"].map(t=>({label:t,insertText:t,insertTextRules:M.KeepWhitespace,kind:O.Keyword,range:void 0}))]}}function pc(e,t){return zs(e,t)}function dc(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"].map(n=>({label:n,insertText:n,insertTextRules:M.KeepWhitespace,kind:O.TypeParameter,sortText:O.TypeParameter.toString().padStart(2,"0"),range:void 0})),...Qe(e,t,e.container.element(t),[I.Enum,I.Schema]).suggestions]}}function zs(e,t){const n=e.container.element(t),s=n==null?void 0:n.parent;if(!((s==null?void 0:s.symbol)instanceof dt))return X();const{symbolTable:r}=s.symbol;return Ot({suggestions:[...r.entries()].flatMap(([i])=>{const a=he(i).unwrap_or(void 0);if(a===void 0)return[];const{name:o}=a;return{label:o,insertText:o,insertTextRules:M.KeepWhitespace,kind:it(I.Column),range:void 0}})})}function an(e,t){if(!t.callee)return-1;const n=[t.callee,...t.args],s=n.findIndex(r=>e<=r.end);return s===-1?n.length:s}class Ys{constructor(t){this.compiler=t}provideDefinition(t,n){var a,o;const{uri:s}=t,r=rn(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const u=i.pop();if(!(u!=null&&u.referee))continue;let h;if((a=u.referee)!=null&&a.declaration&&[Oe.PRIMARY_EXPRESSION,Oe.VARIABLE,Oe.PARTIAL_INJECTION].includes(u==null?void 0:u.kind)?{declaration:h}=u.referee:(o=u.referee)!=null&&o.injectorDeclaration&&(h=u.referee.injectorDeclaration),h){const{startPos:f,endPos:d}=h;return[{range:{startColumn:f.column+1,startLineNumber:f.line+1,endColumn:d.column+1,endLineNumber:d.line+1},uri:s}]}}return[]}}class Qs{constructor(t){this.compiler=t}provideReferences(t,n){const{uri:s}=t,r=rn(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const a=i.pop();if(a&&[Oe.ELEMENT_DECLARATION,Oe.FUNCTION_APPLICATION,Oe.PRIMARY_EXPRESSION].includes(a==null?void 0:a.kind)){const{symbol:o}=a;if(o!=null&&o.references.length)return o.references.map(({startPos:u,endPos:h})=>({range:{startColumn:u.column+1,startLineNumber:u.line+1,endColumn:h.column+1,endLineNumber:h.line+1},uri:s}))}}return[]}}const Ec=Object.freeze(Object.defineProperty({__proto__:null,CompletionItemInsertTextRule:M,CompletionItemKind:O,DBMLCompletionItemProvider:Hs,DBMLDefinitionProvider:Ys,DBMLReferencesProvider:Qs},Symbol.toStringTag,{value:"Module"}));function Nc(){return this.parse._().getValue().ast}function Tc(){return this.parse._().getErrors()}function mc(){return this.parse._().getValue().tokens}function bc(){return this.parse._().getValue().rawDb}function Ic(){return this.parse._().getValue().ast.symbol.symbolTable}function gc(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function _c(){return this.parse.tokens().filter(Ss)}function Ac(e){return e.symbolTable?[...e.symbolTable.entries()].map(([t,n])=>({...he(t).unwrap(),symbol:n})):[]}function Lc(e,t){var s;if(e.length===0)return[];const n=[];for(let r=t;r;r=r instanceof P?r.parent:void 0){if(!((s=r.symbol)!=null&&s.symbolTable))continue;const{symbolTable:i}=r.symbol;let a=[i],o=[];for(const u of e)o=a.flatMap(h=>Gl(u).flatMap(f=>{const d=h.get(f),N=he(f).unwrap_or(void 0);return!d||!N?[]:{...N,symbol:d}})),a=o.flatMap(h=>h.symbol.symbolTable?h.symbol.symbolTable:[]);n.push(...o)}return n}function vc(e,t){return`${e.join(".")}@${t.id}`}function yc(e){const t=this.token.flatStream(),{index:n,token:s}=this.container.token(e),r=n===void 0?-1:$o(t,u=>!u.isInvalid,n);if(r===-1)return[this.parse.ast()];const i=t[r].start;let a=this.parse.ast();const o=[a];for(;;){const h=ul(a).find(f=>et(i,f));if(h===void 0||h instanceof Q)break;o.push(h),a=h}if((s==null?void 0:s.kind)===p.COLON)return o;for(;o.length>0;){let u=!1;const h=U(o);if(h instanceof w){const f=this.parse.source();for(let d=h.end;d<e;d+=1)f[d]===`
|
|
12
|
-
`&&(o.pop(),
|
|
11
|
+
`)}function Ds(e){if(e){if($(e))return{value:B(e).unwrap(),type:"string"};if(we(e))return{type:"number",value:Mt(e)};if(ve(e))return{value:e.expression.variable.value.toLowerCase(),type:"boolean"};if(e instanceof ee&&e.value)return{value:e.value.value,type:"expression"};if(Kt(e))return{value:ge(e).map(R).and_then(j).unwrap(),type:"string"};throw new Error("Unreachable")}}function Rs(e){let t="",n=null;for(e instanceof H&&(n=e.argumentList.elementList.map(i=>we(i)?Ut(i):$(i)?B(i).unwrap():j(i).unwrap()).join(","),t=`(${n})`,e=e.callee);e instanceof H||e instanceof ue;)e instanceof H?(t=`(${e.argumentList.elementList.map(a=>we(a)?Ut(a):$(a)?B(a).unwrap():j(a).unwrap()).join(",")})${t}`,e=e.callee):e instanceof ue&&(t=`${`[${e.indexer.elementList.map(a=>a.name.expression.literal.value).join(",")}]`}${t}`,e=e.array);const{name:s,schemaName:r}=De(e);return r.length>1?new J({schemaName:r.length===0?null:r[0],type_name:`${s}${t}`,args:n},[new c(l.UNSUPPORTED,"Nested schema is not supported",e)]):new J({schemaName:r.length===0?null:r[0],type_name:`${s}${t}`,args:n})}class Us{constructor(t,n){this.declarationNode=t,this.env=n,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=g(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);const t=[...this.interpretName(this.declarationNode.name),...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n,schemaName:s}=De(t);return s.length>1?(this.table.name=n,this.table.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.table.name=n,this.table.schemaName=s.length?s[0]:null,[])}interpretAlias(t){if(!t)return[];const n=W(t).unwrap_or(null);return n&&(this.env.aliases.push({name:n,kind:"table",value:{tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=n),[]}interpretSettingList(t){const n=M(t).getValue();this.table.headerColor=n[E.HeaderColor]?.length?tt(n[E.HeaderColor]?.at(0)?.value):void 0;const[s]=n[E.Note]||[];return this.table.note=s&&{value:B(s?.value).map(ie).unwrap(),token:g(s)},[]}interpretBody(t){const[n,s]=te(t.body,r=>r instanceof L||r instanceof Le);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{switch(n.type?.value.toLowerCase()){case b.Note:return this.table.note={value:B(n.body instanceof le?n.body.body[0].callee:n.body.callee).map(ie).unwrap(),token:g(n)},[];case b.Indexes:return this.interpretIndexes(n);case b.Check:return this.interpretChecks(n);default:return[]}})}interpretInjection(t,n){const s={order:n,token:g(t)};return s.name=t.partial.variable.value,this.table.partials.push(s),[]}interpretFields(t){const r=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([a])=>re(a).unwrap_or(null)?.kind===T.Column).length?[]:[new c(l.EMPTY_TABLE,"A Table must have at least one column",this.declarationNode)],i=t.flatMap((a,o)=>a instanceof L?this.interpretColumn(a):this.interpretInjection(a,o));return[...r,...i]}interpretColumn(t){const n=[],s={};s.name=W(t.callee).unwrap();const r=Rs(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=g(t),s.inline_refs=[];const i=t.args.slice(1);if(R(i)instanceof D){const a=M(i.pop()).getValue();s.pk=!!a[E.PK]?.length||!!a[E.PrimaryKey]?.length,s.increment=!!a[E.Increment]?.length,s.unique=!!a[E.Unique]?.length,s.not_null=a[E.NotNull]?.length?!0:a[E.Null]?.length?!1:void 0,s.dbdefault=Ds(a[E.Default]?.at(0)?.value);const o=a[E.Note]?.at(0);s.note=o&&{value:B(o.value).map(ie).unwrap(),token:g(o)};const h=a[E.Ref]||[];s.inline_refs=h.flatMap(u=>{const[d]=ut(u.value.expression);if(Zt(d,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",u)),[];const I=u.value.op,_=Y(u.value.expression).unwrap();let v;if(_.length===1){const[k]=_;v={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[k],relation:I.value,token:g(u)}}else if(_.length===2){const[k,V]=_;v={schemaName:null,tableName:k,fieldNames:[V],relation:I.value,token:g(u)}}else if(_.length===3){const[k,V,ce]=_;v={schemaName:k,tableName:V,fieldNames:[ce],relation:I.value,token:g(u)}}else{n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",u));const k=_.pop(),V=_.pop();v={schemaName:_.join("."),tableName:V,fieldNames:[k],relation:I.value,token:g(u)}}const w=this.registerInlineRefToEnv(t,d,v,u);return n.push(...w),w.length===0?v:[]});const f=a[E.Check]||[];s.checks=f.map(u=>{const d=g(u),I=u.value.value.value;return{token:d,expression:I}})}return s.pk||=i.some(a=>j(a).unwrap().toLowerCase()==="pk"),s.unique||=i.some(a=>j(a).unwrap().toLowerCase()==="unique"),this.table.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.table.indexes.push(...t.body.body.map(n=>{const s={columns:[]},r=n;s.token=g(r);const i=[r.callee,...r.args];if(R(i)instanceof D){const a=M(i.pop()).getValue();s.pk=!!a[E.PK]?.length,s.unique=!!a[E.Unique]?.length,s.name=B(a[E.Name]?.at(0)?.value).unwrap_or(void 0);const o=a[E.Note]?.at(0);s.note=o&&{value:B(o.value).unwrap(),token:g(o)},s.type=j(a[E.Type]?.at(0)?.value).unwrap_or(void 0)}return i.flatMap(a=>{if(!(a instanceof H))return a;const o=[];for(;a instanceof H;)o.push(a.argumentList),a=a.callee;return o.push(a),o}).forEach(a=>{const{functional:o,nonFunctional:h}=ct(a).unwrap();s.columns.push(...o.map(f=>({value:f.value.value,type:"expression",token:g(f)})),...h.map(f=>({value:W(f).unwrap(),type:"column",token:g(f)})))}),s})),[]}interpretChecks(t){return this.table.checks.push(...t.body.body.map(n=>{const s={},r=n;if(s.token=g(r),r.args[0]instanceof D){const i=M(r.args[0]).getValue();s.name=B(i[E.Name]?.at(0)?.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}registerInlineRefToEnv(t,n,s,r){const i=ks(t.symbol,n);if(this.env.refIds[i])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",r),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[i])];const a=xs(s.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:s.token,endpoints:[{...s,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[j(t.callee).unwrap()],token:g(t),relation:a[0]}]}),[]}}class Yl{constructor(t,n){this.declarationNode=t,this.env=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=g(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n}=De(t);return this.note.name=n,[]}interpretSettingList(t){const n=M(t).getValue();return this.note.headerColor=n.headercolor?.length?tt(n.headercolor?.at(0)?.value):void 0,[]}interpretBody(t){const[n,s]=te(t.body,r=>r instanceof L);return n.length!==1||s.length>0?[new c(l.INVALID_NOTE,"Invalid note syntax",t)]:[...this.interpretNote(n[0])]}interpretNote(t){const n=cs(t,"callee.expression.literal.value","");return this.note.content=ie(n),[]}}class Ms{constructor(t,n){this.declarationNode=t,this.env=n,this.container=this.declarationNode.parent instanceof y?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=g(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const n=[],s=Y(this.declarationNode.name).unwrap_or([]);return this.ref.name=s.pop()||null,s.length>1&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name)),this.ref.schemaName=s.join(".")||null,n}interpretBody(t){return t instanceof L?this.interpretField(t):this.interpretField(t.body[0])}interpretField(t){const n=t.callee.op.value,{leftExpression:s,rightExpression:r}=t.callee,i=ut(s),a=ut(r);if(Zt(i,a))return[new c(l.SAME_ENDPOINT,"Two endpoints are the same",t)];const o=ks(i,a);if(this.env.refIds[o])return[new c(l.CIRCULAR_REF,"References with same endpoints exist",this.declarationNode),new c(l.CIRCULAR_REF,"References with same endpoints exist",this.env.refIds[o])];if(t.args[0]){const f=M(t.args[0]).getValue(),u=f.delete?.at(0)?.value;this.ref.onDelete=u instanceof ne?Fe(u).unwrap_or(void 0):j(u).unwrap_or(void 0);const d=f.update?.at(0)?.value;this.ref.onUpdate=d instanceof ne?Fe(d).unwrap_or(void 0):j(d).unwrap_or(void 0),this.ref.color=f.color?.length?tt(f.color?.at(0)?.value):void 0}const h=xs(n);return this.ref.endpoints=[{...Cn(s,this.container),relation:h[0],token:g(s)},{...Cn(r,this.container),relation:h[1],token:g(r)}],this.env.refIds[o]=this.declarationNode,[]}}class Fs{constructor(t,n){this.declarationNode=t,this.env=n,this.tableGroup={tables:[]}}interpret(){const t=[];return this.tableGroup.token=g(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),t.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),t}interpretName(t){const n=[],{name:s,schemaName:r}=De(t);return r.length>=2&&(this.tableGroup.name=s,this.tableGroup.schemaName=r.join("."),n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",this.declarationNode.name))),this.tableGroup.name=s,this.tableGroup.schemaName=r[0]||null,n}interpretBody(t){const[n,s]=te(t.body,r=>r instanceof L);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{switch(n.type?.value.toLowerCase()){case"note":this.tableGroup.note={value:B(n.body instanceof le?n.body.body[0].callee:n.body.callee).map(ie).unwrap(),token:g(n)};break}return[]})}interpretFields(t){const n=[];return this.tableGroup.tables=t.map(s=>{const r=Y(s.callee).unwrap();r.length>2&&n.push(new c(l.UNSUPPORTED,"Nested schema is not supported",s));const i=ge(s.callee).unwrap().pop().referee.id;if(this.env.groupOfTable[i]){const a=this.env.groupOfTable[i],{schemaName:o,name:h}=this.env.tableGroups.get(a),f=o?`${o}.${h}`:h;n.push(new c(l.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r.join(".")}" already appears in group "${f}"`,s))}else this.env.groupOfTable[i]=this.declarationNode;return{name:r.pop(),schemaName:r.join(".")}}),n}interpretSettingList(t){const n=M(t).getValue();this.tableGroup.color=n.color?.length?tt(n.color?.at(0)?.value):void 0;const[s]=n.note||[];return this.tableGroup.note=s&&{value:B(s?.value).map(ie).unwrap(),token:g(s)},[]}}class Bs{constructor(t,n){this.declarationNode=t,this.env=n,this.enum={values:[]}}interpret(){return this.enum.token=g(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){const{name:n,schemaName:s}=De(t);return s.length>1?(this.enum.name=n,this.enum.schemaName=s.join("."),[new c(l.UNSUPPORTED,"Nested schema is not supported",t)]):(this.enum.name=n,this.enum.schemaName=s.length?s[0]:null,[])}interpretBody(t){return t.body.flatMap(n=>{const s=n,r={};r.token=g(s),r.name=j(s.callee).unwrap();const a=M(s.args[0]).getValue().note?.at(0);return r.note=a&&{value:B(a.value).map(ie).unwrap(),token:g(a)},this.enum.values.push(r),[]})}}class Cs{constructor(t,n){this.declarationNode=t,this.env=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=g(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);const t=[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:n,token:s})=>({value:n,type:"column",token:s})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1}},pk:!0}),this.pkColumns.forEach(n=>{n.pk=!1})),t}interpretName(t){const{name:n}=De(t);return this.tablePartial.name=n,[]}interpretSettingList(t){const n=M(t).getValue(),s=Fo(n[E.HeaderColor]);this.tablePartial.headerColor=s?tt(s.value):void 0;const[r]=n[E.Note]||[];return this.tablePartial.note=r&&{value:B(r?.value).map(ie).unwrap(),token:g(r)},[]}interpretBody(t){const[n,s]=te(t.body,r=>r instanceof L);return[...this.interpretFields(n),...this.interpretSubElements(s)]}interpretSubElements(t){return t.flatMap(n=>{switch(n.type?.value.toLowerCase()){case b.Note:return this.tablePartial.note={value:B(n.body instanceof le?n.body.body[0].callee:n.body.callee).map(ie).unwrap(),token:g(n)},[];case b.Indexes:return this.interpretIndexes(n);case b.Check:return this.interpretChecks(n);default:return[]}})}interpretFields(t){return t.flatMap(n=>this.interpretColumn(n))}interpretColumn(t){const n=[],s={};s.name=W(t.callee).unwrap();const r=Rs(t.args[0]);s.type=r.getValue(),n.push(...r.getErrors()),s.token=g(t),s.inline_refs=[];const i=t.args.slice(1);if(R(i)instanceof D){const a=M(i.pop()).getValue();s.pk=!!a[E.PK]?.length||!!a[E.PrimaryKey]?.length,s.increment=!!a[E.Increment]?.length,s.unique=!!a[E.Unique]?.length,s.not_null=a[E.NotNull]?.length?!0:a[E.Null]?.length?!1:void 0,s.dbdefault=Ds(a[E.Default]?.at(0)?.value);const o=a[E.Note]?.at(0);s.note=o&&{value:B(o.value).map(ie).unwrap(),token:g(o)};const h=a[E.Ref]||[];s.inline_refs=h.flatMap(u=>{const[d]=ut(u.value.expression);if(Zt(d,t.symbol))return n.push(new c(l.SAME_ENDPOINT,"Two endpoints are the same",u)),[];const I=u.value.op,_=Y(u.value.expression).unwrap();let v;if(_.length===2){const[w,k]=_;v={schemaName:null,tableName:w,fieldNames:[k],relation:I.value,token:g(u)}}else if(_.length===3){const[w,k,V]=_;v={schemaName:w,tableName:k,fieldNames:[V],relation:I.value,token:g(u)}}else{n.push(new c(l.UNSUPPORTED,"Unsupported",u));const w=_.pop(),k=_.pop();v={schemaName:_.join("."),tableName:k,fieldNames:[w],relation:I.value,token:g(u)}}return v});const f=a[E.Check]||[];s.checks=f.map(u=>{const d=g(u),I=u.value.value.value;return{token:d,expression:I}})}return s.pk||=i.some(a=>j(a).unwrap().toLowerCase()==="pk"),s.unique||=i.some(a=>j(a).unwrap().toLowerCase()==="unique"),this.tablePartial.fields.push(s),s.pk&&this.pkColumns.push(s),n}interpretIndexes(t){return this.tablePartial.indexes.push(...t.body.body.map(n=>{const s={columns:[]},r=n;s.token=g(r);const i=[r.callee,...r.args];if(R(i)instanceof D){const a=M(i.pop()).getValue();s.pk=!!a[E.PK]?.length,s.unique=!!a[E.Unique]?.length,s.name=B(a[E.Name]?.at(0)?.value).unwrap_or(void 0);const o=a[E.Note]?.at(0);s.note=o&&{value:B(o.value).unwrap(),token:g(o)},s.type=j(a[E.Type]?.at(0)?.value).unwrap_or(void 0)}return i.flatMap(a=>{if(!(a instanceof H))return a;const o=[];let h=a;for(;h instanceof H;)o.push(h.argumentList),h=h.callee;return o.push(h),o}).forEach(a=>{const{functional:o,nonFunctional:h}=ct(a).unwrap();s.columns.push(...o.map(f=>({value:f.value.value,type:"expression",token:g(f)})),...h.map(f=>({value:W(f).unwrap(),type:"column",token:g(f)})))}),s})),[]}interpretChecks(t){return this.tablePartial.checks.push(...t.body.body.map(n=>{const s={},r=n;if(s.token=g(r),r.args[0]instanceof D){const i=M(r.args[0]).getValue();s.name=B(i[E.Name]?.at(0)?.value).unwrap_or(void 0)}return s.expression=r.callee.value.value,s})),[]}}class Ql{constructor(t,n){this.declarationNode=t,this.env=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=g(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(t){if(!t)return this.project.name=null,[];const{name:n}=De(t);return this.project.name=n,[]}interpretBody(t){return t.body.flatMap(n=>{const s=n;switch(s.type?.value.toLowerCase()){case"table":{const r=new Us(s,this.env).interpret();return this.project.tables.push(this.env.tables.get(s)),r}case"ref":{const r=new Ms(s,this.env).interpret();return this.project.refs.push(this.env.ref.get(s)),r}case"tablegroup":{const r=new Fs(s,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(s)),r}case"enum":{const r=new Bs(s,this.env).interpret();return this.project.enums.push(this.env.enums.get(s)),r}case"note":return this.project.note={value:B(s.body instanceof le?s.body.body[0].callee:s.body.callee).map(ie).unwrap(),token:g(s)},[];case"tablepartial":{const r=new Cs(s,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(s)),r}default:return this.project[s.type.value.toLowerCase()]=B(s.body.callee).unwrap(),[]}})}}function Jl(e){return{schemas:[],tables:Array.from(e.tables.values()),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values())}}class Zl{constructor(t){this.ast=t,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableGroups:new Map,groupOfTable:{},aliases:[],project:new Map,tablePartials:new Map}}interpret(){const t=this.ast.body.flatMap(n=>{switch(ye(n).unwrap_or(void 0)){case b.Table:return new Us(n,this.env).interpret();case b.Note:return new Yl(n,this.env).interpret();case b.Ref:return new Ms(n,this.env).interpret();case b.TableGroup:return new Fs(n,this.env).interpret();case b.TablePartial:return new Cs(n,this.env).interpret();case b.Enum:return new Bs(n,this.env).interpret();case b.Project:return new Ql(n,this.env).interpret();default:return[]}});return new J(Jl(this.env),t)}}var S=(e=>(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))(S||{}),U=(e=>(e[e.None=0]="None",e[e.KeepWhitespace=1]="KeepWhitespace",e[e.InsertAsSnippet=4]="InsertAsSnippet",e))(U||{});function Je(e){switch(e){case T.Schema:return S.Module;case T.Table:case T.TablePartial:return S.Class;case T.Column:case T.TableGroupField:return S.Field;case T.Enum:return S.Enum;case T.EnumField:return S.EnumMember;case T.TableGroup:return S.Struct;default:return S.Text}}function ht(e,t){if(!e||Rt(e))return!1;for(const n of e.trailingTrivia){if(n.start>t)break;if(n.kind===p.NEWLINE&&n.end<=t)return!1}return!0}function G(){return{suggestions:[]}}function ft(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:` ${t.insertText}`}))}}function Lt(e){return{...e,suggestions:e.suggestions.map(t=>({...t,insertText:!t.insertText||!t.insertText.split("").every(Ze)?`"${t.insertText??""}"`:t.insertText}))}}function en(e,t){return e.getOffsetAt(t)}class Vs{constructor(t,n=[]){this.compiler=t,this.triggerCharacters=n}provideCompletionItems(t,n){const s=en(t,n),r=this.compiler.token.flatStream(),{token:i,index:a}=this.compiler.container.token(s),o=a===void 0?r[0]:r[a+1];if([...i?.trailingTrivia||[],...i?.leadingTrivia||[],...o?.leadingTrivia||[]].find(u=>$o(u)&&Ke(s,u)))return G();if(a===void 0)return jn();if([p.STRING_LITERAL,p.QUOTED_STRING].includes(i.kind)&&Ke(s,i))return G();const h=this.compiler.container.element(s);if(this.compiler.container.scopeKind(s)===A.TOPLEVEL||h instanceof y&&h.type&&h.type.start<=s&&h.type.end>=s)return jn();const f=[...this.compiler.container.stack(s)].reverse();for(const u of f)if(u instanceof Z)switch(u.op?.value){case">":case"<":case"<>":case"-":return Vn(this.compiler,s,u)}else if(u instanceof fe)switch(u.op?.value){case">":case"<":case"<>":case"-":return Vn(this.compiler,s,u);case".":return Gs(this.compiler,s,u)}else{if(u instanceof se)return Gn(this.compiler,s,u);if(u instanceof D)return Gn(this.compiler,s,u);if(u instanceof pe)return tc(this.compiler,s);if(u instanceof Le)return ec(this.compiler,s);if(u instanceof L)return Xn(this.compiler,s,u);if(u instanceof y&&(u.bodyColon&&s>=u.bodyColon.end||u.body&&Ke(s,u.body)))return Xn(this.compiler,s,void 0)}return G()}}function ec(e,t){const n=e.container.element(t);return Xe(e,t,n,[T.TablePartial])}function Vn(e,t,n){const s=e.container.scopeKind(t);if([A.REF,A.TABLE,A.TABLEPARTIAL].includes(s)){const r=Xe(e,t,e.container.element(t),[T.Table,T.Schema,T.Column]);return ht(n.op,t)?ft(r):r}return G()}function Xe(e,t,n,s){if(n===void 0)return G();let r=n;const i={suggestions:[]};for(;r;){if(r?.symbol?.symbolTable){const{symbol:a}=r;i.suggestions.push(...e.symbol.members(a).filter(({kind:o})=>s.includes(o)).map(({name:o,kind:h})=>({label:o,insertText:o,insertTextRules:U.KeepWhitespace,kind:Je(h),sortText:Je(h).toString().padStart(2,"0"),range:void 0})))}r=r instanceof y?r.parent:void 0}return Lt(i)}function tc(e,t){switch(e.container.scopeKind(t)){case A.INDEXES:return Xs(e,t);case A.REF:{const s=[...e.container.stack(t)];for(;s.length>0;){const r=s.pop();if(r instanceof fe&&r.op?.value===".")return Gs(e,t,r)}}return $s(e,t)}return G()}function Gn(e,t,n){const{token:s}=e.container.token(t);if([p.COMMA,p.LBRACKET].includes(s?.kind)){const r=$n(e,t);return s?.kind===p.COMMA&&ht(s,t)?ft(r):r}if(n.name&&n.name.start<=t&&n.name.end>=t)return $n(e,t);if(n.name instanceof ne){const r=nc(e,t,Fe(n.name).unwrap_or(""));return s?.kind===p.COLON&&ht(s,t)?ft(r):r}return G()}function $n(e,t){const n=e.container.element(t);if(n instanceof K)return G();const s=e.container.scopeKind(t);if(n.body&&!Ke(t,n.body)){let r;switch(s){case A.TABLE:case A.TABLEPARTIAL:r=[E.HeaderColor,E.Note];break;case A.TABLEGROUP:r=[E.Color,E.Note];break;default:r=[]}return{suggestions:r.map(i=>({label:i,insertText:`${i}: `,kind:S.Field,insertTextRules:U.KeepWhitespace,range:void 0}))}}switch(s){case A.TABLE:case A.TABLEPARTIAL:return{suggestions:[...[E.PK,E.PrimaryKey,E.Null,E.NotNull,E.Increment,E.Unique].map(r=>({label:r,insertText:r,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0})),...[E.Ref,E.Default,E.Note,E.Check].map(r=>({label:r,insertText:`${r}: `,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case A.ENUM:return{suggestions:[...[E.Note].map(r=>({label:r,insertText:`${r}: `,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case A.INDEXES:return{suggestions:[...[E.Unique,E.PK].map(r=>({label:r,insertText:r,insertTextRules:U.KeepWhitespace,kind:S.Property,range:void 0})),...[E.Note,E.Name,E.Type].map(r=>({label:r,insertText:`${r}: `,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0}))]};case A.REF:return{suggestions:[E.Update,E.Delete,E.Color].map(r=>({label:r,insertText:`${r}: `,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0}))};case A.CHECKS:return{suggestions:[E.Name].map(r=>({label:r,insertText:`${r}: `,kind:S.Property,insertTextRules:U.KeepWhitespace,range:void 0}))}}return G()}function nc(e,t,n){switch(n?.toLowerCase()){case"update":case"delete":return{suggestions:["cascade","set default","set null","restrict"].map(s=>({label:s,insertText:s,kind:S.Value,insertTextRules:U.KeepWhitespace,range:void 0}))};case"type":return{suggestions:["btree","hash"].map(s=>({label:s,insertText:`${s}`,kind:S.Value,insertTextRules:U.KeepWhitespace,range:void 0}))};case"default":return Xe(e,t,e.container.element(t),[T.Schema,T.Enum])}return G()}function Gs(e,t,n){const s=ge(n).unwrap_or([]);if(s.pop(),s.some(i=>!C(i)))return G();const r=s.map(i=>j(i).unwrap());return Lt({suggestions:e.symbol.ofName(r,e.container.element(t)).flatMap(({symbol:i})=>e.symbol.members(i)).map(({kind:i,name:a})=>({label:a,insertText:a,kind:Je(i),range:void 0}))})}function Xn(e,t,n){switch(e.container.scopeKind(t)){case A.TABLE:case A.TABLEPARTIAL:return rc(e,t,n);case A.PROJECT:return ic(e,t,n);case A.INDEXES:return oc(e,t);case A.ENUM:return sc(e,t,n);case A.REF:{const r=$s(e,t);return e.container.token(t).token?.kind===p.COLON&&ht(e.container.token(t).token,t)?ft(r):r}case A.TABLEGROUP:return ac(e);default:return G()}}function jn(){return{suggestions:["Table","TableGroup","Enum","Project","Ref","TablePartial"].map(e=>({label:e,insertText:e,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))}}function sc(e,t,n){return n?.callee&&tn(t,n)===1?Xe(e,t,e.container.element(t),[T.Schema,T.Table,T.Column]):G()}function rc(e,t,n){const s=["Note","indexes","checks"];if(!n?.callee)return{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))};const r=tn(t,n);return r===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))}:r===1?lc(e,t):G()}function ic(e,t,n){const s=["Table","TableGroup","Enum","Note","Ref","TablePartial"];return n?.callee?tn(t,n)===0?{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))}:G():{suggestions:s.map(i=>({label:i,insertText:i,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))}}function $s(e,t){return Xe(e,t,e.container.element(t),[T.Schema,T.Table,T.Column])}function ac(e){return{suggestions:[...Lt({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([t])=>{const n=re(t).unwrap_or(void 0);if(n===void 0)return[];const{kind:s,name:r}=n;return s!==T.Table&&s!==T.Schema?[]:{label:r,insertText:r,insertTextRules:U.KeepWhitespace,kind:Je(s),range:void 0}})}).suggestions,...["Note"].map(t=>({label:t,insertText:t,insertTextRules:U.KeepWhitespace,kind:S.Keyword,range:void 0}))]}}function oc(e,t){return Xs(e,t)}function lc(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"].map(n=>({label:n,insertText:n,insertTextRules:U.KeepWhitespace,kind:S.TypeParameter,sortText:S.TypeParameter.toString().padStart(2,"0"),range:void 0})),...Xe(e,t,e.container.element(t),[T.Enum,T.Schema]).suggestions]}}function Xs(e,t){const s=e.container.element(t)?.parent;if(!(s?.symbol instanceof lt))return G();const{symbolTable:r}=s.symbol;return Lt({suggestions:[...r.entries()].flatMap(([i])=>{const a=re(i).unwrap_or(void 0);if(a===void 0)return[];const{name:o}=a;return{label:o,insertText:o,insertTextRules:U.KeepWhitespace,kind:Je(T.Column),range:void 0}})})}function tn(e,t){if(!t.callee)return-1;const n=[t.callee,...t.args],s=n.findIndex(r=>e<=r.end);return s===-1?n.length:s}class js{constructor(t){this.compiler=t}provideDefinition(t,n){const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const a=i.pop();if(!a?.referee)continue;let o;if(a.referee?.declaration&&[Ae.PRIMARY_EXPRESSION,Ae.VARIABLE,Ae.PARTIAL_INJECTION].includes(a?.kind)?{declaration:o}=a.referee:a.referee?.injectorDeclaration&&(o=a.referee.injectorDeclaration),o){const{startPos:h,endPos:f}=o;return[{range:{startColumn:h.column+1,startLineNumber:h.line+1,endColumn:f.column+1,endLineNumber:f.line+1},uri:s}]}}return[]}}class Ws{constructor(t){this.compiler=t}provideReferences(t,n){const{uri:s}=t,r=en(t,n),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){const a=i.pop();if(a&&[Ae.ELEMENT_DECLARATION,Ae.FUNCTION_APPLICATION,Ae.PRIMARY_EXPRESSION].includes(a?.kind)){const{symbol:o}=a;if(o?.references.length)return o.references.map(({startPos:h,endPos:f})=>({range:{startColumn:h.column+1,startLineNumber:h.line+1,endColumn:f.column+1,endLineNumber:f.line+1},uri:s}))}}return[]}}const cc=Object.freeze(Object.defineProperty({__proto__:null,CompletionItemInsertTextRule:U,CompletionItemKind:S,DBMLCompletionItemProvider:Vs,DBMLDefinitionProvider:js,DBMLReferencesProvider:Ws},Symbol.toStringTag,{value:"Module"}));function uc(){return this.parse._().getValue().ast}function hc(){return this.parse._().getErrors()}function fc(){return this.parse._().getValue().tokens}function pc(){return this.parse._().getValue().rawDb}function dc(){return this.parse._().getValue().ast.symbol.symbolTable}function Ec(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Nc(){return this.parse.tokens().filter(Bt)}function Tc(e){return e.symbolTable?[...e.symbolTable.entries()].map(([t,n])=>({...re(t).unwrap(),symbol:n})):[]}function mc(e,t){if(e.length===0)return[];const n=[];for(let s=t;s;s=s instanceof y?s.parent:void 0){if(!s.symbol?.symbolTable)continue;const{symbolTable:r}=s.symbol;let i=[r],a=[];for(const o of e)a=i.flatMap(h=>Ul(o).flatMap(f=>{const u=h.get(f),d=re(f).unwrap_or(void 0);return!u||!d?[]:{...d,symbol:u}})),i=a.flatMap(h=>h.symbol.symbolTable?h.symbol.symbolTable:[]);n.push(...a)}return n}function bc(e,t){return`${e.join(".")}@${t.id}`}function Ic(e){const t=this.token.flatStream(),{index:n,token:s}=this.container.token(e),r=n===void 0?-1:Mo(t,h=>!h.isInvalid,n);if(r===-1)return[this.parse.ast()];const i=t[r].start;let a=this.parse.ast();const o=[a];for(;;){const f=rl(a).find(u=>Ke(i,u));if(f===void 0||f instanceof z)break;o.push(f),a=f}if(s?.kind===p.COLON)return o;for(;o.length>0;){let h=!1;const f=R(o);if(f instanceof L){const u=this.parse.source();for(let d=f.end;d<e;d+=1)u[d]===`
|
|
12
|
+
`&&(o.pop(),h=!0)}else f instanceof Z||f instanceof fe?this.container.token(e).token!==f.op&&(o.pop(),h=!0):f instanceof D?f.listCloseBracket&&f.end<=e&&(o.pop(),h=!0):f instanceof pe?f.tupleCloseParen&&f.end<=e&&(o.pop(),h=!0):f instanceof le?f.blockCloseBrace&&f.end<=e&&(o.pop(),h=!0):f instanceof ne||f.end<e&&(o.pop(),h=!0);if(h){const u=R(o);u instanceof y&&u.end<=e&&o.pop()}if(!h)break}return o}function gc(e){const t=this.token.flatStream().findIndex(n=>n.start>=e);return t===void 0?{token:void 0,index:void 0}:t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function _c(e){const t=this.container.stack(e);for(let n=t.length-1;n>=0;n-=1)if(t[n]instanceof y)return t[n];return this.parse.ast()}function Ac(e){return this.container.element(e)?.symbol?.symbolTable}var A=(e=>(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))(A||{});function Lc(e){const t=this.container.element(e);if(t instanceof K)return A.TOPLEVEL;switch(t.type?.value.toLowerCase()){case"table":return A.TABLE;case"enum":return A.ENUM;case"ref":return A.REF;case"tablegroup":return A.TABLEGROUP;case"indexes":return A.INDEXES;case"note":return A.NOTE;case"project":return A.PROJECT;case"tablepartial":return A.TABLEPARTIAL;case"checks":return A.CHECKS;default:return A.CUSTOM}}function Hs(e,t){const n=[...t].sort((r,i)=>i.start-r.start);let s=e;for(const{start:r,end:i,newText:a}of n)s=s.substring(0,r)+a+s.substring(i);return s}function Re(e){return e.startsWith('"')&&e.endsWith('"')&&e.length>=2?e.slice(1,-1):e}function Wn(e){if(typeof e!="string")return{schema:e.schema??Te,table:e.table};const t=e.split(".");if(t.length===1)return{schema:Te,table:Re(t[0])};if(t.length===2)return{schema:Re(t[0]),table:Re(t[1])};const n=t.pop();return{schema:Re(t.join(".")),table:Re(n)}}function Hn(e){return e?e.split("").every(t=>Ze(t)||Me(t))&&!Me(e[0]):!1}function vc(e,t){if(!e.declaration)return!1;const n=e.declaration;if(!n.name)return!1;const s=n.name;return t.substring(s.start,s.end).includes('"')}function yc(e,t,n){const s=!Hn(t),r=!Hn(e),i=n||s,a=n||r;return{schema:e,table:t,formattedSchema:a?`"${e}"`:e,formattedTable:i?`"${t}"`:t,shouldQuoteSchema:a,shouldQuoteTable:i}}function wc(e,t,n){const s=Be(n);if(t===Te){const o=e.get(s);return o instanceof lt?o:null}const r=et(t),i=e.get(r);if(!i||!i.symbolTable)return null;const a=i.symbolTable.get(s);return a instanceof lt?a:null}function Sc(e,t,n,s,r){const i=Be(r);let a;if(s===Te)a=e.get(i);else{const o=et(s),h=e.get(o);if(!h||!h.symbolTable)return!1;a=h.symbolTable.get(i)}return!(!a||t===s&&n===r)}function Pc(e,t,n){let s=e.start-1;for(;s>=0&&/\s/.test(n[s]);)s--;if(s<0||n[s]!==".")return null;for(s--;s>=0&&/\s/.test(n[s]);)s--;if(s<0)return null;let r,i;if(n[s]==='"'){for(i=s+1,s--;s>=0&&n[s]!=='"';)s--;if(s<0)return null;r=s}else{for(i=s+1;s>=0&&/[a-zA-Z0-9_]/.test(n[s]);)s--;r=s+1}const a=n.substring(r,i);return Re(a)===t?{start:r,end:e.end}:null}function Oc(e,t,n,s){const r=[],i=new Set;for(const a of e){const h=Pc(a,t,s)??{start:a.start,end:a.end},f=`${h.start}-${h.end}`;if(i.has(f))continue;i.add(f);const u=n.schema!==Te?`${n.formattedSchema}.${n.formattedTable}`:n.formattedTable;r.push({start:h.start,end:h.end,newText:u})}return r}function xc(e,t){const n=this.parse.source(),s=this.parse.publicSymbolTable(),r=Wn(e),i=Wn(t),a=r.schema,o=r.table,h=i.schema,f=i.table,u=wc(s,a,o);if(!u||Sc(s,a,o,h,f))return n;const d=vc(u,n),I=yc(h,f,d),_=[];if(u.declaration){const w=u.declaration;w.name&&_.push(w.name)}for(const w of u.references)n.substring(w.start,w.end).replace(/"/g,"")===o&&_.push(w);const v=Oc(_,a,I,n);return Hs(n,v)}class kc{constructor(){this.source="",this.cache=new Map,this.nodeIdGenerator=new Xo,this.symbolIdGenerator=new Wo,this.token={invalidStream:this.query(Nc),flatStream:this.query(Ec)},this.parse={source:()=>this.source,_:this.query(this.interpret),ast:this.query(uc),errors:this.query(hc),tokens:this.query(fc),rawDb:this.query(pc),publicSymbolTable:this.query(dc)},this.container={stack:this.query(Ic),token:this.query(gc),element:this.query(_c),scope:this.query(Ac),scopeKind:this.query(Lc)},this.symbol={ofName:this.query(mc,bc),members:this.query(Tc)}}setSource(t){this.source=t,this.cache.clear(),this.nodeIdGenerator.reset(),this.symbolIdGenerator.reset()}query(t,n){const s=Symbol();return(...r)=>{if(r.length===0){if(this.cache.has(s))return this.cache.get(s);const h=t.apply(this,r);return this.cache.set(s,h),h}const i=n?n(...r):r[0];let a=this.cache.get(s);if(a instanceof Map&&a.has(i))return a.get(i);const o=t.apply(this,r);return a instanceof Map||(a=new Map,this.cache.set(s,a)),a.set(i,o),o}}interpret(){const t=new il(this.source).lex().chain(n=>new ll(n,this.nodeIdGenerator).parse()).chain(({ast:n,tokens:s})=>new zl(n,this.symbolIdGenerator).analyze().map(()=>({ast:n,tokens:s})));return t.getErrors().length>0?t:t.chain(({ast:n,tokens:s})=>new Zl(n).interpret().map(r=>({ast:n,tokens:s,rawDb:r})))}renameTable(t,n){return xc.call(this,t,n)}applyTextEdits(t){return Hs(this.parse.source(),t)}initMonacoServices(){return{definitionProvider:new js(this),referenceProvider:new Ws(this),autocompletionProvider:new Vs(this)}}}exports.CompileError=c;exports.CompileErrorCode=l;exports.Compiler=kc;exports.ElementDeclarationNode=y;exports.ElementKind=b;exports.ProgramNode=K;exports.ScopeKind=A;exports.SyntaxNode=x;exports.SyntaxNodeKind=Ae;exports.SyntaxToken=z;exports.SyntaxTokenKind=p;exports.addQuoteIfNeeded=el;exports.serialize=jo;exports.services=cc;
|