From fb3ee0e4fe7c65d2635752c3c70f8f7ccc7cb333 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Sat, 23 Nov 2024 23:46:30 -0600 Subject: [PATCH] deploy --- .github/workflows/deploy.yml | 40 +++ priv/static/squared_away.min.mjs | 16 ++ priv/static/squared_away.mjs | 266 +++++++++++++----- src/squared_away.gleam | 2 +- src/squared_away/squared_away_lang.gleam | 47 +++- .../typechecker/typed_expr.gleam | 23 +- 6 files changed, 288 insertions(+), 106 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 priv/static/squared_away.min.mjs diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..6426ad8 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,40 @@ +name: Deploy to Cloudflare Pages + +on: + push: + branches: + - main + +jobs: + deploy: + name: Deploy to Cloudflare Pages + runs-on: ubuntu-latest + permissions: + contents: read + deployments: write + steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Set up Gleam + uses: erlef/setup-beam@v1 + with: + otp-version: "27.0" + gleam-version: "1.5.1" + rebar3-version: "3" + - name: Install dependencies + run: gleam deps download + - name: Build app + run: gleam run -m lustre/dev build app --minify + - name: Copy output to dist + run: | + mkdir -p dist + cp index.html dist/index.html + cp -r priv dist/priv + - name: Update path in index.html to use minified app + run: sed -i 's|priv/static/squared_away.mjs|priv/static/squared_away.min.mjs|' dist/index.html + - name: Deploy with Wrangler + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: pages deploy dist --project-name squared-away \ No newline at end of file diff --git a/priv/static/squared_away.min.mjs b/priv/static/squared_away.min.mjs new file mode 100644 index 0000000..e8cea41 --- /dev/null +++ b/priv/static/squared_away.min.mjs @@ -0,0 +1,16 @@ +var p=class{withFields(t){let r=Object.keys(this).map(n=>n in t?t[n]:this[n]);return new this.constructor(...r)}},Ae=class{static fromArray(t,r){let n=r||new si;for(let i=t.length-1;i>=0;--i)n=new mn(t[i],n);return n}[Symbol.iterator](){return new gs(this)}toArray(){return[...this]}atLeastLength(t){for(let r of this){if(t<=0)return!0;t--}return t<=0}hasLength(t){for(let r of this){if(t<=0)return!1;t--}return t===0}countLength(){let t=0;for(let r of this)t++;return t}};function m(e,t){return new mn(e,t)}function d(e,t){return Ae.fromArray(e,t)}var gs=class{#e;constructor(t){this.#e=t}next(){if(this.#e instanceof si)return{done:!0};{let{head:t,tail:r}=this.#e;return this.#e=r,{value:t,done:!1}}}},si=class extends Ae{},mn=class extends Ae{constructor(t,r){super(),this.head=t,this.tail=r}},wr=class e{constructor(t){if(!(t instanceof Uint8Array))throw"BitArray can only be constructed from a Uint8Array";this.buffer=t}get length(){return this.buffer.length}byteAt(t){return this.buffer[t]}floatFromSlice(t,r,n){return Xu(this.buffer,t,r,n)}intFromSlice(t,r,n,i){return Vu(this.buffer,t,r,n,i)}binaryFromSlice(t,r){return new e(this.buffer.slice(t,r))}sliceAfter(t){return new e(this.buffer.slice(t))}},li=class{constructor(t){this.value=t}};function Vu(e,t,r,n,i){let s=0;if(n)for(let o=t;o=t;o--)s=s*256+e[o];if(i){let l=2**((r-t)*8-1);s>=l&&(s-=l*2)}return s}function Xu(e,t,r,n){let i=new DataView(e.buffer),s=r-t;if(s===8)return i.getFloat64(t,!n);if(s===4)return i.getFloat32(t,!n);{let o=`Sized floats must be 32-bit or 64-bit on JavaScript, got size of ${s*8} bits`;throw new globalThis.Error(o)}}var hr=class e extends p{static isResult(t){return t instanceof e}},f=class extends hr{constructor(t){super(),this[0]=t}isOk(){return!0}},_=class extends hr{constructor(t){super(),this[0]=t}isOk(){return!1}};function g(e,t){let r=[e,t];for(;r.length;){let n=r.pop(),i=r.pop();if(n===i)continue;if(!ql(n)||!ql(i)||!ia(n,i)||Zu(n,i)||Qu(n,i)||ea(n,i)||ta(n,i)||ra(n,i)||na(n,i))return!1;let o=Object.getPrototypeOf(n);if(o!==null&&typeof o.equals=="function")try{if(n.equals(i))continue;return!1}catch{}let[l,u]=Ku(n);for(let a of l(n))r.push(u(n,a),u(i,a))}return!0}function Ku(e){if(e instanceof Map)return[t=>t.keys(),(t,r)=>t.get(r)];{let t=e instanceof globalThis.Error?["message"]:[];return[r=>[...t,...Object.keys(r)],(r,n)=>r[n]]}}function Zu(e,t){return e instanceof Date&&(e>t||er===t[n]))}function ea(e,t){return Array.isArray(e)&&e.length!==t.length}function ta(e,t){return e instanceof Map&&e.size!==t.size}function ra(e,t){return e instanceof Set&&(e.size!=t.size||[...e].some(r=>!t.has(r)))}function na(e,t){return e instanceof RegExp&&(e.source!==t.source||e.flags!==t.flags)}function ql(e){return typeof e=="object"&&e!==null}function ia(e,t){return typeof e!="object"&&typeof t!="object"&&(!e||!t)||[Promise,WeakSet,WeakMap,Function].some(n=>e instanceof n)?!1:e.constructor===t.constructor}function oi(e,t){return Math.trunc(ui(e,t))}function ui(e,t){return t===0?0:e/t}function G(e,t,r,n,i,s){let o=new globalThis.Error(i);o.gleam_error=e,o.module=t,o.line=r,o.function=n,o.fn=n;for(let l in s)o[l]=s[l];return o}var Q=class extends p{},X=class extends p{},le=class extends p{};var N=class extends p{constructor(t){super(),this[0]=t}},E=class extends p{};function Sl(e,t){if(e instanceof N){let r=e[0];return new f(r)}else return new _(t)}function bs(e){if(e.isOk()){let t=e[0];return new N(t)}else return new E}function ks(e,t){if(e instanceof N){let r=e[0];return new N(t(r))}else return new E}function Il(e){return e instanceof N?e[0]:new E}var Fl=new WeakMap,vs=new DataView(new ArrayBuffer(8)),Os=0;function Ts(e){let t=Fl.get(e);if(t!==void 0)return t;let r=Os++;return Os===2147483647&&(Os=0),Fl.set(e,r),r}function Ls(e,t){return e^t+2654435769+(e<<6)+(e>>2)|0}function Bs(e){let t=0,r=e.length;for(let n=0;n>16^t)^r}function sa(e){return Bs(e.toString())}function la(e){let t=Object.getPrototypeOf(e);if(t!==null&&typeof t.hashCode=="function")try{let n=e.hashCode(e);if(typeof n=="number")return n}catch{}if(e instanceof Promise||e instanceof WeakSet||e instanceof WeakMap)return Ts(e);if(e instanceof Date)return Wl(e.getTime());let r=0;if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),Array.isArray(e)||e instanceof Uint8Array)for(let n=0;n{r=r+ze(n)|0});else if(e instanceof Map)e.forEach((n,i)=>{r=r+Ls(ze(n),ze(i))|0});else{let n=Object.keys(e);for(let i=0;i>>t&oa}function fi(e,t){return 1<>1&1431655765,e=(e&858993459)+(e>>2&858993459),e=e+(e>>4)&252645135,e+=e>>8,e+=e>>16,e&127}function js(e,t){return fa(e&t-1)}function Me(e,t,r){let n=e.length,i=new Array(n);for(let s=0;s=ua){let a=new Array(32),c=xn(r,t);a[c]=Ns(Ps,t+st,r,n,i,s);let $=0,x=e.bitmap;for(let w=0;w<32;w++){if(x&1){let h=e.array[$++];a[w]=h}x=x>>>1}return{type:it,size:u+1,array:a}}else{let a=ca(e.array,l,{type:Oe,k:n,v:i});return s.val=!0,{type:qe,bitmap:e.bitmap|o,array:a}}}}function da(e,t,r,n,i,s){if(r===e.hash){let o=As(e,n);if(o!==-1)return e.array[o].v===i?e:{type:Yt,hash:r,array:Me(e.array,o,{type:Oe,k:n,v:i})};let l=e.array.length;return s.val=!0,{type:Yt,hash:r,array:Me(e.array,l,{type:Oe,k:n,v:i})}}return wn({type:qe,bitmap:fi(e.hash,t),array:[e]},t,r,n,i,s)}function As(e,t){let r=e.array.length;for(let n=0;n{r=r.set(i,n)}),r}static new(){return new e(void 0,0)}constructor(t,r){this.root=t,this.size=r}get(t,r){if(this.root===void 0)return r;let n=ai(this.root,0,ze(t),t);return n===void 0?r:n.v}set(t,r){let n={val:!1},i=this.root===void 0?Ps:this.root,s=wn(i,0,ze(t),t,r,n);return s===this.root?this:new e(s,n.val?this.size+1:this.size)}delete(t){if(this.root===void 0)return this;let r=qs(this.root,0,ze(t),t);return r===this.root?this:r===void 0?e.new():new e(r,this.size-1)}has(t){return this.root===void 0?!1:ai(this.root,0,ze(t),t)!==void 0}entries(){if(this.root===void 0)return[];let t=[];return this.forEach((r,n)=>t.push([n,r])),t}forEach(t){zl(this.root,t)}hashCode(){let t=0;return this.forEach((r,n)=>{t=t+Ls(ze(r),ze(n))|0}),t}equals(t){if(!(t instanceof e)||this.size!==t.size)return!1;let r=!0;return this.forEach((n,i)=>{r=r&&g(t.get(i,!n),n)}),r}};var ci=void 0,Ml={};function Gl(e){return/^[-+]?(\d+)$/.test(e)?new f(parseInt(e)):new _(ci)}function Hl(e){return/^[-+]?(\d+)\.(\d+)([eE][-+]?\d+)?$/.test(e)?new f(parseFloat(e)):new _(ci)}function Jl(e){return e.toString()}function Ss(e){let t=e.toString().replace("+","");if(t.indexOf(".")>=0)return t;{let r=t.indexOf("e");return r>=0?t.slice(0,r)+".0"+t.slice(r):t+".0"}}function Is(e,t,r){return typeof e.replaceAll<"u"?e.replaceAll(t,r):e.replace(new RegExp(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),r)}function Yl(e){if(e==="")return 0;let t=Ws(e);if(t){let r=0;for(let n of t)r++;return r}else return e.match(/./gsu).length}function Fs(e){let t=Ws(e);return t?Ae.fromArray(Array.from(t).map(r=>r.segment)):Ae.fromArray(e.match(/./gsu))}var Dl;function Ws(e){if(globalThis.Intl&&Intl.Segmenter)return Dl||=new Intl.Segmenter,Dl.segment(e)[Symbol.iterator]()}function Us(e){return e.toUpperCase()}function Vl(e,t){let r=e[Symbol.iterator](),n=r.next().value||"",i=r.next();for(;!i.done;)n=n+t+i.value,i=r.next();return n}function zs(e){let t="";for(let r of e)t=t+r;return t}function Ms(e,t,r){if(r<=0||t>=e.length)return"";let n=Ws(e);if(n){for(;t-- >0;)n.next();let i="";for(;r-- >0;){let s=n.next().value;if(s===void 0)break;i+=s.segment}return i}else return e.match(/./gsu).slice(t,t+r).join("")}function hn(e,t){return e.indexOf(t)>=0}function Xl(e,t){return e.endsWith(t)}function Kl(e,t){let r=e.indexOf(t);if(r>=0){let n=e.slice(0,r),i=e.slice(r+t.length);return new f([n,i])}else return new _(ci)}var Zl=[" "," ",` +`,"\v","\f","\r","\x85","\u2028","\u2029"].join(""),ya=new RegExp(`^([${Zl}]*)`,"g"),ga=new RegExp(`([${Zl}]*)$`,"g");function Ql(e){return Ds(eo(e))}function Ds(e){return e.replace(ya,"")}function eo(e){return e.replace(ga,"")}function to(e){return Math.ceil(e)}function ro(e,t){return Math.pow(e,t)}function no(){return At.new()}function pi(e){return e.size}function Ve(e){return Ae.fromArray(e.entries())}function io(e,t){return t.delete(e)}function Rs(e,t){let r=e.get(t,Ml);return r===Ml?new _(ci):new f(r)}function so(e,t,r){return r.set(e,t)}function Gs(e){if(typeof e=="string")return"String";if(typeof e=="boolean")return"Bool";if(e instanceof hr)return"Result";if(e instanceof Ae)return"List";if(e instanceof wr)return"BitArray";if(e instanceof At)return"Dict";if(Number.isInteger(e))return"Int";if(Array.isArray(e))return`Tuple of ${e.length} elements`;if(typeof e=="number")return"Float";if(e===null)return"Null";if(e===void 0)return"Nil";{let t=typeof e;return t.charAt(0).toUpperCase()+t.slice(1)}}function di(e,t){return ba(e,Gs(t))}function ba(e,t){return new _(Ae.fromArray([new Vt(e,t,Ae.fromArray([]))]))}function lo(e){return typeof e=="string"?new f(e):di("String",e)}function oo(e){return Number.isInteger(e)?new f(e):di("Int",e)}function uo(e){return typeof e=="boolean"?new f(e):di("Bool",e)}function ao(e,t){let r=()=>di("Dict",e);if(e instanceof At||e instanceof WeakMap||e instanceof Map){let n=Rs(e,t);return new f(n.isOk()?new N(n[0]):new E)}else return e===null?r():Object.getPrototypeOf(e)==Object.prototype?Rl(e,t,()=>new f(new E)):Rl(e,t,r)}function Rl(e,t,r){try{return t in e?new f(new N(e[t])):r()}catch{return r()}}function lt(e){let t=typeof e;if(e===!0)return"True";if(e===!1)return"False";if(e===null)return"//js(null)";if(e===void 0)return"Nil";if(t==="string")return ka(e);if(t==="bigint"||Number.isInteger(e))return e.toString();if(t==="number")return Ss(e);if(Array.isArray(e))return`#(${e.map(lt).join(", ")})`;if(e instanceof Ae)return La(e);if(e instanceof li)return Ba(e);if(e instanceof wr)return Ea(e);if(e instanceof p)return Ta(e);if(e instanceof At)return va(e);if(e instanceof Set)return`//js(Set(${[...e].map(lt).join(", ")}))`;if(e instanceof RegExp)return`//js(${e})`;if(e instanceof Date)return`//js(Date("${e.toISOString()}"))`;if(e instanceof Function){let r=[];for(let n of Array(e.length).keys())r.push(String.fromCharCode(n+97));return`//fn(${r.join(", ")}) { ... }`}return Oa(e)}function ka(e){let t='"';for(let r=0;r"~"&&n<"\xA0"?t+="\\u{"+n.charCodeAt(0).toString(16).toUpperCase().padStart(4,"0")+"}":t+=n}}return t+='"',t}function va(e){let t="dict.from_list([",r=!0;return e.forEach((n,i)=>{r||(t=t+", "),t=t+"#("+lt(i)+", "+lt(n)+")",r=!1}),t+"])"}function Oa(e){let t=Object.getPrototypeOf(e)?.constructor?.name||"Object",r=[];for(let s of Object.keys(e))r.push(`${lt(s)}: ${lt(e[s])}`);let n=r.length?" "+r.join(", ")+" ":"";return`//js(${t==="Object"?"":t+" "}{${n}})`}function Ta(e){let t=Object.keys(e).map(r=>{let n=lt(e[r]);return isNaN(parseInt(r))?`${r}: ${n}`:n}).join(", ");return t?`${e.constructor.name}(${t})`:e.constructor.name}function La(e){return`[${e.toArray().map(lt).join(", ")}]`}function Ea(e){return`<<${Array.from(e.buffer).join(", ")}>>`}function Ba(e){return`//utfcodepoint(${String.fromCodePoint(e.value)})`}function co(e){return Hl(e)}function yn(e){return Ss(e)}function Ca(e){return to(e)}function $i(e,t){let r=Ca(t)-t>0;return e<0&&r||e===0&&t<0?new _(void 0):new f(ro(e,t))}function po(e){return-1*e}function Pa(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return n;{let i=r.head;e=r.tail,t=i+n}}}function $o(e){return Pa(e,0)}function Hs(e){return Gl(e)}function me(e){return Jl(e)}function ja(e){return e}function mo(e,t){let n=ja(e);return $i(n,t)}function De(e,t){return e===t?new X:e{let a=St(n,u);if(a.isOk()){let c=a[0];return de(l,u,c)}else return l};if(i.hasLength(0))return s;{let l=i.head,u=i.tail;e=n,t=u,r=o(s,l)}}}function Wa(e,t){return Fa(t,e,oe())}function wo(e,t){return Wa(t,e)}function Ua(e,t){return de(e,t[0],t[1])}function za(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return n;{let i=r.head;e=r.tail,t=Ua(n,i)}}}function Ma(e,t){let n=Ve(t);return za(n,e)}function ho(e,t){return Ma(e,t)}function Ys(e,t){return io(t,e)}function Da(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return i;{let o=n.head[0],l=n.head[1];e=n.tail,t=s(i,o,l),r=s}}}function gr(e,t,r){let i=Ve(e);return Da(i,t,r)}function Ra(e,t){let r=(n,i,s)=>de(n,i,e(i,s));return gr(t,oe(),r)}function gn(e,t){return Ra(t,e)}function yo(e){return e[1]}var It=class extends p{constructor(t){super(),this[0]=t}},br=class extends p{constructor(t){super(),this[0]=t}},K=class extends p{},ot=class extends p{};function xe(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return n;{let i=r.head;e=r.tail,t=m(i,n)}}}function A(e){return xe(e,d([]))}function _i(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return!1;if(r.atLeastLength(1)&&g(r.head,n)){let i=r.head;return!0}else e=r.tail,t=n}}function Ga(e){return(t,r)=>{let n=St(t,e(r));if(n.isOk()){let i=n[0];return de(t,e(r),m(r,i))}else return de(t,e(r),d([r]))}}function Ha(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return A(s);{let o=n.head,l=n.tail,u=i(o)?m(o,s):s;e=l,t=i,r=u}}}function kr(e,t){return Ha(e,t,d([]))}function Ja(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return A(s);{let o=n.head,l=n.tail,u=(()=>{let a=i(o);if(a.isOk()){let c=a[0];return m(c,s)}else return s})();e=l,t=i,r=u}}}function bn(e,t){return Ja(e,t,d([]))}function Ya(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return A(s);{let o=n.head;e=n.tail,t=i,r=m(i(o),s)}}}function F(e,t){return Ya(e,t,d([]))}function Va(e,t,r,n){for(;;){let i=e,s=t,o=r,l=n;if(i.hasLength(0))return A(l);{let u=i.head,a=i.tail,c=m(s(u,o),l);e=a,t=s,r=o+1,n=c}}}function mi(e,t){return Va(e,t,0,d([]))}function Xa(e,t,r){for(;;){let n=e,i=t,s=r;if(i<=0)return A(s);if(n.hasLength(0))return A(s);{let l=n.head;e=n.tail,t=i-1,r=m(l,s)}}}function Vs(e,t){return Xa(e,t,d([]))}function Ka(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return n;{let i=r.head;e=r.tail,t=m(i,n)}}}function kn(e,t){return Ka(A(e),t)}function Za(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return n;{let i=r.head;e=r.tail,t=m(i,n)}}}function Qa(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return A(n);{let i=r.head;e=r.tail,t=Za(i,n)}}}function Zt(e){return Qa(e,d([]))}function ue(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return i;{let o=n.head;e=n.tail,t=s(i,o),r=s}}}function bo(e,t){return ue(e,oe(),Ga(t))}function ef(e,t,r,n){for(;;){let i=e,s=t,o=r,l=n;if(i.hasLength(0))return s;{let u=i.head;e=i.tail,t=o(s,u,l),r=o,n=l+1}}}function xi(e,t,r){return ef(e,t,r,0)}function wi(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return i;{let o=n.head,l=n.tail,u=s(i,o);if(u instanceof It){let a=u[0];e=l,t=a,r=s}else return u[0]}}}function vn(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return new _(void 0);{let i=r.head,s=r.tail;if(n(i))return new f(i);e=s,t=n}}}function hi(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return new _(void 0);{let i=r.head,s=r.tail,o=n(i);if(o.isOk()){let l=o[0];return new f(l)}else e=s,t=n}}}function On(e,t){for(;;){let r=e,n=t;if(r.hasLength(0))return!1;{let i=r.head,s=r.tail;if(n(i))return!0;e=s,t=n}}}function Tn(e){if(e.hasLength(0))return d([]);{let t=e.head,r=e.tail;return m(t,Tn(kr(r,n=>!g(n,t))))}}function tf(e,t,r,n,i,s){for(;;){let o=e,l=t,u=r,a=n,c=i,$=s,x=m(c,u);if(o.hasLength(0))return a instanceof K?m(xe(x,d([])),$):m(x,$);{let w=o.head,h=o.tail,b=l(c,w);if(b instanceof le&&a instanceof ot)e=h,t=l,r=x,n=a,i=w,s=$;else if(b instanceof Q&&a instanceof K)e=h,t=l,r=x,n=a,i=w,s=$;else if(b instanceof X&&a instanceof K)e=h,t=l,r=x,n=a,i=w,s=$;else if(b instanceof le&&a instanceof K){let L=a instanceof K?m(xe(x,d([])),$):m(x,$);if(h.hasLength(0))return m(d([w]),L);{let T=h.head,U=h.tail,v=(()=>{let k=l(w,T);return k instanceof Q?new K:k instanceof X?new K:new ot})();e=U,t=l,r=d([w]),n=v,i=T,s=L}}else if(b instanceof Q&&a instanceof ot){let L=a instanceof K?m(xe(x,d([])),$):m(x,$);if(h.hasLength(0))return m(d([w]),L);{let T=h.head,U=h.tail,v=(()=>{let k=l(w,T);return k instanceof Q?new K:k instanceof X?new K:new ot})();e=U,t=l,r=d([w]),n=v,i=T,s=L}}else{let L=a instanceof K?m(xe(x,d([])),$):m(x,$);if(h.hasLength(0))return m(d([w]),L);{let T=h.head,U=h.tail,v=(()=>{let k=l(w,T);return k instanceof Q?new K:k instanceof X?new K:new ot})();e=U,t=l,r=d([w]),n=v,i=T,s=L}}}}}function rf(e,t,r,n){for(;;){let i=e,s=t,o=r,l=n;if(i.hasLength(0))return xe(s,l);if(s.hasLength(0))return xe(i,l);{let u=i.head,a=i.tail,c=s.head,$=s.tail,x=o(u,c);x instanceof Q?(e=a,t=s,r=o,n=m(u,l)):x instanceof le?(e=i,t=$,r=o,n=m(c,l)):(e=i,t=$,r=o,n=m(c,l))}}}function nf(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return xe(s,d([]));if(n.hasLength(1)){let o=n.head;return xe(m(xe(o,d([])),s),d([]))}else{let o=n.head,l=n.tail.head,u=n.tail.tail,a=rf(o,l,i,d([]));e=u,t=i,r=m(a,s)}}}function sf(e,t,r,n){for(;;){let i=e,s=t,o=r,l=n;if(i.hasLength(0))return xe(s,l);if(s.hasLength(0))return xe(i,l);{let u=i.head,a=i.tail,c=s.head,$=s.tail,x=o(u,c);x instanceof Q?(e=i,t=$,r=o,n=m(c,l)):x instanceof le?(e=a,t=s,r=o,n=m(u,l)):(e=a,t=s,r=o,n=m(u,l))}}}function lf(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return xe(s,d([]));if(n.hasLength(1)){let o=n.head;return xe(m(xe(o,d([])),s),d([]))}else{let o=n.head,l=n.tail.head,u=n.tail.tail,a=sf(o,l,i,d([]));e=u,t=i,r=m(a,s)}}}function of(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return d([]);if(n.hasLength(1)&&i instanceof K)return n.head;if(n.hasLength(1)&&i instanceof ot){let o=n.head;return xe(o,d([]))}else i instanceof K?(e=nf(n,s,d([])),t=new ot,r=s):(e=lf(n,s,d([])),t=new K,r=s)}}function gt(e,t){if(e.hasLength(0))return d([]);if(e.hasLength(1)){let r=e.head;return d([r])}else{let r=e.head,n=e.tail.head,i=e.tail.tail,s=(()=>{let l=t(r,n);return l instanceof Q?new K:l instanceof X?new K:new ot})(),o=tf(i,t,d([r]),s,n,d([]));return of(o,new K,t)}}function uf(e,t,r){for(;;){let n=e,i=t,s=r,o=De(n,i);if(o instanceof X)return m(i,s);o instanceof le?(e=n,t=i+1,r=m(i,s)):(e=n,t=i-1,r=m(i,s))}}function Xs(e,t){return uf(e,t,d([]))}function af(e,t,r){for(;;){let n=e,i=t,s=r;if(n.hasLength(0))return A(s);{let o=n.head,l=n.tail;if(i(o))e=l,t=i,r=m(o,s);else return A(s)}}}function ko(e,t){return af(e,t,d([]))}function ff(e,t,r,n,i){for(;;){let s=e,o=t,l=r,u=n,a=i;if(s.atLeastLength(1)){let c=s.head,$=s.tail,x=o(c);if(g(x,l))e=$,t=o,r=x,n=m(c,u),i=a;else{let h=m(A(u),a);e=$,t=o,r=x,n=d([c]),i=h}}else return A(m(A(u),a))}}function vo(e,t){if(e.hasLength(0))return d([]);{let r=e.head,n=e.tail;return ff(n,t,t(r),d([r]),d([]))}}function Ln(e){return zs(e)}function yi(e){return e}function Ft(e){return e}function pf(e){let r=Ft(e),n=Fs(r),i=A(n);return Ln(i)}function To(e){return pf(e)}function Wt(e){return Yl(e)}function $f(e){let r=yi(e),n=To(r);return Ft(n)}function Ks(e){return $f(e)}function bi(e,t,r){let i=yi(e),s=Is(i,t,r);return Ft(s)}function Lo(e){return Us(e)}function _f(e,t,r){if(r<0)return"";if(t<0){let s=Wt(e)+t;return s<0?"":Ms(e,s,r)}else return Ms(e,t,r)}function vr(e,t){return t<0?e:_f(e,t,Wt(e)-t)}function Eo(e,t){return Xl(e,t)}function ki(e,t){return Kl(e,t)}function En(e,t){return Vl(e,t)}function Bo(e){return Ql(e)}function H(e){return Ds(e)}function Qt(e){let t=lt(e);return Ft(t)}function Or(e){return!e.isOk()}function er(e,t){if(e.isOk()){let r=e[0];return new f(t(r))}else{let r=e[0];return new _(r)}}function tr(e,t){if(e.isOk()){let r=e[0];return new f(r)}else{let r=e[0];return new _(t(r))}}function O(e,t){if(e.isOk()){let r=e[0];return t(r)}else{let r=e[0];return new _(r)}}function Co(e,t){return e.isOk()?e[0]:t}function Po(e){return tr(e,t=>{})}function vi(e,t){if(e.isOk()){let r=e[0];return new f(r)}else return new _(t)}var Vt=class extends p{constructor(t,r,n){super(),this.expected=t,this.found=r,this.path=n}};function Zs(e){return Gs(e)}function yf(e){return oo(e)}function Oi(e){return uo(e)}function jo(e){return t=>{if(e.hasLength(0))return new _(d([new Vt("another type",Zs(t),d([]))]));{let r=e.head,n=e.tail,i=r(t);if(i.isOk()){let s=i[0];return new f(s)}else return jo(n)(t)}}}function gf(e,t){let r=t,n=jo(d([Bn,s=>er(yf(s),me)])),i=(()=>{let s=n(r);if(s.isOk())return s[0];{let o=d(["<",Zs(r),">"]),l=Ln(o);return Ft(l)}})();return e.withFields({path:m(i,e.path)})}function bf(e,t){return tr(e,r=>F(r,t))}function Bn(e){return lo(e)}function Ut(e,t){return r=>{let n=new Vt("field","nothing",d([]));return O(ao(r,e),i=>{let o=Sl(i,d([n])),l=O(o,t);return bf(l,u=>gf(u,e))})}}var Ti=class e{constructor(t){this.promise=t}static wrap(t){return t instanceof Promise?new e(t):t}static unwrap(t){return t instanceof e?t.promise:t}};function Qs(e){return new Promise(t=>e(r=>{t(Ti.wrap(r))}))}function el(e,t){return e.then(r=>t(Ti.unwrap(r)))}function No(e){return e?"True":"False"}function M(e,t,r){return e?t:r()}var Li=class extends p{constructor(t){super(),this.all=t}};function qo(e){return new Li(d([t=>e(t.dispatch,t.emit,t.select,t.root)]))}function rl(e){return qo((t,r,n,i)=>e(t))}function ae(){return new Li(d([]))}var Br=class extends p{constructor(t){super(),this.content=t}},re=class extends p{constructor(t,r,n,i,s,o,l){super(),this.key=t,this.namespace=r,this.tag=n,this.attrs=i,this.children=s,this.self_closing=o,this.void=l}},Cn=class extends p{constructor(t){super(),this.subtree=t}},Cr=class extends p{constructor(t,r,n){super(),this[0]=t,this[1]=r,this.as_property=n}},Pn=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}};function Nf(e){if(e instanceof Cr)return new _(void 0);{let t=e[0],r=e[1],n=vr(t,2);return new f([n,r])}}function Af(e,t,r){return xi(e,t,(n,i,s)=>{let o=r+"-"+me(s);return So(i,n,o)})}function So(e,t,r){for(;;){let n=e,i=t,s=r;if(n instanceof Br)return i;if(n instanceof Cn){let o=n.subtree;e=o(),t=i,r=s}else{let o=n.attrs,l=n.children,u=ue(o,i,(a,c)=>{let $=Nf(c);if($.isOk()){let x=$[0][0],w=$[0][1];return de(a,s+"-"+x,w)}else return a});return Af(l,u,s)}}}function Io(e){return So(e,oe(),"0")}function Pr(e,t){return new Cr(e,t,!1)}function Wo(e,t){return new Pn("on"+e,t)}function jr(e){return Pr("style",ue(e,"",(t,r)=>{let n=r[0],i=r[1];return t+n+":"+i+";"}))}function bt(e){return Pr("class",e)}function Uo(){return bt("")}function jn(e){return Pr("id",e)}function Nn(e){return Pr("type",e)}function zo(e){return Pr("value",e)}function nl(e){return Pr("for",e)}function Re(e,t,r){return e==="area"?new re("","",e,t,d([]),!1,!0):e==="base"?new re("","",e,t,d([]),!1,!0):e==="br"?new re("","",e,t,d([]),!1,!0):e==="col"?new re("","",e,t,d([]),!1,!0):e==="embed"?new re("","",e,t,d([]),!1,!0):e==="hr"?new re("","",e,t,d([]),!1,!0):e==="img"?new re("","",e,t,d([]),!1,!0):e==="input"?new re("","",e,t,d([]),!1,!0):e==="link"?new re("","",e,t,d([]),!1,!0):e==="meta"?new re("","",e,t,d([]),!1,!0):e==="param"?new re("","",e,t,d([]),!1,!0):e==="source"?new re("","",e,t,d([]),!1,!0):e==="track"?new re("","",e,t,d([]),!1,!0):e==="wbr"?new re("","",e,t,d([]),!1,!0):new re("","",e,t,r,!1,!1)}function Mo(e){return new Br(e)}var nr=class extends p{constructor(t){super(),this.dict=t}};function Do(){return new nr(oe())}function Sf(e,t){return new nr(Ys(e.dict,t))}function An(e){return Kt(e.dict)}function Ro(e,t,r){return gr(e.dict,t,(n,i,s)=>r(n,i))}function If(e,t){return ue(t,e,Sf)}function Ff(e,t){return new nr(wo(e.dict,t))}function Go(e,t){return pi(e.dict)>pi(t.dict)?[e,t]:[t,e]}function Wf(e,t){let r=Go(e,t),n=r[0],i=r[1];return Ff(n,An(i))}function Uf(e,t){return If(e,An(t))}var Ho=void 0;function Jo(e,t){return new nr(de(e.dict,t,Ho))}function sl(e){let t=ue(e,oe(),(r,n)=>de(r,n,Ho));return new nr(t)}function zf(e,t){let r=Go(e,t),n=r[0],i=r[1];return Ro(i,n,Jo)}function Yo(e,t){return Uf(zf(e,t),Wf(e,t))}var Bi=class extends p{constructor(t){super(),this[0]=t}},Ci=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}},Pi=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}};function Xo(e){return g(e.created,oe())&&g(e.removed,Do())&&g(e.updated,oe())}var ji=class extends p{constructor(t){super(),this[0]=t}},Ni=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}},qn=class extends p{constructor(t){super(),this[0]=t}},ut=class extends p{constructor(t){super(),this[0]=t}},Sn=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}},Ai=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}};var In=class extends p{},qi=class extends p{constructor(t,r){super(),this[0]=t,this[1]=r}},Si=class extends p{constructor(t){super(),this[0]=t}},Ii=class extends p{constructor(t){super(),this[0]=t}};window&&window.customElements&&window.customElements.define("lustre-fragment",class extends HTMLElement{constructor(){super()}});function ll(e,t,r){let n,i=[{prev:e,next:t,parent:e.parentNode}];for(;i.length;){let{prev:s,next:o,parent:l}=i.pop();for(;o.subtree!==void 0;)o=o.subtree();if(o.content!==void 0)if(s)if(s.nodeType===Node.TEXT_NODE)s.textContent!==o.content&&(s.textContent=o.content),n??=s;else{let u=document.createTextNode(o.content);l.replaceChild(u,s),n??=u}else{let u=document.createTextNode(o.content);l.appendChild(u),n??=u}else if(o.tag!==void 0){let u=Rf({prev:s,next:o,dispatch:r,stack:i});s?s!==u&&l.replaceChild(u,s):l.appendChild(u),n??=u}}return n}function Rf({prev:e,next:t,dispatch:r,stack:n}){let i=t.namespace||"http://www.w3.org/1999/xhtml",s=e&&e.nodeType===Node.ELEMENT_NODE&&e.localName===t.tag&&e.namespaceURI===(t.namespace||"http://www.w3.org/1999/xhtml"),o=s?e:i?document.createElementNS(i,t.tag):document.createElement(t.tag),l;if(Fn.has(o))l=Fn.get(o);else{let v=new Map;Fn.set(o,v),l=v}let u=s?new Set(l.keys()):null,a=s?new Set(Array.from(e.attributes,v=>v.name)):null,c=null,$=null,x=null;if(s&&t.tag==="textarea"){let v=t.children[Symbol.iterator]().next().value?.content;v!==void 0&&(o.value=v)}let w=[];for(let v of t.attrs){let k=v[0],z=v[1];if(v.as_property)o[k]!==z&&(o[k]=z),s&&a.delete(k);else if(k.startsWith("on")){let se=k.slice(2),Ye=r(z,se==="input");l.has(se)||o.addEventListener(se,Wn),l.set(se,Ye),s&&u.delete(se)}else if(k.startsWith("data-lustre-on-")){let se=k.slice(15),Ye=r(Gf);l.has(se)||o.addEventListener(se,Wn),l.set(se,Ye),o.setAttribute(k,z)}else k.startsWith("delegate:data-")||k.startsWith("delegate:aria-")?(o.setAttribute(k,z),w.push([k.slice(10),z])):k==="class"?c=c===null?z:c+" "+z:k==="style"?$=$===null?z:$+z:k==="dangerous-unescaped-html"?x=z:(o.getAttribute(k)!==z&&o.setAttribute(k,z),(k==="value"||k==="selected")&&(o[k]=z),s&&a.delete(k))}if(c!==null&&(o.setAttribute("class",c),s&&a.delete("class")),$!==null&&(o.setAttribute("style",$),s&&a.delete("style")),s){for(let v of a)o.removeAttribute(v);for(let v of u)l.delete(v),o.removeEventListener(v,Wn)}if(t.tag==="slot"&&window.queueMicrotask(()=>{for(let v of o.assignedElements())for(let[k,z]of w)v.hasAttribute(k)||v.setAttribute(k,z)}),t.key!==void 0&&t.key!=="")o.setAttribute("data-lustre-key",t.key);else if(x!==null)return o.innerHTML=x,o;let h=o.firstChild,b=null,L=null,T=null,U=Fi(t).next().value;if(s&&U!==void 0&&U.key!==void 0&&U.key!==""){b=new Set,L=Ko(e),T=Ko(t);for(let v of Fi(t))h=Hf(h,v,o,n,T,L,b)}else for(let v of Fi(t))n.unshift({prev:h,next:v,parent:o}),h=h?.nextSibling;for(;h;){let v=h.nextSibling;o.removeChild(h),h=v}return o}var Fn=new WeakMap;function Wn(e){let t=e.currentTarget;if(!Fn.has(t)){t.removeEventListener(e.type,Wn);return}let r=Fn.get(t);if(!r.has(e.type)){t.removeEventListener(e.type,Wn);return}r.get(e.type)(e)}function Gf(e){let t=e.currentTarget,r=t.getAttribute(`data-lustre-on-${e.type}`),n=JSON.parse(t.getAttribute("data-lustre-data")||"{}"),i=JSON.parse(t.getAttribute("data-lustre-include")||"[]");switch(e.type){case"input":case"change":i.push("target.value");break}return{tag:r,data:i.reduce((s,o)=>{let l=o.split(".");for(let u=0,a=s,c=e;ul.send(u))}constructor(t,[r,n],i,s){this.root=t,this.#e=r,this.#s=i,this.#r=s,this.#t=window.requestAnimationFrame(()=>this.#n(n.all.toArray(),!0))}root;send(t){if(t instanceof qn){if(t[0]instanceof Ii){this.#t=window.cancelAnimationFrame(this.#t),this.#i=[],this.#e=t[0][0];let r=this.#r(this.#e),n=(s,o=!1)=>l=>{let u=s(l);u instanceof f&&this.send(new ut(u[0],o))},i=this.root.firstChild??this.root.appendChild(document.createTextNode(""));ll(i,r,n)}}else if(t instanceof ut){let r=t[0],n=t[1]??!1;this.#i.push(r),n?(this.#t=window.cancelAnimationFrame(this.#t),this.#n()):this.#t||(this.#t=window.requestAnimationFrame(()=>this.#n()))}else if(t instanceof Sn){let r=t[0],n=t[1];this.root.dispatchEvent(new CustomEvent(r,{detail:n,bubbles:!0,composed:!0}))}else if(t instanceof In)for(this.#t=window.cancelAnimationFrame(this.#t),this.#e=null,this.#s=null,this.#r=null,this.#i=null;this.root.firstChild;)this.root.firstChild.remove()}#e;#s;#r;#i=[];#t;#n(t=[],r=!1){if(this.#t=void 0,!this.#l(t,r))return;let n=this.#r(this.#e),i=(o,l=!1)=>u=>{let a=o(u);a instanceof f&&this.send(new ut(a[0],l))},s=this.root.firstChild??this.root.appendChild(document.createTextNode(""));ll(s,n,i)}#l(t=[],r=!1){for(;this.#i.length>0;){let n=this.#i.shift(),[i,s]=this.#s(this.#e,n);r||=this.#e!==i,t=t.concat(s.all.toArray()),this.#e=i}for(;t.length>0;){let n=t.shift(),i=u=>this.send(new ut(u)),s=(u,a)=>this.root.dispatchEvent(new CustomEvent(u,{detail:a,bubbles:!0,composed:!0})),o=()=>{},l=this.root;n({dispatch:i,emit:s,select:o,root:l})}return this.#i.length>0?this.#l(t,r):r}},Qo=ol.start;var ul=class e{static start({init:t,update:r,view:n,on_attribute_change:i},s){let o=new e(t(s),r,n,i);return new f(l=>o.send(l))}constructor([t,r],n,i,s){this.#e=t,this.#s=n,this.#i=i,this.#t=i(t),this.#u=s,this.#n=new Map,this.#l=Io(this.#t),this.#o(r.all.toArray())}send(t){if(t instanceof ji){for(let r of t[0]){let n=this.#u.get(r[0]);if(!n)continue;let i=n(r[1]);i instanceof _||this.#r.push(i)}this.#o()}else if(t instanceof Ni)this.#r=this.#r.concat(t[0].toArray()),this.#o(t[1].all.toArray());else if(!(t instanceof qn))if(t instanceof ut)this.#r.push(t[0]),this.#o();else if(t instanceof Sn){let r=new Ci(t[0],t[1]);for(let[n,i]of this.#n)i(r)}else if(t instanceof Ai){let r=this.#l.get(t[0]);if(!r)return;let n=r(t[1]);if(n instanceof _)return;this.#r.push(n[0]),this.#o()}else if(t instanceof qi){let r=Kt(this.#u),n=new Pi(r,this.#t);this.#n=this.#n.set(t[0],t[1]),t[1](n)}else t instanceof Si&&(this.#n=this.#n.delete(t[0]))}#e;#s;#r;#i;#t;#n;#l;#u;#o(t=[]){if(!this.#a(!1,t))return;let r=this.#i(this.#e),n=elements(this.#t,r);if(!Xo(n)){let i=new Bi(n);for(let[s,o]of this.#n)o(i)}this.#t=r,this.#l=n.handlers}#a(t=!1,r=[]){for(;this.#r.length>0;){let n=this.#r.shift(),[i,s]=this.#s(this.#e,n);t||=this.#e!==i,r=r.concat(s.all.toArray()),this.#e=i}for(;r.length>0;)r.shift()({dispatch:u=>this.send(new ut(u)),emit:(u,a)=>this.root.dispatchEvent(new CustomEvent(u,{detail:a,bubbles:!0,composed:!0})),select:()=>{},root:null});return this.#r.length>0?this.#a(t,r):t}},Jf=ul.start,al=()=>globalThis.window&&window.document;var fl=class extends p{constructor(t,r,n,i){super(),this.init=t,this.update=r,this.view=n,this.on_attribute_change=i}};var Wi=class extends p{constructor(t){super(),this.selector=t}},Un=class extends p{};function eu(e,t,r){return new fl(e,t,r,new E)}function tu(e,t,r){return M(!al(),new _(new Un),()=>Qo(e,t,r))}function ru(e){return Mo(e)}function nu(e,t){return Re("h4",e,t)}function at(e,t){return Re("div",e,t)}function cl(e,t){return Re("p",e,t)}function iu(e,t){return Re("table",e,t)}function su(e,t){return Re("tbody",e,t)}function pl(e,t){return Re("td",e,t)}function lu(e,t){return Re("tr",e,t)}function ou(e,t){return Re("button",e,t)}function zn(e){return Re("input",e,d([]))}function Mn(e,t){return Re("label",e,t)}function ir(e,t){return Wo(e,t)}function uu(e){return ir("click",t=>new f(e))}function au(e){return ir("focus",t=>new f(e))}function fu(e){return ir("blur",t=>new f(e))}function Xf(e){let t=e;return Ut("target",Ut("value",Bn))(t)}function dl(e){return ir("input",t=>{let r=Xf(t);return er(r,e)})}function Kf(e){let t=e;return Ut("target",Ut("checked",Oi))(t)}function $l(e){return ir("change",t=>{let r=Kf(t);return er(r,e)})}var ft=class extends p{constructor(t,r,n){super(),this.title=t,this.info=r,this.hint=n}};var sr=class extends p{constructor(t){super(),this.context=t}};var Z=class extends p{constructor(t){super(),this.context=t}};var ct=class extends p{constructor(t){super(),this.context=t}};function pu(e,t,r){return e.slice(t,t+r)}function Dn(e,t){return e.slice(t)}var Ui=class extends p{constructor(t){super(),this.position=t}},ml=class extends p{constructor(t){super(),this.start=t}},xl=class extends p{},zi=class extends p{},ee=class extends p{},V=class extends p{},fe=class extends p{},ne=class extends p{};function sc(e){return e instanceof xl?`\r +`:` +`}function lc(e,t){return hn(e,'"')?'"'+bi(e,'"','""')+'"':hn(e,t)||hn(e,` +`)?'"'+e+'"':e}function du(e,t,r){let n=sc(r),i=F(e,s=>{let o=F(s,l=>lc(l,t));return En(o,t)});return En(i,n)}function pt(e,t,r,n){let i=pu(e,t,r);return n instanceof fe||n instanceof V||n instanceof ne?i:bi(i,'""','"')}function _l(e,t,r,n,i,s,o){for(;;){let l=e,u=t,a=r,c=n,$=i,x=s,w=o;if(l.startsWith(",")&&w instanceof fe){let h=l.slice(1),b=pt(u,a,c,w),L=m(b,$),T=a+c+1;e=h,t=u,r=T,n=0,i=L,s=x,o=new fe}else if(l.startsWith(",")&&w instanceof ne){let h=l.slice(1),b=pt(u,a,c,w),L=m(b,$),T=a+c+1;e=h,t=u,r=T,n=0,i=L,s=x,o=new fe}else if(l.startsWith(",")&&w instanceof V){let h=l.slice(1),b=pt(u,a,c,w),L=m(b,$),T=a+c+1;e=h,t=u,r=T,n=0,i=L,s=x,o=new fe}else if(l.startsWith('",')&&w instanceof ee){let h=l.slice(2),b=pt(u,a,c,w),L=m(b,$),T=a+c+2;e=h,t=u,r=T,n=0,i=L,s=x,o=new fe}else if(l===""&&w instanceof V){let h=pt(u,a,c,w),b=A(m(h,$));return new f(A(m(b,x)))}else if(l==='"'&&w instanceof ee){let h=pt(u,a,c,w),b=A(m(h,$));return new f(A(m(b,x)))}else if(l===""&&w instanceof fe){let h=A(m("",$));return new f(A(m(h,x)))}else{if(l===""&&w instanceof ne)return new f(A(x));if(l===""&&w instanceof ee)return new _(new ml(a));if(l.startsWith(` +`)&&w instanceof V){let h=l.slice(1),b=pt(u,a,c,w),L=A(m(b,$)),T=m(L,x),U=a+c+1;e=h,t=u,r=U,n=0,i=d([]),s=T,o=new ne}else if(l.startsWith(`\r +`)&&w instanceof V){let h=l.slice(2),b=pt(u,a,c,w),L=A(m(b,$)),T=m(L,x),U=a+c+2;e=h,t=u,r=U,n=0,i=d([]),s=T,o=new ne}else if(l.startsWith(`" +`)&&w instanceof ee){let h=l.slice(2),b=pt(u,a,c,w),L=A(m(b,$)),T=m(L,x),U=a+c+2;e=h,t=u,r=U,n=0,i=d([]),s=T,o=new ne}else if(l.startsWith(`"\r +`)&&w instanceof ee){let h=l.slice(3),b=pt(u,a,c,w),L=A(m(b,$)),T=m(L,x),U=a+c+3;e=h,t=u,r=U,n=0,i=d([]),s=T,o=new ne}else if(l.startsWith(` +`)&&w instanceof fe){let h=l.slice(1),b=A(m("",$)),L=m(b,x);e=h,t=u,r=a+1,n=0,i=d([]),s=L,o=new ne}else if(l.startsWith(`\r +`)&&w instanceof fe){let h=l.slice(2),b=A(m("",$)),L=m(b,x);e=h,t=u,r=a+2,n=0,i=d([]),s=L,o=new ne}else if(l.startsWith(` +`)&&w instanceof ne)e=l.slice(1),t=u,r=a+1,n=0,i=$,s=x,o=w;else if(l.startsWith(`\r +`)&&w instanceof ne)e=l.slice(2),t=u,r=a+2,n=0,i=$,s=x,o=w;else if(l.startsWith('""')&&w instanceof ee)e=l.slice(2),t=u,r=a,n=c+2,i=$,s=x,o=w;else{if(l.startsWith('"')&&w instanceof V)return new _(new Ui(a+c));if(l.startsWith('"')&&w instanceof ee)return new _(new Ui(a+c));if(l.startsWith('"')&&w instanceof fe){let h=l.slice(1),b=new ee;e=h,t=u,r=a+1,n=0,i=$,s=x,o=b}else if(l.startsWith('"')&&w instanceof ne){let h=l.slice(1),b=new ee;e=h,t=u,r=a+1,n=0,i=$,s=x,o=b}else if(w instanceof fe){let h=w instanceof ee?new ee:w instanceof fe?new V:w instanceof ne?new V:new V;e=Dn(l,1),t=u,r=a,n=c+1,i=$,s=x,o=h}else if(w instanceof ne){let h=w instanceof ee?new ee:w instanceof fe?new V:w instanceof ne?new V:new V;e=Dn(l,1),t=u,r=a,n=c+1,i=$,s=x,o=h}else if(w instanceof V){let h=w instanceof ee?new ee:w instanceof fe?new V:w instanceof ne?new V:new V;e=Dn(l,1),t=u,r=a,n=c+1,i=$,s=x,o=h}else{let h=w instanceof ee?new ee:w instanceof fe?new V:w instanceof ne?new V:new V;e=Dn(l,1),t=u,r=a,n=c+1,i=$,s=x,o=h}}}}}function $u(e){for(;;){let t=e;if(t.startsWith(` +`))e=t.slice(1);else if(t.startsWith(`\r +`))e=t.slice(2);else if(t.startsWith('"')){let r=t.slice(1);return _l(r,t,1,0,d([]),d([]),new ee)}else if(t.startsWith(",")){let r=t.slice(1);return _l(r,t,1,0,d([""]),d([]),new fe)}else return _l(t,t,0,0,d([]),d([]),new V)}}var Rn=class extends p{constructor(t,r){super(),this.inner=t,this.cells=r}},Nr=class extends p{constructor(t,r){super(),this.row=t,this.col=r}};function Ar(e){let t=e.row,r=e.col;return"("+me(t)+","+me(r)+")"}function lr(e){return e.row}function qr(e){return e.col}function Mi(e,t,r){let n=Xs(1,e),i=Xs(1,t),s=ue(i,[oe(),d([])],(u,a)=>{let c=u[0],$=u[1],x=ue(n,[oe(),d([])],(b,L)=>{let T=b[0],U=b[1];return[de(T,new Nr(a,L),r),m(new Nr(a,L),U)]}),w=x[0],h=x[1];return[ho(c,w),Zt(d([h,$]))]}),o=s[0],l=s[1];return new Rn(o,l)}function Di(e,t,r){return e.withFields({inner:de(e.inner,t,r)})}function wl(e,t){let r=e.inner,n=Ve(r);return hi(n,i=>{let s=i[0],o=i[1];return g(o,t)?new f(s):new _(void 0)})}function Ri(e,t,r){return gr(e.inner,t,r)}function Gn(e,t){return new Rn(gn(e.inner,t),e.cells)}function J(e,t){let r=St(e.inner,t);if(!r.isOk())throw G("let_assert","squared_away/squared_away_lang/grid",84,"get","Pattern match failed, no pattern matched the value.",{value:r});return r[0]}function or(e,t){return vn(e.cells,r=>r.row===t.row&&r.col===t.col+1)}function Sr(e,t){return vn(e.cells,r=>r.row===t.row+1&&r.col===t.col)}function _u(e,t){return vn(e.cells,r=>r.row+1===t.row&&r.col===t.col)}function mu(e,t){return vn(e.cells,r=>r.row===t.row&&r.col+1===t.col)}function xu(e,t){let r=e.row,n=e.col,i=t.row,s=t.col;return r!==i&&s!==n?new f(new Nr(r,s)):new _(void 0)}function dt(e){return Ve(e.inner)}function wu(e){let t=dt(e),r=gt(t,(s,o)=>{let l=s[0].row,u=s[0].col,a=o[0].row,c=o[0].col,$=De(l,a);return $ instanceof X?De(u,c):$}),n=vo(r,s=>s[0].row),i=F(n,s=>F(s,o=>o[1]));return du(i,",",new zi)}function hu(e,t,r){let n=$u(e);if(!n.isOk())throw G("let_assert","squared_away/squared_away_lang/grid",140,"from_src_csv","Pattern match failed, no pattern matched the value.",{value:n});let i=n[0],s=(()=>{let l=Vs(i,r),u=F(l,$=>Vs($,t)),a=mi(u,($,x)=>mi($,(w,h)=>[new Nr(x+1,h+1),w])),c=Zt(a);return Js(c)})(),o=Kt(s);return new Rn(s,o)}function kt(e){return BigInt(e)}function Hi(e){try{return new f(BigInt(e))}catch{return new _(void 0)}}function Ji(e){return e.toString()}function hl(){return 0n}function Yi(e,t){return e+t}function yl(e,t){return e-t}function Pe(e,t){return e*t}function Ir(e,t){return t===0n?0n:e/t}function Hn(e,t){return t===0n?0n:(e%t+t)%t}function gl(e,t){return t<0?new _(void 0):new f(e**t)}var $t=class extends p{constructor(t,r){super(),this.numerator=t,this.denominator=r}};function Xe(e){return new $t(kt(e),kt(1))}function ac(e){for(;;){let t=e;if(t.startsWith("0"))e=t.slice(1);else return t.startsWith(".")?t.slice(1):t}}function fc(e,t,r,n){for(;;){let i=e,s=t,o=r,l=n;if(i===0)return l;{let u=Pe(s,kt(10)),a=(()=>{let c=Ir(u,o);return Ji(c)})();e=i-1,t=Hn(u,o),r=o,n=l+a}}}function Fr(e,t){let r=e.numerator,n=e.denominator,i=Ji(Ir(r,n)),s=Hn(r,n);if(g(s,kt(0)))return i;{let u=fc(t,s,n,i+"."),a=Ks(u),c=ac(a);return Ks(c)}}function yu(e,t){for(;;){let r=e,n=t;if(r.startsWith("1")){let i=r.slice(1),s="1";e=i,t=n+s}else if(r.startsWith("2")){let i=r.slice(1),s="2";e=i,t=n+s}else if(r.startsWith("3")){let i=r.slice(1),s="3";e=i,t=n+s}else if(r.startsWith("4")){let i=r.slice(1),s="4";e=i,t=n+s}else if(r.startsWith("5")){let i=r.slice(1),s="5";e=i,t=n+s}else if(r.startsWith("6")){let i=r.slice(1),s="6";e=i,t=n+s}else if(r.startsWith("7")){let i=r.slice(1),s="7";e=i,t=n+s}else if(r.startsWith("8")){let i=r.slice(1),s="8";e=i,t=n+s}else if(r.startsWith("9")){let i=r.slice(1),s="9";e=i,t=n+s}else if(r.startsWith("0")){let i=r.slice(1),s="0";e=i,t=n+s}else return n!==""?new f([n,r]):new _(void 0)}}function cc(e,t){for(;;){let r=e,n=t;if(g(r,hl()))return n;e=Hn(n,r),t=r}}function Jn(e){let t=e.numerator,r=e.denominator,n=cc(t,r);return new $t(Ir(t,n),Ir(r,n))}function bl(e){return O(yu(e,""),t=>{let r=t[0],n=t[1];return O(Hi(r),i=>{if(n.startsWith(".")){let s=n.slice(1);return O(yu(s,""),o=>{let l=o[0],u=o[1];return O(gl(kt(10),kt(Wt(l))),a=>O(Hi(l),c=>new f([Jn(new $t(Yi(Pe(i,a),c),a)),u])))})}else return new f([new $t(i,kt(1)),n])})})}function kl(e,t){let r=e.numerator,n=e.denominator,i=t.numerator,s=t.denominator;return Jn(new $t(Yi(Pe(r,s),Pe(i,n)),Pe(n,s)))}function vl(e,t){let r=e.numerator,n=e.denominator,i=t.numerator,s=t.denominator;return Jn(new $t(yl(Pe(r,s),Pe(i,n)),Pe(n,s)))}function _t(e,t){let r=e.numerator,n=e.denominator,i=t.numerator,s=t.denominator;return Jn(new $t(Pe(r,i),Pe(n,s)))}function Yn(e,t){let r=e.numerator,n=e.denominator,i=t.numerator,s=t.denominator;return Jn(new $t(Pe(r,s),Pe(n,i)))}function gu(e){return ue(e,Xe(0),kl)}var te=class extends p{},ur=class extends p{constructor(t){super(),this.f=t}},ar=class extends p{constructor(t){super(),this.cents=t}},fr=class extends p{constructor(t){super(),this.percent=t}},Ke=class extends p{constructor(t){super(),this.txt=t}},zt=class extends p{constructor(t){super(),this.txt=t}},cr=class extends p{constructor(t,r){super(),this.row=t,this.col=r}},pr=class extends p{constructor(t){super(),this.n=t}},vt=class extends p{constructor(t){super(),this.val=t}},dr=class extends p{constructor(t,r){super(),this.op=t,this.expr=r}},$e=class extends p{constructor(t,r,n){super(),this.lhs=t,this.op=r,this.rhs=n}},$r=class extends p{constructor(t){super(),this.inner=t}},_r=class extends p{constructor(t){super(),this.key=t}},Le=class extends p{},Ee=class extends p{},R=class extends p{},ie=class extends p{},we=class extends p{},Fe=class extends p{},We=class extends p{},he=class extends p{},ye=class extends p{},ge=class extends p{},be=class extends p{},Ze=class extends p{},Qe=class extends p{},Mt=class extends p{},Ge=class extends p{},mt=class extends p{};function Xi(e){return e instanceof Le?"+":e instanceof Ze?"&&":e instanceof ie?"/":e instanceof Fe?"==":e instanceof ge?">":e instanceof be?">=":e instanceof he?"<":e instanceof ye?"<=":e instanceof R?"*":e instanceof We?"!=":e instanceof Qe?"||":e instanceof we?"**":e instanceof Ee?"-":"mustbe"}function bu(e){return e instanceof Ge?"-":"!"}var Dt=class extends p{},j=class extends p{},He=class extends p{},q=class extends p{},S=class extends p{},Rt=class extends p{},B=class extends p{},W=class extends p{};function Ol(e){return e instanceof Dt?"Empty":e instanceof j?"Floating Point Number":e instanceof He?"Text":e instanceof q?"Integer":e instanceof S?"Boolean (True or False)":e instanceof Rt?"Test Result (Pass or Fail)":e instanceof B?"Usd":"Percent"}var et=class extends p{constructor(t){super(),this.type_=t}},Ot=class extends p{constructor(t,r){super(),this.type_=t,this.f=r}},Ur=class extends p{constructor(t,r){super(),this.type_=t,this.cents=r}},Tt=class extends p{constructor(t,r){super(),this.type_=t,this.percent=r}},tt=class extends p{constructor(t,r,n){super(),this.type_=t,this.key=r,this.txt=n}},je=class extends p{constructor(t,r,n,i){super(),this.type_=t,this.key=r,this.row_label=n,this.col_label=i}},Je=class extends p{constructor(t,r){super(),this.type_=t,this.txt=r}},Lt=class extends p{constructor(t,r){super(),this.type_=t,this.n=r}},Et=class extends p{constructor(t,r){super(),this.type_=t,this.b=r}},ke=class extends p{constructor(t,r,n){super(),this.type_=t,this.op=r,this.expr=n}},y=class extends p{constructor(t,r,n,i){super(),this.type_=t,this.lhs=r,this.op=n,this.rhs=i}},Bt=class extends p{constructor(t,r){super(),this.type_=t,this.expr=r}},rt=class extends p{constructor(t,r){super(),this.type_=t,this.keys=r}};function Wr(e,t){if(e instanceof je){let r=e.key,n=e.row_label,i=e.col_label;return t(r,n,i)}else if(e instanceof ke){let r=e.type_,n=e.op,i=e.expr,s=Wr(i,t);if(s.isOk()){let o=s[0];return new f(new ke(r,n,o))}else return new _(void 0)}else if(e instanceof y){let r=e.type_,n=e.lhs,i=e.op,s=e.rhs,o=Wr(n,t),l=Wr(s,t);if(o.isOk()&&l.isOk()){let u=o[0],a=l[0];return new f(new y(r,u,i,a))}else return new _(void 0)}else return new f(e)}function xt(e){if(e instanceof Et)return e.b?"TRUE":"FALSE";if(e instanceof je){let t=e.row_label,r=e.col_label;return t+"_"+r}else{if(e instanceof et)return"";if(e instanceof Ot){let t=e.f;return yn(t)}else if(e instanceof Lt){let t=e.n;return me(t)}else if(e instanceof Tt){let t=e.percent;return Fr(_t(t,Xe(100)),100)+"%"}else{if(e instanceof tt)return e.txt;if(e instanceof Je)return e.txt;if(e instanceof Bt){let t=e.expr;return"("+xt(t)+")"}else if(e instanceof ke){let t=e.op,r=e.expr;return bu(t)+xt(r)}else if(e instanceof y){let t=e.lhs,r=e.op,n=e.rhs;return xt(t)+" "+Xi(r)+" "+xt(n)}else{if(e instanceof rt)return"sum";{let t=e.cents,r="$"+Fr(t,100),n=ki(r,".");if(!n.isOk()&&!n[0])return r+".00";{let i=n[0][1];return Wt(i)===1?r+"0":r}}}}}}function zr(e){return e instanceof tt||e instanceof ke||e instanceof y||e instanceof rt||e instanceof je?"="+xt(e):xt(e)}var Be=class extends p{constructor(t){super(),this.context=t}},Kn=class extends p{constructor(t,r,n){super(),this.lhs=t,this.rhs=r,this.binary_op=n}},Zi=class extends p{constructor(t,r){super(),this.lhs=t,this.rhs=r}};function pc(e){return e instanceof Le?"Addition `+`":e instanceof Ze?"Boolean And `&&`":e instanceof ie?"Division `/`":e instanceof Fe?"Equality Check `==`":e instanceof ge?"Greater Than Check `>`":e instanceof be?"Greater Than Or Equal Check `>=`":e instanceof he?"Less Than Check `<`":e instanceof ye?"Less Than or Equal Check `<=`":e instanceof R?"Multiplication `*`":e instanceof We?"Not Equal Check `!=`":e instanceof Qe?"Boolean Or `||`":e instanceof we?"To The Power Of `**`":e instanceof Ee?"Subtraction `-`":"MustBe `mustbe`"}function ku(e){if(e instanceof Kn){let t=e.lhs,r=e.rhs,n=e.binary_op;return new ft("Unexpected arguments to binary operation "+pc(n),"Got "+Ol(t)+" on the left and "+Ol(r)+" on the right",new E)}else if(e instanceof Be){let t=e.context;return new ft("Type Error",t,new E)}else{let t=e.lhs,r=e.rhs;return new ft("Cannot multiply USD * USD","You're multiplying two values that both represent United States Dollars. You have "+vr(zr(t),1)+" on the left and "+vr(zr(r),1)+" on the right.",new N(`This is *probably* a mistake, as "dollars squared" doesn't make much sense as a unit.`))}}var Qi=class extends p{constructor(t){super(),this[0]=t}},Zn=class extends p{constructor(t){super(),this[0]=t}},_e=class extends p{constructor(t){super(),this[0]=t}},Gt=class extends p{constructor(t){super(),this[0]=t}};function Ou(e){if(e instanceof _e){let t=e[0];return ku(t)}else if(e instanceof Zn){let t=e[0];return new ft("",t.context,new E)}else if(e instanceof Gt){let t=e[0];return new ft("",t.context,new E)}else return new ft("Compiler error",Qt(e),new E)}var Ct=class extends p{},mr=class extends p{constructor(t){super(),this.inner=t}},P=class extends p{constructor(t){super(),this.n=t}},C=class extends p{constructor(t){super(),this.f=t}},D=class extends p{constructor(t){super(),this.cents=t}},ve=class extends p{constructor(t){super(),this.percent=t}},I=class extends p{constructor(t){super(),this.b=t}},wt=class extends p{},nt=class extends p{};function Qn(e){if(e instanceof Ct)return"";if(e instanceof mr)return e.inner;if(e instanceof P){let t=e.n;return me(t)}else if(e instanceof I){let t=e.b,r=No(t);return Lo(r)}else if(e instanceof C){let t=e.f;return yn(t)}else if(e instanceof ve){let t=e.percent;return Fr(_t(t,Xe(100)),100)+"%"}else{if(e instanceof wt)return"Test Failure";if(e instanceof nt)return"Test Passing";{let t=e.cents,r="$"+Fr(t,100),n=ki(r,".");if(!n.isOk()&&!n[0])return r+".00";{let i=n[0][1];return Wt(i)===1?r+"0":r}}}}function Mr(e,t){for(;;){let r=e,n=t;if(n instanceof et)return new f(new Ct);if(n instanceof Je){let i=n.txt;return new f(new mr(i))}else if(n instanceof Ur){let i=n.cents;return new f(new D(i))}else if(n instanceof Tt){let i=n.percent;return new f(new ve(i))}else if(n instanceof Bt){let i=n.expr;e=r,t=i}else if(n instanceof je){let i=n.key,s=J(r,i);if(s.isOk()){let o=s[0];e=r,t=o}else return new f(new Ct)}else if(n instanceof tt){let i=n.key,s=n.txt,o=J(r,i);if(o.isOk()){let l=o[0];if(l instanceof tt&&l.txt===s){let u=l.txt;return new _(new Gt(new sr("Label points to itself")))}else e=r,t=l}else{let l=o[0];return new _(l)}}else if(n instanceof Et){let i=n.b;return new f(new I(i))}else if(n instanceof Lt){let i=n.n;return new f(new P(i))}else if(n instanceof Ot){let i=n.f;return new f(new C(i))}else if(n instanceof ke){let i=n.op,s=n.expr;return O(Mr(r,s),o=>{if(i instanceof Ge&&o instanceof P){let l=o.n;return new f(new P(-l))}else if(i instanceof Ge&&o instanceof C){let l=o.f;return new f(new C(po(l)))}else if(i instanceof mt&&o instanceof I){let l=o.b;return new f(new I(!l))}else if(i instanceof mt&&o instanceof ve){let l=o.percent;return new f(new ve(vl(Xe(1),l)))}else return new _(new Gt(new sr("These should be the only options if the typechecker is working")))})}else if(n instanceof y){let i=n.lhs,s=n.op,o=n.rhs;return O(Mr(r,i),l=>O(Mr(r,o),u=>{if(l instanceof P&&s instanceof Le&&u instanceof P){let a=l.n,c=u.n;return new f(new P(a+c))}else if(l instanceof P&&s instanceof Ee&&u instanceof P){let a=l.n,c=u.n;return new f(new P(a-c))}else if(l instanceof P&&s instanceof R&&u instanceof P){let a=l.n,c=u.n;return new f(new P(a*c))}else if(l instanceof P&&s instanceof ie&&u instanceof P){let a=l.n,c=u.n;return new f(new P(oi(a,c)))}else if(l instanceof P&&s instanceof Fe&&u instanceof P){let a=l.n,c=u.n;return new f(new I(a===c))}else if(l instanceof P&&s instanceof We&&u instanceof P){let a=l.n,c=u.n;return new f(new I(a!==c))}else if(l instanceof P&&s instanceof ge&&u instanceof P){let a=l.n,c=u.n;return new f(new I(a>c))}else if(l instanceof P&&s instanceof be&&u instanceof P){let a=l.n,c=u.n;return new f(new I(a>=c))}else if(l instanceof P&&s instanceof he&&u instanceof P){let a=l.n,c=u.n;return new f(new I(ac))}else if(l instanceof C&&s instanceof be&&u instanceof C){let a=l.f,c=u.f;return new f(new I(a>=c))}else if(l instanceof C&&s instanceof he&&u instanceof C){let a=l.f,c=u.f;return new f(new I(a{let l=dt(r),u=bn(l,a=>{let c=a[0],$=a[1];if(_i(s,c))if($.isOk()){let w=$[0],h=Mr(r,w);return Po(h)}else return new _(void 0);else return new _(void 0)});return kr(u,a=>a instanceof wt?!1:!(a instanceof nt))})();if(i instanceof j){let l=F(o,c=>{if(!(c instanceof C))throw G("let_assert","squared_away/squared_away_lang/interpreter",220,"","Pattern match failed, no pattern matched the value.",{value:c});return c.f}),u=$o(l),a=new C(u);return new f(a)}else if(i instanceof q){let l=F(o,c=>{if(!(c instanceof P))throw G("let_assert","squared_away/squared_away_lang/interpreter",228,"","Pattern match failed, no pattern matched the value.",{value:c});return c.n}),u=xo(l),a=new P(u);return new f(a)}else if(i instanceof B){let l=F(o,c=>{if(!(c instanceof D))throw G("let_assert","squared_away/squared_away_lang/interpreter",236,"","Pattern match failed, no pattern matched the value.",{value:c});return c.cents}),u=gu(l),a=new D(u);return new f(a)}else return new _(new Gt(new sr("internal compiler error sum function interpret")))}}}var Dr=class extends p{},xr=class extends p{},Rr=class extends p{},Gr=class extends p{},Hr=class extends p{},ts=class extends p{},Jr=class extends p{},Yr=class extends p{},Vr=class extends p{},Xr=class extends p{},Kr=class extends p{},Zr=class extends p{},Qr=class extends p{},en=class extends p{constructor(t){super(),this.n=t}},tn=class extends p{constructor(t){super(),this.f=t}},rn=class extends p{constructor(t){super(),this.dollars=t}},nn=class extends p{constructor(t){super(),this.percent=t}},sn=class extends p{},ln=class extends p{},on=class extends p{},un=class extends p{},an=class extends p{},fn=class extends p{},Ht=class extends p{constructor(t){super(),this.key=t}},cn=class extends p{constructor(t){super(),this.txt=t}},pn=class extends p{},Pt=class extends p{constructor(t){super(),this.key=t}},dn=class extends p{};function ht(e){if(e.atLeastLength(1)&&e.head instanceof Dr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Le,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof xr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Ee,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Rr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new R,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Gr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new ie,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Hr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new we,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Yr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new We,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Jr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Fe,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Kr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new ye,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Xr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new he,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Qr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new be,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof Zr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new ge,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof on){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Ze,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof un){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Qe,n),i]))})}else if(e.atLeastLength(1)&&e.head instanceof dn){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return M(g(n,new te),new _(new Z("No item on right hand side of binary operation.")),()=>new f([s=>new $e(s,new Mt,n),i]))})}else return new _(new Z("Not a binary operation"))}function ce(e){if(e.hasLength(0))return new f([new te,d([])]);if(e.atLeastLength(1)&&e.head instanceof cn){let t=e.head.txt,r=e.tail;return new f([new Ke(t),r])}else if(e.atLeastLength(3)&&e.head instanceof Ht&&e.tail.head instanceof pn&&e.tail.tail.head instanceof Ht){let t=e.head.key,r=e.tail.tail.head.key,n=e.tail.tail.tail,i=ht(n);if(i.isOk()){let s=i[0][0],o=i[0][1];return new f([s(new cr(t,r)),o])}else return new f([new cr(t,r),n])}else if(e.atLeastLength(1)&&e.head instanceof Pt){let t=e.head.key,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new _r(t)),s])}else return new f([new _r(t),r])}else if(e.atLeastLength(1)&&e.head instanceof Ht){let t=e.head.key,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new zt(t)),s])}else return new f([new zt(t),r])}else if(e.atLeastLength(1)&&e.head instanceof en){let t=e.head.n,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new pr(t)),s])}else return new f([new pr(t),r])}else if(e.atLeastLength(1)&&e.head instanceof tn){let t=e.head.f,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new ur(t)),s])}else return new f([new ur(t),r])}else if(e.atLeastLength(1)&&e.head instanceof sn){let t=e.tail,r=ht(t);if(r.isOk()){let n=r[0][0],i=r[0][1];return new f([n(new vt(!0)),i])}else return new f([new vt(!0),t])}else if(e.atLeastLength(1)&&e.head instanceof ln){let t=e.tail,r=ht(t);if(r.isOk()){let n=r[0][0],i=r[0][1];return new f([n(new vt(!1)),i])}else return new f([new vt(!1),t])}else if(e.atLeastLength(1)&&e.head instanceof rn){let t=e.head.dollars,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new ar(t)),s])}else return new f([new ar(t),r])}else if(e.atLeastLength(1)&&e.head instanceof nn){let t=e.head.percent,r=e.tail,n=ht(r);if(n.isOk()){let i=n[0][0],s=n[0][1];return new f([i(new fr(t)),s])}else return new f([new fr(t),r])}else if(e.atLeastLength(1)&&e.head instanceof xr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return new f([new dr(new Ge,n),i])})}else if(e.atLeastLength(1)&&e.head instanceof Vr){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];return new f([new dr(new mt,n),i])})}else if(e.atLeastLength(1)&&e.head instanceof an){let t=e.tail;return O(ce(t),r=>{let n=r[0],i=r[1];if(i.atLeastLength(1)&&i.head instanceof fn){let s=i.tail,o=ht(s);if(o.isOk()){let l=o[0][0],u=o[0][1];return new f([l(new $r(n)),u])}else return new f([new $r(n),s])}else return new _(new Z("missing closing parentheses"))})}else{let t=e.head;return new _(new Z("Unexpected token: "+Qt(t)))}}function Lu(e){return O(ce(e),t=>{let r=t[0],n=t[1];return n.hasLength(0)?new f(r):new _(new Z("After parsing there were leftover tokens "+Qt(n)))})}function Eu(e,t){for(;;){let r=e,n=t;if(r.startsWith("A")){let i=r.slice(1),s="A";e=i,t=n+s}else if(r.startsWith("B")){let i=r.slice(1),s="B";e=i,t=n+s}else if(r.startsWith("C")){let i=r.slice(1),s="C";e=i,t=n+s}else if(r.startsWith("D")){let i=r.slice(1),s="D";e=i,t=n+s}else if(r.startsWith("E")){let i=r.slice(1),s="E";e=i,t=n+s}else if(r.startsWith("F")){let i=r.slice(1),s="F";e=i,t=n+s}else if(r.startsWith("G")){let i=r.slice(1),s="G";e=i,t=n+s}else if(r.startsWith("H")){let i=r.slice(1),s="H";e=i,t=n+s}else if(r.startsWith("I")){let i=r.slice(1),s="I";e=i,t=n+s}else if(r.startsWith("J")){let i=r.slice(1),s="J";e=i,t=n+s}else if(r.startsWith("K")){let i=r.slice(1),s="K";e=i,t=n+s}else if(r.startsWith("L")){let i=r.slice(1),s="L";e=i,t=n+s}else if(r.startsWith("M")){let i=r.slice(1),s="M";e=i,t=n+s}else if(r.startsWith("N")){let i=r.slice(1),s="N";e=i,t=n+s}else if(r.startsWith("O")){let i=r.slice(1),s="O";e=i,t=n+s}else if(r.startsWith("P")){let i=r.slice(1),s="P";e=i,t=n+s}else if(r.startsWith("Q")){let i=r.slice(1),s="Q";e=i,t=n+s}else if(r.startsWith("R")){let i=r.slice(1),s="R";e=i,t=n+s}else if(r.startsWith("S")){let i=r.slice(1),s="S";e=i,t=n+s}else if(r.startsWith("T")){let i=r.slice(1),s="T";e=i,t=n+s}else if(r.startsWith("U")){let i=r.slice(1),s="U";e=i,t=n+s}else if(r.startsWith("V")){let i=r.slice(1),s="V";e=i,t=n+s}else if(r.startsWith("W")){let i=r.slice(1),s="W";e=i,t=n+s}else if(r.startsWith("X")){let i=r.slice(1),s="X";e=i,t=n+s}else if(r.startsWith("Y")){let i=r.slice(1),s="Y";e=i,t=n+s}else if(r.startsWith("Z")){let i=r.slice(1),s="Z";e=i,t=n+s}else if(r.startsWith("a")){let i=r.slice(1),s="a";e=i,t=n+s}else if(r.startsWith("b")){let i=r.slice(1),s="b";e=i,t=n+s}else if(r.startsWith("c")){let i=r.slice(1),s="c";e=i,t=n+s}else if(r.startsWith("d")){let i=r.slice(1),s="d";e=i,t=n+s}else if(r.startsWith("e")){let i=r.slice(1),s="e";e=i,t=n+s}else if(r.startsWith("f")){let i=r.slice(1),s="f";e=i,t=n+s}else if(r.startsWith("g")){let i=r.slice(1),s="g";e=i,t=n+s}else if(r.startsWith("h")){let i=r.slice(1),s="h";e=i,t=n+s}else if(r.startsWith("i")){let i=r.slice(1),s="i";e=i,t=n+s}else if(r.startsWith("j")){let i=r.slice(1),s="j";e=i,t=n+s}else if(r.startsWith("k")){let i=r.slice(1),s="k";e=i,t=n+s}else if(r.startsWith("l")){let i=r.slice(1),s="l";e=i,t=n+s}else if(r.startsWith("m")){let i=r.slice(1),s="m";e=i,t=n+s}else if(r.startsWith("n")){let i=r.slice(1),s="n";e=i,t=n+s}else if(r.startsWith("o")){let i=r.slice(1),s="o";e=i,t=n+s}else if(r.startsWith("p")){let i=r.slice(1),s="p";e=i,t=n+s}else if(r.startsWith("q")){let i=r.slice(1),s="q";e=i,t=n+s}else if(r.startsWith("r")){let i=r.slice(1),s="r";e=i,t=n+s}else if(r.startsWith("s")){let i=r.slice(1),s="s";e=i,t=n+s}else if(r.startsWith("t")){let i=r.slice(1),s="t";e=i,t=n+s}else if(r.startsWith("u")){let i=r.slice(1),s="u";e=i,t=n+s}else if(r.startsWith("v")){let i=r.slice(1),s="v";e=i,t=n+s}else if(r.startsWith("w")){let i=r.slice(1),s="w";e=i,t=n+s}else if(r.startsWith("x")){let i=r.slice(1),s="x";e=i,t=n+s}else if(r.startsWith("y")){let i=r.slice(1),s="y";e=i,t=n+s}else if(r.startsWith("z")){let i=r.slice(1),s="z";e=i,t=n+s}else return n===""?new _(void 0):new f([n,r])}}function Bu(e,t){for(;;){let r=e,n=t;if(r==="")return new f(A(n));if(r.startsWith("mustbe")){let i=r.slice(6);e=H(i),t=m(new dn,n)}else if(r.startsWith("sum")){let i=r.slice(3);e=H(i),t=m(new Pt(new E),n)}else if(r.startsWith("&&")){let i=r.slice(2);e=H(i),t=m(new on,n)}else if(r.startsWith("||")){let i=r.slice(2);e=H(i),t=m(new un,n)}else if(r.startsWith("**")){let i=r.slice(2);e=H(i),t=m(new Hr,n)}else if(r.startsWith("==")){let i=r.slice(2);e=H(i),t=m(new Jr,n)}else if(r.startsWith("!=")){let i=r.slice(2);e=H(i),t=m(new Yr,n)}else if(r.startsWith("<=")){let i=r.slice(2);e=H(i),t=m(new Kr,n)}else if(r.startsWith(">=")){let i=r.slice(2);e=H(i),t=m(new Qr,n)}else if(r.startsWith("+")){let i=r.slice(1);e=H(i),t=m(new Dr,n)}else if(r.startsWith("-")){let i=r.slice(1);e=H(i),t=m(new xr,n)}else if(r.startsWith("*")){let i=r.slice(1);e=H(i),t=m(new Rr,n)}else if(r.startsWith("/")){let i=r.slice(1);e=H(i),t=m(new Gr,n)}else if(r.startsWith("=")){let i=r.slice(1);e=H(i),t=m(new ts,n)}else if(r.startsWith("!")){let i=r.slice(1);e=H(i),t=m(new Vr,n)}else if(r.startsWith("<")){let i=r.slice(1);e=H(i),t=m(new Xr,n)}else if(r.startsWith(">")){let i=r.slice(1);e=H(i),t=m(new Zr,n)}else if(r.startsWith("(")){let i=r.slice(1);e=H(i),t=m(new an,n)}else if(r.startsWith(")")){let i=r.slice(1);e=H(i),t=m(new fn,n)}else if(r.startsWith("_")){let i=r.slice(1);e=H(i),t=m(new pn,n)}else return O((()=>{let i=Eu(r,"");return vi(i,new ct("Could not understand provided txt: "+r))})(),i=>{let s=i[0],o=i[1];return Bu(H(o),m(new Ht(s),n))})}}function Cu(e){let t=Bo(e);if(t==="")return new f(d([]));if(t.startsWith("=")){let r=t.slice(1);return Bu(H(r),d([]))}else{if(t==="TRUE")return new f(d([new sn]));if(t==="FALSE")return new f(d([new ln]));if(t.startsWith("$")){let r=t.slice(1);return O((()=>{let n=bl(r);return vi(n,new ct("Could not parse USD literal"))})(),n=>{let i=n[0],s=n[1];return M(s!=="",new _(new ct("Found extra content after USD literal")),()=>new f(d([new rn(i)])))})}else{let r=t,n=Eu(r,"");if(n.isOk()){let i=n[0][0],s=n[0][1];return s===""?new f(d([new cn(i)])):new _(new ct("Unexpected content: "+s))}else{if(Eo(r,"%"))return O((()=>{let s=bl(r);return vi(s,new ct("Expected valid number before % sign."))})(),s=>{let o=s[0],l=s[1];return M(l!=="%",new _(new ct("Expected valid number before % literal")),()=>new f(d([new nn(Yn(o,Xe(100)))])))});{let s=co(r);if(s.isOk()){let o=s[0];return new f(d([new tn(o)]))}else{let o=Hs(r);if(o.isOk()){let l=o[0];return new f(d([new en(l)]))}else return new _(new ct("duh"))}}}}}}function jt(e,t){if(t instanceof te)return new f(new et(new Dt));if(t instanceof _r){let r=t.key;if(!(r instanceof N))throw G("let_assert","squared_away/squared_away_lang/typechecker",21,"typecheck","Pattern match failed, no pattern matched the value.",{value:r});let n=r[0],i=(()=>{let l=dt(e),u=kr(l,$=>{let x=$[0];return qr(x)===qr(n)&&lr(x){let w=$[0],h=x[0];return De(lr(w),lr(h))}),c=A(a);return ko(c,$=>{let x=$[1];return!(x.isOk()&&x[0]instanceof Ke)})})(),s=F(i,l=>l[0]),o=F(i,l=>l[1]);return M(On(o,Or),new _(new _e(new Be("Cell above sum expression has error"))),()=>{let l=(()=>{let u=F(o,c=>{if(!c.isOk())throw G("let_assert","squared_away/squared_away_lang/typechecker",59,"","Pattern match failed, no pattern matched the value.",{value:c});return c[0]}),a=Tn(u);return F(a,c=>jt(e,c))})();return M(On(l,Or),new _(new _e(new Be("Cell above sum expression has type error"))),()=>{let u=(()=>{let a=F(l,$=>{if(!$.isOk())throw G("let_assert","squared_away/squared_away_lang/typechecker",76,"","Pattern match failed, no pattern matched the value.",{value:$});return $[0].type_}),c=Tn(a);return kr(c,$=>!g($,new Rt))})();return u.hasLength(1)&&u.head instanceof j?new f(new rt(new j,s)):u.hasLength(1)&&u.head instanceof q?new f(new rt(new q,s)):u.hasLength(1)&&u.head instanceof B?new f(new rt(new B,s)):u.hasLength(1)&&u.head instanceof W?new f(new rt(new W,s)):new _(new _e(new Be("sum function can only be used on floats, integers, and USD.")))})})}else if(t instanceof Ke){let r=t.txt,n=Ri(e,0,(i,s,o)=>{if(o.isOk()&&o[0]instanceof Ke&&r===o[0].txt){let l=o[0].txt;return i+1}else return i});return n===1?new f(new Je(new Dt,r)):n>1?new _(new _e(new Be("Duplicate Label"))):new _(new _e(new Be("This is an internal compiler error.")))}else if(t instanceof zt){let r=t.txt,n=(()=>{let s=dt(e),o=wi(s,new E,(a,c)=>{if(c[1].isOk()&&c[1][0]instanceof Ke&&c[1][0].txt===r){let $=c[0],x=c[1][0].txt;return new br(new N($))}else return new It(new E)}),l=ks(o,a=>or(e,a)),u=ks(l,bs);return Il(u)})();if(n instanceof E)return new _(new _e(new Be("Label doesn't point to anything")));{let i=n[0],s=J(e,i);if(s.isOk())if(s.isOk()&&s[0]instanceof zt&&s[0].txt===r){let o=s[0].txt;return new _(new _e(new Be("Label points to itself")))}else{let o=s[0],l=jt(e,o);if(l.isOk()){let u=l[0];return new f(new tt(u.type_,i,r))}else{let u=l[0];return new _(u)}}else{let o=s[0];return new _(o)}}}else if(t instanceof cr){let r=t.row,n=t.col,i=(()=>{let o=dt(e);return wi(o,new E,(l,u)=>{if(u[1].isOk()&&u[1][0]instanceof Ke&&u[1][0].txt===n){let a=u[0],c=u[1][0].txt;return new br(new N(a))}else return new It(new E)})})();if(i instanceof E)return new _(new _e(new Be("No label called: "+n)));{let s=i[0],o=(()=>{let u=dt(e);return wi(u,new E,(a,c)=>{if(c[1].isOk()&&c[1][0]instanceof Ke&&c[1][0].txt===r){let $=c[0],x=c[1][0].txt;return new br(new N($))}else return new It(new E)})})();if(o instanceof E)return new _(new _e(new Be("No label called: "+r)));{let l=o[0],u=xu(l,s);if(u.isOk()){let a=u[0],c=J(e,a);if(c.isOk()){let $=c[0],x=jt(e,$);if(x.isOk()){let w=x[0];return new f(new je(w.type_,a,r,n))}else{let w=x[0];return new _(w)}}else{let $=c[0];return new _($)}}else return new _(new _e(new Be("Labels "+r+" and "+n+" do not intersect")))}}}else if(t instanceof vt){let r=t.val;return new f(new Et(new S,r))}else if(t instanceof ur){let r=t.f;return new f(new Ot(new j,r))}else if(t instanceof ar){let r=t.cents;return new f(new Ur(new B,r))}else if(t instanceof fr){let r=t.percent;return new f(new Tt(new W,r))}else if(t instanceof pr){let r=t.n;return new f(new Lt(new q,r))}else if(t instanceof $r){let r=t.inner;return O(jt(e,r),n=>new f(new Bt(n.type_,n)))}else if(t instanceof dr){let r=t.op,n=t.expr;return O(jt(e,n),i=>{let s=i.type_;return r instanceof Ge&&s instanceof q?new f(new ke(i.type_,r,i)):r instanceof Ge&&s instanceof j?new f(new ke(i.type_,r,i)):r instanceof Ge&&s instanceof B?new f(new ke(i.type_,r,i)):r instanceof mt&&s instanceof S?new f(new ke(i.type_,r,i)):r instanceof mt&&s instanceof W?new f(new ke(i.type_,r,i)):new _(new _e(new Be("Unexpected type and operator combination")))})}else{let r=t.lhs,n=t.op,i=t.rhs;return O(jt(e,r),s=>O(jt(e,i),o=>{let l=s.type_,u=o.type_;if(l instanceof j&&n instanceof Le&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof j&&n instanceof Ee&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof j&&n instanceof R&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof j&&n instanceof ie&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof j&&n instanceof we&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof j&&n instanceof we&&u instanceof q)return new f(new y(new j,s,n,o));if(l instanceof B&&n instanceof R&&u instanceof q)return new f(new y(new B,s,n,o));if(l instanceof B&&n instanceof ie&&u instanceof q)return new f(new y(new B,s,n,o));if(l instanceof W&&n instanceof we&&u instanceof q)return new f(new y(new W,s,n,o));if(l instanceof B&&n instanceof Le&&u instanceof B)return new f(new y(new B,s,n,o));if(l instanceof B&&n instanceof Ee&&u instanceof B)return new f(new y(new B,s,n,o));if(l instanceof B&&n instanceof ie&&u instanceof B)return new f(new y(new W,s,n,o));if(l instanceof B&&n instanceof R&&u instanceof B)return new _(new _e(new Zi(s,o)));if(l instanceof W&&n instanceof R&&u instanceof B)return new f(new y(new B,s,n,o));if(l instanceof B&&n instanceof R&&u instanceof W)return new f(new y(new B,s,n,o));if(l instanceof B&&n instanceof ie&&u instanceof W)return new f(new y(new B,s,n,o));if(l instanceof W&&n instanceof ie&&u instanceof W)return new f(new y(new W,s,n,o));if(l instanceof W&&n instanceof R&&u instanceof W)return new f(new y(new W,s,n,o));if(l instanceof W&&n instanceof we&&u instanceof W)return new f(new y(new W,s,n,o));if(l instanceof S&&n instanceof Ze&&u instanceof S)return new f(new y(new S,s,n,o));if(l instanceof S&&n instanceof Qe&&u instanceof S)return new f(new y(new S,s,n,o));if(l instanceof q&&n instanceof we&&u instanceof j)return new f(new y(new j,s,n,o));if(l instanceof q&&n instanceof Le&&u instanceof q)return new f(new y(new q,s,n,o));if(l instanceof q&&n instanceof Ee&&u instanceof q)return new f(new y(new q,s,n,o));if(l instanceof q&&n instanceof R&&u instanceof q)return new f(new y(new q,s,n,o));if(l instanceof q&&n instanceof ie&&u instanceof q)return new f(new y(new q,s,n,o));if(l instanceof q&&n instanceof R&&u instanceof B)return new f(new y(new B,s,n,o));if(n instanceof Fe&&g(l,u)){let a=l,c=u;return new f(new y(new S,s,n,o))}else if(n instanceof We&&g(l,u)){let a=l,c=u;return new f(new y(new S,s,n,o))}else{if(l instanceof j&&n instanceof he&&u instanceof j)return new f(new y(new S,s,n,o));if(l instanceof j&&n instanceof ye&&u instanceof j)return new f(new y(new S,s,n,o));if(l instanceof j&&n instanceof be&&u instanceof j)return new f(new y(new S,s,n,o));if(l instanceof j&&n instanceof ge&&u instanceof j)return new f(new y(new S,s,n,o));if(l instanceof q&&n instanceof he&&u instanceof q)return new f(new y(new S,s,n,o));if(l instanceof q&&n instanceof ye&&u instanceof q)return new f(new y(new S,s,n,o));if(l instanceof q&&n instanceof be&&u instanceof q)return new f(new y(new S,s,n,o));if(l instanceof q&&n instanceof ge&&u instanceof q)return new f(new y(new S,s,n,o));if(l instanceof He&&n instanceof he&&u instanceof He)return new f(new y(new S,s,n,o));if(l instanceof He&&n instanceof ye&&u instanceof He)return new f(new y(new S,s,n,o));if(l instanceof He&&n instanceof be&&u instanceof He)return new f(new y(new S,s,n,o));if(l instanceof He&&n instanceof ge&&u instanceof He)return new f(new y(new S,s,n,o));if(l instanceof B&&n instanceof he&&u instanceof B)return new f(new y(new S,s,n,o));if(l instanceof B&&n instanceof ye&&u instanceof B)return new f(new y(new S,s,n,o));if(l instanceof B&&n instanceof be&&u instanceof B)return new f(new y(new S,s,n,o));if(l instanceof B&&n instanceof ge&&u instanceof B)return new f(new y(new S,s,n,o));if(l instanceof W&&n instanceof he&&u instanceof W)return new f(new y(new S,s,n,o));if(l instanceof W&&n instanceof ye&&u instanceof W)return new f(new y(new S,s,n,o));if(l instanceof W&&n instanceof be&&u instanceof W)return new f(new y(new S,s,n,o));if(l instanceof W&&n instanceof ge&&u instanceof W)return new f(new y(new S,s,n,o));if(n instanceof Mt&&g(u,l)){let a=l,c=u;return new f(new y(new Rt,s,n,o))}else{let a=l,c=n,$=u;return new _(new _e(new Kn(a,$,c)))}}}))}}function Pu(e){return Gn(e,(t,r)=>{if(r.isOk()){let n=r[0];return Mr(e,n)}else{let n=r[0];return new _(n)}})}function rs(e){return Gn(e,(t,r)=>{if(r.isOk()){let n=r[0];return jt(e,n)}else{let n=r[0];return new _(n)}})}function ei(e,t,r){for(;;){let n=e,i=t,s=r;if(i instanceof y){let o=i.lhs,l=i.rhs,u=ei(n,o,d([])),a=ei(n,l,d([])),c=(()=>{let $=Yo(sl(u),sl(a));return An($)})();return Zt(d([c,s]))}else{if(i instanceof Et)return s;if(i instanceof rt){let o=i.keys,l=F(o,a=>{let c=J(n,a);if(c.isOk()){let $=c[0];return ei(n,$,d([a]))}else return d([a])}),u=Zt(l);return kn(u,s)}else if(i instanceof je){let o=i.key,l=J(n,o);if(l.isOk()){let u=l[0];e=n,t=u,r=m(o,s)}else return m(o,s)}else{if(i instanceof et)return s;if(i instanceof Ot)return s;if(i instanceof Bt){let o=i.expr;e=n,t=o,r=s}else{if(i instanceof Lt)return s;if(i instanceof tt){let o=i.key,l=J(n,o);if(l.isOk()){let u=l[0];e=n,t=u,r=m(o,s)}else return m(o,s)}else{if(i instanceof Je)return s;if(i instanceof Tt)return s;if(i instanceof ke){let o=i.expr;e=n,t=o,r=s}else return s}}}}}}function ns(e){return Gn(e,(t,r)=>{if(r.isOk()){let n=r[0],i=F(n,u=>u instanceof Pt&&u.key instanceof E?new Pt(new N(t)):u),o=Lu(i);return tr(o,l=>new Zn(l))}else{let n=r[0];return new _(n)}})}function is(e){return Gn(e,(t,r)=>{let n=Cu(r);return tr(n,i=>new Qi(i))})}function Nu(e){let t=document.getElementById(e);t.focus();let r=t.value.length;setTimeout(()=>{t.setSelectionRange(r,r)},0)}function Au(e,t){let r=new Blob([e],{type:"text/csv"}),n=URL.createObjectURL(r),i=document.createElement("a");i.href=n,i.download=t,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(n)}function qu(){return document.getElementById("csvupload").files[0].text()}var Ll=class extends p{constructor(t,r,n,i,s,o,l,u,a,c){super(),this.holding_shift=t,this.grid_width=r,this.grid_height=n,this.display_formulas=i,this.display_coords=s,this.active_cell=o,this.src_grid=l,this.type_checked_grid=u,this.value_grid=a,this.errors_to_display=c}},El=class extends p{},ss=class extends p{constructor(t){super(),this.to=t}},ls=class extends p{constructor(t){super(),this.to=t}},os=class extends p{constructor(t,r){super(),this.key=t,this.val=r}},us=class extends p{constructor(t){super(),this.key=t}},as=class extends p{},fs=class extends p{},cs=class extends p{constructor(t){super(),this.path=t}},Bl=class extends p{constructor(t){super(),this.file_content=t}},ps=class extends p{constructor(t){super(),this.cell=t}},ds=class extends p{constructor(t){super(),this.cell=t}},$s=class extends p{constructor(t){super(),this.cell=t}},_s=class extends p{constructor(t){super(),this.cell=t}},ms=class extends p{constructor(t){super(),this.cell=t}},xs=class extends p{constructor(t){super(),this.cell=t}},ws=class extends p{constructor(t){super(),this.cell=t}};function Cl(e){return rl(t=>Nu(e))}function ri(e){let t=is(e.src_grid),r=ns(t),n=rs(r),i=Pu(n),s=Ri(i,d([]),(o,l,u)=>{if(u.isOk())return o;{let a=u[0];return m([l,a],o)}});return e.withFields({value_grid:i,type_checked_grid:n,errors_to_display:s})}function xc(e,t){return O(Ut("key",Bn)(e),r=>O(Ut("shiftKey",Oi)(e),n=>r==="ArrowUp"?new f(new ps(t)):r==="ArrowLeft"?new f(new ds(t)):r==="ArrowRight"&&n?new f(new xs(t)):r==="ArrowRight"?new f(new $s(t)):r==="ArrowDown"&&n?new f(new ws(t)):r==="ArrowDown"?new f(new _s(t)):r==="Enter"?new f(new ms(t)):new _(d([]))))}function ti(e,t){if(t.isOk()){let r=t[0],n=Ar(r);return[e.withFields({active_cell:new N(r)}),Cl(n)]}else return[e,ae()]}function Jt(e){return d([ru(e)])}function wc(e){return at(d([jr(d([["background-color","#ffe6e6"],["color","#b30000"],["padding","20px"],["border-radius","20px"]]))]),m(nu(d([]),Jt(e.title)),m(cl(d([]),Jt(e.info)),(()=>{let t=e.hint;if(t instanceof E)return d([]);{let r=t[0];return d([cl(d([]),Jt(r))])}})())))}function hc(e){let t=(()=>{let T=hi(e.errors_to_display,U=>g(new N(U[0]),e.active_cell)?new f(wc((()=>{let k=U[1];return Ou(k)})())):new _(void 0));return Co(T,at(d([]),d([])))})(),r=(()=>{let T=e.src_grid.cells,U=bo(T,lr),v=gn(U,(se,Ye)=>{let Iu=(()=>{let Fu=gt(Ye,(pe,hs)=>De(qr(pe),qr(hs)));return F(Fu,pe=>{let hs=ir("keydown",Ce=>xc(Ce,pe)),ys=dl(Ce=>new os(pe,Ce)),Wu=fu(new as),Uu=au(new us(pe)),zu=jn(Ar(pe)),Mu=(()=>{let Ce=(()=>{let Ue=e.display_formulas,Ne=g(e.active_cell,new N(pe));if(Ue)return J(e.src_grid,pe);if(!Ue&&Ne)return J(e.src_grid,pe);{let _n=J(e.value_grid,pe);if(_n.isOk()){let Nl=_n[0];return Qn(Nl)}else return J(e.src_grid,pe)}})();return zo(Ce)})(),Du=(()=>{if(g(e.active_cell,new N(pe))||e.display_formulas)return"left";{let Ue=J(e.value_grid,pe);if(Ue.isOk()){let Ne=Ue[0];return Ne instanceof ve||Ne instanceof P||Ne instanceof C||Ne instanceof D||Ne instanceof I?"right":Ne instanceof wt||Ne instanceof nt||Ne instanceof Ct?"center":"left"}else return"left"}})(),Ru=On(e.errors_to_display,Ce=>g(Ce[0],pe)),Gu=Ru?bt("errorcell"):Uo(),$n=(()=>{let Ce=J(e.value_grid,pe);if(Ce.isOk()){let Ue=Ce[0];return Ue instanceof mr?["#4a4a4a","#f2f2f2"]:Ue instanceof nt?["#006400","#e6ffe6"]:Ue instanceof wt?["#b30000","#ffe6e6"]:["black","white"]}else return["#b30000","#ffe6e6"]})(),Pl=(()=>{let Ce=e.active_cell;if(Ce instanceof E)return $n;{let Ue=Ce[0],Ne=J(e.type_checked_grid,Ue);if(Ne.isOk()){let _n=Ne[0];if(_n.type_ instanceof Rt){let Al=J(e.value_grid,Ue);return Al.isOk()&&Al[0]instanceof nt&&(()=>{let Yu=ei(e.type_checked_grid,_n,d([]));return _i(Yu,pe)})()?["#006400","#e6ffe6"]:$n}else return $n}else return $n}})(),Hu=Pl[0],Ju=Pl[1],jl=zn(d([ys,Uu,Wu,Mu,hs,zu,Nn("text"),Gu,jr(d([["background-color",Ju],["color",Hu],["text-align",Du]]))]));return e.display_coords?pl(d([]),d([Mn(d([]),Jt(Ar(pe)+": ")),jl])):pl(d([]),d([jl]))})})();return lu(d([]),Iu)}),k=Ve(v),z=gt(k,(se,Ye)=>De(se[0],Ye[0]));return F(z,se=>se[1])})(),n=iu(d([bt("tg")]),d([su(d([]),r)])),i=zn(d([Nn("checkbox"),jn("formula_mode"),$l(T=>new ss(T))])),s=Mn(d([nl("formula_mode")]),Jt("Show formulas")),o=zn(d([Nn("checkbox"),jn("grid_mode"),$l(T=>new ls(T))])),l=Mn(d([nl("grid_mode")]),Jt("Show grid coordinates")),u=ou(d([uu(new fs)]),Jt("Save")),a=zn(d([Nn("file"),jn("csvupload"),dl(T=>new cs(T))])),c=(()=>{let T=e.value_grid,U=dt(T),v=F(U,yo);return ue(v,[0,0],(k,z)=>{let se=k[0],Ye=k[1];return z.isOk()&&z[0]instanceof nt?[se+1,Ye+1]:z.isOk()&&z[0]instanceof wt?[se,Ye+1]:[se,Ye]})})(),$=c[0],x=c[1],w=$===x?["#006400","#e6ffe6"]:["#b30000","#ffe6e6"],h=w[0],b=w[1],L=Mn(d([jr(d([["color",h],["background-color",b]]))]),Jt(me($)+"/"+me(x)+" tests passing"));return at(d([jr(d([["text-align","center"]]))]),d([at(d([]),d([at(d([bt("menu-item")]),d([i,s])),at(d([bt("menu-item")]),d([o,l])),at(d([bt("menu-item")]),d([a])),at(d([bt("menu-item")]),d([u])),at(d([bt("menu-item")]),d([L]))])),n,t]))}var ni=7,ii=20;function yc(e){let t=Mi(ni,ii,""),r=Mi(ni,ii,new f(new et(new Dt))),n=Mi(ni,ii,new f(new Ct));return[(()=>{let s=new Ll(!1,ni,ii,!1,!1,new E,t,r,n,d([]));return ri(s)})(),ae()]}function gc(e,t){if(t instanceof El)return[e,ae()];if(t instanceof os){let r=t.key,n=t.val,i=e.withFields({src_grid:Di(e.src_grid,r,n)});return[ri(i),ae()]}else if(t instanceof ss){let r=t.to;return[e.withFields({display_formulas:r}),ae()]}else if(t instanceof ls){let r=t.to;return[e.withFields({display_coords:r}),ae()]}else if(t instanceof us){let r=t.key;return[e.withFields({active_cell:new N(r)}),ae()]}else{if(t instanceof as)return[e.withFields({active_cell:new E}),ae()];if(t instanceof ps){let r=t.cell;return ti(e,_u(e.src_grid,r))}else if(t instanceof ds){let r=t.cell;return ti(e,mu(e.src_grid,r))}else if(t instanceof $s){let r=t.cell;return ti(e,or(e.src_grid,r))}else if(t instanceof _s){let r=t.cell;return ti(e,Sr(e.src_grid,r))}else if(t instanceof ms){let r=t.cell;return ti(e,Sr(e.src_grid,r))}else if(t instanceof xs){let r=t.cell,n=or(e.src_grid,r);if(!n.isOk()&&!n[0])return[e,ae()];{let i=n[0],s=is(e.src_grid),o=ns(s),l=rs(o),u=J(l,r);return M(Or(u),[e,ae()],()=>{if(!u.isOk())throw G("let_assert","squared_away",207,"","Pattern match failed, no pattern matched the value.",{value:u});let a=u[0],c=Wr(a,($,x,w)=>{let h=wl(e.src_grid,w);if(!h.isOk())throw G("let_assert","squared_away",215,"","Pattern match failed, no pattern matched the value.",{value:h});let b=h[0];return O(or(e.src_grid,b),L=>{let T=J(l,L);return O((v=>{if(v.isOk()&&v[0]instanceof Je){let k=v[0].txt;return new f(k)}else return new _(void 0)})(T),v=>{let k=or(e.src_grid,$);if(!k.isOk())throw G("let_assert","squared_away",235,"","Pattern match failed, no pattern matched the value.",{value:k});let z=k[0];return new f(new je(a.type_,z,x,v))})})});if(c.isOk()){let $=c[0],x=zr($),w=Di(e.src_grid,i,x),h=Ar(i),b=e.withFields({src_grid:w,active_cell:new N(i)});return[ri(b),Cl(h)]}else return[e,ae()]})}}else if(t instanceof ws){let r=t.cell,n=Sr(e.src_grid,r);if(!n.isOk()&&!n[0])return[e,ae()];{let i=n[0],s=is(e.src_grid),o=ns(s),l=rs(o),u=J(l,r);return M(Or(u),[e,ae()],()=>{if(!u.isOk())throw G("let_assert","squared_away",275,"","Pattern match failed, no pattern matched the value.",{value:u});let a=u[0],c=Wr(a,($,x,w)=>{let h=wl(e.src_grid,x);if(!h.isOk())throw G("let_assert","squared_away",280,"","Pattern match failed, no pattern matched the value.",{value:h});let b=h[0];return O(Sr(e.src_grid,b),L=>{let T=J(l,L);return O((v=>{if(v.isOk()&&v[0]instanceof Je){let k=v[0].txt;return new f(k)}else return new _(void 0)})(T),v=>{let k=Sr(e.src_grid,$);if(!k.isOk())throw G("let_assert","squared_away",299,"","Pattern match failed, no pattern matched the value.",{value:k});let z=k[0];return new f(new je(a.type_,z,v,w))})})});if(c.isOk()){let $=c[0],x=zr($),w=Di(e.src_grid,i,x),h=Ar(i),b=e.withFields({src_grid:w,active_cell:new N(i)});return[ri(b),Cl(h)]}else return[e,ae()]})}}else if(t instanceof fs){let r=wu(e.src_grid);return Au(r,"myspreadsheet.csv"),[e,ae()]}else if(t instanceof cs){let r=rl(n=>{el(qu(),i=>Qs(s=>(n(new Bl(i)),s(void 0))))});return[e,r]}else{let r=t.file_content,n=hu(r,ni,ii);return[(()=>{let s=e.withFields({src_grid:n});return ri(s)})(),ae()]}}}function Su(){let e=eu(yc,gc,hc),t=tu(e,"#app",void 0);if(!t.isOk())throw G("let_assert","squared_away",32,"main","Pattern match failed, no pattern matched the value.",{value:t})}Su(); diff --git a/priv/static/squared_away.mjs b/priv/static/squared_away.mjs index 65fd794..f974d2b 100644 --- a/priv/static/squared_away.mjs +++ b/priv/static/squared_away.mjs @@ -1181,9 +1181,15 @@ function power(base, exponent) { function new_map() { return Dict.new(); } +function map_size(map6) { + return map6.size; +} function map_to_list(map6) { return List.fromArray(map6.entries()); } +function map_remove(key, map6) { + return map6.delete(key); +} function map_get(map6, key) { const value3 = map6.get(key, NOT_FOUND); if (value3 === NOT_FOUND) { @@ -1523,6 +1529,37 @@ function do_keys(dict) { function keys(dict) { return do_keys(dict); } +function insert_taken(loop$dict, loop$desired_keys, loop$acc) { + while (true) { + let dict = loop$dict; + let desired_keys = loop$desired_keys; + let acc = loop$acc; + let insert$1 = (taken, key) => { + let $ = get(dict, key); + if ($.isOk()) { + let value3 = $[0]; + return insert(taken, key, value3); + } else { + return taken; + } + }; + if (desired_keys.hasLength(0)) { + return acc; + } else { + let first2 = desired_keys.head; + let rest = desired_keys.tail; + loop$dict = dict; + loop$desired_keys = rest; + loop$acc = insert$1(acc, first2); + } + } +} +function do_take(desired_keys, dict) { + return insert_taken(dict, desired_keys, new$()); +} +function take(dict, desired_keys) { + return do_take(desired_keys, dict); +} function insert_pair(dict, pair) { return insert(dict, pair[0], pair[1]); } @@ -1548,6 +1585,9 @@ function do_merge(dict, new_entries) { function merge(dict, new_entries) { return do_merge(dict, new_entries); } +function delete$(dict, key) { + return map_remove(key, dict); +} function do_fold(loop$list, loop$initial, loop$fun) { while (true) { let list = loop$list; @@ -1743,7 +1783,7 @@ function do_index_map(loop$list, loop$fun, loop$index, loop$acc) { function index_map(list, fun) { return do_index_map(list, fun, 0, toList([])); } -function do_take(loop$list, loop$n, loop$acc) { +function do_take2(loop$list, loop$n, loop$acc) { while (true) { let list = loop$list; let n = loop$n; @@ -1764,8 +1804,8 @@ function do_take(loop$list, loop$n, loop$acc) { } } } -function take(list, n) { - return do_take(list, n, toList([])); +function take2(list, n) { + return do_take2(list, n, toList([])); } function do_append(loop$first, loop$second) { while (true) { @@ -2844,6 +2884,63 @@ var Set2 = class extends CustomType { function new$3() { return new Set2(new$()); } +function delete$2(set2, member) { + return new Set2(delete$(set2.dict, member)); +} +function to_list2(set2) { + return keys(set2.dict); +} +function fold3(set2, initial, reducer) { + return fold(set2.dict, initial, (a, k, _) => { + return reducer(a, k); + }); +} +function drop(set2, disallowed) { + return fold2(disallowed, set2, delete$2); +} +function take3(set2, desired) { + return new Set2(take(set2.dict, desired)); +} +function order(first2, second2) { + let $ = map_size(first2.dict) > map_size(second2.dict); + if ($) { + return [first2, second2]; + } else { + return [second2, first2]; + } +} +function intersection(first2, second2) { + let $ = order(first2, second2); + let larger = $[0]; + let smaller = $[1]; + return take3(larger, to_list2(smaller)); +} +function difference(first2, second2) { + return drop(first2, to_list2(second2)); +} +var token = void 0; +function insert2(set2, member) { + return new Set2(insert(set2.dict, member, token)); +} +function from_list2(members) { + let dict = fold2( + members, + new$(), + (m, k) => { + return insert(m, k, token); + } + ); + return new Set2(dict); +} +function union(first2, second2) { + let $ = order(first2, second2); + let larger = $[0]; + let smaller = $[1]; + return fold3(smaller, larger, insert2); +} +function symmetric_difference(first2, second2) { + return difference(union(first2, second2), intersection(first2, second2)); +} // build/dev/javascript/lustre/lustre/internals/patch.mjs var Diff = class extends CustomType { @@ -4250,11 +4347,11 @@ function from_src_csv(src, width, height) { } let src$1 = $[0]; let inner = (() => { - let _pipe = take(src$1, height); + let _pipe = take2(src$1, height); let _pipe$1 = map2( _pipe, (_capture) => { - return take(_capture, width); + return take2(_capture, width); } ); let _pipe$2 = index_map( @@ -4876,48 +4973,6 @@ function visit_cross_labels(te, f) { return new Ok(te); } } -function dependency_list(te, acc) { - if (te instanceof BinaryOp2) { - let lhs = te.lhs; - let rhs = te.rhs; - return flatten2( - toList([ - dependency_list(lhs, toList([])), - dependency_list(rhs, toList([])), - acc - ]) - ); - } else if (te instanceof BooleanLiteral2) { - return acc; - } else if (te instanceof BuiltinSum2) { - let keys2 = te.keys; - return flatten2(toList([keys2, acc])); - } else if (te instanceof CrossLabel2) { - let key = te.key; - return prepend(key, acc); - } else if (te instanceof Empty3) { - return acc; - } else if (te instanceof FloatLiteral2) { - return acc; - } else if (te instanceof Group2) { - let inner = te.expr; - return flatten2(toList([dependency_list(inner, toList([])), acc])); - } else if (te instanceof IntegerLiteral2) { - return acc; - } else if (te instanceof Label2) { - let key = te.key; - return prepend(key, acc); - } else if (te instanceof LabelDef2) { - return acc; - } else if (te instanceof PercentLiteral2) { - return acc; - } else if (te instanceof UnaryOp2) { - let inner = te.expr; - return flatten2(toList([dependency_list(inner, toList([])), acc])); - } else { - return acc; - } -} function do_to_string2(te) { if (te instanceof BooleanLiteral2) { let b = te.b; @@ -5408,7 +5463,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 135, + 134, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -5424,7 +5479,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 139, + 138, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -5559,7 +5614,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 221, + 220, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -5580,7 +5635,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 229, + 228, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -5601,7 +5656,7 @@ function interpret(loop$env, loop$expr) { throw makeError( "let_assert", "squared_away/squared_away_lang/interpreter", - 237, + 236, "", "Pattern match failed, no pattern matched the value.", { value: v } @@ -7426,24 +7481,87 @@ function typecheck_grid(input2) { } ); } -function dependency_list2(input2, key, acc) { - let $ = get4(input2, key); - if (!$.isOk()) { - return acc; - } else { - let te = $[0]; - let deps = dependency_list(te, toList([])); - let double_deps = (() => { +function dependency_list(loop$input, loop$te, loop$acc) { + while (true) { + let input2 = loop$input; + let te = loop$te; + let acc = loop$acc; + if (te instanceof BinaryOp2) { + let lhs = te.lhs; + let rhs = te.rhs; + let lhs$1 = dependency_list(input2, lhs, toList([])); + let rhs$1 = dependency_list(input2, rhs, toList([])); + let deps = (() => { + let _pipe = symmetric_difference( + from_list2(lhs$1), + from_list2(rhs$1) + ); + return to_list2(_pipe); + })(); + return flatten2(toList([deps, acc])); + } else if (te instanceof BooleanLiteral2) { + return acc; + } else if (te instanceof BuiltinSum2) { + let keys2 = te.keys; let _pipe = map2( - deps, - (_capture) => { - return dependency_list2(input2, _capture, toList([])); + keys2, + (k) => { + let $ = get4(input2, k); + if (!$.isOk()) { + return toList([k]); + } else { + let te$1 = $[0]; + return dependency_list(input2, te$1, toList([k])); + } } ); let _pipe$1 = flatten2(_pipe); - return append(_pipe$1, deps); - })(); - return double_deps; + return append(_pipe$1, acc); + } else if (te instanceof CrossLabel2) { + let key = te.key; + let $ = get4(input2, key); + if (!$.isOk()) { + return prepend(key, acc); + } else { + let te$1 = $[0]; + loop$input = input2; + loop$te = te$1; + loop$acc = prepend(key, acc); + } + } else if (te instanceof Empty3) { + return acc; + } else if (te instanceof FloatLiteral2) { + return acc; + } else if (te instanceof Group2) { + let inner = te.expr; + loop$input = input2; + loop$te = inner; + loop$acc = acc; + } else if (te instanceof IntegerLiteral2) { + return acc; + } else if (te instanceof Label2) { + let key = te.key; + let $ = get4(input2, key); + if (!$.isOk()) { + return prepend(key, acc); + } else { + let te$1 = $[0]; + loop$input = input2; + loop$te = te$1; + loop$acc = prepend(key, acc); + } + } else if (te instanceof LabelDef2) { + return acc; + } else if (te instanceof PercentLiteral2) { + return acc; + } else if (te instanceof UnaryOp2) { + let inner = te.expr; + loop$input = input2; + loop$te = inner; + loop$acc = acc; + } else { + return acc; + } } } function parse_grid(input2) { @@ -7879,9 +7997,9 @@ function view(model) { let $4 = get4(model.value_grid, active_cell); if ($4.isOk() && $4[0] instanceof TestPass) { let $5 = (() => { - let _pipe$32 = dependency_list2( + let _pipe$32 = dependency_list( model.type_checked_grid, - active_cell, + typed_expr, toList([]) ); return contains(_pipe$32, key); @@ -8178,7 +8296,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 201, + 207, "", "Pattern match failed, no pattern matched the value.", { value: maybe_expr } @@ -8193,7 +8311,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 209, + 215, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -8220,7 +8338,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 229, + 235, "", "Pattern match failed, no pattern matched the value.", { value: $1 } @@ -8279,7 +8397,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 269, + 275, "", "Pattern match failed, no pattern matched the value.", { value: maybe_expr } @@ -8294,7 +8412,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 274, + 280, "", "Pattern match failed, no pattern matched the value.", { value: $ } @@ -8321,7 +8439,7 @@ function update(model, msg) { throw makeError( "let_assert", "squared_away", - 293, + 299, "", "Pattern match failed, no pattern matched the value.", { value: $1 } diff --git a/src/squared_away.gleam b/src/squared_away.gleam index be0bae5..0301780 100644 --- a/src/squared_away.gleam +++ b/src/squared_away.gleam @@ -447,7 +447,7 @@ fn view(model: Model) -> element.Element(Msg) { case squared_away_lang.dependency_list( model.type_checked_grid, - active_cell, + typed_expr, [], ) |> list.contains(key) diff --git a/src/squared_away/squared_away_lang.gleam b/src/squared_away/squared_away_lang.gleam index 659e9f0..180df5a 100644 --- a/src/squared_away/squared_away_lang.gleam +++ b/src/squared_away/squared_away_lang.gleam @@ -1,6 +1,7 @@ import gleam/list import gleam/option import gleam/result +import gleam/set import squared_away/squared_away_lang/error import squared_away/squared_away_lang/grid import squared_away/squared_away_lang/interpreter @@ -34,18 +35,46 @@ pub fn typecheck_grid( pub fn dependency_list( input: grid.Grid(Result(typed_expr.TypedExpr, error.CompileError)), - key: grid.GridKey, + te: typed_expr.TypedExpr, acc: List(grid.GridKey), ) -> List(grid.GridKey) { - case grid.get(input, key) { - Error(_) -> acc - Ok(te) -> { - let deps = typed_expr.dependency_list(te, []) - let double_deps = - list.map(deps, dependency_list(input, _, [])) - |> list.flatten - |> list.append(deps) + case te { + typed_expr.BinaryOp(_, lhs:, op: _, rhs:) -> { + let lhs = dependency_list(input, lhs, []) + let rhs = dependency_list(input, rhs, []) + let deps = + set.symmetric_difference(set.from_list(lhs), set.from_list(rhs)) + |> set.to_list + list.flatten([deps, acc]) } + typed_expr.BooleanLiteral(_, _) -> acc + typed_expr.BuiltinSum(_, keys) -> + list.map(keys, fn(k) { + case grid.get(input, k) { + Error(_) -> [k] + Ok(te) -> dependency_list(input, te, [k]) + } + }) + |> list.flatten + |> list.append(acc) + typed_expr.CrossLabel(_, key, _, _) -> + case grid.get(input, key) { + Error(_) -> [key, ..acc] + Ok(te) -> dependency_list(input, te, [key, ..acc]) + } + typed_expr.Empty(_) -> acc + typed_expr.FloatLiteral(_, _) -> acc + typed_expr.Group(_, inner) -> dependency_list(input, inner, acc) + typed_expr.IntegerLiteral(_, _) -> acc + typed_expr.Label(_, key:, txt: _) -> + case grid.get(input, key) { + Error(_) -> [key, ..acc] + Ok(te) -> dependency_list(input, te, [key, ..acc]) + } + typed_expr.LabelDef(_, _) -> acc + typed_expr.PercentLiteral(_, _) -> acc + typed_expr.UnaryOp(_, _, inner) -> dependency_list(input, inner, acc) + typed_expr.UsdLiteral(_, _) -> acc } } diff --git a/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam b/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam index 0e9a483..bdc5fc1 100644 --- a/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam +++ b/src/squared_away/squared_away_lang/typechecker/typed_expr.gleam @@ -1,6 +1,7 @@ import gleam/float import gleam/int import gleam/list +import gleam/set import gleam/string import squared_away/squared_away_lang/grid import squared_away/squared_away_lang/parser/expr @@ -57,28 +58,6 @@ pub fn visit_cross_labels( } } -pub fn dependency_list( - te: TypedExpr, - acc: List(grid.GridKey), -) -> List(grid.GridKey) { - case te { - BinaryOp(_, lhs:, op: _, rhs:) -> - list.flatten([dependency_list(lhs, []), dependency_list(rhs, []), acc]) - BooleanLiteral(_, _) -> acc - BuiltinSum(_, keys) -> list.flatten([keys, acc]) - CrossLabel(_, key, _, _) -> [key, ..acc] - Empty(_) -> acc - FloatLiteral(_, _) -> acc - Group(_, inner) -> list.flatten([dependency_list(inner, []), acc]) - IntegerLiteral(_, _) -> acc - Label(_, key:, txt: _) -> [key, ..acc] - LabelDef(_, _) -> acc - PercentLiteral(_, _) -> acc - UnaryOp(_, _, inner) -> list.flatten([dependency_list(inner, []), acc]) - UsdLiteral(_, _) -> acc - } -} - pub fn to_string(te: TypedExpr) -> String { case te { Label(_, _, _)