bit2 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bit2.js +1 -1
- package/package.json +1 -1
package/dist/bit2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.BiEval=n():e.BiEval=n()}(this,(()=>(()=>{"use strict";var e={612:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.evaluateToLambdaAST=h,n.forward=function(e){let n=u.parse(e),t=d.translate(n);return p.evaluateTermNode(h(t))},n.backward=function(e,n){let t=u.parse(e),r=h(d.translate(t));return(0,y.fuse)({},n,r).map((({newTermNode:e,remainingOperation:n})=>{let t=(0,a.flatten)((0,b.unLambdalize)(e));try{let e=c.unPartialEval(t),n=c.flatten(e);return f.printToSurface(n)}catch(e){return""}}))};const s=i(t(661)),a=t(446),l=t(619),p=i(t(238)),c=i(t(887)),u=i(t(577)),d=i(t(775)),f=i(t(69)),y=t(963),b=t(784);function h(e){const n=new Map,t=s.scopelize(e),[r,o]=(0,a.partialEval)(n,t),i=(0,a.flatten)(o);return(0,l.lambdalize)(i)}},75:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.findVariablesAndFields=function(e){let n=[],t=[];return function e(r){switch(r.type){case"variable":n.push(r);break;case"field":"variable"===r.object.type?t.push({variable:r.object,field:r.field}):e(r.object);break;case"binary":e(r.left),e(r.right);break;case"unary":e(r.operand);break;case"array":r.elements.forEach(e);break;case"object":Object.values(r.fields).forEach(e);break;case"freeze":e(r.expression)}}(e),{variables:n,fields:t}}},143:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.prettyPrint=function e(n){switch(n.type){case"constant":let t=n.value;if("string"==typeof t)return'"'+String(t)+'"';if("object"!=typeof t||null===t)return String(t);if(!Array.isArray(t))return e(t);if(0===t.length)return"[]";if(0!==t.length)return"["+t.map(e).join(", ")+"]";case"variable":return n.name;case"binary":return e(n.left)+n.operator+e(n.right);case"unary":return n.operator+e(n.operand);case"field":return e(n.object)+"."+n.field;case"array":return"["+n.elements.map((n=>e(n))).join(",")+"]";case"freeze":return"!"+e(n.expression);case"object":let r=n.fields;return"{"+Object.keys(r).map((n=>n+":"+e(r[n]))).join(", ")+"}";default:return""}},n.prettyPrintBinaryOperator=function(e){return e},n.prettyPrintUnaryOperator=function(e){return e}},235:(e,n)=>{function t(e,n){if(null===e)console.log(`${n}null`);else if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)console.log(`${n}${e}`);else if("object"==typeof e){console.log(`${n}{`);const r=e;for(const e in r)if(r.hasOwnProperty(e)){const o=n+" ";console.log(`${o}${e}:`),t(r[e],o+" ")}console.log(`${n}}`)}else if("constant"==typeof e)t(e.value,n+" ");else{if(void 0!==e)throw new Error("Unhandled value type: "+typeof e);console.log(`${n}undefined`)}}Object.defineProperty(n,"__esModule",{value:!0}),n.printExpression=function e(n,r=""){switch(n.type){case"constant":t(n.value,r+" ");break;case"variable":console.log(`${r}Variable: ${n.name}`);break;case"binary":console.log(`${r}BinaryOperation: ${n.operator}`),e(n.left,r+" "),e(n.right,r+" ");break;case"unary":console.log(`${r}UnaryOperation: ${n.operator}`),e(n.operand,r+" ");break;case"field":console.log(`${r}FieldAccess: ${n.field}`),e(n.object,r+" ");break;case"array":console.log(`${r}ArrayLiteral:`),n.elements.forEach((n=>e(n,r+" ")));break;case"object":console.log(`${r}ObjectLiteral:`),Object.keys(n.fields).forEach((t=>{console.log(`${r} ${t} = `),e(n.fields[t],r+" ")}));break;case"freeze":console.log(`${r}Freeze:`),e(n.expression,r+" ")}},n.printConstantValue=t},454:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.seq=function(...e){return{type:"seq",nodes:e}},n.constNode=function(e){return{type:"const",value:e}},n.space=function(e){return{type:"space",width:e}},n.declare=function(e,n,t){return{type:"declare",name:e,value:n,isBindingUpdated:t}},n.exp=function(e){return{type:"exp",expression:e}},n.loop=function(e,n,t,r,o){return{type:"loop",lst:e,separator:n,front:t,rear:r,body:o}},n.ite=function(e,n,t){return{type:"ite",condition:e,trueBranch:n,falseBranch:t}},n.assign=function(e,n,t){return{type:"assign",name:e,value:n,isBindingUpdated:t}},n.sep=function(e){return{type:"sep",value:e}},n.nop=function(){return{type:"nop"}},n.bot=function(){return{type:"bot"}},n.end=function(){return{type:"end"}}},69:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.printToSurface=function e(n){let t="";switch(n.type){case"const":return n.value;case"space":return" ".repeat(n.width);case"declare":return t="«",t+="var ",t+=s.prettyPrint(n.name),t+="=",t+=s.prettyPrint(n.value),t+="»",t;case"assign":return t="«",t+=s.prettyPrint(n.name),t+="=",t+=s.prettyPrint(n.value),t+="»",t;case"exp":return t="«",t+=s.prettyPrint(n.expression),t+="»",t;case"seq":return n.nodes.map((n=>e(n))).join("");case"ite":t="«if "+s.prettyPrint(n.condition)+"»",t+=e(n.trueBranch);let r=n.falseBranch;return"ite"===r.type||"seq"===r.type&&1==r.nodes.length?t+="«elseif"+e(r).slice(3):"bot"!==r.type&&"seq"===r.type&&0!=r.nodes.length&&(t+="«else»",t+=e(r)),t.endsWith("«endif»")||(t+="«endif»"),t;case"loop":return t="«for "+s.prettyPrint(n.body.variable)+" in "+s.prettyPrint(n.lst),n.separator.value&&(t+=' separator "'+n.separator.value+'"'),n.front.value&&(t+=' front "'+n.front.value+'"'),n.rear.value&&(t+=' rear "'+n.rear.value+'"'),t+="»",t+=e(n.body.body),t+="«endfor»",t;default:return""}return""};const s=i(t(143))},963:function(e,n,t){var r=this&&this.__rest||function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t};Object.defineProperty(n,"__esModule",{value:!0}),n.fuse=p,n.fuseExp=c,n.valueToConstantExpr=w,n.printEnvironment=function(e){console.log("{\n");for(const n in e)if(e.hasOwnProperty(n)){const[t,r]=e[n];console.log(`${n}: {`),console.log(" val: "),(0,a.printValue)(t," "),console.log(",marks: ["),r.forEach(((e,n)=>{(0,a.printValue)(e," "),n<r.length-1&&console.log(", ")})),console.log("]\n },\n")}console.log("}")},n.fuseBulk=m,n.fuseBulk1=function(e,n,t){if("id"===n.type)return p(E(e),n,t);if("bulk"!==n.type||!n.operations)throw new Error("Invalid bulk operation");if(0==n.operations.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];if("seq"===t.type&&0==t.nodes.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];const[r,...o]=n.operations;if("seq"===t.type){const r=t.nodes[0],o=t.nodes.slice(1),i=m(e,n,r),s=[];for(const e of i){const n=m(e.newEnv,e.remainingOperation,{type:"seq",nodes:o});for(const t of n){let n=[];"seq"!=t.newTermNode.type?n.push(t.newTermNode):n=t.newTermNode.nodes,s.push({newEnv:t.newEnv,newTermNode:{type:"seq",nodes:[e.newTermNode,...n]},remainingOperation:t.remainingOperation})}}return s}if("lambda"===t.type){let r=N(n);return p(E(e),r,t)}return"insert"===r.type||"delete"===r.type||"replace"===r.type?p(E(e),r,t).map((e=>{let n=e.remainingOperation;if("id"===n.type||"insert"===n.type||"delete"===n.type||"replace"===n.type){let n=(0,l.evaluateTermNode)(e.newTermNode).length;const t=o.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")}));let r={type:"bulk",operations:[e.remainingOperation,...t]};return[{newEnv:e.newEnv,newTermNode:e.newTermNode,remainingOperation:r}]}throw new Error("nested bulk current not supported")})).reduce(((e,n)=>e.concat(n)),[]):"id"===r.type?0==o.length?p(E(e),r,t):m(e,{type:"bulk",operations:o},t):[]};const o=t(63),i=t(75),s=t(446),a=t(893),l=t(238);function p(e,n,t){if("const"!==t.type&&"sep"!==t.type&&"loopfront"!==t.type&&"looprear"!==t.type||"string"!=typeof t.value)if("space"===t.type)switch(n.type){case"insert":const{str:r,position:i}=n;if(0==t.width)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];if(0==i)return[{newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:r},t]},remainingOperation:{type:"id"}}];if(i<t.width){if((0,o.isWhitespace)(r))return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:r.length+t.width}),remainingOperation:{type:"id"}}];throw new Error(`Cannot insert non-space between space term: ${n}`)}if(i===t.width)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:r,position:i-t.width}}];{const n=i-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:r,position:n}}]}case"delete":const{str:s,position:a}=n;if(0!==a){if(a<t.width&&a+s.length<=t.width){const n=t.width-s.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}if(a<t.width&&a+s.length>t.width){const n=a,r=s.substring(t.width-a-1);return[{newEnv:E(e),newTermNode:{type:"space",width:n},remainingOperation:{type:"delete",str:r,position:0}}]}{const n=a-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"delete",str:s,position:n}}]}}if((0,o.isWhitespace)(s)&&s.length<=t.width){const n=t.width-s.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}if(s.length>t.width){const n=s.slice(t.width);return[{newEnv:E(e),newTermNode:{type:"bot"},remainingOperation:{type:"delete",str:n,position:0}}]}case"replace":const{str1:l,str2:p,position:c}=n;if(0!==c){if(c<t.width&&c+l.length<=t.width){if((0,o.isWhitespace)(p))return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:p.length+t.width-l.length}),remainingOperation:{type:"id"}}];{const n=" ".repeat(c)+p+" ".repeat(t.width-(c+l.length));return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"id"}}]}}if(c<t.width&&c+l.length>t.width){const n=" ".repeat(c),r=t.width-c,o=p.substring(0,r),i={type:"replace",str1:l.substring(r),str2:p.substring(r),position:0},s={type:"const",value:n+o};return[{newEnv:E(e),newTermNode:s,remainingOperation:i}]}{const n=c-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"replace",str1:l,str2:p,position:n}}]}}if(l.length<=t.width){if((0,o.isWhitespace)(p)){const n=t.width-l.length+p.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}return[{newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:p},Object.assign(Object.assign({},t),{width:t.width-l.length})]},remainingOperation:{type:"id"}}]}if(l.length>t.width){const n=p.slice(0,t.width),r=l.slice(t.width),o=p.slice(t.width);return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"replace",str1:r,str2:o,position:0}}]}case"bulk":return m(e,n,t);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}else if("exp"===t.type){const s=t.binding,l=s[0],u=s[1],d="number"==typeof(a=u)||"boolean"==typeof a||"string"==typeof a?String(a):"Unknown";switch(n.type){case"insert":const{str:s,position:a}=n;if(0===a){let n=[];if(n.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:s},t]},remainingOperation:{type:"id"}}),!(0,o.containsNewlineOrSpace)(s)){let r=function(e,n){try{if(v(JSON.parse(n)))return n+e}catch(e){return}}(d,s);if(void 0!==r)try{let o=y(r,u),{newEnv:i,newExp:s}=c(e,o,l);n.push({newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"id"}})}catch(e){}}return n}if(a<d.length){const n=y(d.slice(0,a)+s+d.slice(a),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(a==d.length){let r=[];if(!(0,o.containsNewlineOrSpace)(s)){const n=function(e,n){return e+n}(d,s);if(void 0!==n)try{const o=y(n,u);let{newEnv:i,newExp:s}=c(e,o,l);r.push({newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"id"}})}catch(e){console.error(e)}}let i=E(e);return l.name&&(i[l.name]=[u,[u]]),r.push({newEnv:i,newTermNode:t,remainingOperation:Object.assign(Object.assign({},n),{position:0})}),r}{const r=a-d.length;if(l.name){let n=l.name;e[n]=[u,[u]]}return[{newEnv:E(e),newTermNode:t,remainingOperation:Object.assign(Object.assign({},n),{position:r})}]}case"delete":const{str:f,position:g}=n;if(0===g){if(f.length<d.length){const n=y(d.slice(f.length),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(f.length==d.length){if(l.name){let n=l.name;if("string"==typeof u){let{newEnv:r,newExp:o}=c(e,"",l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,""]}),remainingOperation:{type:"id"}},{newEnv:b(E(e),n),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}]}return[{newEnv:b(E(e),n),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}]}if(l){let n=l.object.name,r=l.field,o=e[n][0];if(0==e[n][1].length)throw new Error("Fields does not existed:"+r);let i=e[n][1][0];if(0==i.fields[r].length){let s=[];if("string"==typeof o.fields[r]){let{newEnv:n,newExp:r}=c(e,"",l);s.push({newEnv:E(n),newTermNode:Object.assign(Object.assign({},t),{binding:[r,""]}),remainingOperation:{type:"id"}})}let a=h(o,r),p=h(i,r),u=b(E(e),n);return u[n]=[a,[p]],s.push({newEnv:E(u),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}),s}throw new Error(`field has been updated, cannot be remvoed: ${r}$`)}}else if(f.length>d.length){let n=f.slice(0,d.length),r=f.slice(d.length),o={type:"delete",str:n,position:0},i=p(E(e),o,t),s={type:"delete",str:r,position:0};return i.forEach((e=>{e.remainingOperation=s})),i}}else{if(g+f.length<=d.length){const n=y(d.slice(0,g)+d.slice(g+f.length),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(g<=d.length&&g+f.length>d.length){const n=d.slice(0,g),r=f.slice(d.length-g-1),o=y(n,u);let{newEnv:i,newExp:s}=c(e,o,l);return[{newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"delete",str:r,position:0}}]}if(g>d.length){const n=g-d.length;let[{newEnv:r,newTermNode:o,remainingOperation:i}]=p(E(e),{type:"id"},t);return[{newEnv:E(r),newTermNode:o,remainingOperation:{type:"delete",str:f,position:n}}]}}case"replace":const{str1:w,str2:O,position:j}=n;if(0===j){if(d.startsWith(w)){const n=y(O+d.slice(w.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(w.startsWith(d)){const n=y(O.slice(0,d.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);const i=w.slice(d.length),s=O.slice(d.length);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"replace",str1:i,str2:s,position:0}}]}throw new Error(`unsupported replacement: ${w}; ${O}`)}if(j<d.length){const n=y(d.slice(0,j)+O+d.slice(j+w.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(j>=d.length){const r=j-d.length;let[{newEnv:o,newTermNode:i,remainingOperation:s}]=p(E(e),{type:"id"},t);return[{newEnv:E(o),newTermNode:i,remainingOperation:Object.assign(Object.assign({},n),{position:r})}]}throw new Error("Unsupported replacement");case"bulk":return m(e,n,t);case"id":let{variables:N,fields:x}=(0,i.findVariablesAndFields)(l);return N.forEach((n=>{e=function(e,n){if(!(e.name in n))throw new Error(`Variable ${e.name} not found in environment.`);let t=n[e.name][0],r=b(n,e.name);return r[e.name]=[t,[t]],r}(n,e)})),x.forEach((({variable:n,field:t})=>{e=function(e,n,t){let o=n.name;if(!(o in t))throw new Error(`Variable ${o} not found in environment.`);let i=t[o][0],s=function(e,n,t){const o=e.fields,i=n,s=(o[i],r(o,["symbol"==typeof i?i:i+""]));return s[n]=t.fields[n],{type:"object",fields:s}}(t[o][1][0],e,i),a=b(t,o);return a[o]=[i,[s]],a}(t,n,e)})),[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}}else{if("lambda"===t.type){let r=t.marker;if("loopitem"===r.type){let o=[],i=t.variable.name,s=t.binding[0],a=t.binding[1],l=E(e);l=j(l,i,a,s);let u="";if(!r.lst)throw new Error("exp is not a Variable with a name property in loopitem's marker");{let e=r.lst.name;u=e+"_new"}let d=p(E(l),n,t.body).map((({newEnv:n,newTermNode:r,remainingOperation:o})=>{let a=E(n);if(i in a){let n=a[i][0],l=a[u][0];"object"==typeof n&&null!==n&&"type"in n&&"object"===n.type&&0===Object.keys(n.fields).length||l.push(n),a[u]=[l,[l]],a=b(E(a),i);let{newEnv:p,newExp:d}=c(a,n,s);return e[i]&&(p[i]=e[i]),{newEnv:p,newTermNode:{type:"lambda",variable:t.variable,body:"seq"!=r.type?{type:"seq",nodes:[r]}:r,binding:[d,n],marker:t.marker},remainingOperation:o}}return e[i]&&(a[i]=e[i]),{newEnv:a,newTermNode:{type:"lambda",variable:t.variable,body:"seq"!=r.type?{type:"seq",nodes:[r]}:r,binding:[{type:"constant",value:null},null],marker:t.marker},remainingOperation:o}}));return o.concat(d)}{let r=[];if("bulk"===n.type&&n.operations.length>0){let o=n.operations;const[i,...s]=o;if("insert"===i.type&&0===i.position){let n=i.str.length,o={type:"bulk",operations:s.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")}))},a=p(E(e),o,t);a.map((e=>(e.newTermNode={type:"seq",nodes:[{type:"const",value:i.str},e.newTermNode]},e))),r=r.concat(a)}}else if("insert"===n.type&&0===n.position){let o=p(E(e),{type:"id"},t);o.map((e=>(e.newTermNode={type:"seq",nodes:[{type:"const",value:n.str},e.newTermNode]},e))),r=r.concat(o)}let o=t.variable.name,i=t.binding[0],s=t.binding[1],a=E(e);a=j(a,o,s,i);let l=p(E(a),n,t.body).map((({newEnv:n,newTermNode:r,remainingOperation:a})=>{if(!(o in n))throw new Error("valued expression of "+o+" was deleted in the body.");let l=n[o][0],p=n[o][1].length>0;delete n[o];let u=function(e,n){let t=E(e);for(const e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);return t}(e,n);if(p){let{newEnv:e,newExp:n}=c(u,l,i);return{newEnv:e,newTermNode:{type:"lambda",variable:t.variable,body:r,binding:[n,l],isBindingUpdated:!0,marker:t.marker},remainingOperation:a}}return{newEnv:u,newTermNode:{type:"lambda",variable:t.variable,body:r,binding:[i,s],isBindingUpdated:!1,marker:t.marker},remainingOperation:a}}));return r=r.concat(l),r}}if("branchstart"===t.type||"branchend"===t.type||"nop"===t.type){if("branchend"===t.type){let n=t.condition[0],r=t.condition[1];try{let[t,o]=(0,s.evaluateExpr)(g(e),n);if(o!==r)throw new Error("Violate BX properties: updates change if-then-else branch.")}catch(e){throw new Error(`Error evaluating condition expression fail during backward: ${e}`)}}let r=[];switch(r.push({newEnv:E(e),newTermNode:t,remainingOperation:n}),n.type){case"insert":const{str:o,position:i}=n;0===i&&r.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:o},t]},remainingOperation:{type:"id"}});case"delete":case"replace":case"id":return r;case"bulk":return m(e,n,t);default:throw new Error(`Unhandled operation type: ${n}`)}}else{if("seq"===t.type){if("bulk"===n.type)return m(e,n,t);const r=t.nodes;let o=[{newEnv:e,newTermNode:{type:"seq",nodes:[]},remainingOperation:n}];for(const e of r){const n=[];for(const t of o){const r=p(E(t.newEnv),t.remainingOperation,e);for(const e of r){const r=("seq"===t.newTermNode.type?t.newTermNode.nodes:[t.newTermNode]).concat("seq"===e.newTermNode.type?e.newTermNode.nodes:[e.newTermNode]);n.push({newEnv:e.newEnv,newTermNode:{type:"seq",nodes:r},remainingOperation:e.remainingOperation})}}o=n}return o.map((e=>e))}if("end"!==t.type)throw new Error("Operation can only be applied to ConstNode with string value");{let r=[];switch(n.type){case"insert":const{str:o,position:i}=n;if(i>=0)return r.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:o},t]},remainingOperation:{type:"id"}}),r;throw new Error(`Unhandled operation type: ${n.type}, ${n.position}, ${n.str} for end term`);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n.type}`)}}}}else{if("loopfront"===t.type){let n=t.lst;if(!n.name)throw new Error("exp is not a Variable with a name property in loopfront");{let t=n.name;e[t+"_new"]=[[],[]]}}else if("looprear"===t.type){let n=t.lst;if(!n.name)throw new Error("exp is not a Variable with a name property in loopfront");{let t=n.name,r=e[t+"_new"][0];r=r.reverse(),e[t]=[r,[r]]}}const r=t.value;switch(n.type){case"insert":const{str:o,position:i}=n;if(0===i)return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:o+r}),remainingOperation:{type:"id"}}];if(i<r.length){const n=r.slice(0,i)+o+r.slice(i);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(i===r.length)return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:r+o}),remainingOperation:{type:"id"}},{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:o,position:i-r.length}}];{const n=i-r.length;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:o,position:n}}]}case"delete":const{str:s,position:a}=n;if(0===a){if(r.startsWith(s)&&s.length<=r.length){const n=r.slice(s.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(s.startsWith(r)&&s.length>r.length){const n=s.slice(r.length);return[{newEnv:E(e),newTermNode:{type:"bot"},remainingOperation:{type:"delete",str:n,position:0}}]}throw new Error("cannot delete, not match. delStr: "+s+", s_c: "+r)}if(a<r.length&&a+s.length<=r.length){const n=r.slice(0,a)+r.slice(a+s.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(a<r.length&&a+s.length>r.length){const n=r.substring(0,a),t=s.substring(r.length-1-a);return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"delete",str:t,position:0}}]}{const n=a-r.length;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"delete",str:s,position:n}}]}case"replace":const{str1:l,str2:p,position:c}=n;if(0!==c){if(c<r.length&&c+l.length<=r.length){const n=r.slice(0,c)+p+r.slice(c+l.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(c<r.length&&c+l.length>r.length){const n=r.substring(0,c),t=r.substring(c),o=p.substring(0,t.length),i={type:"replace",str1:l.substring(t.length),str2:p.substring(t.length),position:0},s={type:"const",value:n+o};return[{newEnv:E(e),newTermNode:s,remainingOperation:i}]}{const n=c-r.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:r}),remainingOperation:{type:"replace",str1:l,str2:p,position:n}}]}}if(r.startsWith(l)&&l.length<=r.length){const n=p+r.slice(l.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(l.startsWith(r)&&l.length>r.length){const n=p.slice(0,r.length),o=l.slice(r.length),i=p.slice(r.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"replace",str1:o,str2:i,position:0}}]}case"bulk":return m(e,n,t);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}}var a}function c(e,n,t){switch(t.type){case"constant":return{newEnv:e,newExp:w(n)};case"variable":if(!(t.name in e))throw new Error(`Variable ${t.name} not found in environment.`);const[o,i]=e[t.name];if(0===i.length){const r=E(e);return r[t.name]=[n,[n]],{newEnv:r,newExp:t}}if(1===i.length&&i[0]===n)return{newEnv:e,newExp:t};throw new Error(`Fail, variable cannot be updated to different value ${t.name}, previous: ${i[0]}, new: ${n}`);case"freeze":let[a,l]=(0,s.evaluateExpr)(g(e),t.expression);if(l!==n)throw new Error(`Fail, freezed expression cannot be changed, old: ${n}, new: ${l}`);return{newEnv:e,newExp:t};case"field":const p=t.object;if("variable"===p.type&&p.name in e){const[o,i]=e[p.name];if("object"===o.type){const s={type:"object",fields:Object.assign(Object.assign({},o.fields),{[t.field]:n})},a=function(e,n,t){const o=e.fields,i=n,s=(o[i],r(o,["symbol"==typeof i?i:i+""]));return s[n]=[t],{type:"object",fields:s}}(i[0],t.field,n),l=E(e);return l[p.name]=[s,[a]],{newEnv:l,newExp:t}}if("object"==typeof o)return{newEnv:E(e),newExp:t};throw new Error("Field access's value is not an object")}throw new Error("Field access not start with variable.");case"binary":let d=g(e),[y,b]=(0,s.evaluateExpr)(d,t.left);if("number"==typeof n){if("number"!=typeof n||null===n)throw new Error("Value must be a non-null number");switch(t.operator){case"+":let r=c(e,n-b,t.right);return{newEnv:r.newEnv,newExp:Object.assign(Object.assign({},t),{right:r.newExp})};case"-":let o=c(e,b-n,t.right);return{newEnv:o.newEnv,newExp:Object.assign(Object.assign({},t),{right:o.newExp})};case"*":let i=c(e,n/b,t.right);return{newEnv:i.newEnv,newExp:Object.assign(Object.assign({},t),{right:i.newExp})};case"/":let s=c(e,b/n,t.right);return{newEnv:s.newEnv,newExp:Object.assign(Object.assign({},t),{right:s.newExp})}}}else if("string"==typeof n){let r=n.slice(0,b.length),o=n.slice(b.length),i=c(e,r,t.left),s=c(i.newEnv,o,t.right);return{newEnv:s.newEnv,newExp:{type:"binary",left:i.newExp,operator:t.operator,right:s.newExp}}}case"unary":return{newEnv:e,newExp:t};case"array":return{newEnv:e,newExp:{type:"array",elements:u(t.elements,n)}};case"object":let h={},m=n.fields;for(const e in m)if(m.hasOwnProperty(e)){const n=m[e];h[e]=f(n)}return{newEnv:e,newExp:{type:"object",fields:h}};default:throw new Error(`Unsupported expression type: ${t.type}`)}}function u(e,n){const t=[];for(let r=0;r<n.length;r++)r<e.length?t.push(d(e[r],n[r])):t.push(f(n[r]));return t}function d(e,n){switch(e.type){case"constant":return Object.assign(Object.assign({},e),{value:n});case"array":return Object.assign(Object.assign({},e),{elements:u(e.elements,n)});case"object":return Object.assign(Object.assign({},e),{fields:Object.keys(e.fields).reduce(((t,r)=>(t[r]=Object.assign(Object.assign({},e.fields[r]),{value:n.fields[r]}),t)),{})});default:throw new Error(`Unsupported expression type: ${e.type}`)}}function f(e){if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"array",elements:e.map(f)};if("object"==typeof e&&null!==e)return{type:"object",fields:Object.keys(e.fields).reduce(((n,t)=>(n[t]={type:"constant",value:e.fields[t]},n)),{})};throw new Error("Unsupported value type: "+typeof e)}function y(e,n){if("number"==typeof n){const n=parseFloat(e);if(isNaN(n))throw new Error("convert to number fail: "+e);return n}if("boolean"==typeof n){if("true"===e)return!0;if("false"===e)return!1;throw new Error("convert to boolean fail: ${s}")}if("string"==typeof n)return e;throw new Error("Unsupported type: "+typeof n)}function b(e,n){const t=E(e);return delete t[n],t}function h(e,n){const t=e.fields,o=n;return t[o],{type:"object",fields:r(t,["symbol"==typeof o?o:o+""])}}function g(e){const n=new Map;for(const t in e)e.hasOwnProperty(t)&&n.set(t,e[t][0]);return n}function w(e){if(null===e||"number"==typeof e||"boolean"==typeof e||"string"==typeof e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"constant",value:e.map((e=>w(e)))};if("object"===e.type){const n=e,t={};for(const e in n.fields)n.fields.hasOwnProperty(e)&&(t[e]=w(n.fields[e]));return{type:"constant",value:{type:"object",fields:t}}}throw new Error("Unhandled value type: "+typeof e)}function m(e,n,t){if("id"===n.type)return p(E(e),n,t);if("bulk"!==n.type||!n.operations)throw new Error("Invalid bulk operation");if(0===n.operations.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];if("seq"===t.type&&0===t.nodes.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];if("lambda"===t.type){let r=N(n);return p(E(e),r,t)}if("seq"===t.type){const r=[{env:e,termNodes:[...t.nodes],processedNodes:[],bulkOp:n}],o=[];for(;r.length>0;){const e=r.pop(),{env:n,termNodes:t,processedNodes:i,bulkOp:s}=e;if(0===t.length){o.push({newEnv:n,newTermNode:{type:"seq",nodes:i},remainingOperation:s});continue}const[a,...l]=t,p=m(n,s,a);for(const e of p){const n=[...i,e.newTermNode];r.push({env:e.newEnv,termNodes:l,processedNodes:n,bulkOp:e.remainingOperation})}}return o}const[r,...o]=n.operations;if("insert"===r.type||"delete"===r.type||"replace"===r.type){const n=p(E(e),r,t);let i=[];for(const e of n){const n=e.remainingOperation;if("id"!==n.type&&"insert"!==n.type&&"delete"!==n.type&&"replace"!==n.type)throw new Error("nested bulk currently not supported");{let n=(0,l.evaluateTermNode)(e.newTermNode).length;const t=o.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")})),r={type:"bulk",operations:[e.remainingOperation,...t]};i.push({newEnv:e.newEnv,newTermNode:e.newTermNode,remainingOperation:r})}}return i}return"id"===r.type?0===o.length?p(E(e),r,t):m(e,{type:"bulk",operations:o},t):[]}function v(e){return!!("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e||Array.isArray(e)&&e.every(v)||"object"==typeof e&&null!==e&&"object"===e.type&&"object"==typeof e.fields)}function O(e,n=new WeakMap){if(null===e||"object"!=typeof e)return e;if(n.has(e))return n.get(e);if(Array.isArray(e)){const t=[];n.set(e,t);for(const r of e)t.push(O(r,n));return t}if(function(e){return e&&"object"==typeof e&&"object"===e.type&&"fields"in e}(e)){const t={},r={type:"object",fields:t};n.set(e,r);for(const r in e.fields)e.fields.hasOwnProperty(r)&&(t[r]=O(e.fields[r],n));return r}const t={};n.set(e,t);for(const r in e)e.hasOwnProperty(r)&&(t[r]=O(e[r],n));return t}function E(e,n=new WeakMap){if(n.has(e))return n.get(e);const t={};n.set(e,t);for(const r in e)if(e.hasOwnProperty(r)){const[o,i]=e[r];t[r]=[O(o,n),O(i,n)]}return t}function j(e,n,t,r){if("number"==typeof t||"boolean"==typeof t||"string"==typeof t||null===t)"field"==r.type&&"length"==r.field?e[n]=[t,[t]]:e[n]=[t,[]];else if(Array.isArray(t))e[n]=[t,[]];else if("object"==typeof t&&null!==t&&"fields"in t){const r={type:"object",fields:{}};for(const e in t.fields)r.fields[e]=[];e[n]=[t,[r]]}return e}function N(e){if("bulk"===e.type){const n=e.operations.map(N);return Object.assign(Object.assign({},e),{operations:n})}return Object.assign({},e)}},238:(e,n)=>{function t(e){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)return e.toString();if("object"===e.type){const n=e;let r="{";for(const e in n.fields)n.fields.hasOwnProperty(e)&&(r+=`${e}: ${t(n.fields[e])}, `);return r.length>1&&(r=r.slice(0,-2)),r+="}",r}if(Array.isArray(e)){const n=e;let r="[";for(const e of n)r+=`${t(e)}, `;return r.length>1&&(r=r.slice(0,-2)),r+="]",r}throw new Error("Unhandled value type: "+typeof e)}Object.defineProperty(n,"__esModule",{value:!0}),n.evaluateTermNode=function e(n){switch(n.type){case"const":case"sep":case"loopfront":case"looprear":return n.value;case"space":return" ".repeat(n.width);case"exp":return String(t(n.binding[1]));case"seq":return n.nodes.map((n=>e(n))).join("");case"lambda":return e(n.body);case"branchstart":case"branchend":case"end":case"bot":case"nop":return"";default:throw new Error(`Unhandled term node type: ${n.type}`)}},n.printValue=t},619:(e,n)=>{function t(e){let n=e.type;if("seq"===n)return r(e);if("declare"===n||"assign"===n)throw new Error("declare|assign node shall not be visible here.");if("lambda"===n){let n=e,r=t(n.body);return{type:"lambda",variable:n.variable,body:r,binding:n.binding,isBindingUpdated:n.isBindingUpdated,marker:n.marker}}return e}function r(e){let n=e.nodes,i=[];for(let e=0;e<n.length;e++){let s=n[e];if("declare"===s.type||"assign"===s.type){let t=s,a=t.name,[l,p]=o(n,e+1,a),{nodes:c}=r({type:"seq",nodes:l}),u=c.pop();if(void 0===u)throw new Error("lastNode should be declareend or others");if("declareend"!=u.type){c.push(u);let e={type:"lambda",variable:t.name,body:{type:"seq",nodes:c},binding:t.value,isBindingUpdated:!1,marker:{type:s.type}};i.push(e)}else{let e={type:"lambda",variable:t.name,body:{type:"seq",nodes:c},binding:t.value,isBindingUpdated:!1,marker:{type:s.type}};i.push(e),"declare"!=s.type&&i.push(u)}e=p}else i.push(t(s))}return{type:"seq",nodes:i}}function o(e,n,t){let r=[],o=n;for(;o<e.length;o++){if("declareend"===e[o].type&&e[o].name.name===t.name)return r.push(e[o]),[r,o];r.push(e[o])}return[r,o]}Object.defineProperty(n,"__esModule",{value:!0}),n.lambdalize=t},784:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.unLambdalize=function e(n){switch(n.type){case"lambda":{const{variable:t,body:r,binding:o,marker:i,isBindingUpdated:s}=n;let a;switch(i.type){case"declare":return a=e(r),{type:"seq",nodes:[{type:"declare",name:t,value:o,isBindingUpdated:s},a]};case"assign":return a=e(r),{type:"seq",nodes:[{type:"assign",name:t,value:o,isBindingUpdated:s},a]};default:return{type:"lambda",variable:t,body:e(r),binding:o,isBindingUpdated:s,marker:i}}}case"seq":return{type:"seq",nodes:n.nodes.map(e)};default:return n}}},893:(e,n,t)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.printNode=function e(n,t=""){switch(console.log(t+n.type),n.type){case"const":case"sep":console.log(t+" Value: "+n.value);break;case"space":console.log(t+" Width: "+n.width);break;case"declare":case"assign":console.log(t+" Name: "+n.name.name),o(n.value,t+" ");break;case"exp":o(n.binding,t+" ");break;case"seq":n.nodes.forEach((n=>e(n,t+" ")));break;case"branchstart":o(n.condition,t+" ");break;case"loopfront":console.log(t+" front: "+n.value);break;case"looprear":console.log(t+" rear: "+n.value);break;case"lambda":console.log(t+" Variable: "+n.variable.name),e(n.body,t+" "),o(n.binding,t+" "),s(n.marker,t+" ");break;case"callstart":console.log(t+" Name: "+n.name);break;case"end":console.log(`${t} End`)}},n.printBinding=o,n.printValue=i,n.printMarker=s;const r=t(235);function o(e,n){(0,r.printExpression)(e[0],n),i(e[1],n)}function i(e,n){if(null===e)console.log(`${n}null`);else if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)console.log(`${n}${e}`);else{if("object"!=typeof e)throw new Error("Unhandled value type: "+typeof e);{console.log(`${n}{`);const t=e;for(const e in t)if(t.hasOwnProperty(e)){const r=n+" ";console.log(`${r}${e}:`),i(t[e],r+" ")}console.log(`${n}}`)}}}function s(e,n=""){console.log(n+e.type)}},446:(e,n)=>{function t(e,n){switch(n.type){case"constant":return[e,n.value];case"variable":const r=e.get(n.name);if(void 0===r)throw new Error(`Variable '${n.name}' not found in environment`);return[e,r];case"binary":let[o,i]=t(e,n.left),[s,a]=t(o,n.right);switch(n.operator){case"+":return[s,i+a];case"-":return[s,i-a];case"*":return[s,i*a];case"/":return[s,i/a];case"&&":return[s,i&&a];case"||":return[s,i||a];case">":return[s,i>a];case"<":return[s,i<a];case">=":return[s,i>=a];case"<=":return[s,i<=a];case"==":return[s,i==a];case"!=":return[s,i!=a];default:throw new Error("Unsupported binary operator")}case"unary":let[l,p]=t(e,n.operand);if("not"===n.operator)return[l,!p];throw new Error("Unsupported unary operator");case"field":let c,[u,d]=t(e,n.object);if("string"!=typeof d&&("object"!=typeof d||null===d))throw new Error(`Cannot access field '${n.field}' from non-object`);if("string"==typeof d?c=d[n.field]:Array.isArray(d)?"length"===n.field&&(c=d.length):c=d.fields[n.field],void 0===c)throw new Error(`Field '${n.field}' not found in object`);return[u,c];case"array":let f=[],y=e;for(const e of n.elements){let[n,r]=t(y,e);f.push(r),y=n}return[y,f];case"object":let b={type:"object",fields:{}},h=e;for(const e in n.fields)if(n.fields.hasOwnProperty(e)){let[r,o]=t(h,n.fields[e]);b.fields[e]=o,h=r}return[h,b];case"freeze":return t(e,n.expression);default:throw new Error("Unhandled expression type")}}Object.defineProperty(n,"__esModule",{value:!0}),n.partialEval=function e(n,r){switch(r.type){case"const":return[n,{type:"const",value:r.value}];case"space":return[n,{type:"space",width:r.width}];case"declare":const[o,i]=t(n,r.value);return o.set(r.name.name,i),[o,{type:"declare",name:r.name,value:[r.value,i],isBindingUpdated:!1}];case"declareend":return[n,r];case"assign":const[s,a]=t(n,r.value);return s.set(r.name.name,a),[s,{type:"assign",name:r.name,value:[r.value,a],isBindingUpdated:!1}];case"exp":const[l,p]=t(n,r.expression);return[l,{type:"exp",binding:[r.expression,p]}];case"seq":let c=n;const u=[];for(const n of r.nodes){const[t,r]=e(c,n);u.push(r),c=t}return[c,{type:"seq",nodes:u}];case"ite":const[d,f]=t(n,r.condition);if(!0===f){const[n,t]=e(d,r.trueBranch);return[n,{type:"seq",nodes:[{type:"branchstart",condition:[r.condition,f],trueBranch:r.trueBranch,falseBranch:r.falseBranch},t,{type:"branchend",condition:[r.condition,f]}]}]}if(!1===f){const[n,t]=e(d,r.falseBranch);return[n,{type:"seq",nodes:[{type:"branchstart",condition:[r.condition,f],trueBranch:r.trueBranch,falseBranch:r.falseBranch},t,{type:"branchend",condition:[r.condition,f]}]}]}throw new Error(`Condition does not evaluate to boolean: ${f}`);case"loop":const{lst:y,separator:b,front:h,rear:g,body:w}=r,[m,v]=t(n,y);if(Array.isArray(v)&&0===v.length)return[m,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},{type:"looprear",lst:y,value:g.value}]}];if(Array.isArray(v)&&1===v.length){const t=v[0],r=w.variable.name,o=new Map(n);o.set(r,t);const[i,s]=e(o,w.body);return[i,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},{type:"lambda",variable:w.variable,binding:[{type:"constant",value:t},t],marker:{type:"loopitem",lst:y},body:s},{type:"looprear",lst:y,value:g.value}]}]}if(Array.isArray(v)&&v.length>1){let t=new Map(n),o=[];for(let n=0;n<v.length;n++){const r=v[n],i=w.variable.name;t.set(i,r);const[s,a]=e(t,w.body);t=s,o.push({type:"lambda",variable:w.variable,body:a,binding:[{type:"constant",value:r},r],isBindingUpdated:!1,marker:{type:"loopitem",lst:y}})}let i=o[o.length-1];for(let e=o.length-2;e>=0;e--){let n=o[e];i={type:"lambda",variable:n.variable,binding:n.binding,marker:n.marker,body:{type:"seq",nodes:[n.body,r.separator,i]}}}return[t,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},i,{type:"looprear",lst:y,value:g.value}]}]}throw new Error("Unsupported type or value for e_arr: "+typeof v);case"nop":return[n,{type:"nop"}];case"bot":return[n,{type:"bot"}];case"end":return[n,{type:"end"}];default:throw new Error(`Unhandled term node type: ${r.type}`)}},n.evaluateExpr=t,n.flatten=function e(n){return"seq"===n.type?{type:"seq",nodes:n.nodes.map((n=>e(n))).flatMap((e=>"seq"===e.type?e.nodes:[e]))}:"lambda"===n.type?Object.assign(Object.assign({},n),{body:e(n.body)}):n}},887:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.unPartialEval=l,n.flatten=function e(n){if("seq"===n.type){const t=n.nodes.map((n=>e(n)));return 1==t.length?t[0]:{type:"seq",nodes:t.flatMap((e=>"seq"===e.type?e.nodes:[e]))}}return"ite"===n.type?Object.assign(Object.assign({},n),{trueBranch:e(n.trueBranch),falseBranch:e(n.falseBranch)}):"loop"===n.type?Object.assign(Object.assign({},n),{body:Object.assign(Object.assign({},n.body),{body:e(n.body.body)})}):n};const s=i(t(454));function a(e){return e[0]}function l(e){switch(e.type){case"const":return s.constNode(e.value);case"space":return s.space(e.width);case"declare":return s.declare(e.name,a(e.value),e.isBindingUpdated);case"assign":return s.assign(e.name,a(e.value),e.isBindingUpdated);case"exp":return s.exp(a(e.binding));case"nop":return s.nop();case"end":return s.end();case"bot":return s.bot();case"seq":return p(e);case"lambda":return c(e);case"sep":return e;default:throw new Error(`Unknown node type: ${e.type}`)}}function p(e){const n=e.nodes,t=[];for(let e=0;e<n.length;e++){const o=n[e];if("branchstart"===o.type){const r=o.condition[0],i=o.condition[1],a=o.trueBranch,l=o.falseBranch;let c=1;const u=[];for(let t=e+1;t<n.length;t++){const e=n[t];if("branchstart"===e.type&&c++,"branchend"===e.type){if(1==c)break;c--,u.push(n[t])}else u.push(n[t])}i?t.push(s.ite(r,p({type:"seq",nodes:u}),l)):t.push(s.ite(r,a,p({type:"seq",nodes:u}))),e+=u.length+1}else if("loopfront"===o.type){let i=o,a=null,l=null,p=null,c=n[++e];if("looprear"===c.type)a=c;else{let t=c;if([l,p]=u(t),c=n[++e],"looprear"!==c.type)throw new Error("Shall end with looprear node");a=c}if(""===i.value&&""===a.value&&null===l&&null===p)t.push(s.bot());else if(null===l||d(l))t.push(s.loop(i.lst,i.separator,{type:"front",value:o.value},{type:"rear",value:a.value},i.body));else{if("bot"===l.type)throw new Error("lambda is bot node");if("lambdawithexpr"!==l.type)throw new Error("Must be lambda in loopitem");t.push(s.loop(i.lst,null===p?i.separator:p,{type:"front",value:o.value},{type:"rear",value:a.value},{type:"lambda",variable:(r=l).variable,body:r.body}))}}else t.push(l(o))}var r;return s.seq(...t)}function c(e){let{variable:n,body:t,binding:r,marker:o}=e;return{type:"lambdawithexpr",variable:n,body:l(t),exp:(i=r[1],Array.isArray(i)?{type:"array",elements:i.map(f)}:{type:"array",elements:[f(i)]})};var i}function u(e){let n=e,t=e.variable.name,r=e.body,o=null,i=[],s=null;for(let e of r.nodes)"sep"===e.type?s=e:"lambda"===e.type&&e.variable.name===t?o=e:i.push(e);if(n.body=i.every(d)?{type:"bot"}:{type:"seq",nodes:i},null==o)return"bot"===n.body.type?[{type:"bot"},null]:[c(n),null];{let[e,t]=u(o);if("bot"===e.type&&null===t)return[c(n),s];if("bot"===n.body.type&&null===s)return[e,t];if("bot"===n.body.type&&""===(null==s?void 0:s.value))return[e,t];{let r=c(n);if(l=e,y((a=r).variable,l.variable)&&h(a.body,l.body)){if(null===t)return[r,s];if(null!=s&&t.value===s.value)return[r,s];throw new Error("sepNode not equal")}throw new Error("lambda body not equal")}}var a,l}function d(e){return"bot"===e.type}function f(e){if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"array",elements:e.map(f)};if("object"===e.type){const n={};for(const t in e.fields)if(e.fields.hasOwnProperty(t)){const r=e.fields[t];n[t]={type:"constant",value:r}}return{type:"object",fields:n}}throw new Error("Unsupported Value type")}function y(e,n){return e.name===n.name}function b(e,n){if(e.type!==n.type)return!1;switch(e.type){case"constant":const t=e,r=n;return null===t.value&&null===r.value||("object"==typeof t.value&&"object"==typeof r.value?b(t.value,r.value):t.value===r.value);case"variable":return e.name===n.name;case"binary":const o=e,i=n;return o.operator===i.operator&&b(o.left,i.left)&&b(o.right,i.right);case"unary":const s=e,a=n;return s.operator===a.operator&&b(s.operand,a.operand);case"field":const l=e,p=n;return l.field===p.field&&b(l.object,p.object);case"array":const c=e,u=n;return c.elements.length===u.elements.length&&c.elements.every(((e,n)=>b(e,u.elements[n])));case"object":const d=e,f=n,y=Object.keys(d.fields),h=Object.keys(f.fields);return y.length===h.length&&y.every((e=>f.fields.hasOwnProperty(e)&&b(d.fields[e],f.fields[e])));case"freeze":return b(e.expression,n.expression);default:return!1}}function h(e,n){if(e.type!==n.type)return!1;switch(e.type){case"const":return e.value===n.value;case"space":return e.width===n.width;case"declare":const t=e,r=n;return!t.isBindingUpdated||!r.isBindingUpdated||y(t.name,r.name)&&b(t.value,r.value);case"assign":const o=e,i=n;return!o.isBindingUpdated||!i.isBindingUpdated||y(o.name,i.name)&&b(o.value,i.value);case"exp":return b(e.expression,n.expression);case"seq":const s=e.nodes.filter((e=>!("const"===e.type&&""===e.value))),a=n.nodes.filter((e=>!("const"===e.type&&""===e.value)));return s.length===a.length&&s.every(((e,n)=>h(e,a[n])));case"ite":const l=e,p=n;return b(l.condition,p.condition)&&h(l.trueBranch,p.trueBranch)&&h(l.falseBranch,p.falseBranch);case"loop":const c=e,u=n;return b(c.lst,u.lst)&&c.separator.value===u.separator.value&&c.front.value===u.front.value&&c.rear.value===u.rear.value&&function(e,n){return y(e.variable,n.variable)&&h(e.body,n.body)}(c.body,u.body);case"nop":case"bot":case"end":return!0;case"call":const d=e,f=n;return h(d.func,f.func)&&Object.keys(d.args).length===Object.keys(f.args).length&&Object.keys(d.args).every((e=>b(d.args[e],f.args[e])));case"lambdawithexpr":const g=e,w=n;return y(g.variable,w.variable)&&h(g.body,w.body);default:return!1}}},661:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.scopelize=function e(n){switch(n.type){case"declare":return{type:"seq",nodes:[n,{type:"declareend",name:n.name}]};case"seq":return function(n){let t=new s.Stack,r=[];for(let o of n.nodes){if("declare"===o.type){let e={type:"declareend",name:o.name};t.push(e)}"declare"===o.type?r.push(o):r.push(e(o))}if(0==r.length)return n;{let e=r.pop();for("end"!==e.type&&r.push(e);!t.isEmpty();){let e=t.pop();if(!e)throw new Error("endNode is undefined.");r.push(e)}"end"===(null==e?void 0:e.type)&&r.push(e)}return Object.assign(Object.assign({},n),{nodes:r})}(n);case"ite":let t=n.trueBranch,r=n.falseBranch;return{type:"ite",condition:n.condition,trueBranch:e(t),falseBranch:e(r)};case"loop":let o=n.body,i=o.body;return Object.assign(Object.assign({},n),{body:Object.assign(Object.assign({},o),{body:e(i)})});case"call":case"const":case"space":case"declareend":case"assign":case"exp":case"nop":case"bot":case"end":case"lambdawithexpr":case"sep":return n}return{type:"bot"}};const s=i(t(694))},577:(e,n)=>{function t(e){const n=/«[^»]*»/g;let t;const r=[];let o=0;for(;null!==(t=n.exec(e));)o<t.index&&r.push(e.slice(o,t.index)),r.push(t[0]),o=n.lastIndex;return o<e.length&&r.push(e.slice(o)),r}function r(e){const n=[];let t=0;for(;t<e.length;){const i=e[t];if("string"==typeof i&&i.startsWith("«")&&i.endsWith("»")){const s=i.slice(1,-1).trim(),[a]=s.split(" ");switch(a.toUpperCase()){case"VAR":const i=s.split("=");n.push({type:"Directive",content:{type:"declare",name:i[0].split(" ")[1].trim(),expr:o(i[1].trim())}});break;case"IF":const a=s.match(/^(IF)\s+/i);if(a){const i=s.slice(a[0].length).trim(),l=[],p=[];let c=1,u=t+1;for(;u<e.length;){let n=e[u];if("string"==typeof n&&n.startsWith("«"))if(n.includes("ENDIF")||n.includes("endif")){if(c--,c<=0)break}else if((n.includes("else")||n.includes("ELSE"))&&1===c){if(c=0,!n.includes("if")&&!n.includes("IF")){u++;continue}n=n.replace(/else(?=if)/,"")}c>0?l.push(n):p.push(n),u++}const d=r(l),f=r(p);t=u,n.push({type:"Directive",content:{type:"if",expr:o(i),thenBranch:d,elseBranch:f}})}break;case"FOR":const l=/for\s+(\w+)\s+in\s+([^\s]+)(?:\s+separator\s+"([^"]*)")?(?:\s+front\s+"([^"]*)")?(?:\s+rear\s+"([^"]*)")?/i,p=s.match(l);if(!p)throw new Error("Invalid for directive syntax");const[,c,u,d="",f="",y=""]=p,b=[];let h=1,g=t+1;for(;g<e.length&&h>0;){const n=e[g];if("string"==typeof n&&n.startsWith("«"))if(n.toLowerCase().includes("endfor")){if(h--,0===h)break}else n.toLowerCase().includes("for")&&h++;h>0&&b.push(n),g++}const w=r(b);t=g,n.push({type:"Directive",content:{type:"for",name:c.trim(),expr:o(u.trim()),separator:{type:"separator",value:d},front:{type:"front",value:f},rear:{type:"rear",value:y},fragment:w}});break;default:if(s.includes("=")){const e=s.split("=");n.push({type:"Directive",content:{type:"assign",name:e[0].split(" ")[0].trim(),expr:o(e[1].trim())}})}else n.push({type:"Directive",content:{type:"exp",expr:o(s)}})}}else n.push(i);t++}return 1===n.length?n[0]:{type:"fragmentList",fragments:n}}function o(e){const n=function(e){const n=/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(&&|\|\||[<>!=]=|[{}[\](),.:;!+\-*/<>])|(\s+)|([^\s{}[\](),.:;!+\-*/<>!=&|]+)/g,t=[];let r;for(;null!==(r=n.exec(e));)void 0!==r[1]?t.push(`"${r[1]}"`):void 0!==r[2]?t.push(`'${r[2]}'`):void 0!==r[3]?t.push(r[3]):void 0!==r[5]&&t.push(r[5]);return t}(e);let t=0;function r(){if("("===n[t]){t++;const e=o();if(")"===n[t])return t++,e;throw new Error("Mismatched parentheses")}if("["===n[t]){t++;const e=[];for(;"]"!==n[t];)","===n[t]?t++:e.push(o());return t++,{type:"array",elements:e}}if("{"===n[t]){t++;const e={};for(;"}"!==n[t];)if(","===n[t])t++;else{const r=n[t++];if(":"!==n[t])throw new Error("Expected colon in object literal");{t++;const n=o();e[r]=n}}return t++,{type:"object",fields:e}}if("-"===n[t]&&!isNaN(Number(n[t+1])))return t++,{type:"constant",value:-Number(n[t++])};if(!isNaN(Number(n[t])))return{type:"constant",value:Number(n[t++])};if(/^['"].*['"]$/.test(n[t]))return{type:"constant",value:n[t++].slice(1,-1)};switch(n[t]){case"null":return t++,{type:"constant",value:null};case"true":return t++,{type:"constant",value:!0};case"false":return t++,{type:"constant",value:!1}}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n[t])){let e={type:"variable",name:n[t++]};for(;"."===n[t];){if(t++,/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n[t]))return{type:"field",object:e,field:n[t++]};throw new Error("Expected property name after '.'")}return e}if("!"===n[t])return t++,{type:"freeze",expression:r()};throw new Error(`Unexpected token: ${n[t]}`)}function o(){let e=r();for(;["+","-","*","/","&&","||",">","<",">=","<=","!=","==","=="].includes(n[t]);)e={type:"binary",operator:n[t++],left:e,right:r()};return e}return o()}Object.defineProperty(n,"__esModule",{value:!0}),n.parse=function(e){return r(t(e))},n.tokenize=t,n.parseTokens=r},775:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.translate=function(e){const n=a(e);return n.push(s.end()),s.seq(...n)};const s=i(t(454));function a(e){if("string"==typeof e)return function(e){const n=[];let t="";for(let r of e)if(" "===r){if(t.length>0){if(t.endsWith("\n")){const e=t.split(/(\n)/);for(const t of e)""!=t&&n.push(s.constNode(t))}else n.push(s.constNode(t));t=""}n.push(s.space(1))}else t+=r;if(t.length>0)if(t.endsWith("\n")){const e=t.split(/(\n)/);for(const t of e)""!=t&&n.push(s.constNode(t))}else n.push(s.constNode(t));return n}(e);switch(e.type){case"Directive":switch(e.content.type){case"declare":return[s.declare({type:"variable",name:e.content.name},e.content.expr,!1)];case"assign":return[s.assign({type:"variable",name:e.content.name},e.content.expr,!1)];case"exp":return[s.exp(e.content.expr)];case"if":return[s.ite(e.content.expr,{type:"seq",nodes:a(e.content.thenBranch)},l(e.content.elseBranch))];case"for":return[s.loop(e.content.expr,{type:"sep",value:e.content.separator.value},{type:"front",value:e.content.front.value},{type:"rear",value:e.content.rear.value},{type:"lambda",variable:{type:"variable",name:e.content.name},body:{type:"seq",nodes:a(e.content.fragment)}})];default:throw new Error(`Unknown directive: ${e}`)}case"fragmentList":return e.fragments.flatMap(a);default:throw new Error(`Unknown fragment: ${e}`)}}function l(e){if((n=e)&&"if"===n.type){const n=e;return s.ite(n.expr,{type:"seq",nodes:a(n.thenBranch)},l(n.elseBranch))}return function(e){return e&&"bot"===e.type}(e)?s.bot():{type:"seq",nodes:a(e)};var n}},694:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.Stack=void 0,n.Stack=class{constructor(){this.items=[]}push(e){this.items.push(e)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}clear(){this.items=[]}print(){console.log(this.items.toString())}}},63:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.isWhitespace=function(e){return/^( +)$/.test(e)},n.containsNewlineOrSpace=function(e){return/[\n\s]/.test(e)}}},n={};return function t(r){var o=n[r];if(void 0!==o)return o.exports;var i=n[r]={exports:{}};return e[r].call(i.exports,i,i.exports,t),i.exports}(612)})()));
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define([],n):"object"==typeof exports?exports.BiEval=n():e.BiEval=n()}(this,(()=>(()=>{"use strict";var e={612:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.evaluateToLambdaAST=h,n.forward=function(e){let n=u.parse(e),t=d.translate(n);return p.evaluateTermNode(h(t))},n.backward=function(e,n){let t=u.parse(e),r=h(d.translate(t)),o=(0,y.fuse)({},n,r).map((({newTermNode:e,remainingOperation:n})=>{let t=(0,a.flatten)((0,b.unLambdalize)(e));try{let e=c.unPartialEval(t),n=c.flatten(e);return f.printToSurface(n)}catch(e){return""}}));return o=o.filter((e=>""!=e)),Array.from(new Set(o))};const s=i(t(661)),a=t(446),l=t(619),p=i(t(238)),c=i(t(887)),u=i(t(577)),d=i(t(775)),f=i(t(69)),y=t(963),b=t(784);function h(e){const n=new Map,t=s.scopelize(e),[r,o]=(0,a.partialEval)(n,t),i=(0,a.flatten)(o);return(0,l.lambdalize)(i)}},75:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.findVariablesAndFields=function(e){let n=[],t=[];return function e(r){switch(r.type){case"variable":n.push(r);break;case"field":"variable"===r.object.type?t.push({variable:r.object,field:r.field}):e(r.object);break;case"binary":e(r.left),e(r.right);break;case"unary":e(r.operand);break;case"array":r.elements.forEach(e);break;case"object":Object.values(r.fields).forEach(e);break;case"freeze":e(r.expression)}}(e),{variables:n,fields:t}}},143:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.prettyPrint=function e(n){switch(n.type){case"constant":let t=n.value;if("string"==typeof t)return'"'+String(t)+'"';if("object"!=typeof t||null===t)return String(t);if(!Array.isArray(t))return e(t);if(0===t.length)return"[]";if(0!==t.length)return"["+t.map(e).join(", ")+"]";case"variable":return n.name;case"binary":return e(n.left)+n.operator+e(n.right);case"unary":return n.operator+e(n.operand);case"field":return e(n.object)+"."+n.field;case"array":return"["+n.elements.map((n=>e(n))).join(",")+"]";case"freeze":return"!"+e(n.expression);case"object":let r=n.fields;return"{"+Object.keys(r).map((n=>n+":"+e(r[n]))).join(", ")+"}";default:return""}},n.prettyPrintBinaryOperator=function(e){return e},n.prettyPrintUnaryOperator=function(e){return e}},235:(e,n)=>{function t(e,n){if(null===e)console.log(`${n}null`);else if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)console.log(`${n}${e}`);else if("object"==typeof e){console.log(`${n}{`);const r=e;for(const e in r)if(r.hasOwnProperty(e)){const o=n+" ";console.log(`${o}${e}:`),t(r[e],o+" ")}console.log(`${n}}`)}else if("constant"==typeof e)t(e.value,n+" ");else{if(void 0!==e)throw new Error("Unhandled value type: "+typeof e);console.log(`${n}undefined`)}}Object.defineProperty(n,"__esModule",{value:!0}),n.printExpression=function e(n,r=""){switch(n.type){case"constant":t(n.value,r+" ");break;case"variable":console.log(`${r}Variable: ${n.name}`);break;case"binary":console.log(`${r}BinaryOperation: ${n.operator}`),e(n.left,r+" "),e(n.right,r+" ");break;case"unary":console.log(`${r}UnaryOperation: ${n.operator}`),e(n.operand,r+" ");break;case"field":console.log(`${r}FieldAccess: ${n.field}`),e(n.object,r+" ");break;case"array":console.log(`${r}ArrayLiteral:`),n.elements.forEach((n=>e(n,r+" ")));break;case"object":console.log(`${r}ObjectLiteral:`),Object.keys(n.fields).forEach((t=>{console.log(`${r} ${t} = `),e(n.fields[t],r+" ")}));break;case"freeze":console.log(`${r}Freeze:`),e(n.expression,r+" ")}},n.printConstantValue=t},454:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.seq=function(...e){return{type:"seq",nodes:e}},n.constNode=function(e){return{type:"const",value:e}},n.space=function(e){return{type:"space",width:e}},n.declare=function(e,n,t){return{type:"declare",name:e,value:n,isBindingUpdated:t}},n.exp=function(e){return{type:"exp",expression:e}},n.loop=function(e,n,t,r,o){return{type:"loop",lst:e,separator:n,front:t,rear:r,body:o}},n.ite=function(e,n,t){return{type:"ite",condition:e,trueBranch:n,falseBranch:t}},n.assign=function(e,n,t){return{type:"assign",name:e,value:n,isBindingUpdated:t}},n.sep=function(e){return{type:"sep",value:e}},n.nop=function(){return{type:"nop"}},n.bot=function(){return{type:"bot"}},n.end=function(){return{type:"end"}}},69:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.printToSurface=function e(n){let t="";switch(n.type){case"const":return n.value;case"space":return" ".repeat(n.width);case"declare":return t="«",t+="var ",t+=s.prettyPrint(n.name),t+="=",t+=s.prettyPrint(n.value),t+="»",t;case"assign":return t="«",t+=s.prettyPrint(n.name),t+="=",t+=s.prettyPrint(n.value),t+="»",t;case"exp":return t="«",t+=s.prettyPrint(n.expression),t+="»",t;case"seq":return n.nodes.map((n=>e(n))).join("");case"ite":t="«if "+s.prettyPrint(n.condition)+"»",t+=e(n.trueBranch);let r=n.falseBranch;return"ite"===r.type||"seq"===r.type&&1==r.nodes.length?t+="«elseif"+e(r).slice(3):"bot"!==r.type&&"seq"===r.type&&0!=r.nodes.length&&(t+="«else»",t+=e(r)),t.endsWith("«endif»")||(t+="«endif»"),t;case"loop":return t="«for "+s.prettyPrint(n.body.variable)+" in "+s.prettyPrint(n.lst),n.separator.value&&(t+=' separator "'+n.separator.value+'"'),n.front.value&&(t+=' front "'+n.front.value+'"'),n.rear.value&&(t+=' rear "'+n.rear.value+'"'),t+="»",t+=e(n.body.body),t+="«endfor»",t;default:return""}return""};const s=i(t(143))},963:function(e,n,t){var r=this&&this.__rest||function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t};Object.defineProperty(n,"__esModule",{value:!0}),n.fuse=p,n.fuseExp=c,n.valueToConstantExpr=w,n.printEnvironment=function(e){console.log("{\n");for(const n in e)if(e.hasOwnProperty(n)){const[t,r]=e[n];console.log(`${n}: {`),console.log(" val: "),(0,a.printValue)(t," "),console.log(",marks: ["),r.forEach(((e,n)=>{(0,a.printValue)(e," "),n<r.length-1&&console.log(", ")})),console.log("]\n },\n")}console.log("}")},n.fuseBulk=m,n.fuseBulk1=function(e,n,t){if("id"===n.type)return p(E(e),n,t);if("bulk"!==n.type||!n.operations)throw new Error("Invalid bulk operation");if(0==n.operations.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];if("seq"===t.type&&0==t.nodes.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];const[r,...o]=n.operations;if("seq"===t.type){const r=t.nodes[0],o=t.nodes.slice(1),i=m(e,n,r),s=[];for(const e of i){const n=m(e.newEnv,e.remainingOperation,{type:"seq",nodes:o});for(const t of n){let n=[];"seq"!=t.newTermNode.type?n.push(t.newTermNode):n=t.newTermNode.nodes,s.push({newEnv:t.newEnv,newTermNode:{type:"seq",nodes:[e.newTermNode,...n]},remainingOperation:t.remainingOperation})}}return s}if("lambda"===t.type){let r=N(n);return p(E(e),r,t)}return"insert"===r.type||"delete"===r.type||"replace"===r.type?p(E(e),r,t).map((e=>{let n=e.remainingOperation;if("id"===n.type||"insert"===n.type||"delete"===n.type||"replace"===n.type){let n=(0,l.evaluateTermNode)(e.newTermNode).length;const t=o.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")}));let r={type:"bulk",operations:[e.remainingOperation,...t]};return[{newEnv:e.newEnv,newTermNode:e.newTermNode,remainingOperation:r}]}throw new Error("nested bulk current not supported")})).reduce(((e,n)=>e.concat(n)),[]):"id"===r.type?0==o.length?p(E(e),r,t):m(e,{type:"bulk",operations:o},t):[]};const o=t(63),i=t(75),s=t(446),a=t(893),l=t(238);function p(e,n,t){if("const"!==t.type&&"sep"!==t.type&&"loopfront"!==t.type&&"looprear"!==t.type||"string"!=typeof t.value)if("space"===t.type)switch(n.type){case"insert":const{str:r,position:i}=n;if(0==t.width)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];if(0==i)return[{newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:r},t]},remainingOperation:{type:"id"}}];if(i<t.width){if((0,o.isWhitespace)(r))return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:r.length+t.width}),remainingOperation:{type:"id"}}];throw new Error(`Cannot insert non-space between space term: ${n}`)}if(i===t.width)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:r,position:i-t.width}}];{const n=i-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:r,position:n}}]}case"delete":const{str:s,position:a}=n;if(0!==a){if(a<t.width&&a+s.length<=t.width){const n=t.width-s.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}if(a<t.width&&a+s.length>t.width){const n=a,r=s.substring(t.width-a-1);return[{newEnv:E(e),newTermNode:{type:"space",width:n},remainingOperation:{type:"delete",str:r,position:0}}]}{const n=a-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"delete",str:s,position:n}}]}}if((0,o.isWhitespace)(s)&&s.length<=t.width){const n=t.width-s.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}if(s.length>t.width){const n=s.slice(t.width);return[{newEnv:E(e),newTermNode:{type:"bot"},remainingOperation:{type:"delete",str:n,position:0}}]}case"replace":const{str1:l,str2:p,position:c}=n;if(0!==c){if(c<t.width&&c+l.length<=t.width){if((0,o.isWhitespace)(p))return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:p.length+t.width-l.length}),remainingOperation:{type:"id"}}];{const n=" ".repeat(c)+p+" ".repeat(t.width-(c+l.length));return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"id"}}]}}if(c<t.width&&c+l.length>t.width){const n=" ".repeat(c),r=t.width-c,o=p.substring(0,r),i={type:"replace",str1:l.substring(r),str2:p.substring(r),position:0},s={type:"const",value:n+o};return[{newEnv:E(e),newTermNode:s,remainingOperation:i}]}{const n=c-t.width;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"replace",str1:l,str2:p,position:n}}]}}if(l.length<=t.width){if((0,o.isWhitespace)(p)){const n=t.width-l.length+p.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{width:n}),remainingOperation:{type:"id"}}]}return[{newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:p},Object.assign(Object.assign({},t),{width:t.width-l.length})]},remainingOperation:{type:"id"}}]}if(l.length>t.width){const n=p.slice(0,t.width),r=l.slice(t.width),o=p.slice(t.width);return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"replace",str1:r,str2:o,position:0}}]}case"bulk":return m(e,n,t);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}else if("exp"===t.type){const s=t.binding,l=s[0],u=s[1],d="number"==typeof(a=u)||"boolean"==typeof a||"string"==typeof a?String(a):"Unknown";switch(n.type){case"insert":const{str:s,position:a}=n;if(0===a){let n=[];if(n.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:s},t]},remainingOperation:{type:"id"}}),!(0,o.containsNewlineOrSpace)(s)){let r=function(e,n){try{if(v(JSON.parse(n)))return n+e}catch(e){return}}(d,s);if(void 0!==r)try{let o=y(r,u),{newEnv:i,newExp:s}=c(e,o,l);n.push({newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"id"}})}catch(e){}}return n}if(a<d.length){const n=y(d.slice(0,a)+s+d.slice(a),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(a==d.length){let r=[];if(!(0,o.containsNewlineOrSpace)(s)){const n=function(e,n){return e+n}(d,s);if(void 0!==n)try{const o=y(n,u);let{newEnv:i,newExp:s}=c(e,o,l);r.push({newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"id"}})}catch(e){console.error(e)}}let i=E(e);return l.name&&(i[l.name]=[u,[u]]),r.push({newEnv:i,newTermNode:t,remainingOperation:Object.assign(Object.assign({},n),{position:0})}),r}{const r=a-d.length;if(l.name){let n=l.name;e[n]=[u,[u]]}return[{newEnv:E(e),newTermNode:t,remainingOperation:Object.assign(Object.assign({},n),{position:r})}]}case"delete":const{str:f,position:g}=n;if(0===g){if(f.length<d.length){const n=y(d.slice(f.length),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(f.length==d.length){if(l.name){let n=l.name;if("string"==typeof u){let{newEnv:r,newExp:o}=c(e,"",l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,""]}),remainingOperation:{type:"id"}},{newEnv:b(E(e),n),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}]}return[{newEnv:b(E(e),n),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}]}if(l){let n=l.object.name,r=l.field,o=e[n][0];if(0==e[n][1].length)throw new Error("Fields does not existed:"+r);let i=e[n][1][0];if(0==i.fields[r].length){let s=[];if("string"==typeof o.fields[r]){let{newEnv:n,newExp:r}=c(e,"",l);s.push({newEnv:E(n),newTermNode:Object.assign(Object.assign({},t),{binding:[r,""]}),remainingOperation:{type:"id"}})}let a=h(o,r),p=h(i,r),u=b(E(e),n);return u[n]=[a,[p]],s.push({newEnv:E(u),newTermNode:{type:"bot"},remainingOperation:{type:"id"}}),s}throw new Error(`field has been updated, cannot be remvoed: ${r}$`)}}else if(f.length>d.length){let n=f.slice(0,d.length),r=f.slice(d.length),o={type:"delete",str:n,position:0},i=p(E(e),o,t),s={type:"delete",str:r,position:0};return i.forEach((e=>{e.remainingOperation=s})),i}}else{if(g+f.length<=d.length){const n=y(d.slice(0,g)+d.slice(g+f.length),u);let{newEnv:r,newExp:o}=c(e,n,l);return[{newEnv:E(r),newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(g<=d.length&&g+f.length>d.length){const n=d.slice(0,g),r=f.slice(d.length-g-1),o=y(n,u);let{newEnv:i,newExp:s}=c(e,o,l);return[{newEnv:E(i),newTermNode:Object.assign(Object.assign({},t),{binding:[s,o]}),remainingOperation:{type:"delete",str:r,position:0}}]}if(g>d.length){const n=g-d.length;let[{newEnv:r,newTermNode:o,remainingOperation:i}]=p(E(e),{type:"id"},t);return[{newEnv:E(r),newTermNode:o,remainingOperation:{type:"delete",str:f,position:n}}]}}case"replace":const{str1:w,str2:O,position:j}=n;if(0===j){if(d.startsWith(w)){const n=y(O+d.slice(w.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(w.startsWith(d)){const n=y(O.slice(0,d.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);const i=w.slice(d.length),s=O.slice(d.length);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"replace",str1:i,str2:s,position:0}}]}throw new Error(`unsupported replacement: ${w}; ${O}`)}if(j<d.length){const n=y(d.slice(0,j)+O+d.slice(j+w.length),u);let{newEnv:r,newExp:o}=c(E(e),n,l);return[{newEnv:r,newTermNode:Object.assign(Object.assign({},t),{binding:[o,n]}),remainingOperation:{type:"id"}}]}if(j>=d.length){const r=j-d.length;let[{newEnv:o,newTermNode:i,remainingOperation:s}]=p(E(e),{type:"id"},t);return[{newEnv:E(o),newTermNode:i,remainingOperation:Object.assign(Object.assign({},n),{position:r})}]}throw new Error("Unsupported replacement");case"bulk":return m(e,n,t);case"id":let{variables:N,fields:x}=(0,i.findVariablesAndFields)(l);return N.forEach((n=>{e=function(e,n){if(!(e.name in n))throw new Error(`Variable ${e.name} not found in environment.`);let t=n[e.name][0],r=b(n,e.name);return r[e.name]=[t,[t]],r}(n,e)})),x.forEach((({variable:n,field:t})=>{e=function(e,n,t){let o=n.name;if(!(o in t))throw new Error(`Variable ${o} not found in environment.`);let i=t[o][0],s=function(e,n,t){const o=e.fields,i=n,s=(o[i],r(o,["symbol"==typeof i?i:i+""]));return s[n]=t.fields[n],{type:"object",fields:s}}(t[o][1][0],e,i),a=b(t,o);return a[o]=[i,[s]],a}(t,n,e)})),[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}}else{if("lambda"===t.type){let r=t.marker;if("loopitem"===r.type){let o=[],i=t.variable.name,s=t.binding[0],a=t.binding[1],l=E(e);l=j(l,i,a,s);let u="";if(!r.lst)throw new Error("exp is not a Variable with a name property in loopitem's marker");{let e=r.lst.name;u=e+"_new"}let d=p(E(l),n,t.body).map((({newEnv:n,newTermNode:r,remainingOperation:o})=>{let a=E(n);if(i in a){let n=a[i][0],l=a[u][0];"object"==typeof n&&null!==n&&"type"in n&&"object"===n.type&&0===Object.keys(n.fields).length||l.push(n),a[u]=[l,[l]],a=b(E(a),i);let{newEnv:p,newExp:d}=c(a,n,s);return e[i]&&(p[i]=e[i]),{newEnv:p,newTermNode:{type:"lambda",variable:t.variable,body:"seq"!=r.type?{type:"seq",nodes:[r]}:r,binding:[d,n],marker:t.marker},remainingOperation:o}}return e[i]&&(a[i]=e[i]),{newEnv:a,newTermNode:{type:"lambda",variable:t.variable,body:"seq"!=r.type?{type:"seq",nodes:[r]}:r,binding:[{type:"constant",value:null},null],marker:t.marker},remainingOperation:o}}));return o.concat(d)}{let r=[];if("bulk"===n.type&&n.operations.length>0){let o=n.operations;const[i,...s]=o;if("insert"===i.type&&0===i.position){let n=i.str.length,o={type:"bulk",operations:s.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")}))},a=p(E(e),o,t);a.map((e=>(e.newTermNode={type:"seq",nodes:[{type:"const",value:i.str},e.newTermNode]},e))),r=r.concat(a)}}else if("insert"===n.type&&0===n.position){let o=p(E(e),{type:"id"},t);o.map((e=>(e.newTermNode={type:"seq",nodes:[{type:"const",value:n.str},e.newTermNode]},e))),r=r.concat(o)}let o=t.variable.name,i=t.binding[0],s=t.binding[1],a=E(e);a=j(a,o,s,i);let l=p(E(a),n,t.body).map((({newEnv:n,newTermNode:r,remainingOperation:a})=>{if(!(o in n))throw new Error("valued expression of "+o+" was deleted in the body.");let l=n[o][0],p=n[o][1].length>0;delete n[o];let u=function(e,n){let t=E(e);for(const e in n)n.hasOwnProperty(e)&&(t[e]=n[e]);return t}(e,n);if(p){let{newEnv:e,newExp:n}=c(u,l,i);return{newEnv:e,newTermNode:{type:"lambda",variable:t.variable,body:r,binding:[n,l],isBindingUpdated:!0,marker:t.marker},remainingOperation:a}}return{newEnv:u,newTermNode:{type:"lambda",variable:t.variable,body:r,binding:[i,s],isBindingUpdated:!1,marker:t.marker},remainingOperation:a}}));return r=r.concat(l),r}}if("branchstart"===t.type||"branchend"===t.type||"nop"===t.type){if("branchend"===t.type){let n=t.condition[0],r=t.condition[1];try{let[t,o]=(0,s.evaluateExpr)(g(e),n);if(o!==r)throw new Error("Violate BX properties: updates change if-then-else branch.")}catch(e){throw new Error(`Error evaluating condition expression fail during backward: ${e}`)}}let r=[];switch(r.push({newEnv:E(e),newTermNode:t,remainingOperation:n}),n.type){case"insert":const{str:o,position:i}=n;0===i&&r.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:o},t]},remainingOperation:{type:"id"}});case"delete":case"replace":case"id":return r;case"bulk":return m(e,n,t);default:throw new Error(`Unhandled operation type: ${n}`)}}else{if("seq"===t.type){if("bulk"===n.type)return m(e,n,t);const r=t.nodes;let o=[{newEnv:e,newTermNode:{type:"seq",nodes:[]},remainingOperation:n}];for(const e of r){const n=[];for(const t of o){const r=p(E(t.newEnv),t.remainingOperation,e);for(const e of r){const r=("seq"===t.newTermNode.type?t.newTermNode.nodes:[t.newTermNode]).concat("seq"===e.newTermNode.type?e.newTermNode.nodes:[e.newTermNode]);n.push({newEnv:e.newEnv,newTermNode:{type:"seq",nodes:r},remainingOperation:e.remainingOperation})}}o=n}return o.map((e=>e))}if("end"!==t.type)throw new Error("Operation can only be applied to ConstNode with string value");{let r=[];switch(n.type){case"insert":const{str:o,position:i}=n;if(i>=0)return r.push({newEnv:E(e),newTermNode:{type:"seq",nodes:[{type:"const",value:o},t]},remainingOperation:{type:"id"}}),r;throw new Error(`Unhandled operation type: ${n.type}, ${n.position}, ${n.str} for end term`);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n.type}`)}}}}else{if("loopfront"===t.type){let n=t.lst;if(!n.name)throw new Error("exp is not a Variable with a name property in loopfront");{let t=n.name;e[t+"_new"]=[[],[]]}}else if("looprear"===t.type){let n=t.lst;if(!n.name)throw new Error("exp is not a Variable with a name property in loopfront");{let t=n.name,r=e[t+"_new"][0];r=r.reverse(),e[t]=[r,[r]]}}const r=t.value;switch(n.type){case"insert":const{str:o,position:i}=n;if(0===i)return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:o+r}),remainingOperation:{type:"id"}}];if(i<r.length){const n=r.slice(0,i)+o+r.slice(i);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(i===r.length)return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:r+o}),remainingOperation:{type:"id"}},{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:o,position:i-r.length}}];{const n=i-r.length;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"insert",str:o,position:n}}]}case"delete":const{str:s,position:a}=n;if(0===a){if(r.startsWith(s)&&s.length<=r.length){const n=r.slice(s.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(s.startsWith(r)&&s.length>r.length){const n=s.slice(r.length);return[{newEnv:E(e),newTermNode:{type:"bot"},remainingOperation:{type:"delete",str:n,position:0}}]}throw new Error("cannot delete, not match. delStr: "+s+", s_c: "+r)}if(a<r.length&&a+s.length<=r.length){const n=r.slice(0,a)+r.slice(a+s.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(a<r.length&&a+s.length>r.length){const n=r.substring(0,a),t=s.substring(r.length-1-a);return[{newEnv:E(e),newTermNode:{type:"const",value:n},remainingOperation:{type:"delete",str:t,position:0}}]}{const n=a-r.length;return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"delete",str:s,position:n}}]}case"replace":const{str1:l,str2:p,position:c}=n;if(0!==c){if(c<r.length&&c+l.length<=r.length){const n=r.slice(0,c)+p+r.slice(c+l.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(c<r.length&&c+l.length>r.length){const n=r.substring(0,c),t=r.substring(c),o=p.substring(0,t.length),i={type:"replace",str1:l.substring(t.length),str2:p.substring(t.length),position:0},s={type:"const",value:n+o};return[{newEnv:E(e),newTermNode:s,remainingOperation:i}]}{const n=c-r.length;return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:r}),remainingOperation:{type:"replace",str1:l,str2:p,position:n}}]}}if(r.startsWith(l)&&l.length<=r.length){const n=p+r.slice(l.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"id"}}]}if(l.startsWith(r)&&l.length>r.length){const n=p.slice(0,r.length),o=l.slice(r.length),i=p.slice(r.length);return[{newEnv:E(e),newTermNode:Object.assign(Object.assign({},t),{value:n}),remainingOperation:{type:"replace",str1:o,str2:i,position:0}}]}case"bulk":return m(e,n,t);case"id":return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];default:throw new Error(`Unhandled operation type: ${n}`)}}var a}function c(e,n,t){switch(t.type){case"constant":return{newEnv:e,newExp:w(n)};case"variable":if(!(t.name in e))throw new Error(`Variable ${t.name} not found in environment.`);const[o,i]=e[t.name];if(0===i.length){const r=E(e);return r[t.name]=[n,[n]],{newEnv:r,newExp:t}}if(1===i.length&&i[0]===n)return{newEnv:e,newExp:t};throw new Error(`Fail, variable cannot be updated to different value ${t.name}, previous: ${i[0]}, new: ${n}`);case"freeze":let[a,l]=(0,s.evaluateExpr)(g(e),t.expression);if(l!==n)throw new Error(`Fail, freezed expression cannot be changed, old: ${n}, new: ${l}`);return{newEnv:e,newExp:t};case"field":const p=t.object;if("variable"===p.type&&p.name in e){const[o,i]=e[p.name];if("object"===o.type){const s={type:"object",fields:Object.assign(Object.assign({},o.fields),{[t.field]:n})},a=function(e,n,t){const o=e.fields,i=n,s=(o[i],r(o,["symbol"==typeof i?i:i+""]));return s[n]=[t],{type:"object",fields:s}}(i[0],t.field,n),l=E(e);return l[p.name]=[s,[a]],{newEnv:l,newExp:t}}if("object"==typeof o)return{newEnv:E(e),newExp:t};throw new Error("Field access's value is not an object")}throw new Error("Field access not start with variable.");case"binary":let d=g(e),[y,b]=(0,s.evaluateExpr)(d,t.left);if("number"==typeof n){if("number"!=typeof n||null===n)throw new Error("Value must be a non-null number");switch(t.operator){case"+":let r=c(e,n-b,t.right);return{newEnv:r.newEnv,newExp:Object.assign(Object.assign({},t),{right:r.newExp})};case"-":let o=c(e,b-n,t.right);return{newEnv:o.newEnv,newExp:Object.assign(Object.assign({},t),{right:o.newExp})};case"*":let i=c(e,n/b,t.right);return{newEnv:i.newEnv,newExp:Object.assign(Object.assign({},t),{right:i.newExp})};case"/":let s=c(e,b/n,t.right);return{newEnv:s.newEnv,newExp:Object.assign(Object.assign({},t),{right:s.newExp})}}}else if("string"==typeof n){let r=n.slice(0,b.length),o=n.slice(b.length),i=c(e,r,t.left),s=c(i.newEnv,o,t.right);return{newEnv:s.newEnv,newExp:{type:"binary",left:i.newExp,operator:t.operator,right:s.newExp}}}case"unary":return{newEnv:e,newExp:t};case"array":return{newEnv:e,newExp:{type:"array",elements:u(t.elements,n)}};case"object":let h={},m=n.fields;for(const e in m)if(m.hasOwnProperty(e)){const n=m[e];h[e]=f(n)}return{newEnv:e,newExp:{type:"object",fields:h}};default:throw new Error(`Unsupported expression type: ${t.type}`)}}function u(e,n){const t=[];for(let r=0;r<n.length;r++)r<e.length?t.push(d(e[r],n[r])):t.push(f(n[r]));return t}function d(e,n){switch(e.type){case"constant":return Object.assign(Object.assign({},e),{value:n});case"array":return Object.assign(Object.assign({},e),{elements:u(e.elements,n)});case"object":return Object.assign(Object.assign({},e),{fields:Object.keys(e.fields).reduce(((t,r)=>(t[r]=Object.assign(Object.assign({},e.fields[r]),{value:n.fields[r]}),t)),{})});default:throw new Error(`Unsupported expression type: ${e.type}`)}}function f(e){if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"array",elements:e.map(f)};if("object"==typeof e&&null!==e)return{type:"object",fields:Object.keys(e.fields).reduce(((n,t)=>(n[t]={type:"constant",value:e.fields[t]},n)),{})};throw new Error("Unsupported value type: "+typeof e)}function y(e,n){if("number"==typeof n){const n=parseFloat(e);if(isNaN(n))throw new Error("convert to number fail: "+e);return n}if("boolean"==typeof n){if("true"===e)return!0;if("false"===e)return!1;throw new Error("convert to boolean fail: ${s}")}if("string"==typeof n)return e;throw new Error("Unsupported type: "+typeof n)}function b(e,n){const t=E(e);return delete t[n],t}function h(e,n){const t=e.fields,o=n;return t[o],{type:"object",fields:r(t,["symbol"==typeof o?o:o+""])}}function g(e){const n=new Map;for(const t in e)e.hasOwnProperty(t)&&n.set(t,e[t][0]);return n}function w(e){if(null===e||"number"==typeof e||"boolean"==typeof e||"string"==typeof e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"constant",value:e.map((e=>w(e)))};if("object"===e.type){const n=e,t={};for(const e in n.fields)n.fields.hasOwnProperty(e)&&(t[e]=w(n.fields[e]));return{type:"constant",value:{type:"object",fields:t}}}throw new Error("Unhandled value type: "+typeof e)}function m(e,n,t){if("id"===n.type)return p(E(e),n,t);if("bulk"!==n.type||!n.operations)throw new Error("Invalid bulk operation");if(0===n.operations.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:{type:"id"}}];if("seq"===t.type&&0===t.nodes.length)return[{newEnv:E(e),newTermNode:t,remainingOperation:n}];if("lambda"===t.type){let r=N(n);return p(E(e),r,t)}if("seq"===t.type){const r=[{env:e,termNodes:[...t.nodes],processedNodes:[],bulkOp:n}],o=[];for(;r.length>0;){const e=r.pop(),{env:n,termNodes:t,processedNodes:i,bulkOp:s}=e;if(0===t.length){o.push({newEnv:n,newTermNode:{type:"seq",nodes:i},remainingOperation:s});continue}const[a,...l]=t,p=m(n,s,a);for(const e of p){const n=[...i,e.newTermNode];r.push({env:e.newEnv,termNodes:l,processedNodes:n,bulkOp:e.remainingOperation})}}return o}const[r,...o]=n.operations;if("insert"===r.type||"delete"===r.type||"replace"===r.type){const n=p(E(e),r,t);let i=[];for(const e of n){const n=e.remainingOperation;if("id"!==n.type&&"insert"!==n.type&&"delete"!==n.type&&"replace"!==n.type)throw new Error("nested bulk currently not supported");{let n=(0,l.evaluateTermNode)(e.newTermNode).length;const t=o.map((e=>{if("id"===e.type)return e;if("position"in e)return Object.assign(Object.assign({},e),{position:e.position-n});throw new Error("All operations must have positions")})),r={type:"bulk",operations:[e.remainingOperation,...t]};i.push({newEnv:e.newEnv,newTermNode:e.newTermNode,remainingOperation:r})}}return i}return"id"===r.type?0===o.length?p(E(e),r,t):m(e,{type:"bulk",operations:o},t):[]}function v(e){return!!("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e||Array.isArray(e)&&e.every(v)||"object"==typeof e&&null!==e&&"object"===e.type&&"object"==typeof e.fields)}function O(e,n=new WeakMap){if(null===e||"object"!=typeof e)return e;if(n.has(e))return n.get(e);if(Array.isArray(e)){const t=[];n.set(e,t);for(const r of e)t.push(O(r,n));return t}if(function(e){return e&&"object"==typeof e&&"object"===e.type&&"fields"in e}(e)){const t={},r={type:"object",fields:t};n.set(e,r);for(const r in e.fields)e.fields.hasOwnProperty(r)&&(t[r]=O(e.fields[r],n));return r}const t={};n.set(e,t);for(const r in e)e.hasOwnProperty(r)&&(t[r]=O(e[r],n));return t}function E(e,n=new WeakMap){if(n.has(e))return n.get(e);const t={};n.set(e,t);for(const r in e)if(e.hasOwnProperty(r)){const[o,i]=e[r];t[r]=[O(o,n),O(i,n)]}return t}function j(e,n,t,r){if("number"==typeof t||"boolean"==typeof t||"string"==typeof t||null===t)"field"==r.type&&"length"==r.field?e[n]=[t,[t]]:e[n]=[t,[]];else if(Array.isArray(t))e[n]=[t,[]];else if("object"==typeof t&&null!==t&&"fields"in t){const r={type:"object",fields:{}};for(const e in t.fields)r.fields[e]=[];e[n]=[t,[r]]}return e}function N(e){if("bulk"===e.type){const n=e.operations.map(N);return Object.assign(Object.assign({},e),{operations:n})}return Object.assign({},e)}},238:(e,n)=>{function t(e){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)return e.toString();if("object"===e.type){const n=e;let r="{";for(const e in n.fields)n.fields.hasOwnProperty(e)&&(r+=`${e}: ${t(n.fields[e])}, `);return r.length>1&&(r=r.slice(0,-2)),r+="}",r}if(Array.isArray(e)){const n=e;let r="[";for(const e of n)r+=`${t(e)}, `;return r.length>1&&(r=r.slice(0,-2)),r+="]",r}throw new Error("Unhandled value type: "+typeof e)}Object.defineProperty(n,"__esModule",{value:!0}),n.evaluateTermNode=function e(n){switch(n.type){case"const":case"sep":case"loopfront":case"looprear":return n.value;case"space":return" ".repeat(n.width);case"exp":return String(t(n.binding[1]));case"seq":return n.nodes.map((n=>e(n))).join("");case"lambda":return e(n.body);case"branchstart":case"branchend":case"end":case"bot":case"nop":return"";default:throw new Error(`Unhandled term node type: ${n.type}`)}},n.printValue=t},619:(e,n)=>{function t(e){let n=e.type;if("seq"===n)return r(e);if("declare"===n||"assign"===n)throw new Error("declare|assign node shall not be visible here.");if("lambda"===n){let n=e,r=t(n.body);return{type:"lambda",variable:n.variable,body:r,binding:n.binding,isBindingUpdated:n.isBindingUpdated,marker:n.marker}}return e}function r(e){let n=e.nodes,i=[];for(let e=0;e<n.length;e++){let s=n[e];if("declare"===s.type||"assign"===s.type){let t=s,a=t.name,[l,p]=o(n,e+1,a),{nodes:c}=r({type:"seq",nodes:l}),u=c.pop();if(void 0===u)throw new Error("lastNode should be declareend or others");if("declareend"!=u.type){c.push(u);let e={type:"lambda",variable:t.name,body:{type:"seq",nodes:c},binding:t.value,isBindingUpdated:!1,marker:{type:s.type}};i.push(e)}else{let e={type:"lambda",variable:t.name,body:{type:"seq",nodes:c},binding:t.value,isBindingUpdated:!1,marker:{type:s.type}};i.push(e),"declare"!=s.type&&i.push(u)}e=p}else i.push(t(s))}return{type:"seq",nodes:i}}function o(e,n,t){let r=[],o=n;for(;o<e.length;o++){if("declareend"===e[o].type&&e[o].name.name===t.name)return r.push(e[o]),[r,o];r.push(e[o])}return[r,o]}Object.defineProperty(n,"__esModule",{value:!0}),n.lambdalize=t},784:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.unLambdalize=function e(n){switch(n.type){case"lambda":{const{variable:t,body:r,binding:o,marker:i,isBindingUpdated:s}=n;let a;switch(i.type){case"declare":return a=e(r),{type:"seq",nodes:[{type:"declare",name:t,value:o,isBindingUpdated:s},a]};case"assign":return a=e(r),{type:"seq",nodes:[{type:"assign",name:t,value:o,isBindingUpdated:s},a]};default:return{type:"lambda",variable:t,body:e(r),binding:o,isBindingUpdated:s,marker:i}}}case"seq":return{type:"seq",nodes:n.nodes.map(e)};default:return n}}},893:(e,n,t)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.printNode=function e(n,t=""){switch(console.log(t+n.type),n.type){case"const":case"sep":console.log(t+" Value: "+n.value);break;case"space":console.log(t+" Width: "+n.width);break;case"declare":case"assign":console.log(t+" Name: "+n.name.name),o(n.value,t+" ");break;case"exp":o(n.binding,t+" ");break;case"seq":n.nodes.forEach((n=>e(n,t+" ")));break;case"branchstart":o(n.condition,t+" ");break;case"loopfront":console.log(t+" front: "+n.value);break;case"looprear":console.log(t+" rear: "+n.value);break;case"lambda":console.log(t+" Variable: "+n.variable.name),e(n.body,t+" "),o(n.binding,t+" "),s(n.marker,t+" ");break;case"callstart":console.log(t+" Name: "+n.name);break;case"end":console.log(`${t} End`)}},n.printBinding=o,n.printValue=i,n.printMarker=s;const r=t(235);function o(e,n){(0,r.printExpression)(e[0],n),i(e[1],n)}function i(e,n){if(null===e)console.log(`${n}null`);else if("number"==typeof e||"boolean"==typeof e||"string"==typeof e)console.log(`${n}${e}`);else{if("object"!=typeof e)throw new Error("Unhandled value type: "+typeof e);{console.log(`${n}{`);const t=e;for(const e in t)if(t.hasOwnProperty(e)){const r=n+" ";console.log(`${r}${e}:`),i(t[e],r+" ")}console.log(`${n}}`)}}}function s(e,n=""){console.log(n+e.type)}},446:(e,n)=>{function t(e,n){switch(n.type){case"constant":return[e,n.value];case"variable":const r=e.get(n.name);if(void 0===r)throw new Error(`Variable '${n.name}' not found in environment`);return[e,r];case"binary":let[o,i]=t(e,n.left),[s,a]=t(o,n.right);switch(n.operator){case"+":return[s,i+a];case"-":return[s,i-a];case"*":return[s,i*a];case"/":return[s,i/a];case"&&":return[s,i&&a];case"||":return[s,i||a];case">":return[s,i>a];case"<":return[s,i<a];case">=":return[s,i>=a];case"<=":return[s,i<=a];case"==":return[s,i==a];case"!=":return[s,i!=a];default:throw new Error("Unsupported binary operator")}case"unary":let[l,p]=t(e,n.operand);if("not"===n.operator)return[l,!p];throw new Error("Unsupported unary operator");case"field":let c,[u,d]=t(e,n.object);if("string"!=typeof d&&("object"!=typeof d||null===d))throw new Error(`Cannot access field '${n.field}' from non-object`);if("string"==typeof d?c=d[n.field]:Array.isArray(d)?"length"===n.field&&(c=d.length):c=d.fields[n.field],void 0===c)throw new Error(`Field '${n.field}' not found in object`);return[u,c];case"array":let f=[],y=e;for(const e of n.elements){let[n,r]=t(y,e);f.push(r),y=n}return[y,f];case"object":let b={type:"object",fields:{}},h=e;for(const e in n.fields)if(n.fields.hasOwnProperty(e)){let[r,o]=t(h,n.fields[e]);b.fields[e]=o,h=r}return[h,b];case"freeze":return t(e,n.expression);default:throw new Error("Unhandled expression type")}}Object.defineProperty(n,"__esModule",{value:!0}),n.partialEval=function e(n,r){switch(r.type){case"const":return[n,{type:"const",value:r.value}];case"space":return[n,{type:"space",width:r.width}];case"declare":const[o,i]=t(n,r.value);return o.set(r.name.name,i),[o,{type:"declare",name:r.name,value:[r.value,i],isBindingUpdated:!1}];case"declareend":return[n,r];case"assign":const[s,a]=t(n,r.value);return s.set(r.name.name,a),[s,{type:"assign",name:r.name,value:[r.value,a],isBindingUpdated:!1}];case"exp":const[l,p]=t(n,r.expression);return[l,{type:"exp",binding:[r.expression,p]}];case"seq":let c=n;const u=[];for(const n of r.nodes){const[t,r]=e(c,n);u.push(r),c=t}return[c,{type:"seq",nodes:u}];case"ite":const[d,f]=t(n,r.condition);if(!0===f){const[n,t]=e(d,r.trueBranch);return[n,{type:"seq",nodes:[{type:"branchstart",condition:[r.condition,f],trueBranch:r.trueBranch,falseBranch:r.falseBranch},t,{type:"branchend",condition:[r.condition,f]}]}]}if(!1===f){const[n,t]=e(d,r.falseBranch);return[n,{type:"seq",nodes:[{type:"branchstart",condition:[r.condition,f],trueBranch:r.trueBranch,falseBranch:r.falseBranch},t,{type:"branchend",condition:[r.condition,f]}]}]}throw new Error(`Condition does not evaluate to boolean: ${f}`);case"loop":const{lst:y,separator:b,front:h,rear:g,body:w}=r,[m,v]=t(n,y);if(Array.isArray(v)&&0===v.length)return[m,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},{type:"looprear",lst:y,value:g.value}]}];if(Array.isArray(v)&&1===v.length){const t=v[0],r=w.variable.name,o=new Map(n);o.set(r,t);const[i,s]=e(o,w.body);return[i,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},{type:"lambda",variable:w.variable,binding:[{type:"constant",value:t},t],marker:{type:"loopitem",lst:y},body:s},{type:"looprear",lst:y,value:g.value}]}]}if(Array.isArray(v)&&v.length>1){let t=new Map(n),o=[];for(let n=0;n<v.length;n++){const r=v[n],i=w.variable.name;t.set(i,r);const[s,a]=e(t,w.body);t=s,o.push({type:"lambda",variable:w.variable,body:a,binding:[{type:"constant",value:r},r],isBindingUpdated:!1,marker:{type:"loopitem",lst:y}})}let i=o[o.length-1];for(let e=o.length-2;e>=0;e--){let n=o[e];i={type:"lambda",variable:n.variable,binding:n.binding,marker:n.marker,body:{type:"seq",nodes:[n.body,r.separator,i]}}}return[t,{type:"seq",nodes:[{type:"loopfront",lst:y,value:h.value,body:w,separator:b},i,{type:"looprear",lst:y,value:g.value}]}]}throw new Error("Unsupported type or value for e_arr: "+typeof v);case"nop":return[n,{type:"nop"}];case"bot":return[n,{type:"bot"}];case"end":return[n,{type:"end"}];default:throw new Error(`Unhandled term node type: ${r.type}`)}},n.evaluateExpr=t,n.flatten=function e(n){return"seq"===n.type?{type:"seq",nodes:n.nodes.map((n=>e(n))).flatMap((e=>"seq"===e.type?e.nodes:[e]))}:"lambda"===n.type?Object.assign(Object.assign({},n),{body:e(n.body)}):n}},887:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.unPartialEval=l,n.flatten=function e(n){if("seq"===n.type){const t=n.nodes.map((n=>e(n)));return 1==t.length?t[0]:{type:"seq",nodes:t.flatMap((e=>"seq"===e.type?e.nodes:[e]))}}return"ite"===n.type?Object.assign(Object.assign({},n),{trueBranch:e(n.trueBranch),falseBranch:e(n.falseBranch)}):"loop"===n.type?Object.assign(Object.assign({},n),{body:Object.assign(Object.assign({},n.body),{body:e(n.body.body)})}):n};const s=i(t(454));function a(e){return e[0]}function l(e){switch(e.type){case"const":return s.constNode(e.value);case"space":return s.space(e.width);case"declare":return s.declare(e.name,a(e.value),e.isBindingUpdated);case"assign":return s.assign(e.name,a(e.value),e.isBindingUpdated);case"exp":return s.exp(a(e.binding));case"nop":return s.nop();case"end":return s.end();case"bot":return s.bot();case"seq":return p(e);case"lambda":return c(e);case"sep":return e;default:throw new Error(`Unknown node type: ${e.type}`)}}function p(e){const n=e.nodes,t=[];for(let e=0;e<n.length;e++){const o=n[e];if("branchstart"===o.type){const r=o.condition[0],i=o.condition[1],a=o.trueBranch,l=o.falseBranch;let c=1;const u=[];for(let t=e+1;t<n.length;t++){const e=n[t];if("branchstart"===e.type&&c++,"branchend"===e.type){if(1==c)break;c--,u.push(n[t])}else u.push(n[t])}i?t.push(s.ite(r,p({type:"seq",nodes:u}),l)):t.push(s.ite(r,a,p({type:"seq",nodes:u}))),e+=u.length+1}else if("loopfront"===o.type){let i=o,a=null,l=null,p=null,c=n[++e];if("looprear"===c.type)a=c;else{let t=c;if([l,p]=u(t),c=n[++e],"looprear"!==c.type)throw new Error("Shall end with looprear node");a=c}if(""===i.value&&""===a.value&&null===l&&null===p)t.push(s.bot());else if(null===l||d(l))t.push(s.loop(i.lst,i.separator,{type:"front",value:o.value},{type:"rear",value:a.value},i.body));else{if("bot"===l.type)throw new Error("lambda is bot node");if("lambdawithexpr"!==l.type)throw new Error("Must be lambda in loopitem");t.push(s.loop(i.lst,null===p?i.separator:p,{type:"front",value:o.value},{type:"rear",value:a.value},{type:"lambda",variable:(r=l).variable,body:r.body}))}}else t.push(l(o))}var r;return s.seq(...t)}function c(e){let{variable:n,body:t,binding:r,marker:o}=e;return{type:"lambdawithexpr",variable:n,body:l(t),exp:(i=r[1],Array.isArray(i)?{type:"array",elements:i.map(f)}:{type:"array",elements:[f(i)]})};var i}function u(e){let n=e,t=e.variable.name,r=e.body,o=null,i=[],s=null;for(let e of r.nodes)"sep"===e.type?s=e:"lambda"===e.type&&e.variable.name===t?o=e:i.push(e);if(n.body=i.every(d)?{type:"bot"}:{type:"seq",nodes:i},null==o)return"bot"===n.body.type?[{type:"bot"},null]:[c(n),null];{let[e,t]=u(o);if("bot"===e.type&&null===t)return[c(n),s];if("bot"===n.body.type&&null===s)return[e,t];if("bot"===n.body.type&&""===(null==s?void 0:s.value))return[e,t];{let r=c(n);if(l=e,y((a=r).variable,l.variable)&&h(a.body,l.body)){if(null===t)return[r,s];if(null!=s&&t.value===s.value)return[r,s];throw new Error("sepNode not equal")}throw new Error("lambda body not equal")}}var a,l}function d(e){return"bot"===e.type}function f(e){if("number"==typeof e||"boolean"==typeof e||"string"==typeof e||null===e)return{type:"constant",value:e};if(Array.isArray(e))return{type:"array",elements:e.map(f)};if("object"===e.type){const n={};for(const t in e.fields)if(e.fields.hasOwnProperty(t)){const r=e.fields[t];n[t]={type:"constant",value:r}}return{type:"object",fields:n}}throw new Error("Unsupported Value type")}function y(e,n){return e.name===n.name}function b(e,n){if(e.type!==n.type)return!1;switch(e.type){case"constant":const t=e,r=n;return null===t.value&&null===r.value||("object"==typeof t.value&&"object"==typeof r.value?b(t.value,r.value):t.value===r.value);case"variable":return e.name===n.name;case"binary":const o=e,i=n;return o.operator===i.operator&&b(o.left,i.left)&&b(o.right,i.right);case"unary":const s=e,a=n;return s.operator===a.operator&&b(s.operand,a.operand);case"field":const l=e,p=n;return l.field===p.field&&b(l.object,p.object);case"array":const c=e,u=n;return c.elements.length===u.elements.length&&c.elements.every(((e,n)=>b(e,u.elements[n])));case"object":const d=e,f=n,y=Object.keys(d.fields),h=Object.keys(f.fields);return y.length===h.length&&y.every((e=>f.fields.hasOwnProperty(e)&&b(d.fields[e],f.fields[e])));case"freeze":return b(e.expression,n.expression);default:return!1}}function h(e,n){if(e.type!==n.type)return!1;switch(e.type){case"const":return e.value===n.value;case"space":return e.width===n.width;case"declare":const t=e,r=n;return!t.isBindingUpdated||!r.isBindingUpdated||y(t.name,r.name)&&b(t.value,r.value);case"assign":const o=e,i=n;return!o.isBindingUpdated||!i.isBindingUpdated||y(o.name,i.name)&&b(o.value,i.value);case"exp":return b(e.expression,n.expression);case"seq":const s=e.nodes.filter((e=>!("const"===e.type&&""===e.value))),a=n.nodes.filter((e=>!("const"===e.type&&""===e.value)));return s.length===a.length&&s.every(((e,n)=>h(e,a[n])));case"ite":const l=e,p=n;return b(l.condition,p.condition)&&h(l.trueBranch,p.trueBranch)&&h(l.falseBranch,p.falseBranch);case"loop":const c=e,u=n;return b(c.lst,u.lst)&&c.separator.value===u.separator.value&&c.front.value===u.front.value&&c.rear.value===u.rear.value&&function(e,n){return y(e.variable,n.variable)&&h(e.body,n.body)}(c.body,u.body);case"nop":case"bot":case"end":return!0;case"call":const d=e,f=n;return h(d.func,f.func)&&Object.keys(d.args).length===Object.keys(f.args).length&&Object.keys(d.args).every((e=>b(d.args[e],f.args[e])));case"lambdawithexpr":const g=e,w=n;return y(g.variable,w.variable)&&h(g.body,w.body);default:return!1}}},661:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.scopelize=function e(n){switch(n.type){case"declare":return{type:"seq",nodes:[n,{type:"declareend",name:n.name}]};case"seq":return function(n){let t=new s.Stack,r=[];for(let o of n.nodes){if("declare"===o.type){let e={type:"declareend",name:o.name};t.push(e)}"declare"===o.type?r.push(o):r.push(e(o))}if(0==r.length)return n;{let e=r.pop();for("end"!==e.type&&r.push(e);!t.isEmpty();){let e=t.pop();if(!e)throw new Error("endNode is undefined.");r.push(e)}"end"===(null==e?void 0:e.type)&&r.push(e)}return Object.assign(Object.assign({},n),{nodes:r})}(n);case"ite":let t=n.trueBranch,r=n.falseBranch;return{type:"ite",condition:n.condition,trueBranch:e(t),falseBranch:e(r)};case"loop":let o=n.body,i=o.body;return Object.assign(Object.assign({},n),{body:Object.assign(Object.assign({},o),{body:e(i)})});case"call":case"const":case"space":case"declareend":case"assign":case"exp":case"nop":case"bot":case"end":case"lambdawithexpr":case"sep":return n}return{type:"bot"}};const s=i(t(694))},577:(e,n)=>{function t(e){const n=/«[^»]*»/g;let t;const r=[];let o=0;for(;null!==(t=n.exec(e));)o<t.index&&r.push(e.slice(o,t.index)),r.push(t[0]),o=n.lastIndex;return o<e.length&&r.push(e.slice(o)),r}function r(e){const n=[];let t=0;for(;t<e.length;){const i=e[t];if("string"==typeof i&&i.startsWith("«")&&i.endsWith("»")){const s=i.slice(1,-1).trim(),[a]=s.split(" ");switch(a.toUpperCase()){case"VAR":const i=s.split("=");n.push({type:"Directive",content:{type:"declare",name:i[0].split(" ")[1].trim(),expr:o(i[1].trim())}});break;case"IF":const a=s.match(/^(IF)\s+/i);if(a){const i=s.slice(a[0].length).trim(),l=[],p=[];let c=1,u=t+1;for(;u<e.length;){let n=e[u];if("string"==typeof n&&n.startsWith("«"))if(n.includes("ENDIF")||n.includes("endif")){if(c--,c<=0)break}else if((n.includes("else")||n.includes("ELSE"))&&1===c){if(c=0,!n.includes("if")&&!n.includes("IF")){u++;continue}n=n.replace(/else(?=if)/,"")}c>0?l.push(n):p.push(n),u++}const d=r(l),f=r(p);t=u,n.push({type:"Directive",content:{type:"if",expr:o(i),thenBranch:d,elseBranch:f}})}break;case"FOR":const l=/for\s+(\w+)\s+in\s+([^\s]+)(?:\s+separator\s+"([^"]*)")?(?:\s+front\s+"([^"]*)")?(?:\s+rear\s+"([^"]*)")?/i,p=s.match(l);if(!p)throw new Error("Invalid for directive syntax");const[,c,u,d="",f="",y=""]=p,b=[];let h=1,g=t+1;for(;g<e.length&&h>0;){const n=e[g];if("string"==typeof n&&n.startsWith("«"))if(n.toLowerCase().includes("endfor")){if(h--,0===h)break}else n.toLowerCase().includes("for")&&h++;h>0&&b.push(n),g++}const w=r(b);t=g,n.push({type:"Directive",content:{type:"for",name:c.trim(),expr:o(u.trim()),separator:{type:"separator",value:d},front:{type:"front",value:f},rear:{type:"rear",value:y},fragment:w}});break;default:if(s.includes("=")){const e=s.split("=");n.push({type:"Directive",content:{type:"assign",name:e[0].split(" ")[0].trim(),expr:o(e[1].trim())}})}else n.push({type:"Directive",content:{type:"exp",expr:o(s)}})}}else n.push(i);t++}return 1===n.length?n[0]:{type:"fragmentList",fragments:n}}function o(e){const n=function(e){const n=/"([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)'|(&&|\|\||[<>!=]=|[{}[\](),.:;!+\-*/<>])|(\s+)|([^\s{}[\](),.:;!+\-*/<>!=&|]+)/g,t=[];let r;for(;null!==(r=n.exec(e));)void 0!==r[1]?t.push(`"${r[1]}"`):void 0!==r[2]?t.push(`'${r[2]}'`):void 0!==r[3]?t.push(r[3]):void 0!==r[5]&&t.push(r[5]);return t}(e);let t=0;function r(){if("("===n[t]){t++;const e=o();if(")"===n[t])return t++,e;throw new Error("Mismatched parentheses")}if("["===n[t]){t++;const e=[];for(;"]"!==n[t];)","===n[t]?t++:e.push(o());return t++,{type:"array",elements:e}}if("{"===n[t]){t++;const e={};for(;"}"!==n[t];)if(","===n[t])t++;else{const r=n[t++];if(":"!==n[t])throw new Error("Expected colon in object literal");{t++;const n=o();e[r]=n}}return t++,{type:"object",fields:e}}if("-"===n[t]&&!isNaN(Number(n[t+1])))return t++,{type:"constant",value:-Number(n[t++])};if(!isNaN(Number(n[t])))return{type:"constant",value:Number(n[t++])};if(/^['"].*['"]$/.test(n[t]))return{type:"constant",value:n[t++].slice(1,-1)};switch(n[t]){case"null":return t++,{type:"constant",value:null};case"true":return t++,{type:"constant",value:!0};case"false":return t++,{type:"constant",value:!1}}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n[t])){let e={type:"variable",name:n[t++]};for(;"."===n[t];){if(t++,/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n[t]))return{type:"field",object:e,field:n[t++]};throw new Error("Expected property name after '.'")}return e}if("!"===n[t])return t++,{type:"freeze",expression:r()};throw new Error(`Unexpected token: ${n[t]}`)}function o(){let e=r();for(;["+","-","*","/","&&","||",">","<",">=","<=","!=","==","=="].includes(n[t]);)e={type:"binary",operator:n[t++],left:e,right:r()};return e}return o()}Object.defineProperty(n,"__esModule",{value:!0}),n.parse=function(e){return r(t(e))},n.tokenize=t,n.parseTokens=r},775:function(e,n,t){var r=this&&this.__createBinding||(Object.create?function(e,n,t,r){void 0===r&&(r=t);var o=Object.getOwnPropertyDescriptor(n,t);o&&!("get"in o?!n.__esModule:o.writable||o.configurable)||(o={enumerable:!0,get:function(){return n[t]}}),Object.defineProperty(e,r,o)}:function(e,n,t,r){void 0===r&&(r=t),e[r]=n[t]}),o=this&&this.__setModuleDefault||(Object.create?function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}:function(e,n){e.default=n}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var n={};if(null!=e)for(var t in e)"default"!==t&&Object.prototype.hasOwnProperty.call(e,t)&&r(n,e,t);return o(n,e),n};Object.defineProperty(n,"__esModule",{value:!0}),n.translate=function(e){const n=a(e);return n.push(s.end()),s.seq(...n)};const s=i(t(454));function a(e){if("string"==typeof e)return function(e){const n=[];let t="";for(let r of e)if(" "===r){if(t.length>0){if(t.endsWith("\n")){const e=t.split(/(\n)/);for(const t of e)""!=t&&n.push(s.constNode(t))}else n.push(s.constNode(t));t=""}n.push(s.space(1))}else t+=r;if(t.length>0)if(t.endsWith("\n")){const e=t.split(/(\n)/);for(const t of e)""!=t&&n.push(s.constNode(t))}else n.push(s.constNode(t));return n}(e);switch(e.type){case"Directive":switch(e.content.type){case"declare":return[s.declare({type:"variable",name:e.content.name},e.content.expr,!1)];case"assign":return[s.assign({type:"variable",name:e.content.name},e.content.expr,!1)];case"exp":return[s.exp(e.content.expr)];case"if":return[s.ite(e.content.expr,{type:"seq",nodes:a(e.content.thenBranch)},l(e.content.elseBranch))];case"for":return[s.loop(e.content.expr,{type:"sep",value:e.content.separator.value},{type:"front",value:e.content.front.value},{type:"rear",value:e.content.rear.value},{type:"lambda",variable:{type:"variable",name:e.content.name},body:{type:"seq",nodes:a(e.content.fragment)}})];default:throw new Error(`Unknown directive: ${e}`)}case"fragmentList":return e.fragments.flatMap(a);default:throw new Error(`Unknown fragment: ${e}`)}}function l(e){if((n=e)&&"if"===n.type){const n=e;return s.ite(n.expr,{type:"seq",nodes:a(n.thenBranch)},l(n.elseBranch))}return function(e){return e&&"bot"===e.type}(e)?s.bot():{type:"seq",nodes:a(e)};var n}},694:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.Stack=void 0,n.Stack=class{constructor(){this.items=[]}push(e){this.items.push(e)}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}isEmpty(){return 0===this.items.length}size(){return this.items.length}clear(){this.items=[]}print(){console.log(this.items.toString())}}},63:(e,n)=>{Object.defineProperty(n,"__esModule",{value:!0}),n.isWhitespace=function(e){return/^( +)$/.test(e)},n.containsNewlineOrSpace=function(e){return/[\n\s]/.test(e)}}},n={};return function t(r){var o=n[r];if(void 0!==o)return o.exports;var i=n[r]={exports:{}};return e[r].call(i.exports,i,i.exports,t),i.exports}(612)})()));
|