@runtimeverificationinc/tsk
Version:
TypeScript/JavaScript library for K Framework functionality
1 lines • 83.3 kB
JavaScript
import Mn from"safe-stable-stringify";import*as Fe from"crypto";import*as Yt from"fs";import*as Ie from"path";function B(s){return Object.freeze({...s})}function we(s){let t={};for(let[e,n]of s)t[e]=n;return Object.freeze(t)}function mn(s){return typeof s=="object"&&s!==null&&Object.isFrozen(s)}function hn(s,t,e){let n={...t};for(let[r,i]of Object.entries(e)){let o=n[r];o!==void 0?n[r]=s(o,i):n[r]=i}return n}function Ae(s){if(s==null)throw new Error("Expected value other than null/undefined");return s}function dn(s){let t={};for(let[e,n]of Object.entries(s))n!=null&&(t[e]=n);return t}var ge=class s{constructor(t){this._f=t}call(t){return this._f(t)}then(t){return new s(e=>t(this._f(e)))}},Jn=new ge(s=>s);function We(s,t){return function*(){let e=s[Symbol.iterator](),n=e.next();if(!n.done)for(yield n.value;n=e.next(),!n.done;)yield t,yield n.value}()}function*Z(s){let t=new Set;for(let e of s)t.has(e)||(t.add(e),yield e)}function Et(s){let t=s[Symbol.iterator](),e=t.next();if(e.done)throw new Error("Expected a single element, found none");let n=t.next();if(!n.done)throw new Error(`Expected a single element, found more: ${e.value}, ${n.value}`);return e.value}function jt(s){let t=Fe.createHash("sha256");return t.update(String(s)),t.digest("hex")}function ye(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(ye);let t={};for(let[e,n]of Object.entries(s))t[e]=ye(n);return t}var V=class s{constructor(){this._hash=null}static version(){return 3}toJson(){let t=this.toDict();return JSON.stringify(t)}toString(){return this.toJson()}equals(t){return this.constructor!==t.constructor?!1:this.fieldEquals(t)}get hash(){return this._hash===null&&(this._hash=jt(this.toJson())),this._hash}asShallowTuple(){let t={},e=Object.keys(this).sort();for(let n of e)t[n]=this[n];return Object.values(t)}lessThan(t){if(!(t instanceof s))throw new Error("Cannot compare KAst with non-KAst object");if(this.constructor===t.constructor){let e=this.asShallowTuple(),n=t.asShallowTuple();for(let r=0;r<Math.min(e.length,n.length);r++){if(e[r]<n[r])return!0;if(e[r]>n[r])return!1}return e.length<n.length}return this.constructor.name<t.constructor.name}};function Ee(s){if(s.format!=="KAST")throw new Error(`Invalid format: ${s.format}`);if(s.version!=V.version())throw new Error(`Invalid version: ${s.version}, expected: ${V.version()}`);return s.term}var g=class s extends V{constructor(t){super(),this.name=t}static fromDict(t){return new s(t.name)}toDict(t=!0){return{node:"KSort",name:this.name}}let(t){let e=t??this.name;return new s(e)}fieldEquals(t){let e=t;return this.name===e.name}},b=class s extends V{constructor(t,...e){super();let n;e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,this.name=t,this.params=n.map(r=>typeof r=="string"?new g(r):r)}static fromDict(t){return new s(t.name,t.params.map(e=>g.fromDict(e)))}toDict(t=!0){return{node:"KLabel",name:this.name,params:this.params.map(e=>e.toDict(t))}}let(t={}){let e=t.name??this.name,n=t.params??this.params;return new s(e,n)}apply(...t){return new u(this,t)}fieldEquals(t){let e=t;if(this.name!==e.name||this.params.length!==e.params.length)return!1;for(let n=0;n<this.params.length;n++)if(!this.params[n].equals(e.params[n]))return!1;return!0}},T=class s extends V{static{this.NODES=new Set(["KVariable","KToken","KApply","KAs","KRewrite","KSequence"])}static fromJson(t,e=!0){return s.fromDict(JSON.parse(t),e)}static _fromDictRecursive(t){let e=t.node;switch(e){case"KToken":return K._fromDict(t,[]);case"KVariable":return p._fromDict(t,[]);case"KApply":let n=t.args?.map(c=>s._fromDictRecursive(c))||[];return u._fromDict(t,n);case"KSequence":let r=t.items?.map(c=>s._fromDictRecursive(c))||[];return E._fromDict(t,r);case"KRewrite":let i=s._fromDictRecursive(t.lhs),o=s._fromDictRecursive(t.rhs);return I._fromDict(t,[i,o]);case"KAs":let a=s._fromDictRecursive(t.pattern),l=s._fromDictRecursive(t.alias);return at._fromDict(t,[a,l]);default:throw new Error(`Unknown node type: ${e}`)}}static fromDict(t,e=!0){if(!e)return s._fromDictRecursive(t);let n=[],r=new Map;for(n.push({dct:t});n.length>0;){let i=n.pop();if(r.has(i.dct)){i.parent&&(i.parent.obj[i.parent.key]=r.get(i.dct));continue}let o=i.dct.node;if(o==="KToken"){let a=K._fromDict(i.dct,[]);r.set(i.dct,a),i.parent&&(i.parent.obj[i.parent.key]=a)}else if(o==="KVariable"){let a=p._fromDict(i.dct,[]);r.set(i.dct,a),i.parent&&(i.parent.obj[i.parent.key]=a)}else if(o==="KApply"){let a=i.dct.args||[],l=!0,c=[];for(let m=0;m<a.length;m++)if(r.has(a[m]))c[m]=r.get(a[m]);else{l=!1;break}if(l){let m=u._fromDict(i.dct,c);r.set(i.dct,m),i.parent&&(i.parent.obj[i.parent.key]=m)}else{n.push(i);for(let m=0;m<a.length;m++)r.has(a[m])||n.push({dct:a[m],parent:{obj:c,key:m}})}}else if(o==="KSequence"){let a=i.dct.items||[],l=!0,c=[];for(let m=0;m<a.length;m++)if(r.has(a[m]))c[m]=r.get(a[m]);else{l=!1;break}if(l){let m=E._fromDict(i.dct,c);r.set(i.dct,m),i.parent&&(i.parent.obj[i.parent.key]=m)}else{n.push(i);for(let m=0;m<a.length;m++)r.has(a[m])||n.push({dct:a[m],parent:{obj:c,key:m}})}}else if(o==="KRewrite"){let a=r.has(i.dct.lhs),l=r.has(i.dct.rhs);if(!a||!l)n.push(i),a||n.push({dct:i.dct.lhs}),l||n.push({dct:i.dct.rhs});else{let c=r.get(i.dct.lhs),m=r.get(i.dct.rhs),h=I._fromDict(i.dct,[c,m]);r.set(i.dct,h),i.parent&&(i.parent.obj[i.parent.key]=h)}}else if(o==="KAs"){let a=r.has(i.dct.pattern),l=r.has(i.dct.alias);if(!a||!l)n.push(i),a||n.push({dct:i.dct.pattern}),l||n.push({dct:i.dct.alias});else{let c=r.get(i.dct.pattern),m=r.get(i.dct.alias),h=at._fromDict(i.dct,[c,m]);r.set(i.dct,h),i.parent&&(i.parent.obj[i.parent.key]=h)}}else throw new Error(`Unknown node type: ${o}`)}return r.get(t)}mapInner(t){return this.letTerms(this.terms.map(t))}_toDictRecursive(){let t=this.terms.map(e=>e._toDictRecursive());return this._toDict(t,!1)}toDict(t=!0){if(!t)return this._toDictRecursive();let e=[],n=new Map;for(e.push({item:this,type:"root"});e.length>0;){let r=e.pop();if(!n.has(r.item))if(r.item instanceof s){let i=[...r.item.terms];if(r.item instanceof u&&i.push(r.item.label),r.item instanceof K&&i.push(r.item.sort),r.item instanceof p&&r.item.sort&&i.push(r.item.sort),!i.every(a=>n.has(a))){e.push(r);for(let a of i)n.has(a)||(a instanceof s?e.push({item:a,type:"kinnerTerm"}):a instanceof b?e.push({item:a,type:"label"}):a instanceof g&&e.push({item:a,type:"sort"}));continue}if(r.item instanceof u){let a=r.item.terms.map(l=>n.get(l));n.set(r.item,{node:"KApply",label:n.get(r.item.label),args:a,arity:r.item.arity,variable:!1})}else if(r.item instanceof K)n.set(r.item,{node:"KToken",token:r.item.token,sort:n.get(r.item.sort)});else if(r.item instanceof p){let a={node:"KVariable",name:r.item.name};r.item.sort!==null&&(a.sort=n.get(r.item.sort)),n.set(r.item,a)}else{let a=r.item.terms.map(l=>n.get(l));n.set(r.item,r.item._toDict(a,!0))}}else if(r.item instanceof b){if(!r.item.params.every(o=>n.has(o))){e.push(r);for(let o of r.item.params)n.has(o)||e.push({item:o,type:"labelParam"});continue}n.set(r.item,{node:"KLabel",name:r.item.name,params:r.item.params.map(o=>n.get(o))})}else r.item instanceof g&&n.set(r.item,{node:"KSort",name:r.item.name})}return n.get(this)}static combineMatches(t){let e=new L;for(let n of t)if(n===null||e===null||(e=e.union(n),e===null))return null;return e}},K=class s extends T{constructor(t,e){super(),this.token=t,this.sort=typeof e=="string"?new g(e):e}static _fromDict(t,e){return new s(t.token,g.fromDict(t.sort))}_toDict(t,e=!0){return{node:"KToken",token:this.token,sort:this.sort.toDict(e)}}let(t={}){let e=t.token??this.token,n=t.sort??this.sort;return new s(e,n)}get terms(){return[]}letTerms(t){return this}match(t){return t instanceof s&&t.token===this.token?new L:null}fieldEquals(t){let e=t;return this.token===e.token&&this.sort.equals(e.sort)}},p=class s extends T{constructor(t,e){super(),this.name=t,this.sort=e==null?null:typeof e=="string"?new g(e):e}static _fromDict(t,e){let n=t.sort?g.fromDict(t.sort):null;return new s(t.name,n)}_toDict(t,e=!0){let n={node:"KVariable",name:this.name};return this.sort!==null&&(n.sort=this.sort.toDict(e)),n}let(t={}){let e=t.name??this.name,n=t.sort!==void 0?t.sort:this.sort;return new s(e,n)}letSort(t){return new s(this.name,t)}get terms(){return[]}letTerms(t){return this}match(t){return new L({[this.name]:t})}fieldEquals(t){let e=t;return this.name!==e.name?!1:this.sort===null&&e.sort===null?!0:this.sort===null||e.sort===null?!1:this.sort.equals(e.sort)}},u=class s extends T{constructor(t,...e){super(),this.label=typeof t=="string"?new b(t):t;let n;e.length===1&&Array.isArray(e[0])?n=e[0]:n=e,this.args=n}get arity(){return this.args.length}get isCell(){return this.label.name.length>1&&this.label.name[0]==="<"&&this.label.name[this.label.name.length-1]===">"}static _fromDict(t,e){return new s(b.fromDict(t.label),e)}_toDict(t,e=!0){return{node:"KApply",label:this.label.toDict(e),args:t,arity:this.arity,variable:!1}}let(t={}){let e=t.label??this.label,n=t.args??this.args;return new s(e,n)}get terms(){return this.args}letTerms(t){return this.let({args:t})}match(t){if(t instanceof s&&t.label.name===this.label.name&&t.arity===this.arity){let e=this.args.map((n,r)=>n.match(t.args[r]));return T.combineMatches(e)}return null}fieldEquals(t){let e=t;if(!this.label.equals(e.label)||this.args.length!==e.args.length)return!1;for(let n=0;n<this.args.length;n++)if(!this.args[n].equals(e.args[n]))return!1;return!0}},at=class s extends T{constructor(t,e){super(),this.pattern=t,this.alias=e}static _fromDict(t,e){let[n,r]=e;return new s(n,r)}_toDict(t,e=!0){let[n,r]=t;return{node:"KAs",pattern:n,alias:r}}let(t={}){let e=t.pattern??this.pattern,n=t.alias??this.alias;return new s(e,n)}get terms(){return[this.pattern,this.alias]}letTerms(t){let[e,n]=t;return new s(e,n)}match(t){throw new Error("KAs does not support pattern matching")}fieldEquals(t){let e=t;return this.pattern.equals(e.pattern)&&this.alias.equals(e.alias)}},I=class s extends T{constructor(t,e){super(),this.lhs=t,this.rhs=e}static _fromDict(t,e){let[n,r]=e;return new s(n,r)}_toDict(t,e=!0){let[n,r]=t;return{node:"KRewrite",lhs:n,rhs:r}}let(t={}){let e=t.lhs??this.lhs,n=t.rhs??this.rhs;return new s(e,n)}get terms(){return[this.lhs,this.rhs]}letTerms(t){let[e,n]=t;return new s(e,n)}match(t){if(t instanceof s){let e=this.lhs.match(t.lhs),n=this.rhs.match(t.rhs);return e===null||n===null?null:e.union(n)}return null}applyTop(t){let e=this.lhs.match(t);return e!==null?e.apply(this.rhs):t}apply(t){return N(e=>this.applyTop(e),t)}replaceTop(t){return this.lhs.equals(t)?this.rhs:t}replace(t){return N(e=>this.replaceTop(e),t)}fieldEquals(t){let e=t;return this.lhs.equals(e.lhs)&&this.rhs.equals(e.rhs)}},E=class s extends T{constructor(...t){super();let e;t.length===1&&Array.isArray(t[0])?e=t[0]:e=t;let n=[];for(let r of e)r instanceof s?n.push(...r.items):n.push(r);this.items=n}get arity(){return this.items.length}static _fromDict(t,e){return new s(e)}_toDict(t,e=!0){return{node:"KSequence",items:t,arity:this.arity}}let(t={}){let e=t.items??this.items;return new s(e)}get terms(){return this.items}letTerms(t){return new s(t)}match(t){if(t instanceof s){if(t.arity===this.arity){let e=this.items.map((n,r)=>n.match(t.items[r]));return T.combineMatches(e)}if(this.arity>0&&this.arity<t.arity&&this.items[this.items.length-1]instanceof p){let e=this.items[this.items.length-1],n=this.items.length-1;for(let i=0;i<n;i++)if(this.items[i]instanceof p&&this.items[i].name===e.name)return null;let r=new L({[e.name]:new s(t.items.slice(n))});for(let i=0;i<n;i++){let o=this.items[i].match(t.items[i]);if(r=T.combineMatches([r,o]),r===null)break}return r}}return null}fieldEquals(t){let e=t;if(this.items.length!==e.items.length)return!1;for(let n=0;n<this.items.length;n++)if(!this.items[n].equals(e.items[n]))return!1;return!0}},L=class s{constructor(t={}){t instanceof Map?this._subst=Object.fromEntries(t):this._subst={...t}}get(t){return this._subst[t]}has(t){return t in this._subst}keys(){return Object.keys(this._subst)}values(){return Object.values(this._subst)}entries(){return Object.entries(this._subst)}get size(){return Object.keys(this._subst).length}static fromDict(t,e=!0){let n={};for(let[r,i]of Object.entries(t))n[r]=T.fromDict(i,e);return new s(n)}toDict(t=!0){let e={};for(let[n,r]of this.entries())e[n]=r.toDict(t);return e}union(t){let e={};for(let[n,r]of this.entries())e[n]=r;for(let[n,r]of t.entries())if(n in e){let i=e[n];if(!this.termsEqual(i,r))return null}else e[n]=r;return new s(e)}apply(t){return N(n=>n instanceof p&&this.has(n.name)?this._subst[n.name]:n,t)}termsEqual(t,e){return t instanceof p&&e instanceof p?t.name===e.name&&(t.sort===null&&e.sort===null||t.sort!==null&&e.sort!==null&&t.sort.name===e.sort.name):t.equals(e)}unapply(t){let e=t;for(let[n,r]of this.entries()){let i=r,o=new p(n);e=new I(i,o).replace(e)}return e}static from_pred(t){let e={};if(t instanceof u&&t.label.name==="#Or")throw new Error(`Invalid substitution predicate: wrong connective ${t}`);for(let n of v("#And",t))if(n instanceof u&&n.label.name==="#Equals"&&n.args.length===2){let r=n.args[0],i=n.args[1];if(r instanceof p)e[r.name]=i;else throw new Error(`Invalid substitution predicate: ${n}`)}else throw n instanceof u&&n.label.name==="#Equals"&&n.args.length===2&&n.args[0]instanceof K&&n.args[0].token==="true"?new Error(`Invalid substitution predicate: ${n}`):new Error(`Invalid substitution predicate: ${n}`);return new s(e)}compose(t){let e={};for(let[n,r]of t.entries())e[n]=this.apply(r);for(let[n,r]of this.entries())t.has(n)||(e[n]=r);return new s(e)}minimize(){let t={};for(let[e,n]of this.entries())n instanceof p&&n.name===e||(t[e]=n);return new s(t)}};function N(s,t){let e=[t,[]];for(;;){let n=e[e.length-1],r=e[e.length-2],i=n.length;if(i===r.terms.length){e.pop(),e.pop();let o=s(r.letTerms(n));if(!e||e.length===0)return o;e[e.length-1].push(o)}else e.push(r.terms[i]),e.push([])}}function j(s,t){let e=[s(t),[]];for(;;){let n=e[e.length-1],r=e[e.length-2],i=n.length;if(i===r.terms.length){e.pop(),e.pop();let o=r.letTerms(n);if(e.length===0)return o;e[e.length-1].push(o)}else e.push(s(r.terms[i])),e.push([])}}function zt(s){let t={};return Re(n=>{n instanceof p&&(n.name in t||(t[n.name]=[]),t[n.name].push(n))},s),t}function Se(s){let t={};for(let[e,n]of Object.entries(s)){let r=null;for(let i of n)if(i.sort!==null){if(r===null)r=i.sort;else if(r.name!==i.sort.name){r=null;break}}t[e]=new p(e,r)}return t}function Re(s,t){let e=[t];for(;e.length>0;){let n=e.pop();e.push(...n.terms.slice().reverse()),s(n)}}function Ct(s,t,e){let n=typeof t=="string"?new b(t):t,r=null,i=Array.from(e).reverse();for(let o of i)o.equals(s)||(r===null?r=o:r=n.apply(o,r));return r||s}function v(s,t){let e=[],n=[t];for(;n.length>0;){let r=n.pop();r instanceof u&&r.label.name===s?n.push(...r.args.slice().reverse()):e.push(r)}return e}var W=class{},Te=class extends W{fromDict(t){if(t!=="")throw new Error(`Expected empty string for NoneType, got: ${t}`);return null}toDict(t){if(t!==null)throw new Error(`Expected null for NoneType, got: ${t}`);return""}unparse(t){return null}parse(t){if(t!=="")throw new Error(`Expected empty string for NoneType, got: ${t}`);return null}},kt=class extends W{constructor(t){super(),this.valueType=t}fromDict(t){return t===""?null:this.valueType.fromDict(t)}toDict(t){return t===null?"":this.valueType.toDict(t)}unparse(t){return t===null?null:this.valueType.unparse(t)}parse(t){return t===""?null:this.valueType.parse(t)}},xe=class extends W{fromDict(t){return this.freeze(t)}toDict(t){return this.unfreeze(t)}unparse(t){return String(t)}parse(t){throw new Error(`Parsing a string into an Any attribute type is not supported. Attempted to parse: ${t}`)}freeze(t){if(Array.isArray(t))return t.map(e=>this.freeze(e));if(t&&typeof t=="object"&&t.constructor===Object){let e={};for(let[n,r]of Object.entries(t))e[n]=this.freeze(r);return B(e)}return t}unfreeze(t){if(Array.isArray(t))return t.map(e=>this.unfreeze(e));if(t&&typeof t=="object"&&Object.isFrozen(t)&&!Array.isArray(t)){let e={};for(let[n,r]of Object.entries(t))e[n]=this.unfreeze(r);return e}return t}},Le=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for IntType, got: ${typeof t}`);return parseInt(t,10)}toDict(t){return String(t)}unparse(t){return String(t)}parse(t){return parseInt(t,10)}},De=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for StrType, got: ${typeof t}`);return t}toDict(t){return t}unparse(t){return`"${t}"`}parse(t){return t}},_e=class s extends W{static{this.PARSE_REGEX=/^(\d+),(\d+),(\d+),(\d+)$/}fromDict(t){if(!Array.isArray(t)||t.length!==4)throw new Error(`Expected array of 4 numbers for LocationType, got: ${t}`);let[e,n,r,i]=t;if(typeof e!="number"||typeof n!="number"||typeof r!="number"||typeof i!="number")throw new Error(`Expected array of 4 numbers for LocationType, got: ${t}`);return[e,n,r,i]}toDict(t){return Array.from(t)}unparse(t){return t.join(",")}parse(t){let e=s.PARSE_REGEX.exec(t);if(!e)throw new Error(`Invalid location format: ${t}`);let[,n,r,i,o]=e;return[parseInt(n,10),parseInt(r,10),parseInt(i,10),parseInt(o,10)]}},Ce=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for PathType, got: ${typeof t}`);return t}toDict(t){return t}unparse(t){return`"${t}"`}parse(t){return t}},et=class s{static{this.PATTERN=/%\D|%\d+|[^%]+/g}constructor(t=[]){this.tokens=Array.from(t)}static parse(t){let e=Array.from(t.matchAll(s.PATTERN));if((e.length>0?e[e.length-1].index+e[e.length-1][0].length:0)!==t.length&&t&&t[t.length-1]==="%")throw new Error(`Incomplete escape sequence at the end of format string: ${t}`);return new s(e.map(r=>r[0]))}unparse(){return this.tokens.join("")}},Qt=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for FormatType, got: ${typeof t}`);return et.parse(t)}toDict(t){return t.unparse()}unparse(t){return`"${t.unparse()}"`}parse(t){return et.parse(t)}},Oe=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for ColorType, got: ${typeof t}`);return t}toDict(t){return t}unparse(t){return t}parse(t){return t}},Ne=class extends W{fromDict(t){if(typeof t!="string")throw new Error(`Expected string for ColorsType, got: ${typeof t}`);return this.parse(t)}toDict(t){return this.unparse(t)}unparse(t){return t.join(",")}parse(t){return t.replace(/\s/g,"").split(",")}},y=new Te,w=new xe,bn=new Le,tt=new De,Kn=new _e,gn=new Ce,f=class{constructor(t,e=w){this.name=t,this.type=e}call(t){return new lt(this,t)}},lt=class{constructor(t,e){this.key=t,this.value=e}},d=class s{static{this.ALIAS=new f("alias",y)}static{this.ALIAS_REC=new f("alias-rec",y)}static{this.ANYWHERE=new f("anywhere",y)}static{this.ASSOC=new f("assoc",y)}static{this.AVOID=new f("avoid",y)}static{this.BRACKET=new f("bracket",y)}static{this.BRACKET_LABEL=new f("bracketLabel",w)}static{this.CIRCULARITY=new f("circularity",y)}static{this.CELL=new f("cell",y)}static{this.CELL_COLLECTION=new f("cellCollection",y)}static{this.CELL_FRAGMENT=new f("cellFragment",w)}static{this.CELL_NAME=new f("cellName",tt)}static{this.CELL_OPT_ABSENT=new f("cellOptAbsent",w)}static{this.COLOR=new f("color",new Oe)}static{this.COLORS=new f("colors",new Ne)}static{this.COMM=new f("comm",y)}static{this.CONCAT=new f("concat",w)}static{this.CONCRETE=new f("concrete",new kt(tt))}static{this.CONSTRUCTOR=new f("constructor",y)}static{this.DEPENDS=new f("depends",w)}static{this.DIGEST=new f("digest",w)}static{this.ELEMENT=new f("element",w)}static{this.EXIT=new f("exit",w)}static{this.FORMAT=new f("format",new Qt)}static{this.FRESH_GENERATOR=new f("freshGenerator",y)}static{this.FUNCTION=new f("function",y)}static{this.FUNCTIONAL=new f("functional",y)}static{this.GROUP=new f("group",tt)}static{this.HAS_DOMAIN_VALUES=new f("hasDomainValues",y)}static{this.HOOK=new f("hook",w)}static{this.IDEM=new f("idem",y)}static{this.IMPURE=new f("impure",y)}static{this.INDEX=new f("index",bn)}static{this.INITIALIZER=new f("initializer",y)}static{this.INJECTIVE=new f("injective",y)}static{this.LABEL=new f("label",w)}static{this.LEFT=new f("left",w)}static{this.LOCATION=new f("org.kframework.attributes.Location",Kn)}static{this.MACRO=new f("macro",y)}static{this.MACRO_REC=new f("macro-rec",y)}static{this.MAINCELL=new f("maincell",y)}static{this.MULTIPLICITY=new f("multiplicity",w)}static{this.NO_EVALUATORS=new f("no-evaluators",y)}static{this.OVERLOAD=new f("overload",tt)}static{this.OWISE=new f("owise",y)}static{this.PREDICATE=new f("predicate",w)}static{this.PREFER=new f("prefer",y)}static{this.PRIORITY=new f("priority",w)}static{this.PRIORITIES=new f("priorities",w)}static{this.PRIVATE=new f("private",y)}static{this.PRODUCTION=new f("org.kframework.definition.Production",w)}static{this.PROJECTION=new f("projection",y)}static{this.RIGHT=new f("right",w)}static{this.RETURNS_UNIT=new f("returnsUnit",y)}static{this.SIMPLIFICATION=new f("simplification",w)}static{this.SEQSTRICT=new f("seqstrict",w)}static{this.SORT=new f("org.kframework.kore.Sort",w)}static{this.SOURCE=new f("org.kframework.attributes.Source",gn)}static{this.SMTLEMMA=new f("smt-lemma",y)}static{this.STRICT=new f("strict",w)}static{this.SYMBOL=new f("symbol",tt)}static{this.SYNTAX_MODULE=new f("syntaxModule",tt)}static{this.SYMBOLIC=new f("symbolic",new kt(tt))}static{this.TERMINALS=new f("terminals",tt)}static{this.TERMINATOR_SYMBOL=new f("terminator-symbol",w)}static{this.TOKEN=new f("token",y)}static{this.TOTAL=new f("total",y)}static{this.TRUSTED=new f("trusted",y)}static{this.TYPE=new f("type",w)}static{this.UNIT=new f("unit",tt)}static{this.UNIQUE_ID=new f("UNIQUE_ID",w)}static{this.UNPARSE_AVOID=new f("unparseAvoid",y)}static{this.UPDATE=new f("update",w)}static{this.USER_LIST=new f("userList",w)}static{this.WRAP_ELEMENT=new f("wrapElement",w)}static{this._keys=null}static keys(){if(s._keys===null){let t=[];for(let[e,n]of Object.entries(s))n instanceof f&&t.push([n.name,n]);s._keys=we(t)}return s._keys}},x=class s extends V{constructor(t=[]){super();let e={},n={};for(let r of t){let i=r.key.name;e[i]=r.value,n[i]=r.key}this.atts=B(e),this.keyLookup=B(n)}get size(){return Object.keys(this.atts).length}get(t){return this.atts[t.name]}has(t){return t.name in this.atts}keys(){return Object.keys(this.atts).map(n=>this.keyLookup[n]).filter(n=>n!==void 0)[Symbol.iterator]()}values(){return Object.values(this.atts)[Symbol.iterator]()}entries(){let t=[];for(let e of Object.keys(this.atts)){let n=this.keyLookup[e];if(n){let r=this.atts[e];t.push([n,r])}}return t[Symbol.iterator]()}forEach(t,e){for(let n of Object.keys(this.atts)){let r=this.keyLookup[n];if(r){let i=this.atts[n];t.call(e,i,r,this)}}}[(Symbol.toStringTag,Symbol.iterator)](){return this.entries()}set(t,e){throw new Error("KAtt is immutable")}delete(t){throw new Error("KAtt is immutable")}clear(){throw new Error("KAtt is immutable")}attEntries(){return function*(t){for(let[e,n]of t.entries())yield new lt(e,n)}(this)}static fromDict(t){let e=[],n=t.att||{};for(let[r,i]of Object.entries(n)){let o=d.keys()[r]||new f(r,w),a=o.type.fromDict(i);e.push(new lt(o,a))}return new s(e)}toDict(){let t={};for(let n of Object.keys(this.atts)){let r=this.keyLookup[n];if(r){let i=this.atts[n];t[r.name]=r.type.toDict(i)}}return{node:"KAtt",att:t}}static parse(t){let e=[];for(let[n,r]of Object.entries(t)){let i=d.keys()[n]||new f(n,w),o=i.type.parse(r);e.push(new lt(i,o))}return new s(e)}get pretty(){if(this.size===0)return"";let t=[];for(let e of Object.keys(this.atts)){let n=this.keyLookup[e],r=this.atts[e];if(n){let i=n.type.unparse(r);i===null?t.push(n.name):t.push(`${n.name}(${i})`)}}return`[${t.join(", ")}]`}update(t){let e=[];for(let n of this.attEntries())e.push(n);for(let n of t)e.push(n);return new s(e)}discard(t){let e=Array.isArray(t)?new Set(t):t,n=[];for(let[r,i]of this.atts.entries())e.has(r)||n.push(new lt(r,i));return new s(n)}dropSource(){return this.discard([d.SOURCE,d.LOCATION])}fieldEquals(t){let e=t;if(this.size!==e.size)return!1;for(let[n,r]of this.entries()){if(!e.has(n))return!1;let i=e.get(n);if(r!==i)if(r&&typeof r.equals=="function"&&i&&typeof i.equals=="function"){if(!r.equals(i))return!1}else return!1}return!0}},S=new x;function He(s,t){return s.letAtt(s.att.update(t))}var Jt=class s extends Map{constructor(t){if(super(),t)if(t instanceof Map)for(let[e,n]of t)this.set(e,n);else if(typeof t=="object"&&!(Symbol.iterator in t)){let e=t;for(let[n,r]of Object.entries(e))this.set(n,r)}else for(let e of t)this.increment(e)}increment(t,e=1){this.set(t,this.get(t,0)+e)}decrement(t,e=1){let r=this.get(t,0)-e;r<=0?this.delete(t):this.set(t,r)}get(t,e=0){return super.get(t)??e}update(t){if(t instanceof s||t instanceof Map)for(let[e,n]of t)this.increment(e,n);else if(typeof t=="object"&&!(Symbol.iterator in t)){let e=t;for(let[n,r]of Object.entries(e))this.increment(n,r)}else for(let e of t)this.increment(e)}subtract(t){if(t instanceof s||t instanceof Map)for(let[e,n]of t)this.decrement(e,n);else if(typeof t=="object"&&!(Symbol.iterator in t)){let e=t;for(let[n,r]of Object.entries(e))this.decrement(n,r)}else for(let e of t)this.decrement(e)}mostCommon(t){let e=Array.from(this.entries()).sort((n,r)=>r[1]-n[1]);return t!==void 0?e.slice(0,t):e}leastCommon(t){let e=Array.from(this.entries()).sort((n,r)=>n[1]-r[1]);return t!==void 0?e.slice(0,t):e}elements(){let t=[];for(let[e,n]of this)for(let r=0;r<n;r++)t.push(e);return t}total(){let t=0;for(let e of this.values())t+=e;return t}add(t){let e=new s(this);return e.update(t),e}sub(t){let e=new s(this);return e.subtract(t),e}intersection(t){let e=new s;for(let[n,r]of this){let i=t.get(n,0);i>0&&e.set(n,Math.min(r,i))}return e}union(t){let e=new s(this);for(let[n,r]of t){let i=e.get(n,0);e.set(n,Math.max(i,r))}return e}positive(){let t=new s;for(let[e,n]of this)n>0&&t.set(e,n);return t}toObject(){let t={};for(let[e,n]of this)t[String(e)]=n;return t}toString(){return`Counter({${Array.from(this.entries()).map(([e,n])=>`${String(e)}: ${n}`).join(", ")}})`}static fromKeys(t,e=1){let n=new s;for(let r of t)n.set(r,e);return n}};import In from"fast-deep-equal";import*as je from"fs";import yn from"fast-deep-equal";function Xt(s,t){let e=[],n={},r=[];for(let l of t)if(l.lhs instanceof K)e.push(l);else if(l.lhs instanceof u){let c=l.lhs.label.name;c in n?n[c].push(l):n[c]=[l]}else r.push(l);function i(l){let c=l;if(c instanceof K)for(let m of e)c=m.applyTop(c);else if(c instanceof u){let m=c.label.name;if(m in n)for(let h of n[m])c=h.applyTop(c)}else for(let m of r)c=m.applyTop(c);return c}let o=s,a=null;for(;a===null||!yn(o,a);)a===null?a=o:o=a,a=N(i,a);return a}var wn=new g("Bool"),J=new K("true",wn);var z=class extends V{},St=class s extends z{static{this.NODES=new Set(["KTerminal","KRegexTerminal","KNonTerminal"])}static fromDict(t){let e=t.node;if(!s.NODES.has(e))throw new Error(`Invalid KProductionItem node: ${e}`);switch(e){case"KTerminal":return $._fromDict(t);case"KRegexTerminal":return nt._fromDict(t);case"KNonTerminal":return C._fromDict(t);default:throw new Error(`Unknown node type: ${e}`)}}},nt=class s extends St{constructor(t){super(),this.regex=t}static _fromDict(t){return new s(t.regex)}toDict(){let t={};return t.node="KRegexTerminal",t.regex=this.regex,t}let(t={}){let e=t.regex!==void 0?t.regex:this.regex;return new s(e)}fieldEquals(t){let e=t;return this.regex===e.regex}},C=class s extends St{constructor(t,e){super(),this.sort=t,this.name=e??null}static _fromDict(t){let e=t.name?t.name:null;return new s(g.fromDict(t.sort),e)}toDict(){let t={};return t.node="KNonTerminal",t.sort=this.sort.toDict(),this.name!==null&&(t.name=this.name),t}let(t={}){let e=t.sort||this.sort,n=t.name!==void 0?t.name:this.name;return new s(e,n)}fieldEquals(t){let e=t;return this.sort.equals(e.sort)&&this.name===e.name}},$=class s extends St{constructor(t){super(),this.value=t}static _fromDict(t){return new s(t.value)}toDict(){let t={};return t.node="KTerminal",t.value=this.value,t}let(t={}){let e=t.value!==void 0?t.value:this.value;return new s(e)}fieldEquals(t){let e=t;return this.value===e.value}},F=class s extends z{static{this.NODES=new Set(["KProduction","KSyntaxSort","KSortSynonym","KSyntaxLexical","KSyntaxAssociativity","KSyntaxPriority","KBubble","KRule","KClaim","KContext"])}static fromDict(t){let e=t.node;if(!s.NODES.has(e))throw new Error(`Invalid KSentence node: ${e}`);switch(e){case"KProduction":return ct._fromDict(t);case"KSyntaxSort":return Rt._fromDict(t);case"KSortSynonym":return Ot._fromDict(t);case"KSyntaxLexical":return Nt._fromDict(t);case"KSyntaxAssociativity":return Tt._fromDict(t);case"KSyntaxPriority":return xt._fromDict(t);case"KBubble":return Mt._fromDict(t);case"KRule":return ut._fromDict(t);case"KClaim":return pt._fromDict(t);case"KContext":return vt._fromDict(t);default:throw new Error(`Unimplemented sentence type: ${e}`)}}get uniqueId(){return this.att.get(d.UNIQUE_ID)||null}get source(){let t=this.att.get(d.SOURCE),e=this.att.get(d.LOCATION);return t&&e?`${t}:${e}`:null}get label(){let t=this.att.get(d.LABEL)||this.uniqueId;if(!t)throw new Error(`Found sentence without label or UNIQUE_ID: ${this}`);return t}},ct=class s extends F{constructor(t,e=[],n=[],r,i=S){super(),typeof t=="string"&&(t=new g(t)),typeof r=="string"&&(r=new b(r));let o=Array.from(n).map(a=>typeof a=="string"?new g(a):a);this.sort=t,this.items=Array.from(e),this.params=o,this.klabel=r??null,this.att=i}static _fromDict(t){return new s(g.fromDict(t.sort),t.productionItems?.map(e=>St.fromDict(e))||[],t.params?.map(e=>g.fromDict(e))||[],t.klabel?b.fromDict(t.klabel):null,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KProduction",t.sort=this.sort.toDict(),t.set("productionItems",this.items.map(e=>e.toDict())),t.set("params",this.params.map(e=>e.toDict())),this.klabel&&(t.klabel=this.klabel.toDict()),t.att=this.att.toDict(),t}let(t={}){let e=t.sort!==void 0?t.sort:this.sort,n=t.items!==void 0?t.items:this.items,r=t.params!==void 0?t.params:this.params,i=t.klabel!==void 0?t.klabel:this.klabel,o=t.att!==void 0?t.att:this.att;return new s(e,n,r,i,o)}letAtt(t){return this.let({att:t})}get asSubsort(){if(this.klabel||this.items.length!==1)return null;let t=this.items[0];return t instanceof C?[this.sort,t.sort]:null}get nonTerminals(){return this.items.filter(t=>t instanceof C)}get argumentSorts(){return this.nonTerminals.map(t=>t.sort)}get isPrefix(){function t(r){if(r instanceof $)return["(",",",")"].includes(r.value)?r.value:"t";if(r instanceof C)return"n";if(r instanceof nt)return"r";throw new Error("Unknown production item type")}let e=this.items.map(t).join("");return/^t*\((n(,n)*)?\)$/.test(e)}get isRecord(){return this.isPrefix&&this.nonTerminals.length>0&&this.nonTerminals.every(t=>t.name!==null)}get defaultFormat(){let t;if(this.isRecord){let e=[];for(let n=0;n<this.items.length;n++){let r=this.items[n];if(r instanceof $)r.value==="("?e.push(`%${n+1}...`):e.push(`%${n+1}`);else if(r instanceof C){if(r.name===null)throw new Error("Expected non-terminal to have name in record production");e.push(`${r.name}:`),e.push(`%${n+1}`)}else if(r instanceof nt)throw new Error("Default format is not supported for productions with regex terminals")}t=e.join(" ")}else t=Array.from({length:this.items.length},(e,n)=>`%${n+1}`).join(" ");return et.parse(t)}fieldEquals(t){let e=t;if(!this.sort.equals(e.sort)||this.items.length!==e.items.length)return!1;for(let n=0;n<this.items.length;n++)if(!this.items[n].equals(e.items[n]))return!1;if(this.params.length!==e.params.length)return!1;for(let n=0;n<this.params.length;n++)if(!this.params[n].equals(e.params[n]))return!1;if(!(this.klabel===null&&e.klabel===null)){if(this.klabel===null||e.klabel===null)return!1;if(!this.klabel.equals(e.klabel))return!1}return this.att.equals(e.att)}},Rt=class s extends F{constructor(t,e=[],n=S){super();let r=Array.from(e).map(i=>typeof i=="string"?new g(i):i);this.sort=t,this.params=r,this.att=n}static _fromDict(t){return new s(g.fromDict(t.sort),t.params?.map(e=>g.fromDict(e))||[],t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KSyntaxSort",t.sort=this.sort.toDict(),t.set("params",this.params.map(e=>e.toDict())),t.att=this.att.toDict(),t}let(t={}){let e=t.sort||this.sort,n=t.params!==void 0?t.params:this.params,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;if(!this.sort.equals(e.sort)||this.params.length!==e.params.length)return!1;for(let n=0;n<this.params.length;n++)if(!this.params[n].equals(e.params[n]))return!1;return this.att.equals(e.att)}},Ot=class s extends F{constructor(t,e,n=S){super(),this.newSort=t,this.oldSort=e,this.att=n}static _fromDict(t){return new s(g.fromDict(t.newSort),g.fromDict(t.oldSort),t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KSortSynonym",t.newSort=this.newSort.toDict(),t.oldSort=this.oldSort.toDict(),t.att=this.att.toDict(),t}let(t={}){let e=t.newSort||this.newSort,n=t.oldSort||this.oldSort,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;return this.newSort.equals(e.newSort)&&this.oldSort.equals(e.oldSort)&&this.att.equals(e.att)}},Nt=class s extends F{constructor(t,e,n=S){super(),this.name=t,this.regex=e,this.att=n}static _fromDict(t){return new s(t.name,t.regex,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KSyntaxLexical",t.name=this.name,t.regex=this.regex,t.att=this.att.toDict(),t}let(t={}){let e=t.name!==void 0?t.name:this.name,n=t.regex!==void 0?t.regex:this.regex,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;return this.name===e.name&&this.regex===e.regex&&this.att.equals(e.att)}},An=(n=>(n.LEFT="Left",n.RIGHT="Right",n.NON_ASSOC="NonAssoc",n))(An||{}),Tt=class s extends F{constructor(t,e=new Set,n=S){super(),this.assoc=t,this.tags=new Set(e),this.att=n}static _fromDict(t){return new s(t.assoc,t.tags,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KSyntaxAssociativity",t.assoc=this.assoc,t.tags=Array.from(this.tags),t.att=this.att.toDict(),t}let(t={}){let e=t.assoc||this.assoc,n=t.tags!==void 0?t.tags:this.tags,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;if(this.assoc!==e.assoc||this.tags.size!==e.tags.size)return!1;for(let n of this.tags)if(!e.tags.has(n))return!1;return this.att.equals(e.att)}},xt=class s extends F{constructor(t=[],e=S){super(),this.priorities=Array.from(t).map(n=>new Set(n)),this.att=e}static _fromDict(t){return new s(t.priorities,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KSyntaxPriority",t.set("priorities",this.priorities.map(e=>Array.from(e))),t.att=this.att.toDict(),t}let(t={}){let e=t.priorities!==void 0?t.priorities:this.priorities,n=t.att!==void 0?t.att:this.att;return new s(e,n)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;if(this.priorities.length!==e.priorities.length)return!1;for(let n=0;n<this.priorities.length;n++){let r=this.priorities[n],i=e.priorities[n];if(r.size!==i.size)return!1;for(let o of r)if(!i.has(o))return!1}return this.att.equals(e.att)}},Mt=class s extends F{constructor(t,e,n=S){super(),this.sentenceType=t,this.contents=e,this.att=n}static _fromDict(t){return new s(t.sentenceType,t.contents,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KBubble",t.sentenceType=this.sentenceType,t.contents=this.contents,t.att=this.att.toDict(),t}let(t={}){let e=t.sentenceType!==void 0?t.sentenceType:this.sentenceType,n=t.contents!==void 0?t.contents:this.contents,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;return this.sentenceType===e.sentenceType&&this.contents===e.contents&&this.att.equals(e.att)}},Zt=class extends F{},ut=class s extends Zt{constructor(t,e=J,n=J,r=S){super(),this.body=t,this.requires=e,this.ensures=n,this.att=r}static _fromDict(t){return new s(T.fromDict(t.body),t.requires?T.fromDict(t.requires):J,t.ensures?T.fromDict(t.ensures):J,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KRule",t.body=this.body.toDict(),t.requires=this.requires.toDict(),t.ensures=this.ensures.toDict(),t.att=this.att.toDict(),t}let(t={}){let e=t.body!==void 0?t.body:this.body,n=t.requires!==void 0?t.requires:this.requires,r=t.ensures!==void 0?t.ensures:this.ensures,i=t.att!==void 0?t.att:this.att;return new s(e,n,r,i)}letAtt(t){return this.let({att:t})}get priority(){let t=this.att.get(d.PRIORITY);return t!==void 0?parseInt(t):this.att.has(d.OWISE)?200:50}fieldEquals(t){let e=t;return this.body.equals(e.body)&&this.requires.equals(e.requires)&&this.ensures.equals(e.ensures)&&this.att.equals(e.att)}},pt=class s extends Zt{constructor(t,e=J,n=J,r=S){super(),this.body=t,this.requires=e,this.ensures=n,this.att=r}static _fromDict(t){return new s(T.fromDict(t.body),t.requires?T.fromDict(t.requires):J,t.ensures?T.fromDict(t.ensures):J,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KClaim",t.body=this.body.toDict(),t.requires=this.requires.toDict(),t.ensures=this.ensures.toDict(),t.att=this.att.toDict(),t}let(t={}){let e=t.body!==void 0?t.body:this.body,n=t.requires!==void 0?t.requires:this.requires,r=t.ensures!==void 0?t.ensures:this.ensures,i=t.att!==void 0?t.att:this.att;return new s(e,n,r,i)}letAtt(t){return this.let({att:t})}get isCircularity(){return this.att.has(d.CIRCULARITY)}get isTrusted(){return this.att.has(d.TRUSTED)}get dependencies(){let t=this.att.get(d.DEPENDS);return t?t.split(",").map(e=>e.trim()):[]}fieldEquals(t){let e=t;return this.body.equals(e.body)&&this.requires.equals(e.requires)&&this.ensures.equals(e.ensures)&&this.att.equals(e.att)}},vt=class s extends F{constructor(t,e=J,n=S){super(),this.body=t,this.requires=e,this.att=n}static _fromDict(t){return new s(T.fromDict(t.body),t.requires?T.fromDict(t.requires):J,t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KContext",t.body=this.body.toDict(),t.requires=this.requires.toDict(),t.att=this.att.toDict(),t}let(t={}){let e=t.body!==void 0?t.body:this.body,n=t.requires!==void 0?t.requires:this.requires,r=t.att!==void 0?t.att:this.att;return new s(e,n,r)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;return this.body.equals(e.body)&&this.requires.equals(e.requires)&&this.att.equals(e.att)}},Kt=class s extends z{constructor(t,e=!0){super(),this.name=t,this.public=e}static fromDict(t){return new s(t.name,t.isPublic)}toDict(){let t={};return t.node="KImport",t.name=this.name,t.isPublic=this.public,t}let(t={}){let e=t.name!==void 0?t.name:this.name,n=t.public!==void 0?t.public:this.public;return new s(e,n)}fieldEquals(t){let e=t;return this.name===e.name&&this.public===e.public}},rt=class s extends z{constructor(t,e=[],n=[],r=S){super(),this.name=t,this.sentences=Array.from(e),this.imports=Array.from(n),this.att=r}[Symbol.iterator](){return this.sentences[Symbol.iterator]()}get productions(){return this.sentences.filter(t=>t instanceof ct)}get syntaxProductions(){return this.productions.filter(t=>t.klabel!==null)}get functions(){return this.syntaxProductions.filter(t=>s.isFunction(t))}get constructors(){return this.syntaxProductions.filter(t=>!s.isFunction(t))}get cellCollectionProductions(){return this.syntaxProductions.filter(t=>t.att.has(d.CELL_COLLECTION))}static isFunction(t){function e(n){let r=n.endsWith("CellMapItem")||n.endsWith("CellMap_"),i=new Set(["_Set_","_List_","_Map_","_RangeMap_",".Set",".List",".Map",".RangeMap","SetItem","ListItem","_|->_","_r|->_"]).has(n);return r||i}return(t.att.has(d.FUNCTION)||t.att.has(d.FUNCTIONAL))&&!(t.klabel&&e(t.klabel.name))}get syntaxSorts(){return this.sentences.filter(t=>t instanceof Rt)}get rules(){return this.sentences.filter(t=>t instanceof ut)}get claims(){return this.sentences.filter(t=>t instanceof pt)}get sentenceByUniqueId(){let t={};for(let e of this.sentences)e.uniqueId!==null&&(t[e.uniqueId]=e);return t}mapSentences(t,e){return e===void 0&&(e=F),this.let({sentences:this.sentences.map(n=>n instanceof e?t(n):n)})}static fromDict(t){return new s(t.name,t.localSentences?.map(e=>F.fromDict(e))||[],t.imports?.map(e=>Kt.fromDict(e))||[],t.att?x.fromDict(t.att):S)}toDict(){let t={};return t.node="KFlatModule",t.name=this.name,t.set("localSentences",this.sentences.map(e=>e.toDict())),t.set("imports",this.imports.map(e=>e.toDict())),t.att=this.att.toDict(),t}let(t={}){let e=t.name!==void 0?t.name:this.name,n=t.sentences!==void 0?t.sentences:this.sentences,r=t.imports!==void 0?t.imports:this.imports,i=t.att!==void 0?t.att:this.att;return new s(e,n,r,i)}letAtt(t){return this.let({att:t})}fieldEquals(t){let e=t;if(this.name!==e.name||this.sentences.length!==e.sentences.length)return!1;for(let n=0;n<this.sentences.length;n++)if(!this.sentences[n].equals(e.sentences[n]))return!1;if(this.imports.length!==e.imports.length)return!1;for(let n=0;n<this.imports.length;n++)if(!this.imports[n].equals(e.imports[n]))return!1;return this.att.equals(e.att)}},Ye=class s extends z{constructor(t,e){super(),this.mainModule=t,this.modules=Array.from(e)}static fromDict(t){return new s(t.mainModule,t.term?.map(e=>rt.fromDict(e))||[])}toDict(){let t={};return t.node="KFlatModuleList",t.mainModule=this.mainModule,t.set("term",this.modules.map(e=>e.toDict())),t}let(t={}){let e=t.mainModule!==void 0?t.mainModule:this.mainModule,n=t.modules!==void 0?t.modules:this.modules;return new s(e,n)}fieldEquals(t){let e=t;if(this.mainModule!==e.mainModule||this.modules.length!==e.modules.length)return!1;for(let n=0;n<this.modules.length;n++)if(!this.modules[n].equals(e.modules[n]))return!1;return!0}},gt=class s extends z{constructor(t){super(),this.require=t}static fromDict(t){return new s(t.require)}toDict(){let t={};return t.node="KRequire",t.require=this.require,t}let(t={}){let e=t.require!==void 0?t.require:this.require;return new s(e)}fieldEquals(t){let e=t;return this.require===e.require}},yt=class s extends z{constructor(e,n,r=[],i=S){super();this._initConfig={};this._emptyConfig={};let o=Array.from(n),a=o.filter(c=>c.name===e);if(a.length===0)throw new Error(`Module not found: ${e}`);if(a.length>1)throw new Error(`Module is not unique: ${e}`);let l=a[0];this.mainModuleName=e,this.allModules=o,this.requires=Array.from(r),this.att=i,this.mainModule=l,this._initConfig={},this._emptyConfig={}}[Symbol.iterator](){return this.allModules[Symbol.iterator]()}static fromDict(e){return new s(e.mainModule,e.modules?.map(n=>rt.fromDict(n))||[],e.requires?.map(n=>gt.fromDict(n))||[],e.att?x.fromDict(e.att):S)}toDict(){let e={};return e.node="KDefinition",e.mainModule=this.mainModuleName,e.set("modules",this.allModules.map(n=>n.toDict())),e.set("requires",this.requires.map(n=>n.toDict())),e.att=this.att.toDict(),e}fieldEquals(e){let n=e;if(this.mainModuleName!==n.mainModuleName||this.allModules.length!==n.allModules.length)return!1;for(let r=0;r<this.allModules.length;r++)if(!this.allModules[r].equals(n.allModules[r]))return!1;if(this.requires.length!==n.requires.length)return!1;for(let r=0;r<this.requires.length;r++)if(!this.requires[r].equals(n.requires[r]))return!1;return this.att.equals(n.att)}let(e={}){let n=e.mainModuleName!==void 0?e.mainModuleName:this.mainModuleName,r=e.allModules!==void 0?e.allModules:this.allModules,i=e.requires!==void 0?e.requires:this.requires,o=e.att!==void 0?e.att:this.att;return new s(n,r,i,o)}letAtt(e){return this.let({att:e})}get allModuleNames(){return this.allModules.map(e=>e.name)}get moduleNames(){let e=[this.mainModuleName],n=[];for(;e.length>0;){let r=e.shift();n.includes(r)||(n.push(r),e.push(...this.allModulesDict[r].imports.map(i=>i.name)))}return n}get allModulesDict(){let e={};for(let n of this.allModules)e[n.name]=n;return e}get modules(){return this.moduleNames.map(e=>this.allModulesDict[e])}get productions(){return this.modules.flatMap(e=>e.productions)}get syntaxProductions(){return this.modules.flatMap(e=>e.syntaxProductions)}get functions(){return this.modules.flatMap(e=>e.functions)}get functionLabels(){return this.functions.map(e=>Ae(e.klabel).name)}get constructors(){return this.modules.flatMap(e=>e.constructors)}get cellCollectionProductions(){return this.modules.flatMap(e=>e.cellCollectionProductions)}get rules(){return this.modules.flatMap(e=>e.rules)}get aliasRules(){return this.rules.filter(e=>e.att.has(d.ALIAS))}get macroRules(){return this.rules.filter(e=>e.att.has(d.MACRO)).concat(this.aliasRules)}get semanticRules(){function e(n){return n.body instanceof u&&n.body.label.name==="<generatedTop>"||n.body instanceof I&&n.body.lhs instanceof u&&n.body.lhs.label.name==="<generatedTop>"}return this.rules.filter(e)}get sentenceByUniqueId(){let e={};for(let n of this.allModules)for(let[r,i]of Object.entries(n.sentenceByUniqueId))r in e&&i!==e[r]?console.debug(`Same UNIQUE_ID found for two different sentences: ${[i,e[r]]}`):e[r]=i;return e}productionForCellSort(e){if(!e.name.endsWith("Cell"))throw new Error(`Method productionForCellSort only intended to be called on sorts ending in "Cell", not: ${e}`);try{return Et(this.productions.filter(n=>n.sort===e&&n.att.has(d.CELL)))}catch(n){throw new Error(`Expected a single cell production for sort ${e}`,{cause:n})}}module(e){return this.allModulesDict[e]}get overloads(){let e=(o,a)=>{if(!o.klabel||!a.klabel||o.klabel.name===a.klabel.name||!o.att.has(d.OVERLOAD)||!a.att.has(d.OVERLOAD)||o.att.get(d.OVERLOAD)!==a.att.get(d.OVERLOAD))return!1;let l=[o.sort,...o.argumentSorts],c=[a.sort,...a.argumentSorts];if(l.length!==c.length)return!1;let m=!1;for(let h=0;h<l.length;h++){let A=l[h],D=c[h];if(A!==D){if(this.subsorts(D).has(A)){m=!0;continue}return!1}}return m},n={};for(let o of Object.keys(this.symbols)){let a=this.symbols[o];if(a.att.has(d.OVERLOAD)){let l=a.att.get(d.OVERLOAD);l in n||(n[l]=[]),n[l].push(o)}}let r={};for(let[o,a]of Object.entries(n))for(let l of a)for(let c of a)l!==c&&e.call(this,this.symbols[l],this.symbols[c])&&(c in r||(r[c]=[]),r[c].push(l));let i={};for(let[o,a]of Object.entries(r))i[o]=new Set(a);return B(i)}get priorities(){let e=this.modules.flatMap(i=>i.sentences).filter(i=>i instanceof xt),n=[];for(let i of e)for(let o=0;o<i.priorities.length-1;o++){let a=i.priorities[o],l=i.priorities[o+1];for(let c of a)for(let m of l)n.push([c,m])}let r={};for(let[i,o]of n)r[i]||(r[i]=new Set),r[i].add(o);return B(r)}get leftAssocs(){let e=this.assocs("Left");return B(e)}get rightAssocs(){let e=this.assocs("Right");return B(e)}assocs(e){let n=this.modules.flatMap(i=>i.sentences).filter(i=>i instanceof Tt&&(i.assoc===e||i.assoc==="NonAssoc")),r={};for(let i of n)for(let o of i.tags)for(let a of i.tags)o in r||(r[o]=new Set),r[o].add(a);return r}get subsortTable(){let e={};for(let n of this.productions){let r=n.asSubsort;if(r){let[i,o]=r;e[i.name]||(e[i.name]=new Set),e[i.name].add(o)}}return B(e)}subsorts(e){return this.subsortTable[e.name]||new Set}get brackets(){let e={};for(let n of this.productions)if(n.att.has(d.BRACKET)){if(n.klabel)throw new Error("Bracket production should not have klabel");let r=n.sort;if(r.name in e)throw new Error(`Multiple bracket productions for sort: ${r.name}`);e[r.name]=n}return B(e)}get symbols(){let e={};for(let n of this.productions){if(!n.klabel)continue;let r=n.klabel.name;if(r in e){let i=e[r],o=n.let({att:n.att.dropSource?.()||n.att}),a=i.let({att:i.att.dropSource?.()||i.att});if(!In(o.toDict(),a.toDict()))throw new Error(`Found multiple productions for ${r}: ${[i,n]}`);continue}e[r]=n}return B(e)}get syntaxSymbols(){let e={};for(let[r,i]of Object.entries(this.brackets)){let o=i.att.get(d.BRACKET_LABEL);o&&(e[o]=i)}let n={...this.symbols,...e};return B(n)}sort(e){if(e instanceof K||e instanceof p)return e.sort;if(e instanceof I){let n=this.sort(e.lhs),r=this.sort(e.rhs);return n&&r?this.leastCommonSupersort(n,r):null}if(e instanceof E)return new g("K");if(e instanceof u){let[n,r]=this.resolveSorts(e.label);return n}return null}sortStrict(e){let n=this.sort(e);if(n===null)throw new Error(`Could not determine sort of term: ${e}`);return n}resolveSorts(e){let n=this.symbols[e.name],r={};for(let o=0;o<n.params.length;o++)r[n.params[o].name]=e.params[o];function i(o){return r[o.name]||o}return[i(n.sort),n.argumentSorts.map(i)]}leastCommonSupersort(e,n){return e===n?e:this.subsorts(n).has(e)?n:this.subsorts(e).has(n)?e:null}greatestCommonSubsort(e,n){return e===n||this.subsorts(n).has(e)?e:this.subsorts(e).has(n)?n:null}addKSequenceUnderKProductions(e){return j(r=>{if(!(r instanceof u))return r;let i=this.symbols[r.label.name];return new u(r.label,r.args.map((o,a)=>i.argumentSorts[a].name==="K"&&this.sort(o)?.name!=="K"?new E([o]):o))},e)}sortVars(e,n){let r=new Set(["#Exists","#Forall"]);return e instanceof p&&e.sort===null&&n!==void 0?e.let({sort:n}):e}addSortParams(e){return N(r=>{if(!(r instanceof u))return r;let i=this.symbols[r.label.name];if(r.label.params.length===0&&i.params.length>0){let o={};for(let a=0;a<i.argumentSorts.length;a++){let l=i.argumentSorts[a],c=this.sort(r.args[a]);if(c===null)return console.warn(`Failed to add sort parameter, unable to determine sort for argument in production: ${[i,l,c]}`),r;if(i.params.includes(l)){if(l.name in o&&o[l.name]!==c)return console.warn(`Failed to add sort parameter, sort mismatch: ${[i,l,o[l.name],c]}`),r;l.name in o||(o[l.name]=c)}}if(i.params.every(a=>a.name in o))return r.let({label:new b(r.label.name,i.params.map(a=>o[a.name]))})}return r},e)}addCellMapItems(e){let n={};for(let o of this.cellCollectionProductions){let a=o.att.get(d.ELEMENT),l=o.att.get(d.WRAP_ELEMENT);a&&l&&(n[l]=a)}let r=o=>o instanceof u&&o.label.name in n?new u(n[o.label.name],[o.args[0],o]):o,i=this.removeCellMapItems(e);return N(r,i)}removeCellMapItems(e){let n={};for(let i of this.cellCollectionProductions){let o=i.att.get(d.ELEMENT),a=i.att.get(d.WRAP_ELEMENT);o&&a&&(n[o]=a)}return N(i=>i instanceof u&&i.label.name in n&&i.args.length===2&&i.args[1]instanceof u&&i.args[1].label.name===n[i.label.name]?i.args[1]:i,e)}emptyConfig(e){let n=e.name;return n in this._emp