UNPKG

@runtimeverificationinc/tsk

Version:

TypeScript/JavaScript library for K Framework functionality

1 lines 84.5 kB
"use strict";var vn=Object.create;var te=Object.defineProperty;var qn=Object.getOwnPropertyDescriptor;var Pn=Object.getOwnPropertyNames;var Bn=Object.getPrototypeOf,$n=Object.prototype.hasOwnProperty;var Gn=(s,t)=>{for(var e in t)te(s,e,{get:t[e],enumerable:!0})},sn=(s,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Pn(t))!$n.call(s,r)&&r!==e&&te(s,r,{get:()=>t[r],enumerable:!(n=qn(t,r))||n.enumerable});return s};var Et=(s,t,e)=>(e=s!=null?vn(Bn(s)):{},sn(t||!s||!s.__esModule?te(e,"default",{value:s,enumerable:!0}):e,s)),Un=s=>sn(te({},"__esModule",{value:!0}),s);var dr={};Gn(dr,{AttEntry:()=>lt,AttKey:()=>m,Atts:()=>b,BOOL:()=>dn,CSubst:()=>Lt,CTerm:()=>mt,CTermShow:()=>zt,EMPTY_ATT:()=>R,Format:()=>et,FormatType:()=>Gt,Formatter:()=>Te,KApply:()=>u,KAs:()=>ot,KAssoc:()=>bn,KAst:()=>U,KAtt:()=>L,KBubble:()=>Mt,KClaim:()=>pt,KContext:()=>vt,KDefinition:()=>Kt,KFlatModule:()=>rt,KFlatModuleList:()=>Ye,KImport:()=>dt,KInner:()=>T,KLabel:()=>K,KNonTerminal:()=>O,KOuter:()=>j,KProduction:()=>ct,KProductionItem:()=>St,KRegexTerminal:()=>nt,KRequire:()=>bt,KRewrite:()=>w,KRule:()=>ut,KRuleLike:()=>Ut,KSentence:()=>V,KSequence:()=>E,KSort:()=>y,KSortSynonym:()=>Ot,KSyntaxAssociativity:()=>At,KSyntaxLexical:()=>Nt,KSyntaxPriority:()=>Tt,KSyntaxSort:()=>Rt,KTerminal:()=>G,KToken:()=>g,KVariable:()=>p,PrettyPrinter:()=>Ie,TRUE:()=>J,astToKast:()=>Dn,buildClaim:()=>ge,buildRule:()=>ye,createFrozenRecord:()=>re,createIterativeCTermShow:()=>Ln,ctermBuildClaim:()=>Tn,ctermBuildRule:()=>xn,deepConvert:()=>ee,filterNone:()=>cn,frozenRecord:()=>$,isFrozenRecord:()=>an,kastTerm:()=>ie,mergeWith:()=>ln,readKastDefinition:()=>Hn});module.exports=Un(dr);var An=Et(require("safe-stable-stringify"));var on=Et(require("crypto")),ne=Et(require("fs")),Me=Et(require("path"));function $(s){return Object.freeze({...s})}function re(s){let t={};for(let[e,n]of s)t[e]=n;return Object.freeze(t)}function an(s){return typeof s=="object"&&s!==null&&Object.isFrozen(s)}function ln(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 ve(s){if(s==null)throw new Error("Expected value other than null/undefined");return s}function cn(s){let t={};for(let[e,n]of Object.entries(s))n!=null&&(t[e]=n);return t}var Ne=class s{constructor(t){this._f=t}call(t){return this._f(t)}then(t){return new s(e=>t(this._f(e)))}},Kr=new Ne(s=>s);function un(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*it(s){let t=new Set;for(let e of s)t.has(e)||(t.add(e),yield e)}function _t(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 se(s){let t=on.createHash("sha256");return t.update(String(s)),t.digest("hex")}function ee(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return s.map(ee);let t={};for(let[e,n]of Object.entries(s))t[e]=ee(n);return t}var U=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=se(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 ie(s){if(s.format!=="KAST")throw new Error(`Invalid format: ${s.format}`);if(s.version!=U.version())throw new Error(`Invalid version: ${s.version}, expected: ${U.version()}`);return s.term}var y=class s extends U{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}},K=class s extends U{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 y(r):r)}static fromDict(t){return new s(t.name,t.params.map(e=>y.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}},H=class H extends U{static fromJson(t,e=!0){return H.fromDict(JSON.parse(t),e)}static _fromDictRecursive(t){var n,r;let e=t.node;switch(e){case"KToken":return g._fromDict(t,[]);case"KVariable":return p._fromDict(t,[]);case"KApply":let i=((n=t.args)==null?void 0:n.map(d=>H._fromDictRecursive(d)))||[];return u._fromDict(t,i);case"KSequence":let o=((r=t.items)==null?void 0:r.map(d=>H._fromDictRecursive(d)))||[];return E._fromDict(t,o);case"KRewrite":let a=H._fromDictRecursive(t.lhs),l=H._fromDictRecursive(t.rhs);return w._fromDict(t,[a,l]);case"KAs":let c=H._fromDictRecursive(t.pattern),h=H._fromDictRecursive(t.alias);return ot._fromDict(t,[c,h]);default:throw new Error(`Unknown node type: ${e}`)}}static fromDict(t,e=!0){if(!e)return H._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=g._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 h=0;h<a.length;h++)if(r.has(a[h]))c[h]=r.get(a[h]);else{l=!1;break}if(l){let h=u._fromDict(i.dct,c);r.set(i.dct,h),i.parent&&(i.parent.obj[i.parent.key]=h)}else{n.push(i);for(let h=0;h<a.length;h++)r.has(a[h])||n.push({dct:a[h],parent:{obj:c,key:h}})}}else if(o==="KSequence"){let a=i.dct.items||[],l=!0,c=[];for(let h=0;h<a.length;h++)if(r.has(a[h]))c[h]=r.get(a[h]);else{l=!1;break}if(l){let h=E._fromDict(i.dct,c);r.set(i.dct,h),i.parent&&(i.parent.obj[i.parent.key]=h)}else{n.push(i);for(let h=0;h<a.length;h++)r.has(a[h])||n.push({dct:a[h],parent:{obj:c,key:h}})}}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),h=r.get(i.dct.rhs),d=w._fromDict(i.dct,[c,h]);r.set(i.dct,d),i.parent&&(i.parent.obj[i.parent.key]=d)}}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),h=r.get(i.dct.alias),d=ot._fromDict(i.dct,[c,h]);r.set(i.dct,d),i.parent&&(i.parent.obj[i.parent.key]=d)}}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 H){let i=[...r.item.terms];if(r.item instanceof u&&i.push(r.item.label),r.item instanceof g&&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 H?e.push({item:a,type:"kinnerTerm"}):a instanceof K?e.push({item:a,type:"label"}):a instanceof y&&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 g)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 K){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 y&&n.set(r.item,{node:"KSort",name:r.item.name})}return n.get(this)}static combineMatches(t){let e=new D;for(let n of t)if(n===null||e===null||(e=e.union(n),e===null))return null;return e}};H.NODES=new Set(["KVariable","KToken","KApply","KAs","KRewrite","KSequence"]);var T=H,g=class s extends T{constructor(t,e){super(),this.token=t,this.sort=typeof e=="string"?new y(e):e}static _fromDict(t,e){return new s(t.token,y.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 D: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 y(e):e}static _fromDict(t,e){let n=t.sort?y.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 D({[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 K(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(K.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}},ot=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)}},w=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 M(e=>this.applyTop(e),t)}replaceTop(t){return this.lhs.equals(t)?this.rhs:t}replace(t){return M(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 D({[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}},D=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 M(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 w(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 q("#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 g&&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 M(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 Q(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 oe(s){let t={};return Pe(n=>{n instanceof p&&(n.name in t||(t[n.name]=[]),t[n.name].push(n))},s),t}function qe(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 Pe(s,t){let e=[t];for(;e.length>0;){let n=e.pop();e.push(...n.terms.slice().reverse()),s(n)}}function Bt(s,t,e){let n=typeof t=="string"?new K(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 q(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 Y=class{},Be=class extends Y{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}},ae=class extends Y{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)}},$e=class extends Y{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 $(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}},Ge=class extends Y{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)}},Ue=class extends Y{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}},le=class le extends Y{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=le.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)]}};le.PARSE_REGEX=/^(\d+),(\d+),(\d+),(\d+)$/;var Ve=le,Fe=class extends Y{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}},$t=class $t{constructor(t=[]){this.tokens=Array.from(t)}static parse(t){let e=Array.from(t.matchAll($t.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 $t(e.map(r=>r[0]))}unparse(){return this.tokens.join("")}};$t.PATTERN=/%\D|%\d+|[^%]+/g;var et=$t,Gt=class extends Y{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)}},We=class extends Y{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}},He=class extends Y{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(",")}},I=new Be,S=new $e,Vn=new Ge,at=new Ue,Fn=new Ve,Wn=new Fe,m=class{constructor(t,e=S){this.name=t,this.type=e}call(t){return new lt(this,t)}},lt=class{constructor(t,e){this.key=t,this.value=e}},f=class f{static keys(){if(f._keys===null){let t=[];for(let[e,n]of Object.entries(f))n instanceof m&&t.push([n.name,n]);f._keys=re(t)}return f._keys}};f.ALIAS=new m("alias",I),f.ALIAS_REC=new m("alias-rec",I),f.ANYWHERE=new m("anywhere",I),f.ASSOC=new m("assoc",I),f.AVOID=new m("avoid",I),f.BRACKET=new m("bracket",I),f.BRACKET_LABEL=new m("bracketLabel",S),f.CIRCULARITY=new m("circularity",I),f.CELL=new m("cell",I),f.CELL_COLLECTION=new m("cellCollection",I),f.CELL_FRAGMENT=new m("cellFragment",S),f.CELL_NAME=new m("cellName",at),f.CELL_OPT_ABSENT=new m("cellOptAbsent",S),f.COLOR=new m("color",new We),f.COLORS=new m("colors",new He),f.COMM=new m("comm",I),f.CONCAT=new m("concat",S),f.CONCRETE=new m("concrete",new ae(at)),f.CONSTRUCTOR=new m("constructor",I),f.DEPENDS=new m("depends",S),f.DIGEST=new m("digest",S),f.ELEMENT=new m("element",S),f.EXIT=new m("exit",S),f.FORMAT=new m("format",new Gt),f.FRESH_GENERATOR=new m("freshGenerator",I),f.FUNCTION=new m("function",I),f.FUNCTIONAL=new m("functional",I),f.GROUP=new m("group",at),f.HAS_DOMAIN_VALUES=new m("hasDomainValues",I),f.HOOK=new m("hook",S),f.IDEM=new m("idem",I),f.IMPURE=new m("impure",I),f.INDEX=new m("index",Vn),f.INITIALIZER=new m("initializer",I),f.INJECTIVE=new m("injective",I),f.LABEL=new m("label",S),f.LEFT=new m("left",S),f.LOCATION=new m("org.kframework.attributes.Location",Fn),f.MACRO=new m("macro",I),f.MACRO_REC=new m("macro-rec",I),f.MAINCELL=new m("maincell",I),f.MULTIPLICITY=new m("multiplicity",S),f.NO_EVALUATORS=new m("no-evaluators",I),f.OVERLOAD=new m("overload",at),f.OWISE=new m("owise",I),f.PREDICATE=new m("predicate",S),f.PREFER=new m("prefer",I),f.PRIORITY=new m("priority",S),f.PRIORITIES=new m("priorities",S),f.PRIVATE=new m("private",I),f.PRODUCTION=new m("org.kframework.definition.Production",S),f.PROJECTION=new m("projection",I),f.RIGHT=new m("right",S),f.RETURNS_UNIT=new m("returnsUnit",I),f.SIMPLIFICATION=new m("simplification",S),f.SEQSTRICT=new m("seqstrict",S),f.SORT=new m("org.kframework.kore.Sort",S),f.SOURCE=new m("org.kframework.attributes.Source",Wn),f.SMTLEMMA=new m("smt-lemma",I),f.STRICT=new m("strict",S),f.SYMBOL=new m("symbol",at),f.SYNTAX_MODULE=new m("syntaxModule",at),f.SYMBOLIC=new m("symbolic",new ae(at)),f.TERMINALS=new m("terminals",at),f.TERMINATOR_SYMBOL=new m("terminator-symbol",S),f.TOKEN=new m("token",I),f.TOTAL=new m("total",I),f.TRUSTED=new m("trusted",I),f.TYPE=new m("type",S),f.UNIT=new m("unit",at),f.UNIQUE_ID=new m("UNIQUE_ID",S),f.UNPARSE_AVOID=new m("unparseAvoid",I),f.UPDATE=new m("update",S),f.USER_LIST=new m("userList",S),f.WRAP_ELEMENT=new m("wrapElement",S),f._keys=null;var b=f,L=class s extends U{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=$(e),this.keyLookup=$(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=b.keys()[r]||new m(r,S),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=b.keys()[n]||new m(n,S),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([b.SOURCE,b.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}},R=new L;function pn(s,t){return s.letAtt(s.att.update(t))}var ce=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}};var mn=Et(require("fast-deep-equal")),hn=Et(require("fs"));var fn=Et(require("fast-deep-equal"));function ue(s,t){let e=[],n={},r=[];for(let l of t)if(l.lhs instanceof g)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 g)for(let h of e)c=h.applyTop(c);else if(c instanceof u){let h=c.label.name;if(h in n)for(let d of n[h])c=d.applyTop(c)}else for(let h of r)c=h.applyTop(c);return c}let o=s,a=null;for(;a===null||!(0,fn.default)(o,a);)a===null?a=o:o=a,a=M(i,a);return a}var dn=new y("Bool"),J=new g("true",dn);var j=class extends U{},pe=class pe extends j{static fromDict(t){let e=t.node;if(!pe.NODES.has(e))throw new Error(`Invalid KProductionItem node: ${e}`);switch(e){case"KTerminal":return G._fromDict(t);case"KRegexTerminal":return nt._fromDict(t);case"KNonTerminal":return O._fromDict(t);default:throw new Error(`Unknown node type: ${e}`)}}};pe.NODES=new Set(["KTerminal","KRegexTerminal","KNonTerminal"]);var St=pe,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}},O=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(y.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}},G=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}},fe=class fe extends j{static fromDict(t){let e=t.node;if(!fe.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 At._fromDict(t);case"KSyntaxPriority":return Tt._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(b.UNIQUE_ID)||null}get source(){let t=this.att.get(b.SOURCE),e=this.att.get(b.LOCATION);return t&&e?`${t}:${e}`:null}get label(){let t=this.att.get(b.LABEL)||this.uniqueId;if(!t)throw new Error(`Found sentence without label or UNIQUE_ID: ${this}`);return t}};fe.NODES=new Set(["KProduction","KSyntaxSort","KSortSynonym","KSyntaxLexical","KSyntaxAssociativity","KSyntaxPriority","KBubble","KRule","KClaim","KContext"]);var V=fe,ct=class s extends V{constructor(t,e=[],n=[],r,i=R){super(),typeof t=="string"&&(t=new y(t)),typeof r=="string"&&(r=new K(r));let o=Array.from(n).map(a=>typeof a=="string"?new y(a):a);this.sort=t,this.items=Array.from(e),this.params=o,this.klabel=r??null,this.att=i}static _fromDict(t){var e,n;return new s(y.fromDict(t.sort),((e=t.productionItems)==null?void 0:e.map(r=>St.fromDict(r)))||[],((n=t.params)==null?void 0:n.map(r=>y.fromDict(r)))||[],t.klabel?K.fromDict(t.klabel):null,t.att?L.fromDict(t.att):R)}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 O?[this.sort,t.sort]:null}get nonTerminals(){return this.items.filter(t=>t instanceof O)}get argumentSorts(){return this.nonTerminals.map(t=>t.sort)}get isPrefix(){function t(r){if(r instanceof G)return["(",",",")"].includes(r.value)?r.value:"t";if(r instanceof O)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 G)r.value==="("?e.push(`%${n+1}...`):e.push(`%${n+1}`);else if(r instanceof O){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 V{constructor(t,e=[],n=R){super();let r=Array.from(e).map(i=>typeof i=="string"?new y(i):i);this.sort=t,this.params=r,this.att=n}static _fromDict(t){var e;return new s(y.fromDict(t.sort),((e=t.params)==null?void 0:e.map(n=>y.fromDict(n)))||[],t.att?L.fromDict(t.att):R)}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 V{constructor(t,e,n=R){super(),this.newSort=t,this.oldSort=e,this.att=n}static _fromDict(t){return new s(y.fromDict(t.newSort),y.fromDict(t.oldSort),t.att?L.fromDict(t.att):R)}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 V{constructor(t,e,n=R){super(),this.name=t,this.regex=e,this.att=n}static _fromDict(t){return new s(t.name,t.regex,t.att?L.fromDict(t.att):R)}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)}},bn=(n=>(n.LEFT="Left",n.RIGHT="Right",n.NON_ASSOC="NonAssoc",n))(bn||{}),At=class s extends V{constructor(t,e=new Set,n=R){super(),this.assoc=t,this.tags=new Set(e),this.att=n}static _fromDict(t){return new s(t.assoc,t.tags,t.att?L.fromDict(t.att):R)}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)}},Tt=class s extends V{constructor(t=[],e=R){super(),this.priorities=Array.from(t).map(n=>new Set(n)),this.att=e}static _fromDict(t){return new s(t.priorities,t.att?L.fromDict(t.att):R)}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 V{constructor(t,e,n=R){super(),this.sentenceType=t,this.contents=e,this.att=n}static _fromDict(t){return new s(t.sentenceType,t.contents,t.att?L.fromDict(t.att):R)}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)}},Ut=class extends V{},ut=class s extends Ut{constructor(t,e=J,n=J,r=R){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?L.fromDict(t.att):R)}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(b.PRIORITY);return t!==void 0?parseInt(t):this.att.has(b.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 Ut{constructor(t,e=J,n=J,r=R){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?L.fromDict(t.att):R)}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(b.CIRCULARITY)}get isTrusted(){return this.att.has(b.TRUSTED)}get dependencies(){let t=this.att.get(b.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 V{constructor(t,e=J,n=R){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?L.fromDict(t.att):R)}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)}},dt=class s extends j{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 j{constructor(t,e=[],n=[],r=R){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(b.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(b.FUNCTION)||t.att.has(b.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=V),this.let({sentences:this.sentences.map(n=>n instanceof e?t(n):n)})}static fromDict(t){var e,n;return new s(t.name,((e=t.localSentences)==null?void 0:e.map(r=>V.fromDict(r)))||[],((n=t.imports)==null?void 0:n.map(r=>dt.fromDict(r)))||[],t.att?L.fromDict(t.att):R)}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 j{constructor(t,e){super(),this.mainModule=t,this.modules=Array.from(e)}static fromDict(t){var e;return new s(t.mainModule,((e=t.term)==null?void 0:e.map(n=>rt.fromDict(n)))||[])}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}},bt=class s extends j{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}},Kt=class s extends j{constructor(e,n,r=[],i=R){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){var n,r;return new s(e.mainModule,((n=e.modules)==null?void 0:n.map(i=>rt.fromDict(i)))||[],((r=e.requires)==null?void 0:r.map(i=>bt.fromDict(i)))||[],e.att?L.fromDict(e.att):R)}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=>ve(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(b.ALIAS))}get macroRules(){return this.rules.filter(e=>e.att.has(b.MACRO)).concat(this.aliasRules)}get semanticRules(){function e(n){return n.body instanceof u&&n.body.label.name==="<generatedTop>"||n.body instanceof w&&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 _t(this.productions.filter(n=>n.sort===e&&n.att.has(b.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(b.OVERLOAD)||!a.att.has(b.OVERLOAD)||o.att.get(b.OVERLOAD)!==a.att.get(b.OVERLOAD))return!1;let l=[o.sort,...o.argumentSorts],c=[a.sort,...a.argumentSorts];if(l.length!==c.length)return!1;let h=!1;for(let d=0;d<l.length;d++){let A=l[d],C=c[d];if(A!==C){if(this.subsorts(C).has(A)){h=!0;continue}return!1}}return h},n={};for(let o of Object.keys(this.symbols)){let a=this.symbols[o];if(a.att.has(b.OVERLOAD)){let l=a.att.get(b.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 $(i)}get priorities(){let e=this.modules.flatMap(i=>i.sentences).filter(i=>i instanceof Tt),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 h of l)n.push([c,h])}let r={};for(let[i,o]of n)r[i]||(r[i]=new Set),r[i].add(o);return $(r)}get leftAssocs(){let e=this.assocs("Left");return $(e)}get rightAssocs(){let e=this.assocs("Right");return $(e)}assocs(e){let n=this.modules.flatMap(i=>i.sentences).filter(i=>i instanceof At&&(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 $(e)}subsorts(e){return this.subsortTable[e.name]||new Set}get brackets(){let e={};for(let n of this.productions)if(n.att.has(b.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 $(e)}get symbols(){var n,r,i,o;let e={};for(let a of this.productions){if(!a.klabel)continue;let l=a.klabel.name;if(l in e){let c=e[l],h=a.let({att:((r=(n=a.att).dropSource)==null?void 0:r.call(n))||a.att}),d=c.let({att:((o=(i=c.att).dropSource)==null?void 0:o.call(i))||c.att});if(!(0,mn.default)(h.toDict(),d.toDict()))throw new Error(`Found multiple productions for ${l}: ${[c,a]}`);continue}e[l]=a}return $(e)}get syntaxSymbols(){let e={};for(let[r,i]of Object.entries(this.brackets)){let o=i.att.get(b.BRACKET_LABEL);o&&(e[o]=i)}let n={...this.symbols,...e};return $(n)}sort(e){if(e instanceof g||e instanceof p)return e.sort;if(e instanceof w){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 y("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 Q(r=>{if(!(r instanceof u))return r;let i=this.symbols[r.label.name];return new u(r.label,r.args.map((o,a)=>{var c;return i.argumentSorts[a].name==="K"&&((c=this.sort(o))==null?void 0:c.name)!=="K"?new E([o]):o}))},e)}sortVars(e,n){let r=new Set(["#Exists","#Forall"]);re