"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function St(){const r=[];function e(t){var o,u,a,c;let n=null;const i=r.length;for(let l=0;le){return Object.create(null,{..._t,for:d(r(async function(n){if(n.call.message.arguments.length!==4)throw new Error("message 'for' requires 4 arguments");const i=n.call.message.arguments[0].name;if(!i)throw new Error("message 'for' requires a name for the index");const s=await n.call.evalArgAt(1);if(typeof s!="number")throw new Error("message 'for' requires a number for the start index");const o=await n.call.evalArgAt(2);if(typeof o!="number")throw new Error("message 'for' requires a number for the end index");const u=Object.create(n,{[i]:{value:s,writable:!0}}),a=n.call.message.arguments[3],c=n.call.sender;for(let l=s;l<=o;l++)u[i]=l,await a.doInContext(c,u);return o})),if:d(r("condition",async function(n){return n.condition?n.call.message.arguments.length<2?!0:n.call.evalArgAt(1):n.call.message.arguments.length<3?!1:n.call.evalArgAt(2)})),do:d(r(async function(n){const i=n.call.message.arguments[0];return i&&await i.doInContext(this,n),this}))})}const _t={...K("Receiver"),[Symbol.hasInstance]:d(function(e){var t;return(t=e.hasProto)==null?void 0:t.call(e,this)}),type:{get(){return this[te]}},proto:ie(function(){return Object.getPrototypeOf(this)}),protos:ie(function(){return this.proto?[this.proto]:[]}),hasProto:d(function(e){const t=this.protos;let n=t.includes(e);if(!n){for(const i of t)if(i.hasProto(e)){n=!0;break}}return n}),appendProto:d(function(e){return Object.setPrototypeOf(this,xe(this.proto,e)),this}),prependProto:d(function(e){return Object.setPrototypeOf(this,xe(e,this.proto)),this}),clone:d(async function(){var t;const e=Object.create(this,{[te]:{value:this.type,configurable:!0}});if("init"in e){const n=(t=e.message)==null?void 0:t.call(e);n?(n.setName("init"),await n.doInContext(e)):await e.init()}return e}),updateSlot:d(function(e,t){if(!(e in this))throw new Error(`Slot ${e} not found. Must define slot using := operator before updating.`);return this[e]=t??null,t}),setSlot:d(function(e,t){var n;return this[e]=t??null,t&&e[0]===e[0].toUpperCase()&&typeof t=="object"&&((n=Object.getOwnPropertyDescriptor(t,te))!=null&&n.configurable)&&Object.defineProperty(t,te,{value:e}),t}),newSlot:d(function(e,t){this.setSlot(e,t);const n=`set${e[0].toUpperCase()}${e.slice(1)}`;return Object.defineProperty(this,n,{enumerable:!0,value:function(i){return this.updateSlot(e,i),this}}),t}),hasSlot:d(function(e){return e in this}),getSlot:d(function(e){return this[e]}),slotNames:d(function(){return Object.getOwnPropertyNames(this)}),nil:d(function(){return null}),"==":d(function(e){return this===e}),">":d(function(e){return this>e}),">=":d(function(e){return this>=e}),"<":d(function(e){return thistypeof i=="string"))throw new Error("arguments to method 'split' must be Strings.");const n=new RegExp(t.join("|"),"gu");return this.split(n)}},find:{value:function(e){const t=this.indexOf(e);return t===-1?null:t}},slice:{value:function(e,t){return this.slice(e,t)}}},Rt={...K("Num"),toString:{value:function(){return String(this.value)}},"+":{value:function(e){return this+e}},"-":{value:function(e){return this-e}},"*":{value:function(e){return this*e}},"/":{value:function(e){return this/e}},sqrt:{value:function(){return Math.sqrt(this)}},asCharacter:{value:function(){return String.fromCharCode(this)}}},Nt={...K("Bool"),toString:{value:function(){return String(this.value)}},not:{value:function(){return!this}}},Pt={forward:{value:()=>null}},Ye={...K("List"),clone:{value:function(){return Array.isArray(this)?[...this]:[]}},append:{value:function(...e){return this.push(...e),this}},size:{value:function(){return this.length}},sortInPlace:{value:function(){return this.sort((e,t)=>e-t),this}},sort:{value:function(){const e=this.slice();return Ye.sortInPlace.value.call(e),e}},first:{value:function(){return this[0]??null}},last:{value:function(){return this[this.length-1]??null}},at:{value:function(e){return this[e]??null}},remove:{value:function(e){const t=this.indexOf(e);return t>-1&&this.splice(t,1),this}},atPut:{value:function(e,t){return this[e]=t,this}},join:{value:function(e){return this.join(e)}}};function ee(r){switch(r.call.message.arguments.length){case 1:{const e=r.call.message.arguments[0];return{iterLocals:r,body:t=>e.doInContext(t)}}case 2:{const e=r.call.message.arguments[0].name;if(!e)throw new Error("argument 0 must be a symbol");const t=r.call.message.arguments[1];let n=r.call.sender,i=n.self;i||(i=n,n=null);const s=Object.create(n??i,{[e]:{value:null,writable:!0}});return{iterLocals:s,body:o=>(s[e]=o,t.doInContext(i,s))}}case 3:{const e=r.call.message.arguments[0].name;if(!e)throw new Error("argument 0 must be a symbol");const t=r.call.message.arguments[1].name;if(!t)throw new Error("argument 1 must be a symbol");const n=r.call.message.arguments[2];let i=r.call.sender,s=i.self;s||(s=i,i=null);const o=Object.create(i??s,{[t]:{value:null,writable:!0},[e]:{value:0,writable:!0}});return{iterLocals:o,body:(u,a)=>(o[t]=u,o[e]=a,n.doInContext(s,o))}}default:throw new Error("wrong number of arguments")}}function Lt(...r){return r}const Et={...K("Map"),clone:{value:function(){return this instanceof Map?new Map(this):new Map}},atPut:{value:function(e,t){return this.set(e,t),this}},hasKey:{value:function(e){return this.has(e)}},hasValue:{value:function(e){for(const t of this.values())if(t===e)return!0;return!1}},at:{value:function(e){return this.get(e)??null}},keys:{value:function(){return[...this.keys()]}}},Se=Symbol("MethodApply");class Ct extends Error{constructor(e,t){super(e),this.startMessage=t}}function se(...r){const e=r.slice(0,-1),t=e.length,n=r.slice(-1)[0];async function i(s,o,u,a){let c=s;const l=typeof s;l==="number"?c=a.Num:l==="string"?c=a.Str:l==="boolean"?c=a.Bool:Array.isArray(s)?c=a.List:s instanceof Map?c=a.Map:s===null&&(c=a.Nil);const p=Object.create(c,{self:{value:s},call:{value:Object.create(a.Call,{target:{value:s},activated:{value:n},message:{value:o},sender:{value:u}})}});if(t>0){let m=u,f=m.self;f||(f=m,m=void 0);for(let b=0;b{if(c.isLiteral||c.isEndOfLine||typeof c.name!="string")throw new Error("method() requires all arguments to be symbols.");return c.name});function a(c){return o?W(r,o,this,c,!0):null}return se(...u,a),Object.defineProperty(a,"toString",{value:()=>`method(${[...u,o==null?void 0:o.toString()].join(", ")})`}),a}return Object.defineProperty(r.Receiver,"method",d(se(n))),r}const ae=Symbol("Return");async function W(r,e,t,n,i=!1){let s=e;const o=n??t;let u=null,a=t;do{if(s.isEndOfLine){u=null,a=t,s=s.next;continue}if(s.isLiteral){u=s.name,a=u,s=s.next;continue}if(s.name==="return"){if(i){s=s.arguments[0]??null;continue}if(s.arguments.length===0)return{[ae]:null};if(s.arguments.length===1){const c=await W(r,s.arguments[0],t,n);return{[ae]:c}}else throw new Error("return() can only have one argument")}if(u=Mt(r,s,a,n),typeof u=="function")if(Se in u)u=await u[Se](a,s,o,r);else{const c=await Promise.all((s.arguments??[]).map(l=>W(r,l,o.self??o,n)));u=await u.apply(a,c)}if(typeof(u==null?void 0:u[ae])<"u")return u[ae];a=u,s=s.next}while(s);return u}function Mt(r,e,t,n){const i=e.name;let s=null,o=typeof t;if(o==="number"?s=r.Num[i]:o==="string"?s=r.Str[i]:o==="boolean"?s=r.Bool[i]:Array.isArray(t)?(s=r.List[i],o="List"):t instanceof Map?(s=r.Map[i],o="Map"):t===null?(s=r.Nil[i],o="Nil"):s=t[i],typeof s>"u"&&(n&&(s=n[i]),typeof s>"u"&&Object.hasOwnProperty.call(t,"forward")&&(s=t.forward),typeof s>"u"&&(s=r[i]),typeof s>"u"))throw new Ct(`${(t==null?void 0:t.type)??o} does not respond to '${i}'`,e);return s}const Tt={init:{value:function(){let e=null;return Object.defineProperties(this,{previous:{get(){return(e==null?void 0:e.deref())??null},set(t){e=t&&new WeakRef(t)}},setPrevious:{value:function(t){return this.previous=t,this}},setNext:{value:function(t){return this.next=t,t&&t.setPrevious(this),this}}}),this}},type:{value:"Message"},name:{writable:!0,value:""},setName:{value:function(r){return this.name=r,this}},arguments:{writable:!0,value:[]},setArguments:{value:function(r){return this.arguments=r,this}},next:{writable:!0,value:null},isLiteral:{writable:!0,value:!1},isEndOfLine:{writable:!0,value:!1},characterNumber:{writable:!0,value:0},lineNumber:{writable:!0,value:0},last:{get(){let r=this;for(;r.next;)r=r.next;return r}},toString:{value:function(){var i;let e="",t=this,n=!1;do t.isEndOfLine?(e=e.trimEnd(),e+=";",e+=n?" ":` `):t.isLiteral?e+=JSON.stringify(t.name)+" ":(e+=t.name,((i=t.arguments)==null?void 0:i.length)>0&&(n=!0,e+="(",e+=t.arguments.map(s=>s.toString().trimEnd()).join(", "),e+=")",n=!1),e+=" "),t=t.next;while(t);return e.trim()}},argAt:{value:function(e){return this.arguments[e]??null}}};function M(r){const e=r||"";return function(){throw new Error("this method "+e+" is abstract! (it has no implementation in class "+this.constructor.name+")")}}function V(r,e){if(!r)throw new Error(e||"Assertion failed")}function be(r,e,t){let n;Object.defineProperty(r,e,{get(){return n||(n=t.call(this)),n}})}function kt(r){return r&&Object.assign({},r)}function Xe(r,e){const t=[];for(;e-- >0;)t.push(r());return t}function et(r,e){return new Array(e+1).join(r)}function le(r,e){return Xe(()=>r,e)}function we(r){const e=[];for(let t=0;t{e.indexOf(t)<0&&e.push(t)}),e}function J(r){const e=r[0];return e===e.toUpperCase()}function rt(r){return!J(r)}function nt(r,e,t){const n=t||" ";return r.lengthString.fromCodePoint(parseInt(r,16));function it(r){if(r.charAt(0)==="\\")switch(r.charAt(1)){case"b":return"\b";case"f":return"\f";case"n":return` `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"x":return ve(r.slice(2,4));case"u":return r.charAt(2)==="{"?ve(r.slice(3,-1)):ve(r.slice(2,6));default:return r.charAt(1)}else return r}function Pe(r){if(r==null)return String(r);const e=Object.prototype.toString.call(r);try{let t;return r.constructor&&r.constructor.name?t=r.constructor.name:e.indexOf("[object ")===0?t=e.slice(8,-1):t=typeof r,t+": "+JSON.stringify(String(r))}catch{return e}}const Dt=Object.freeze(Object.defineProperty({__proto__:null,StringBuffer:Q,abstract:M,assert:V,clone:kt,copyWithoutDuplicates:tt,defineLazyProperty:be,getDuplicates:we,isLexical:rt,isSyntactic:J,padLeft:nt,repeat:le,repeatFn:Xe,repeatStr:et,unescapeCodePoint:it,unexpectedObjToString:Pe},Symbol.toStringTag,{value:"Module"})),Bt={Lu:/\p{Lu}/u,Ll:/\p{Ll}/u,Lt:/\p{Lt}/u,Lm:/\p{Lm}/u,Lo:/\p{Lo}/u,Nl:/\p{Nl}/u,Nd:/\p{Nd}/u,Mn:/\p{Mn}/u,Mc:/\p{Mc}/u,Pc:/\p{Pc}/u,Zs:/\p{Zs}/u,L:/\p{Letter}/u,Ltmo:/\p{Lt}|\p{Lm}|\p{Lo}/u};class g{constructor(){if(this.constructor===g)throw new Error("PExpr cannot be instantiated -- it's abstract")}withSource(e){return e&&(this.source=e.trimmed()),this}}const L=Object.create(g.prototype),E=Object.create(g.prototype);class N extends g{constructor(e){super(),this.obj=e}}class C extends g{constructor(e,t){super(),this.from=e,this.to=t,this.matchCodePoint=e.length>1||t.length>1}}class F extends g{constructor(e){super(),this.index=e}}class A extends g{constructor(e){super(),this.terms=e}}class pe extends A{constructor(e,t,n){const i=e.rules[t].body;super([n,i]),this.superGrammar=e,this.name=t,this.body=n}}class he extends A{constructor(e,t,n,i){const s=e.rules[t].body;super([...n,s,...i]),this.superGrammar=e,this.ruleName=t,this.expansionPos=n.length}}class O extends g{constructor(e){super(),this.factors=e}}class T extends g{constructor(e){super(),this.expr=e}}class Z extends T{}class X extends T{}class z extends T{}Z.prototype.operator="*";X.prototype.operator="+";z.prototype.operator="?";Z.prototype.minNumMatches=0;X.prototype.minNumMatches=1;z.prototype.minNumMatches=0;Z.prototype.maxNumMatches=Number.POSITIVE_INFINITY;X.prototype.maxNumMatches=Number.POSITIVE_INFINITY;z.prototype.maxNumMatches=1;class k extends g{constructor(e){super(),this.expr=e}}class D extends g{constructor(e){super(),this.expr=e}}class G extends g{constructor(e){super(),this.expr=e}}class I extends g{constructor(e,t=[]){super(),this.ruleName=e,this.args=t}isSyntactic(){return J(this.ruleName)}toMemoKey(){return this._memoKey||Object.defineProperty(this,"_memoKey",{value:this.toString()}),this._memoKey}}class R extends g{constructor(e){super(),this.category=e,this.pattern=Bt[e]}}function w(r,e){let t;return e?(t=new Error(e.getLineAndColumnMessage()+r),t.shortMessage=r,t.interval=e):t=new Error(r),t}function _e(){return w("Interval sources don't match")}function qt(r){const e=new Error;return Object.defineProperty(e,"message",{enumerable:!0,get(){return r.message}}),Object.defineProperty(e,"shortMessage",{enumerable:!0,get(){return"Expected "+r.getExpectedText()}}),e.interval=r.getInterval(),e}function Gt(r,e,t){const n=e?`Grammar ${r} is not declared in namespace '${e}'`:"Undeclared grammar "+r;return w(n,t)}function $t(r,e){return w("Grammar "+r.name+" is already declared in this namespace")}function Ut(r){return w(`Grammar '${r.name}' does not support incremental parsing`)}function st(r,e,t){return w("Rule "+r+" is not declared in grammar "+e,t)}function Kt(r,e,t){return w("Cannot override rule "+r+" because it is not declared in "+e,t)}function zt(r,e,t){return w("Cannot extend rule "+r+" because it is not declared in "+e,t)}function De(r,e,t,n){let i="Duplicate declaration for rule '"+r+"' in grammar '"+e+"'";return e!==t&&(i+=" (originally declared in '"+t+"')"),w(i,n)}function ot(r,e,t,n){return w("Wrong number of parameters for rule "+r+" (expected "+e+", got "+t+")",n)}function Ht(r,e,t,n){return w("Wrong number of arguments for rule "+r+" (expected "+e+", got "+t+")",n)}function Be(r,e,t){return w("Duplicate parameter names in rule "+r+": "+e.join(", "),t)}function Vt(r,e){return w("Invalid parameter to rule "+r+": "+e+" has arity "+e.getArity()+", but parameter expressions must have arity 1",e.source)}const Wt="NOTE: A _syntactic rule_ is a rule whose name begins with a capital letter. See https://ohmjs.org/d/svl for more details.";function Jt(r,e){return w("Cannot apply syntactic rule "+r+" from here (inside a lexical context)",e.source)}function Qt(r){const{ruleName:e}=r;return w(`applySyntactic is for syntactic rules, but '${e}' is a lexical rule. `+Wt,r.source)}function Zt(r){return w("applySyntactic is not required here (in a syntactic context)",r.source)}function qe(r,e){return w("Incorrect argument type: expected "+r,e.source)}function Yt(r){return w("'...' can appear at most once in a rule body",r.source)}function Xt(r){const e=r._node;V(e&&e.isNonterminal()&&e.ctorName==="escapeChar_unicodeCodePoint");const t=r.children.slice(1,-1).map(i=>i.source),n=t[0].coverageWith(...t.slice(1));return w(`U+${n.contents} is not a valid Unicode code point`,n)}function at(r,e){const t=e.length>0?e[e.length-1].args:[];let n="Nullable expression "+r.expr.substituteParams(t)+" is not allowed inside '"+r.operator+"' (possible infinite loop)";if(e.length>0){const i=e.map(s=>new I(s.ruleName,s.args)).join(` `);n+=` Application stack (most recent application last): `+i}return w(n,r.expr.source)}function ut(r,e,t,n){return w("Rule "+r+" involves an alternation which has inconsistent arity (expected "+e+", got "+t+")",n.source)}function er(r){const e=r.map(t=>t.message);return w(["Errors:"].concat(e).join(` - `),r[0].interval)}function tr(r,e,t,n){let i=n.slice(0,-1).map(a=>{const c=" "+a[0].name+" > "+a[1];return a.length===3?c+" for '"+a[2]+"'":c}).join(` `);i+=` `+e+" > "+r;let s="";r==="_iter"&&(s=[` NOTE: as of Ohm v16, there is no default action for iteration nodes — see `," https://ohmjs.org/d/dsa for details."].join(` `));const o=[`Missing semantic action for '${r}' in ${t} '${e}'.${s}`,"Action stack (most recent call last):",i].join(` `),u=w(o);return u.name="missingSemanticAction",u}function rr(r){if(r.length===1)throw r[0];if(r.length>1)throw er(r)}function nr(r){let e=0;return r.map(t=>{const n=t.toString();return e=Math.max(e,n.length),n}).map(t=>nt(t,e))}function Ge(r,e,t){const n=r.length,i=r.slice(0,t),s=r.slice(t+e.length);return(i+e+s).substr(0,n)}function ir(...r){const e=this,{offset:t}=e,{repeatStr:n}=Dt,i=new Q;i.append("Line "+e.lineNum+", col "+e.colNum+`: `);const s=nr([e.prevLine==null?0:e.lineNum-1,e.lineNum,e.nextLine==null?0:e.lineNum+1]),o=(l,p,h)=>{i.append(h+s[l]+" | "+p+` `)};e.prevLine!=null&&o(0,e.prevLine," "),o(1,e.line,"> ");const u=e.line.length;let a=n(" ",u+1);for(let l=0;l=0&&p<=h,"range start must be >= 0 and <= end");const m=t-e.colNum+1;p=Math.max(0,p-m),h=Math.min(h-m,u),a=Ge(a,n("~",h-p),p)}const c=2+s[1].length+3;return i.append(n(" ",c)),a=Ge(a,"^",e.colNum-1),i.append(a.replace(/ +$/,"")+` `),e.nextLine!=null&&o(2,e.nextLine," "),i.contents()}let Ae=[];function ct(r){Ae.push(r)}function sr(r){Ae.forEach(e=>{e(r)}),Ae=null}function Le(r,e){let t=1,n=1,i=0,s=0,o=null,u=null,a=-1;for(;i=0&&(u=r.slice(a,s).replace(/\r?\n$/,""));const l=r.slice(s,c).replace(/\r$/,"");return{offset:e,lineNum:t,colNum:n,line:l,prevLine:u,nextLine:o,toString:ir}}function Ee(r,e,...t){return Le(r,e).toString(...t)}const $e=(()=>{let r=0;return e=>""+e+r++})();class P{constructor(e,t,n){this.sourceString=e,this.startIdx=t,this.endIdx=n}get contents(){return this._contents===void 0&&(this._contents=this.sourceString.slice(this.startIdx,this.endIdx)),this._contents}get length(){return this.endIdx-this.startIdx}coverageWith(...e){return P.coverage(...e,this)}collapsedLeft(){return new P(this.sourceString,this.startIdx,this.startIdx)}collapsedRight(){return new P(this.sourceString,this.endIdx,this.endIdx)}getLineAndColumn(){return Le(this.sourceString,this.startIdx)}getLineAndColumnMessage(){const e=[this.startIdx,this.endIdx];return Ee(this.sourceString,this.startIdx,e)}minus(e){if(this.sourceString!==e.sourceString)throw _e();return this.startIdx===e.startIdx&&this.endIdx===e.endIdx?[]:this.startIdx=e.startIdx&&this.endIdx<=e.endIdx,"other interval does not cover this one"),new P(this.sourceString,this.startIdx-e.startIdx,this.endIdx-e.startIdx)}trimmed(){const{contents:e}=this,t=this.startIdx+e.match(/^\s*/)[0].length,n=this.endIdx-e.match(/\s*$/)[0].length;return new P(this.sourceString,t,n)}subInterval(e,t){const n=this.startIdx+e;return new P(this.sourceString,n,n+t)}}P.coverage=function(r,...e){let{startIdx:t,endIdx:n}=r;for(const i of e){if(i.sourceString!==r.sourceString)throw _e();t=Math.min(t,i.startIdx),n=Math.max(n,i.endIdx)}return new P(r.sourceString,t,n)};const or=65535;class me{constructor(e){this.source=e,this.pos=0,this.examinedLength=0}atEnd(){const e=this.pos>=this.source.length;return this.examinedLength=Math.max(this.examinedLength,this.pos+1),e}next(){const e=this.source[this.pos++];return this.examinedLength=Math.max(this.examinedLength,this.pos),e}nextCharCode(){const e=this.next();return e&&e.charCodeAt(0)}nextCodePoint(){const e=this.source.slice(this.pos++).codePointAt(0);return e>or&&(this.pos+=1),this.examinedLength=Math.max(this.examinedLength,this.pos),e}matchString(e,t){let n;if(t){for(n=0;n!n.isFluffy());for(let n=0;n0&&(n===t.length-1?e.append(t.length>2?", or ":" or "):e.append(", ")),e.append(t[n].toString());return e.contents()}getInterval(){const e=this.getRightmostFailurePosition();return new P(this.input,e,e)}}class ar{constructor(){this.applicationMemoKeyStack=[],this.memo={},this.maxExaminedLength=0,this.maxRightmostFailureOffset=-1,this.currentLeftRecursion=void 0}isActive(e){return this.applicationMemoKeyStack.indexOf(e.toMemoKey())>=0}enter(e){this.applicationMemoKeyStack.push(e.toMemoKey())}exit(){this.applicationMemoKeyStack.pop()}startLeftRecursion(e,t){t.isLeftRecursion=!0,t.headApplication=e,t.nextLeftRecursion=this.currentLeftRecursion,this.currentLeftRecursion=t;const{applicationMemoKeyStack:n}=this,i=n.indexOf(e.toMemoKey())+1,s=n.slice(i);t.isInvolved=function(o){return s.indexOf(o)>=0},t.updateInvolvedApplicationMemoKeys=function(){for(let o=i;o{const s=n[i];e+s.examinedLength>t?delete n[i]:(this.maxExaminedLength=Math.max(this.maxExaminedLength,s.examinedLength),this.maxRightmostFailureOffset=Math.max(this.maxRightmostFailureOffset,s.rightmostFailureOffset))})}}const ur="✗",cr="✓",lr="⋅",pr="⇒",hr="␉",mr="␊",fr="␍",Oe={succeeded:1<<0,isRootNode:1<<1,isImplicitSpaces:1<<2,isMemoized:1<<3,isHeadOfLeftRecursion:1<<4,terminatesLR:1<<5};function dr(r){return le(" ",r).join("")}function gr(r,e,t){const n=pt(r.slice(e,e+t));return n.length{i(c,s,u+1)}),n.exit&&n.exit.call(t,s,o,u))}this.isRootNode?this.children.forEach(s=>{i(s,null,0)}):i(this,null,0)}toString(){const e=new Q;return this.walk((t,n,i)=>{if(!t)return this.SKIP;if(t.expr.constructor.name!=="Alt"){if(e.append(gr(t.input,t.pos,10)+dr(i*2+1)),e.append((t.succeeded?cr:ur)+" "+t.displayString),t.isHeadOfLeftRecursion&&e.append(" (LR)"),t.succeeded){const s=pt(t.source.contents);e.append(" "+pr+" "),e.append(typeof s=="string"?'"'+s+'"':s)}e.append(` `)}}),e.contents()}}H.prototype.SKIP={};Object.keys(Oe).forEach(r=>{const e=Oe[r];Object.defineProperty(H.prototype,r,{get(){return(this._flags&e)!==0},set(t){t?this._flags|=e:this._flags&=~e}})});g.prototype.allowsSkippingPrecedingSpace=M("allowsSkippingPrecedingSpace");L.allowsSkippingPrecedingSpace=E.allowsSkippingPrecedingSpace=I.prototype.allowsSkippingPrecedingSpace=N.prototype.allowsSkippingPrecedingSpace=C.prototype.allowsSkippingPrecedingSpace=R.prototype.allowsSkippingPrecedingSpace=function(){return!0};A.prototype.allowsSkippingPrecedingSpace=T.prototype.allowsSkippingPrecedingSpace=G.prototype.allowsSkippingPrecedingSpace=D.prototype.allowsSkippingPrecedingSpace=k.prototype.allowsSkippingPrecedingSpace=F.prototype.allowsSkippingPrecedingSpace=O.prototype.allowsSkippingPrecedingSpace=function(){return!1};let re;ct(r=>{re=r});let ue;g.prototype.assertAllApplicationsAreValid=function(r,e){ue=0,this._assertAllApplicationsAreValid(r,e)};g.prototype._assertAllApplicationsAreValid=M("_assertAllApplicationsAreValid");L._assertAllApplicationsAreValid=E._assertAllApplicationsAreValid=N.prototype._assertAllApplicationsAreValid=C.prototype._assertAllApplicationsAreValid=F.prototype._assertAllApplicationsAreValid=R.prototype._assertAllApplicationsAreValid=function(r,e){};G.prototype._assertAllApplicationsAreValid=function(r,e){ue++,this.expr._assertAllApplicationsAreValid(r,e),ue--};A.prototype._assertAllApplicationsAreValid=function(r,e){for(let t=0;t{if(a._assertAllApplicationsAreValid(r,e,u),a.getArity()!==1)throw Vt(this.ruleName,a)})};g.prototype.assertChoicesHaveUniformArity=M("assertChoicesHaveUniformArity");L.assertChoicesHaveUniformArity=E.assertChoicesHaveUniformArity=N.prototype.assertChoicesHaveUniformArity=C.prototype.assertChoicesHaveUniformArity=F.prototype.assertChoicesHaveUniformArity=G.prototype.assertChoicesHaveUniformArity=R.prototype.assertChoicesHaveUniformArity=function(r){};A.prototype.assertChoicesHaveUniformArity=function(r){if(this.terms.length===0)return;const e=this.terms[0].getArity();for(let t=0;t{e.assertIteratedExprsAreNotNullable(r)})};class Ce{constructor(e){this.matchLength=e}get ctorName(){throw new Error("subclass responsibility")}numChildren(){return this.children?this.children.length:0}childAt(e){if(this.children)return this.children[e]}indexOfChild(e){return this.children.indexOf(e)}hasChildren(){return this.numChildren()>0}hasNoChildren(){return!this.hasChildren()}onlyChild(){if(this.numChildren()!==1)throw new Error("cannot get only child of a node of type "+this.ctorName+" (it has "+this.numChildren()+" children)");return this.firstChild()}firstChild(){if(this.hasNoChildren())throw new Error("cannot get first child of a "+this.ctorName+" node, which has no children");return this.childAt(0)}lastChild(){if(this.hasNoChildren())throw new Error("cannot get last child of a "+this.ctorName+" node, which has no children");return this.childAt(this.numChildren()-1)}childBefore(e){const t=this.indexOfChild(e);if(t<0)throw new Error("Node.childBefore() called w/ an argument that is not a child");if(t===0)throw new Error("cannot get child before first child");return this.childAt(t-1)}childAfter(e){const t=this.indexOfChild(e);if(t<0)throw new Error("Node.childAfter() called w/ an argument that is not a child");if(t===this.numChildren()-1)throw new Error("cannot get child after last child");return this.childAt(t+1)}isTerminal(){return!1}isNonterminal(){return!1}isIteration(){return!1}isOptional(){return!1}}class Y extends Ce{get ctorName(){return"_terminal"}isTerminal(){return!0}get primitiveValue(){throw new Error("The `primitiveValue` property was removed in Ohm v17.")}}class vr extends Ce{constructor(e,t,n,i){super(i),this.ruleName=e,this.children=t,this.childOffsets=n}get ctorName(){return this.ruleName}isNonterminal(){return!0}isLexical(){return rt(this.ctorName)}isSyntactic(){return J(this.ctorName)}}class ht extends Ce{constructor(e,t,n,i){super(n),this.children=e,this.childOffsets=t,this.optional=i}get ctorName(){return"_iter"}isIteration(){return!0}isOptional(){return this.optional}}g.prototype.eval=M("eval");L.eval=function(r){const{inputStream:e}=r,t=e.pos,n=e.nextCodePoint();return n!==void 0?(r.pushBinding(new Y(String.fromCodePoint(n).length),t),!0):(r.processFailure(t,this),!1)};E.eval=function(r){const{inputStream:e}=r,t=e.pos;return e.atEnd()?(r.pushBinding(new Y(0),t),!0):(r.processFailure(t,this),!1)};N.prototype.eval=function(r){const{inputStream:e}=r,t=e.pos;return e.matchString(this.obj)?(r.pushBinding(new Y(this.obj.length),t),!0):(r.processFailure(t,this),!1)};C.prototype.eval=function(r){const{inputStream:e}=r,t=e.pos,n=this.matchCodePoint?e.nextCodePoint():e.nextCharCode();return n!==void 0&&this.from.codePointAt(0)<=n&&n<=this.to.codePointAt(0)?(r.pushBinding(new Y(String.fromCodePoint(n).length),t),!0):(r.processFailure(t,this),!1)};F.prototype.eval=function(r){return r.eval(r.currentApplication().args[this.index])};G.prototype.eval=function(r){r.enterLexifiedContext();const e=r.eval(this.expr);return r.exitLexifiedContext(),e};A.prototype.eval=function(r){for(let e=0;e0){const h=i[n-1],m=s[n-1],f=m[m.length-1]+h[h.length-1].matchLength;c=s[0][0],l=f-c}const p=this instanceof z;for(a=0;at.outputRecipe(r,e)))};pe.prototype.outputRecipe=function(r,e){return this.terms[0].outputRecipe(r,e)};he.prototype.outputRecipe=function(r,e){const t=this.terms.slice(0,this.expansionPos),n=this.terms.slice(this.expansionPos+1);return["splice",U(this,e),t.map(i=>i.outputRecipe(r,e)),n.map(i=>i.outputRecipe(r,e))]};O.prototype.outputRecipe=function(r,e){return["seq",U(this,e)].concat(this.factors.map(t=>t.outputRecipe(r,e)))};Z.prototype.outputRecipe=X.prototype.outputRecipe=z.prototype.outputRecipe=k.prototype.outputRecipe=D.prototype.outputRecipe=G.prototype.outputRecipe=function(r,e){return[this.constructor.name.toLowerCase(),U(this,e),this.expr.outputRecipe(r,e)]};I.prototype.outputRecipe=function(r,e){return["app",U(this,e),this.ruleName,this.args.map(t=>t.outputRecipe(r,e))]};R.prototype.outputRecipe=function(r,e){return["unicodeChar",U(this,e),this.category]};g.prototype.introduceParams=M("introduceParams");L.introduceParams=E.introduceParams=N.prototype.introduceParams=C.prototype.introduceParams=F.prototype.introduceParams=R.prototype.introduceParams=function(r){return this};A.prototype.introduceParams=function(r){return this.terms.forEach((e,t,n)=>{n[t]=e.introduceParams(r)}),this};O.prototype.introduceParams=function(r){return this.factors.forEach((e,t,n)=>{n[t]=e.introduceParams(r)}),this};T.prototype.introduceParams=k.prototype.introduceParams=D.prototype.introduceParams=G.prototype.introduceParams=function(r){return this.expr=this.expr.introduceParams(r),this};I.prototype.introduceParams=function(r){const e=r.indexOf(this.ruleName);if(e>=0){if(this.args.length>0)throw new Error("Parameterized rules cannot be passed as arguments to another rule.");return new F(e).withSource(this.source)}else return this.args.forEach((t,n,i)=>{i[n]=t.introduceParams(r)}),this};g.prototype.isNullable=function(r){return this._isNullable(r,Object.create(null))};g.prototype._isNullable=M("_isNullable");L._isNullable=C.prototype._isNullable=F.prototype._isNullable=X.prototype._isNullable=R.prototype._isNullable=function(r,e){return!1};E._isNullable=function(r,e){return!0};N.prototype._isNullable=function(r,e){return typeof this.obj=="string"?this.obj==="":!1};A.prototype._isNullable=function(r,e){return this.terms.length===0||this.terms.some(t=>t._isNullable(r,e))};O.prototype._isNullable=function(r,e){return this.factors.every(t=>t._isNullable(r,e))};Z.prototype._isNullable=z.prototype._isNullable=k.prototype._isNullable=D.prototype._isNullable=function(r,e){return!0};G.prototype._isNullable=function(r,e){return this.expr._isNullable(r,e)};I.prototype._isNullable=function(r,e){const t=this.toMemoKey();if(!Object.prototype.hasOwnProperty.call(e,t)){const{body:n}=r.rules[this.ruleName],i=n.substituteParams(this.args);e[t]=!1,e[t]=i._isNullable(r,e)}return e[t]};g.prototype.substituteParams=M("substituteParams");L.substituteParams=E.substituteParams=N.prototype.substituteParams=C.prototype.substituteParams=R.prototype.substituteParams=function(r){return this};F.prototype.substituteParams=function(r){return r[this.index]};A.prototype.substituteParams=function(r){return new A(this.terms.map(e=>e.substituteParams(r)))};O.prototype.substituteParams=function(r){return new O(this.factors.map(e=>e.substituteParams(r)))};T.prototype.substituteParams=k.prototype.substituteParams=D.prototype.substituteParams=G.prototype.substituteParams=function(r){return new this.constructor(this.expr.substituteParams(r))};I.prototype.substituteParams=function(r){if(this.args.length===0)return this;{const e=this.args.map(t=>t.substituteParams(r));return new I(this.ruleName,e)}};function Ue(r){return/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(r)}function Fe(r){const e=Object.create(null);r.forEach(t=>{e[t]=(e[t]||0)+1}),Object.keys(e).forEach(t=>{if(e[t]<=1)return;let n=1;r.forEach((i,s)=>{i===t&&(r[s]=i+"_"+n++)})})}g.prototype.toArgumentNameList=M("toArgumentNameList");L.toArgumentNameList=function(r,e){return["any"]};E.toArgumentNameList=function(r,e){return["end"]};N.prototype.toArgumentNameList=function(r,e){return typeof this.obj=="string"&&/^[_a-zA-Z0-9]+$/.test(this.obj)?["_"+this.obj]:["$"+r]};C.prototype.toArgumentNameList=function(r,e){let t=this.from+"_to_"+this.to;return Ue(t)||(t="_"+t),Ue(t)||(t="$"+r),[t]};A.prototype.toArgumentNameList=function(r,e){const t=this.terms.map(s=>s.toArgumentNameList(r,!0)),n=[],i=t[0].length;for(let s=0;s{const i=n.toArgumentNameList(r,!0);t=t.concat(i),r+=i.length}),e||Fe(t),t};T.prototype.toArgumentNameList=function(r,e){const t=this.expr.toArgumentNameList(r,e).map(n=>n[n.length-1]==="s"?n+"es":n+"s");return e||Fe(t),t};z.prototype.toArgumentNameList=function(r,e){return this.expr.toArgumentNameList(r,e).map(t=>"opt"+t[0].toUpperCase()+t.slice(1))};k.prototype.toArgumentNameList=function(r,e){return[]};D.prototype.toArgumentNameList=G.prototype.toArgumentNameList=function(r,e){return this.expr.toArgumentNameList(r,e)};I.prototype.toArgumentNameList=function(r,e){return[this.ruleName]};R.prototype.toArgumentNameList=function(r,e){return["$"+r]};F.prototype.toArgumentNameList=function(r,e){return["param"+this.index]};g.prototype.toDisplayString=M("toDisplayString");A.prototype.toDisplayString=O.prototype.toDisplayString=function(){return this.source?this.source.trimmed().contents:"["+this.constructor.name+"]"};L.toDisplayString=E.toDisplayString=T.prototype.toDisplayString=k.prototype.toDisplayString=D.prototype.toDisplayString=G.prototype.toDisplayString=N.prototype.toDisplayString=C.prototype.toDisplayString=F.prototype.toDisplayString=function(){return this.toString()};I.prototype.toDisplayString=function(){if(this.args.length>0){const r=this.args.map(e=>e.toDisplayString());return this.ruleName+"<"+r.join(",")+">"}else return this.ruleName};R.prototype.toDisplayString=function(){return"Unicode ["+this.category+"] character"};function yr(r){return r==="description"||r==="string"||r==="code"}class ${constructor(e,t,n){if(!yr(n))throw new Error("invalid Failure type: "+n);this.pexpr=e,this.text=t,this.type=n,this.fluffy=!1}getPExpr(){return this.pexpr}getText(){return this.text}getType(){return this.type}isDescription(){return this.type==="description"}isStringTerminal(){return this.type==="string"}isCode(){return this.type==="code"}isFluffy(){return this.fluffy}makeFluffy(){this.fluffy=!0}clearFluffy(){this.fluffy=!1}subsumes(e){return this.getText()===e.getText()&&this.type===e.type&&(!this.isFluffy()||this.isFluffy()&&e.isFluffy())}toString(){return this.type==="string"?JSON.stringify(this.getText()):this.getText()}clone(){const e=new $(this.pexpr,this.text,this.type);return this.isFluffy()&&e.makeFluffy(),e}toKey(){return this.toString()+"#"+this.type}}g.prototype.toFailure=M("toFailure");L.toFailure=function(r){return new $(this,"any object","description")};E.toFailure=function(r){return new $(this,"end of input","description")};N.prototype.toFailure=function(r){return new $(this,this.obj,"string")};C.prototype.toFailure=function(r){return new $(this,JSON.stringify(this.from)+".."+JSON.stringify(this.to),"code")};k.prototype.toFailure=function(r){const e=this.expr===L?"nothing":"not "+this.expr.toFailure(r);return new $(this,e,"description")};D.prototype.toFailure=function(r){return this.expr.toFailure(r)};I.prototype.toFailure=function(r){let{description:e}=r.rules[this.ruleName];return e||(e=(/^[aeiouAEIOU]/.test(this.ruleName)?"an":"a")+" "+this.ruleName),new $(this,e,"description")};R.prototype.toFailure=function(r){return new $(this,"a Unicode ["+this.category+"] character","description")};A.prototype.toFailure=function(r){const e="("+this.terms.map(t=>t.toFailure(r)).join(" or ")+")";return new $(this,e,"description")};O.prototype.toFailure=function(r){const e="("+this.factors.map(t=>t.toFailure(r)).join(" ")+")";return new $(this,e,"description")};T.prototype.toFailure=function(r){const e="("+this.expr.toFailure(r)+this.operator+")";return new $(this,e,"description")};g.prototype.toString=M("toString");L.toString=function(){return"any"};E.toString=function(){return"end"};N.prototype.toString=function(){return JSON.stringify(this.obj)};C.prototype.toString=function(){return JSON.stringify(this.from)+".."+JSON.stringify(this.to)};F.prototype.toString=function(){return"$"+this.index};G.prototype.toString=function(){return"#("+this.expr.toString()+")"};A.prototype.toString=function(){return this.terms.length===1?this.terms[0].toString():"("+this.terms.map(r=>r.toString()).join(" | ")+")"};O.prototype.toString=function(){return this.factors.length===1?this.factors[0].toString():"("+this.factors.map(r=>r.toString()).join(" ")+")"};T.prototype.toString=function(){return this.expr+this.operator};k.prototype.toString=function(){return"~"+this.expr};D.prototype.toString=function(){return"&"+this.expr};I.prototype.toString=function(){if(this.args.length>0){const r=this.args.map(e=>e.toString());return this.ruleName+"<"+r.join(",")+">"}else return this.ruleName};R.prototype.toString=function(){return"\\p{"+this.category+"}"};class je extends g{constructor(e){super(),this.obj=e}_getString(e){const t=e.currentApplication().args[this.obj.index];return V(t instanceof N,"expected a Terminal expression"),t.obj}allowsSkippingPrecedingSpace(){return!0}eval(e){const{inputStream:t}=e,n=t.pos,i=this._getString(e);return t.matchString(i,!0)?(e.pushBinding(new Y(i.length),n),!0):(e.processFailure(n,this),!1)}getArity(){return 1}substituteParams(e){return new je(this.obj.substituteParams(e))}toDisplayString(){return this.obj.toDisplayString()+" (case-insensitive)"}toFailure(e){return new $(this,this.obj.toFailure(e)+" (case-insensitive)","description")}_isNullable(e,t){return this.obj._isNullable(e,t)}}let mt;ct(r=>{mt=r.rules.applySyntactic.body});const ye=new I("spaces");class Ir{constructor(e,t,n){this.matcher=e,this.startExpr=t,this.grammar=e.grammar,this.input=e.getInput(),this.inputStream=new me(this.input),this.memoTable=e._memoTable,this.userData=void 0,this.doNotMemoize=!1,this._bindings=[],this._bindingOffsets=[],this._applicationStack=[],this._posStack=[0],this.inLexifiedContextStack=[!1],this.rightmostFailurePosition=-1,this._rightmostFailurePositionStack=[],this._recordedFailuresStack=[],n!==void 0&&(this.positionToRecordFailures=n,this.recordedFailures=Object.create(null))}posToOffset(e){return e-this._posStack[this._posStack.length-1]}enterApplication(e,t){this._posStack.push(this.inputStream.pos),this._applicationStack.push(t),this.inLexifiedContextStack.push(!1),e.enter(t),this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this.rightmostFailurePosition=-1}exitApplication(e,t){const n=this._posStack.pop();this._applicationStack.pop(),this.inLexifiedContextStack.pop(),e.exit(),this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,this._rightmostFailurePositionStack.pop()),t&&this.pushBinding(t,n)}enterLexifiedContext(){this.inLexifiedContextStack.push(!0)}exitLexifiedContext(){this.inLexifiedContextStack.pop()}currentApplication(){return this._applicationStack[this._applicationStack.length-1]}inSyntacticContext(){const e=this.currentApplication();return e?e.isSyntactic()&&!this.inLexifiedContext():this.startExpr.factors[0].isSyntactic()}inLexifiedContext(){return this.inLexifiedContextStack[this.inLexifiedContextStack.length-1]}skipSpaces(){return this.pushFailuresInfo(),this.eval(ye),this.popBinding(),this.popFailuresInfo(),this.inputStream.pos}skipSpacesIfInSyntacticContext(){return this.inSyntacticContext()?this.skipSpaces():this.inputStream.pos}maybeSkipSpacesBefore(e){return e.allowsSkippingPrecedingSpace()&&e!==ye?this.skipSpacesIfInSyntacticContext():this.inputStream.pos}pushBinding(e,t){this._bindings.push(e),this._bindingOffsets.push(this.posToOffset(t))}popBinding(){this._bindings.pop(),this._bindingOffsets.pop()}numBindings(){return this._bindings.length}truncateBindings(e){for(;this._bindings.length>e;)this.popBinding()}getCurrentPosInfo(){return this.getPosInfo(this.inputStream.pos)}getPosInfo(e){let t=this.memoTable[e];return t||(t=this.memoTable[e]=new ar),t}processFailure(e,t){if(this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,e),this.recordedFailures&&e===this.positionToRecordFailures){const n=this.currentApplication();n&&(t=t.substituteParams(n.args)),this.recordFailure(t.toFailure(this.grammar),!1)}}recordFailure(e,t){const n=e.toKey();this.recordedFailures[n]?this.recordedFailures[n].isFluffy()&&!e.isFluffy()&&this.recordedFailures[n].clearFluffy():this.recordedFailures[n]=t?e.clone():e}recordFailures(e,t){Object.keys(e).forEach(n=>{this.recordFailure(e[n],t)})}cloneRecordedFailures(){if(!this.recordedFailures)return;const e=Object.create(null);return Object.keys(this.recordedFailures).forEach(t=>{e[t]=this.recordedFailures[t].clone()}),e}getRightmostFailurePosition(){return this.rightmostFailurePosition}_getRightmostFailureOffset(){return this.rightmostFailurePosition>=0?this.posToOffset(this.rightmostFailurePosition):-1}getMemoizedTraceEntry(e,t){const n=this.memoTable[e];if(n&&t instanceof I){const i=n.memo[t.toMemoKey()];if(i&&i.traceEntry){const s=i.traceEntry.cloneWithExpr(t);return s.isMemoized=!0,s}}return null}getTraceEntry(e,t,n,i){if(t instanceof I){const s=this.currentApplication(),o=s?s.args:[];t=t.substituteParams(o)}return this.getMemoizedTraceEntry(e,t)||new H(this.input,e,this.inputStream.pos,t,n,i,this.trace)}isTracing(){return!!this.trace}hasNecessaryInfo(e){return this.trace&&!e.traceEntry?!1:this.recordedFailures&&this.inputStream.pos+e.rightmostFailureOffset===this.positionToRecordFailures?!!e.failuresAtRightmostPosition:!0}useMemoizedResult(e,t){this.trace&&this.trace.push(t.traceEntry);const n=this.inputStream.pos+t.rightmostFailureOffset;return this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,n),this.recordedFailures&&this.positionToRecordFailures===n&&t.failuresAtRightmostPosition&&this.recordFailures(t.failuresAtRightmostPosition,!0),this.inputStream.examinedLength=Math.max(this.inputStream.examinedLength,t.examinedLength+e),t.value?(this.inputStream.pos+=t.matchLength,this.pushBinding(t.value,e),!0):!1}eval(e){const{inputStream:t}=this,n=this._bindings.length,i=this.userData;let s;this.recordedFailures&&(s=this.recordedFailures,this.recordedFailures=Object.create(null));const o=t.pos,u=this.maybeSkipSpacesBefore(e);let a;this.trace&&(a=this.trace,this.trace=[]);const c=e.eval(this);if(this.trace){const l=this._bindings.slice(n),p=this.getTraceEntry(u,e,c,l);p.isImplicitSpaces=e===ye,p.isRootNode=e===this.startExpr,a.push(p),this.trace=a}return c?this.recordedFailures&&t.pos===this.positionToRecordFailures&&Object.keys(this.recordedFailures).forEach(l=>{this.recordedFailures[l].makeFluffy()}):(t.pos=o,this.truncateBindings(n),this.userData=i),this.recordedFailures&&this.recordFailures(s,!1),e===mt&&this.skipSpaces(),c}getMatchResult(){this.grammar._setUpMatchState(this),this.eval(this.startExpr);let e;this.recordedFailures&&(e=Object.keys(this.recordedFailures).map(n=>this.recordedFailures[n]));const t=this._bindings[0];return t&&(t.grammar=this.grammar),new lt(this.matcher,this.input,this.startExpr,t,this._bindingOffsets[0],this.rightmostFailurePosition,e)}getTrace(){this.trace=[];const e=this.getMatchResult(),t=this.trace[this.trace.length-1];return t.result=e,t}pushFailuresInfo(){this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this._recordedFailuresStack.push(this.recordedFailures)}popFailuresInfo(){this.rightmostFailurePosition=this._rightmostFailurePositionStack.pop(),this.recordedFailures=this._recordedFailuresStack.pop()}}class xr{constructor(e){this.grammar=e,this._memoTable=[],this._input="",this._isMemoTableStale=!1}_resetMemoTable(){this._memoTable=[],this._isMemoTableStale=!1}getInput(){return this._input}setInput(e){return this._input!==e&&this.replaceInputRange(0,this._input.length,e),this}replaceInputRange(e,t,n){const i=this._input,s=this._memoTable;if(e<0||e>i.length||t<0||t>i.length||e>t)throw new Error("Invalid indices: "+e+" and "+t);this._input=i.slice(0,e)+n+i.slice(t),this._input!==i&&s.length>0&&(this._isMemoTableStale=!0);const o=s.slice(t);s.length=e;for(let u=0;uObject.prototype.hasOwnProperty.call(r,e);class Ke{constructor(e,t,n){this._node=e,this.source=t,this._baseInterval=n,e.isNonterminal()&&V(t===n),this._childWrappers=[]}_forgetMemoizedResultFor(e){delete this._node[this._semantics.attributeKeys[e]],this.children.forEach(t=>{t._forgetMemoizedResultFor(e)})}child(e){if(!(0<=e&&eo._node),i=new ht(n,[],-1,!1),s=this._semantics.wrap(i,null,null);return s._childWrappers=t,s}get children(){return this._children()}get ctorName(){return this._node.ctorName}get numChildren(){return this._node.numChildren()}get sourceString(){return this.source.contents}}class q{constructor(e,t){const n=this;if(this.grammar=e,this.checkedActionDicts=!1,this.Wrapper=class extends(t?t.Wrapper:Ke){constructor(i,s,o){super(i,s,o),n.checkActionDictsIfHaventAlready(),this._semantics=n}toString(){return"[semantics wrapper for "+n.grammar.name+"]"}},this.super=t,t){if(!(e.equals(this.super.grammar)||e._inheritsFrom(this.super.grammar)))throw new Error("Cannot extend a semantics for grammar '"+this.super.grammar.name+"' for use with grammar '"+e.name+"' (not a sub-grammar)");this.operations=Object.create(this.super.operations),this.attributes=Object.create(this.super.attributes),this.attributeKeys=Object.create(null);for(const i in this.attributes)Object.defineProperty(this.attributeKeys,i,{value:$e(i)})}else this.operations=Object.create(null),this.attributes=Object.create(null),this.attributeKeys=Object.create(null)}toString(){return"[semantics for "+this.grammar.name+"]"}checkActionDictsIfHaventAlready(){this.checkedActionDicts||(this.checkActionDicts(),this.checkedActionDicts=!0)}checkActionDicts(){let e;for(e in this.operations)this.operations[e].checkActionDict(this.grammar);for(e in this.attributes)this.attributes[e].checkActionDict(this.grammar)}toRecipe(e){function t(i){return i.super!==q.BuiltInSemantics._getSemantics()}let n=`(function(g) { `;if(t(this)){n+=" var semantics = "+this.super.toRecipe(!0)+"(g";const i=this.super.grammar;let s=this.grammar;for(;s!==i;)n+=".superGrammar",s=s.superGrammar;n+=`); `,n+=" return g.extendSemantics(semantics)"}else n+=" return g.createSemantics()";return["Operation","Attribute"].forEach(i=>{const s=this[i.toLowerCase()+"s"];Object.keys(s).forEach(o=>{const{actionDict:u,formals:a,builtInDefault:c}=s[o];let l=o;a.length>0&&(l+="("+a.join(", ")+")");let p;t(this)&&this.super[i.toLowerCase()+"s"][o]?p="extend"+i:p="add"+i,n+=` .`+p+"("+JSON.stringify(l)+", {";const h=[];Object.keys(u).forEach(m=>{if(u[m]!==c){let f=u[m].toString().trim();f=f.replace(/^.*\(/,"function("),h.push(` `+JSON.stringify(m)+": "+f)}}),n+=h.join(",")+` })`})}),n+=`; })`,e||(n=`(function() { var grammar = this.fromRecipe(`+this.grammar.toRecipe()+`); var semantics = `+n+`(grammar); return semantics; }); `),n}addOperationOrAttribute(e,t,n){const i=e+"s",s=ze(t,e),{name:o}=s,{formals:u}=s;this.assertNewName(o,e);const a=Sr(e,o,p),c={_default:a};Object.keys(n).forEach(h=>{c[h]=n[h]});const l=e==="operation"?new oe(o,u,c,a):new Ne(o,c,a);l.checkActionDict(this.grammar),this[i][o]=l;function p(...h){const m=this._semantics[i][o];if(arguments.length!==m.formals.length)throw new Error("Invalid number of arguments passed to "+o+" "+e+" (expected "+m.formals.length+", got "+arguments.length+")");const f=Object.create(null);for(const[S,x]of Object.entries(h)){const y=m.formals[S];f[y]=x}const b=this.args;this.args=f;const v=m.execute(this._semantics,this);return this.args=b,v}e==="operation"?(this.Wrapper.prototype[o]=p,this.Wrapper.prototype[o].toString=function(){return"["+o+" operation]"}):(Object.defineProperty(this.Wrapper.prototype,o,{get:p,configurable:!0}),Object.defineProperty(this.attributeKeys,o,{value:$e(o)}))}extendOperationOrAttribute(e,t,n){const i=e+"s";if(ze(t,"attribute"),!(this.super&&t in this.super[i]))throw new Error("Cannot extend "+e+" '"+t+"': did not inherit an "+e+" with that name");if(Re(this[i],t))throw new Error("Cannot extend "+e+" '"+t+"' again");const s=this[i][t].formals,o=this[i][t].actionDict,u=Object.create(o);Object.keys(n).forEach(a=>{u[a]=n[a]}),this[i][t]=e==="operation"?new oe(t,s,u):new Ne(t,u),this[i][t].checkActionDict(this.grammar)}assertNewName(e,t){if(Re(Ke.prototype,e))throw new Error("Cannot add "+t+" '"+e+"': that's a reserved name");if(e in this.operations)throw new Error("Cannot add "+t+" '"+e+"': an operation with that name already exists");if(e in this.attributes)throw new Error("Cannot add "+t+" '"+e+"': an attribute with that name already exists")}wrap(e,t,n){const i=n||t;return e instanceof this.Wrapper?e:new this.Wrapper(e,t,i)}}function ze(r,e){if(!q.prototypeGrammar)return V(r.indexOf("(")===-1),{name:r,formals:[]};const t=q.prototypeGrammar.match(r,e==="operation"?"OperationSignature":"AttributeSignature");if(t.failed())throw new Error(t.message);return q.prototypeGrammarSemantics(t).parse()}function Sr(r,e,t){return function(...n){const i=(this._semantics.operations[e]||this._semantics.attributes[e]).formals.map(s=>this.args[s]);if(!this.isIteration()&&n.length===1)return t.apply(n[0],i);throw tr(this.ctorName,e,r,ne)}}q.createSemantics=function(r,e){const t=new q(r,e!==void 0?e:q.BuiltInSemantics._getSemantics()),n=function(i){if(!(i instanceof lt))throw new TypeError("Semantics expected a MatchResult, but got "+Pe(i));if(i.failed())throw new TypeError("cannot apply Semantics to "+i.toString());const s=i._cst;if(s.grammar!==r)throw new Error("Cannot use a MatchResult from grammar '"+s.grammar.name+"' with a semantics for '"+r.name+"'");const o=new me(i.input);return t.wrap(s,o.interval(i._cstOffset,i.input.length))};return n.addOperation=function(i,s){return t.addOperationOrAttribute("operation",i,s),n},n.extendOperation=function(i,s){return t.extendOperationOrAttribute("operation",i,s),n},n.addAttribute=function(i,s){return t.addOperationOrAttribute("attribute",i,s),n},n.extendAttribute=function(i,s){return t.extendOperationOrAttribute("attribute",i,s),n},n._getActionDict=function(i){const s=t.operations[i]||t.attributes[i];if(!s)throw new Error('"'+i+'" is not a valid operation or attribute name in this semantics for "'+r.name+'"');return s.actionDict},n._remove=function(i){let s;return i in t.operations?(s=t.operations[i],delete t.operations[i]):i in t.attributes&&(s=t.attributes[i],delete t.attributes[i]),delete t.Wrapper.prototype[i],s},n.getOperationNames=function(){return Object.keys(t.operations)},n.getAttributeNames=function(){return Object.keys(t.attributes)},n.getGrammar=function(){return t.grammar},n.toRecipe=function(i){return t.toRecipe(i)},n.toString=t.toString.bind(t),n._getSemantics=function(){return t},n};class oe{constructor(e,t,n,i){this.name=e,this.formals=t,this.actionDict=n,this.builtInDefault=i}checkActionDict(e){e._checkTopDownActionDict(this.typeName,this.name,this.actionDict)}execute(e,t){try{const{ctorName:n}=t._node;let i=this.actionDict[n];return i?(ne.push([this,n]),i.apply(t,t._children())):t.isNonterminal()&&(i=this.actionDict._nonterminal,i)?(ne.push([this,"_nonterminal",n]),i.apply(t,t._children())):(ne.push([this,"default action",n]),this.actionDict._default.apply(t,t._children()))}finally{ne.pop()}}}oe.prototype.typeName="operation";class Ne extends oe{constructor(e,t,n){super(e,[],t,n)}execute(e,t){const n=t._node,i=e.attributeKeys[this.name];return Re(n,i)||(n[i]=oe.prototype.execute.call(this,e,t)),n[i]}}Ne.prototype.typeName="attribute";const He=["_iter","_terminal","_nonterminal","_default"];function Ve(r){return Object.keys(r.rules).sort().map(e=>r.rules[e])}const br=r=>r.replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029");let ft,dt;class j{constructor(e,t,n,i){if(this.name=e,this.superGrammar=t,this.rules=n,i){if(!(i in n))throw new Error("Invalid start rule: '"+i+"' is not a rule in grammar '"+e+"'");this.defaultStartRule=i}this._matchStateInitializer=void 0,this.supportsIncrementalParsing=!0}matcher(){return new xr(this)}isBuiltIn(){return this===j.ProtoBuiltInRules||this===j.BuiltInRules}equals(e){if(this===e)return!0;if(e==null||this.name!==e.name||this.defaultStartRule!==e.defaultStartRule||!(this.superGrammar===e.superGrammar||this.superGrammar.equals(e.superGrammar)))return!1;const t=Ve(this),n=Ve(e);return t.length===n.length&&t.every((i,s)=>i.description===n[s].description&&i.formals.join(",")===n[s].formals.join(",")&&i.body.toString()===n[s].body.toString())}match(e,t){const n=this.matcher();return n.replaceInputRange(0,0,e),n.match(t)}trace(e,t){const n=this.matcher();return n.replaceInputRange(0,0,e),n.trace(t)}createSemantics(){return q.createSemantics(this)}extendSemantics(e){return q.createSemantics(this,e._getSemantics())}_checkTopDownActionDict(e,t,n){const i=[];for(const s in n){const o=n[s];if(!He.includes(s)&&!(s in this.rules)){i.push(`'${s}' is not a valid semantic action for '${this.name}'`);continue}if(typeof o!="function"){i.push(`'${s}' must be a function in an action dictionary for '${this.name}'`);continue}const u=o.length,a=this._topDownActionArity(s);if(u!==a){let c;s==="_iter"||s==="_nonterminal"?c=`it should use a rest parameter, e.g. \`${s}(...children) {}\`. NOTE: this is new in Ohm v16 — see https://ohmjs.org/d/ati for details.`:c=`expected ${a}, got ${u}`,i.push(`Semantic action '${s}' has the wrong arity: ${c}`)}}if(i.length>0){const s=i.map(u=>"- "+u),o=new Error([`Found errors in the action dictionary of the '${t}' ${e}:`,...s].join(` `));throw o.problems=i,o}}_topDownActionArity(e){return He.includes(e)?0:this.rules[e].body.getArity()}_inheritsFrom(e){let t=this.superGrammar;for(;t;){if(t.equals(e,!0))return!0;t=t.superGrammar}return!1}toRecipe(e=void 0){const t={};this.source&&(t.source=this.source.contents);let n=null;this.defaultStartRule&&(n=this.defaultStartRule);const i={};Object.keys(this.rules).forEach(u=>{const a=this.rules[u],{body:c}=a,l=!this.superGrammar||!this.superGrammar.rules[u];let p;l?p="define":p=c instanceof pe?"extend":"override";const h={};if(a.source&&this.source){const b=a.source.relativeTo(this.source);h.sourceInterval=[b.startIdx,b.endIdx]}const m=l?a.description:null,f=c.outputRecipe(a.formals,this.source);i[u]=[p,h,m,a.formals,f]});let s="null";e?s=e:this.superGrammar&&!this.superGrammar.isBuiltIn()&&(s=this.superGrammar.toRecipe());const o=[...["grammar",t,this.name].map(JSON.stringify),s,...[n,i].map(JSON.stringify)];return br(`[${o.join(",")}]`)}toOperationActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}toAttributeActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}_toOperationOrAttributeActionDictionaryTemplate(){const e=new Q;e.append("{");let t=!0;for(const n in this.rules){const{body:i}=this.rules[n];t?t=!1:e.append(","),e.append(` `),e.append(" "),this.addSemanticActionTemplate(n,i,e)}return e.append(` }`),e.contents()}addSemanticActionTemplate(e,t,n){n.append(e),n.append(": function(");const i=this._topDownActionArity(e);n.append(le("_",i).join(", ")),n.append(`) { `),n.append(" }")}parseApplication(e){let t;if(e.indexOf("<")===-1)t=new I(e);else{const i=ft.match(e,"Base_application");t=dt(i,{})}if(!(t.ruleName in this.rules))throw st(t.ruleName,this.name);const{formals:n}=this.rules[t.ruleName];if(n.length!==t.args.length){const{source:i}=this.rules[t.ruleName];throw ot(t.ruleName,n.length,t.args.length,i)}return t}_setUpMatchState(e){this._matchStateInitializer&&this._matchStateInitializer(e)}}j.ProtoBuiltInRules=new j("ProtoBuiltInRules",void 0,{any:{body:L,formals:[],description:"any character",primitive:!0},end:{body:E,formals:[],description:"end of input",primitive:!0},caseInsensitive:{body:new je(new F(0)),formals:["str"],primitive:!0},lower:{body:new R("Ll"),formals:[],description:"a lowercase letter",primitive:!0},upper:{body:new R("Lu"),formals:[],description:"an uppercase letter",primitive:!0},unicodeLtmo:{body:new R("Ltmo"),formals:[],description:"a Unicode character in Lt, Lm, or Lo",primitive:!0},spaces:{body:new Z(new I("space")),formals:[]},space:{body:new C("\0"," "),formals:[],description:"a space"}});j.initApplicationParser=function(r,e){ft=r,dt=e};class We{constructor(e){this.name=e}sourceInterval(e,t){return this.source.subInterval(e,t-e)}ensureSuperGrammar(){return this.superGrammar||this.withSuperGrammar(this.name==="BuiltInRules"?j.ProtoBuiltInRules:j.BuiltInRules),this.superGrammar}ensureSuperGrammarRuleForOverriding(e,t){const n=this.ensureSuperGrammar().rules[e];if(!n)throw Kt(e,this.superGrammar.name,t);return n}installOverriddenOrExtendedRule(e,t,n,i){const s=we(t);if(s.length>0)throw Be(e,s,i);const o=this.ensureSuperGrammar().rules[e],u=o.formals,a=u?u.length:0;if(t.length!==a)throw ot(e,a,t.length,i);return this.install(e,t,n,o.description,i)}install(e,t,n,i,s,o=!1){return this.rules[e]={body:n.introduceParams(t),formals:t,description:i,source:s,primitive:o},this}withSuperGrammar(e){if(this.superGrammar)throw new Error("the super grammar of a GrammarDecl cannot be set more than once");return this.superGrammar=e,this.rules=Object.create(e.rules),e.isBuiltIn()||(this.defaultStartRule=e.defaultStartRule),this}withDefaultStartRule(e){return this.defaultStartRule=e,this}withSource(e){return this.source=new me(e).interval(0,e.length),this}build(){const e=new j(this.name,this.ensureSuperGrammar(),this.rules,this.defaultStartRule);e._matchStateInitializer=e.superGrammar._matchStateInitializer,e.supportsIncrementalParsing=e.superGrammar.supportsIncrementalParsing;const t=[];let n=!1;return Object.keys(e.rules).forEach(i=>{const{body:s}=e.rules[i];try{s.assertChoicesHaveUniformArity(i)}catch(o){t.push(o)}try{s.assertAllApplicationsAreValid(i,e)}catch(o){t.push(o),n=!0}}),n||Object.keys(e.rules).forEach(i=>{const{body:s}=e.rules[i];try{s.assertIteratedExprsAreNotNullable(e,[])}catch(o){t.push(o)}}),t.length>0&&rr(t),this.source&&(e.source=this.source),e}define(e,t,n,i,s,o){if(this.ensureSuperGrammar(),this.superGrammar.rules[e])throw De(e,this.name,this.superGrammar.name,s);if(this.rules[e])throw De(e,this.name,this.name,s);const u=we(t);if(u.length>0)throw Be(e,u,s);return this.install(e,t,n,i,s,o)}override(e,t,n,i,s){return this.ensureSuperGrammarRuleForOverriding(e,s),this.installOverriddenOrExtendedRule(e,t,n,s),this}extend(e,t,n,i,s){if(!this.ensureSuperGrammar().rules[e])throw zt(e,this.superGrammar.name,s);const o=new pe(this.superGrammar,e,n);return o.source=n.source,this.installOverriddenOrExtendedRule(e,t,o,s),this}}class ce{constructor(){this.currentDecl=null,this.currentRuleName=null}newGrammar(e){return new We(e)}grammar(e,t,n,i,s){const o=new We(t);return n&&o.withSuperGrammar(n instanceof j?n:this.fromRecipe(n)),i&&o.withDefaultStartRule(i),e&&e.source&&o.withSource(e.source),this.currentDecl=o,Object.keys(s).forEach(u=>{this.currentRuleName=u;const a=s[u],c=a[0],l=a[1],p=a[2],h=a[3],m=this.fromRecipe(a[4]);let f;o.source&&l&&l.sourceInterval&&(f=o.source.subInterval(l.sourceInterval[0],l.sourceInterval[1]-l.sourceInterval[0])),o[c](u,h,m,p,f)}),this.currentRuleName=this.currentDecl=null,o.build()}terminal(e){return new N(e)}range(e,t){return new C(e,t)}param(e){return new F(e)}alt(...e){let t=[];for(let n of e)n instanceof g||(n=this.fromRecipe(n)),n instanceof A?t=t.concat(n.terms):t.push(n);return t.length===1?t[0]:new A(t)}seq(...e){let t=[];for(let n of e)n instanceof g||(n=this.fromRecipe(n)),n instanceof O?t=t.concat(n.factors):t.push(n);return t.length===1?t[0]:new O(t)}star(e){return e instanceof g||(e=this.fromRecipe(e)),new Z(e)}plus(e){return e instanceof g||(e=this.fromRecipe(e)),new X(e)}opt(e){return e instanceof g||(e=this.fromRecipe(e)),new z(e)}not(e){return e instanceof g||(e=this.fromRecipe(e)),new k(e)}lookahead(e){return e instanceof g||(e=this.fromRecipe(e)),new D(e)}lex(e){return e instanceof g||(e=this.fromRecipe(e)),new G(e)}app(e,t){return t&&t.length>0&&(t=t.map(function(n){return n instanceof g?n:this.fromRecipe(n)},this)),new I(e,t)}splice(e,t){return new he(this.currentDecl.superGrammar,this.currentRuleName,e.map(n=>this.fromRecipe(n)),t.map(n=>this.fromRecipe(n)))}fromRecipe(e){const t=e[0]==="grammar"?e.slice(1):e.slice(2),n=this[e[0]](...t),i=e[1];return i&&i.sourceInterval&&this.currentDecl&&n.withSource(this.currentDecl.sourceInterval(...i.sourceInterval)),n}}function Me(r){return typeof r=="function"?r.call(new ce):(typeof r=="string"&&(r=JSON.parse(r)),new ce().fromRecipe(r))}const Te=Me(["grammar",{source:`BuiltInRules { alnum (an alpha-numeric character) = letter | digit letter (a letter) = lower | upper | unicodeLtmo digit (a digit) = "0".."9" hexDigit (a hexadecimal digit) = digit | "a".."f" | "A".."F" ListOf = NonemptyListOf | EmptyListOf NonemptyListOf = elem (sep elem)* EmptyListOf = /* nothing */ listOf = nonemptyListOf | emptyListOf nonemptyListOf = elem (sep elem)* emptyListOf = /* nothing */ // Allows a syntactic rule application within a lexical context. applySyntactic = app }`},"BuiltInRules",null,null,{alnum:["define",{sourceInterval:[18,78]},"an alpha-numeric character",[],["alt",{sourceInterval:[60,78]},["app",{sourceInterval:[60,66]},"letter",[]],["app",{sourceInterval:[73,78]},"digit",[]]]],letter:["define",{sourceInterval:[82,142]},"a letter",[],["alt",{sourceInterval:[107,142]},["app",{sourceInterval:[107,112]},"lower",[]],["app",{sourceInterval:[119,124]},"upper",[]],["app",{sourceInterval:[131,142]},"unicodeLtmo",[]]]],digit:["define",{sourceInterval:[146,177]},"a digit",[],["range",{sourceInterval:[169,177]},"0","9"]],hexDigit:["define",{sourceInterval:[181,254]},"a hexadecimal digit",[],["alt",{sourceInterval:[219,254]},["app",{sourceInterval:[219,224]},"digit",[]],["range",{sourceInterval:[231,239]},"a","f"],["range",{sourceInterval:[246,254]},"A","F"]]],ListOf:["define",{sourceInterval:[258,336]},null,["elem","sep"],["alt",{sourceInterval:[282,336]},["app",{sourceInterval:[282,307]},"NonemptyListOf",[["param",{sourceInterval:[297,301]},0],["param",{sourceInterval:[303,306]},1]]],["app",{sourceInterval:[314,336]},"EmptyListOf",[["param",{sourceInterval:[326,330]},0],["param",{sourceInterval:[332,335]},1]]]]],NonemptyListOf:["define",{sourceInterval:[340,388]},null,["elem","sep"],["seq",{sourceInterval:[372,388]},["param",{sourceInterval:[372,376]},0],["star",{sourceInterval:[377,388]},["seq",{sourceInterval:[378,386]},["param",{sourceInterval:[378,381]},1],["param",{sourceInterval:[382,386]},0]]]]],EmptyListOf:["define",{sourceInterval:[392,434]},null,["elem","sep"],["seq",{sourceInterval:[438,438]}]],listOf:["define",{sourceInterval:[438,516]},null,["elem","sep"],["alt",{sourceInterval:[462,516]},["app",{sourceInterval:[462,487]},"nonemptyListOf",[["param",{sourceInterval:[477,481]},0],["param",{sourceInterval:[483,486]},1]]],["app",{sourceInterval:[494,516]},"emptyListOf",[["param",{sourceInterval:[506,510]},0],["param",{sourceInterval:[512,515]},1]]]]],nonemptyListOf:["define",{sourceInterval:[520,568]},null,["elem","sep"],["seq",{sourceInterval:[552,568]},["param",{sourceInterval:[552,556]},0],["star",{sourceInterval:[557,568]},["seq",{sourceInterval:[558,566]},["param",{sourceInterval:[558,561]},1],["param",{sourceInterval:[562,566]},0]]]]],emptyListOf:["define",{sourceInterval:[572,682]},null,["elem","sep"],["seq",{sourceInterval:[685,685]}]],applySyntactic:["define",{sourceInterval:[685,710]},null,["app"],["param",{sourceInterval:[707,710]},0]]}]);j.BuiltInRules=Te;sr(j.BuiltInRules);const ke=Me(["grammar",{source:`Ohm { Grammars = Grammar* Grammar = ident SuperGrammar? "{" Rule* "}" SuperGrammar = "<:" ident Rule = ident Formals? ruleDescr? "=" RuleBody -- define | ident Formals? ":=" OverrideRuleBody -- override | ident Formals? "+=" RuleBody -- extend RuleBody = "|"? NonemptyListOf TopLevelTerm = Seq caseName -- inline | Seq OverrideRuleBody = "|"? NonemptyListOf OverrideTopLevelTerm = "..." -- superSplice | TopLevelTerm Formals = "<" ListOf ">" Params = "<" ListOf ">" Alt = NonemptyListOf Seq = Iter* Iter = Pred "*" -- star | Pred "+" -- plus | Pred "?" -- opt | Pred Pred = "~" Lex -- not | "&" Lex -- lookahead | Lex Lex = "#" Base -- lex | Base Base = ident Params? ~(ruleDescr? "=" | ":=" | "+=") -- application | oneCharTerminal ".." oneCharTerminal -- range | terminal -- terminal | "(" Alt ")" -- paren ruleDescr (a rule description) = "(" ruleDescrText ")" ruleDescrText = (~")" any)* caseName = "--" (~"\\n" space)* name (~"\\n" space)* ("\\n" | &"}") name (a name) = nameFirst nameRest* nameFirst = "_" | letter nameRest = "_" | alnum ident (an identifier) = name terminal = "\\"" terminalChar* "\\"" oneCharTerminal = "\\"" terminalChar "\\"" terminalChar = escapeChar | ~"\\\\" ~"\\"" ~"\\n" "\\u{0}".."\\u{10FFFF}" escapeChar (an escape sequence) = "\\\\\\\\" -- backslash | "\\\\\\"" -- doubleQuote | "\\\\\\'" -- singleQuote | "\\\\b" -- backspace | "\\\\n" -- lineFeed | "\\\\r" -- carriageReturn | "\\\\t" -- tab | "\\\\u{" hexDigit hexDigit? hexDigit? hexDigit? hexDigit? hexDigit? "}" -- unicodeCodePoint | "\\\\u" hexDigit hexDigit hexDigit hexDigit -- unicodeEscape | "\\\\x" hexDigit hexDigit -- hexEscape space += comment comment = "//" (~"\\n" any)* &("\\n" | end) -- singleLine | "/*" (~"*/" any)* "*/" -- multiLine tokens = token* token = caseName | comment | ident | operator | punctuation | terminal | any operator = "<:" | "=" | ":=" | "+=" | "*" | "+" | "?" | "~" | "&" punctuation = "<" | ">" | "," | "--" }`},"Ohm",null,"Grammars",{Grammars:["define",{sourceInterval:[9,32]},null,[],["star",{sourceInterval:[24,32]},["app",{sourceInterval:[24,31]},"Grammar",[]]]],Grammar:["define",{sourceInterval:[36,83]},null,[],["seq",{sourceInterval:[50,83]},["app",{sourceInterval:[50,55]},"ident",[]],["opt",{sourceInterval:[56,69]},["app",{sourceInterval:[56,68]},"SuperGrammar",[]]],["terminal",{sourceInterval:[70,73]},"{"],["star",{sourceInterval:[74,79]},["app",{sourceInterval:[74,78]},"Rule",[]]],["terminal",{sourceInterval:[80,83]},"}"]]],SuperGrammar:["define",{sourceInterval:[87,116]},null,[],["seq",{sourceInterval:[106,116]},["terminal",{sourceInterval:[106,110]},"<:"],["app",{sourceInterval:[111,116]},"ident",[]]]],Rule_define:["define",{sourceInterval:[131,181]},null,[],["seq",{sourceInterval:[131,170]},["app",{sourceInterval:[131,136]},"ident",[]],["opt",{sourceInterval:[137,145]},["app",{sourceInterval:[137,144]},"Formals",[]]],["opt",{sourceInterval:[146,156]},["app",{sourceInterval:[146,155]},"ruleDescr",[]]],["terminal",{sourceInterval:[157,160]},"="],["app",{sourceInterval:[162,170]},"RuleBody",[]]]],Rule_override:["define",{sourceInterval:[188,248]},null,[],["seq",{sourceInterval:[188,235]},["app",{sourceInterval:[188,193]},"ident",[]],["opt",{sourceInterval:[194,202]},["app",{sourceInterval:[194,201]},"Formals",[]]],["terminal",{sourceInterval:[214,218]},":="],["app",{sourceInterval:[219,235]},"OverrideRuleBody",[]]]],Rule_extend:["define",{sourceInterval:[255,305]},null,[],["seq",{sourceInterval:[255,294]},["app",{sourceInterval:[255,260]},"ident",[]],["opt",{sourceInterval:[261,269]},["app",{sourceInterval:[261,268]},"Formals",[]]],["terminal",{sourceInterval:[281,285]},"+="],["app",{sourceInterval:[286,294]},"RuleBody",[]]]],Rule:["define",{sourceInterval:[120,305]},null,[],["alt",{sourceInterval:[131,305]},["app",{sourceInterval:[131,170]},"Rule_define",[]],["app",{sourceInterval:[188,235]},"Rule_override",[]],["app",{sourceInterval:[255,294]},"Rule_extend",[]]]],RuleBody:["define",{sourceInterval:[309,362]},null,[],["seq",{sourceInterval:[324,362]},["opt",{sourceInterval:[324,328]},["terminal",{sourceInterval:[324,327]},"|"]],["app",{sourceInterval:[329,362]},"NonemptyListOf",[["app",{sourceInterval:[344,356]},"TopLevelTerm",[]],["terminal",{sourceInterval:[358,361]},"|"]]]]],TopLevelTerm_inline:["define",{sourceInterval:[385,408]},null,[],["seq",{sourceInterval:[385,397]},["app",{sourceInterval:[385,388]},"Seq",[]],["app",{sourceInterval:[389,397]},"caseName",[]]]],TopLevelTerm:["define",{sourceInterval:[366,418]},null,[],["alt",{sourceInterval:[385,418]},["app",{sourceInterval:[385,397]},"TopLevelTerm_inline",[]],["app",{sourceInterval:[415,418]},"Seq",[]]]],OverrideRuleBody:["define",{sourceInterval:[422,491]},null,[],["seq",{sourceInterval:[445,491]},["opt",{sourceInterval:[445,449]},["terminal",{sourceInterval:[445,448]},"|"]],["app",{sourceInterval:[450,491]},"NonemptyListOf",[["app",{sourceInterval:[465,485]},"OverrideTopLevelTerm",[]],["terminal",{sourceInterval:[487,490]},"|"]]]]],OverrideTopLevelTerm_superSplice:["define",{sourceInterval:[522,543]},null,[],["terminal",{sourceInterval:[522,527]},"..."]],OverrideTopLevelTerm:["define",{sourceInterval:[495,562]},null,[],["alt",{sourceInterval:[522,562]},["app",{sourceInterval:[522,527]},"OverrideTopLevelTerm_superSplice",[]],["app",{sourceInterval:[550,562]},"TopLevelTerm",[]]]],Formals:["define",{sourceInterval:[566,606]},null,[],["seq",{sourceInterval:[580,606]},["terminal",{sourceInterval:[580,583]},"<"],["app",{sourceInterval:[584,602]},"ListOf",[["app",{sourceInterval:[591,596]},"ident",[]],["terminal",{sourceInterval:[598,601]},","]]],["terminal",{sourceInterval:[603,606]},">"]]],Params:["define",{sourceInterval:[610,647]},null,[],["seq",{sourceInterval:[623,647]},["terminal",{sourceInterval:[623,626]},"<"],["app",{sourceInterval:[627,643]},"ListOf",[["app",{sourceInterval:[634,637]},"Seq",[]],["terminal",{sourceInterval:[639,642]},","]]],["terminal",{sourceInterval:[644,647]},">"]]],Alt:["define",{sourceInterval:[651,685]},null,[],["app",{sourceInterval:[661,685]},"NonemptyListOf",[["app",{sourceInterval:[676,679]},"Seq",[]],["terminal",{sourceInterval:[681,684]},"|"]]]],Seq:["define",{sourceInterval:[689,704]},null,[],["star",{sourceInterval:[699,704]},["app",{sourceInterval:[699,703]},"Iter",[]]]],Iter_star:["define",{sourceInterval:[719,736]},null,[],["seq",{sourceInterval:[719,727]},["app",{sourceInterval:[719,723]},"Pred",[]],["terminal",{sourceInterval:[724,727]},"*"]]],Iter_plus:["define",{sourceInterval:[743,760]},null,[],["seq",{sourceInterval:[743,751]},["app",{sourceInterval:[743,747]},"Pred",[]],["terminal",{sourceInterval:[748,751]},"+"]]],Iter_opt:["define",{sourceInterval:[767,783]},null,[],["seq",{sourceInterval:[767,775]},["app",{sourceInterval:[767,771]},"Pred",[]],["terminal",{sourceInterval:[772,775]},"?"]]],Iter:["define",{sourceInterval:[708,794]},null,[],["alt",{sourceInterval:[719,794]},["app",{sourceInterval:[719,727]},"Iter_star",[]],["app",{sourceInterval:[743,751]},"Iter_plus",[]],["app",{sourceInterval:[767,775]},"Iter_opt",[]],["app",{sourceInterval:[790,794]},"Pred",[]]]],Pred_not:["define",{sourceInterval:[809,824]},null,[],["seq",{sourceInterval:[809,816]},["terminal",{sourceInterval:[809,812]},"~"],["app",{sourceInterval:[813,816]},"Lex",[]]]],Pred_lookahead:["define",{sourceInterval:[831,852]},null,[],["seq",{sourceInterval:[831,838]},["terminal",{sourceInterval:[831,834]},"&"],["app",{sourceInterval:[835,838]},"Lex",[]]]],Pred:["define",{sourceInterval:[798,862]},null,[],["alt",{sourceInterval:[809,862]},["app",{sourceInterval:[809,816]},"Pred_not",[]],["app",{sourceInterval:[831,838]},"Pred_lookahead",[]],["app",{sourceInterval:[859,862]},"Lex",[]]]],Lex_lex:["define",{sourceInterval:[876,892]},null,[],["seq",{sourceInterval:[876,884]},["terminal",{sourceInterval:[876,879]},"#"],["app",{sourceInterval:[880,884]},"Base",[]]]],Lex:["define",{sourceInterval:[866,903]},null,[],["alt",{sourceInterval:[876,903]},["app",{sourceInterval:[876,884]},"Lex_lex",[]],["app",{sourceInterval:[899,903]},"Base",[]]]],Base_application:["define",{sourceInterval:[918,979]},null,[],["seq",{sourceInterval:[918,963]},["app",{sourceInterval:[918,923]},"ident",[]],["opt",{sourceInterval:[924,931]},["app",{sourceInterval:[924,930]},"Params",[]]],["not",{sourceInterval:[932,963]},["alt",{sourceInterval:[934,962]},["seq",{sourceInterval:[934,948]},["opt",{sourceInterval:[934,944]},["app",{sourceInterval:[934,943]},"ruleDescr",[]]],["terminal",{sourceInterval:[945,948]},"="]],["terminal",{sourceInterval:[951,955]},":="],["terminal",{sourceInterval:[958,962]},"+="]]]]],Base_range:["define",{sourceInterval:[986,1041]},null,[],["seq",{sourceInterval:[986,1022]},["app",{sourceInterval:[986,1001]},"oneCharTerminal",[]],["terminal",{sourceInterval:[1002,1006]},".."],["app",{sourceInterval:[1007,1022]},"oneCharTerminal",[]]]],Base_terminal:["define",{sourceInterval:[1048,1106]},null,[],["app",{sourceInterval:[1048,1056]},"terminal",[]]],Base_paren:["define",{sourceInterval:[1113,1168]},null,[],["seq",{sourceInterval:[1113,1124]},["terminal",{sourceInterval:[1113,1116]},"("],["app",{sourceInterval:[1117,1120]},"Alt",[]],["terminal",{sourceInterval:[1121,1124]},")"]]],Base:["define",{sourceInterval:[907,1168]},null,[],["alt",{sourceInterval:[918,1168]},["app",{sourceInterval:[918,963]},"Base_application",[]],["app",{sourceInterval:[986,1022]},"Base_range",[]],["app",{sourceInterval:[1048,1056]},"Base_terminal",[]],["app",{sourceInterval:[1113,1124]},"Base_paren",[]]]],ruleDescr:["define",{sourceInterval:[1172,1231]},"a rule description",[],["seq",{sourceInterval:[1210,1231]},["terminal",{sourceInterval:[1210,1213]},"("],["app",{sourceInterval:[1214,1227]},"ruleDescrText",[]],["terminal",{sourceInterval:[1228,1231]},")"]]],ruleDescrText:["define",{sourceInterval:[1235,1266]},null,[],["star",{sourceInterval:[1255,1266]},["seq",{sourceInterval:[1256,1264]},["not",{sourceInterval:[1256,1260]},["terminal",{sourceInterval:[1257,1260]},")"]],["app",{sourceInterval:[1261,1264]},"any",[]]]]],caseName:["define",{sourceInterval:[1270,1338]},null,[],["seq",{sourceInterval:[1285,1338]},["terminal",{sourceInterval:[1285,1289]},"--"],["star",{sourceInterval:[1290,1304]},["seq",{sourceInterval:[1291,1302]},["not",{sourceInterval:[1291,1296]},["terminal",{sourceInterval:[1292,1296]},` `]],["app",{sourceInterval:[1297,1302]},"space",[]]]],["app",{sourceInterval:[1305,1309]},"name",[]],["star",{sourceInterval:[1310,1324]},["seq",{sourceInterval:[1311,1322]},["not",{sourceInterval:[1311,1316]},["terminal",{sourceInterval:[1312,1316]},` `]],["app",{sourceInterval:[1317,1322]},"space",[]]]],["alt",{sourceInterval:[1326,1337]},["terminal",{sourceInterval:[1326,1330]},` `],["lookahead",{sourceInterval:[1333,1337]},["terminal",{sourceInterval:[1334,1337]},"}"]]]]],name:["define",{sourceInterval:[1342,1382]},"a name",[],["seq",{sourceInterval:[1363,1382]},["app",{sourceInterval:[1363,1372]},"nameFirst",[]],["star",{sourceInterval:[1373,1382]},["app",{sourceInterval:[1373,1381]},"nameRest",[]]]]],nameFirst:["define",{sourceInterval:[1386,1418]},null,[],["alt",{sourceInterval:[1402,1418]},["terminal",{sourceInterval:[1402,1405]},"_"],["app",{sourceInterval:[1412,1418]},"letter",[]]]],nameRest:["define",{sourceInterval:[1422,1452]},null,[],["alt",{sourceInterval:[1437,1452]},["terminal",{sourceInterval:[1437,1440]},"_"],["app",{sourceInterval:[1447,1452]},"alnum",[]]]],ident:["define",{sourceInterval:[1456,1489]},"an identifier",[],["app",{sourceInterval:[1485,1489]},"name",[]]],terminal:["define",{sourceInterval:[1493,1531]},null,[],["seq",{sourceInterval:[1508,1531]},["terminal",{sourceInterval:[1508,1512]},'"'],["star",{sourceInterval:[1513,1526]},["app",{sourceInterval:[1513,1525]},"terminalChar",[]]],["terminal",{sourceInterval:[1527,1531]},'"']]],oneCharTerminal:["define",{sourceInterval:[1535,1579]},null,[],["seq",{sourceInterval:[1557,1579]},["terminal",{sourceInterval:[1557,1561]},'"'],["app",{sourceInterval:[1562,1574]},"terminalChar",[]],["terminal",{sourceInterval:[1575,1579]},'"']]],terminalChar:["define",{sourceInterval:[1583,1660]},null,[],["alt",{sourceInterval:[1602,1660]},["app",{sourceInterval:[1602,1612]},"escapeChar",[]],["seq",{sourceInterval:[1621,1660]},["not",{sourceInterval:[1621,1626]},["terminal",{sourceInterval:[1622,1626]},"\\"]],["not",{sourceInterval:[1627,1632]},["terminal",{sourceInterval:[1628,1632]},'"']],["not",{sourceInterval:[1633,1638]},["terminal",{sourceInterval:[1634,1638]},` `]],["range",{sourceInterval:[1639,1660]},"\0","􏿿"]]]],escapeChar_backslash:["define",{sourceInterval:[1703,1758]},null,[],["terminal",{sourceInterval:[1703,1709]},"\\\\"]],escapeChar_doubleQuote:["define",{sourceInterval:[1765,1822]},null,[],["terminal",{sourceInterval:[1765,1771]},'\\"']],escapeChar_singleQuote:["define",{sourceInterval:[1829,1886]},null,[],["terminal",{sourceInterval:[1829,1835]},"\\'"]],escapeChar_backspace:["define",{sourceInterval:[1893,1948]},null,[],["terminal",{sourceInterval:[1893,1898]},"\\b"]],escapeChar_lineFeed:["define",{sourceInterval:[1955,2009]},null,[],["terminal",{sourceInterval:[1955,1960]},"\\n"]],escapeChar_carriageReturn:["define",{sourceInterval:[2016,2076]},null,[],["terminal",{sourceInterval:[2016,2021]},"\\r"]],escapeChar_tab:["define",{sourceInterval:[2083,2132]},null,[],["terminal",{sourceInterval:[2083,2088]},"\\t"]],escapeChar_unicodeCodePoint:["define",{sourceInterval:[2139,2243]},null,[],["seq",{sourceInterval:[2139,2221]},["terminal",{sourceInterval:[2139,2145]},"\\u{"],["app",{sourceInterval:[2146,2154]},"hexDigit",[]],["opt",{sourceInterval:[2155,2164]},["app",{sourceInterval:[2155,2163]},"hexDigit",[]]],["opt",{sourceInterval:[2165,2174]},["app",{sourceInterval:[2165,2173]},"hexDigit",[]]],["opt",{sourceInterval:[2188,2197]},["app",{sourceInterval:[2188,2196]},"hexDigit",[]]],["opt",{sourceInterval:[2198,2207]},["app",{sourceInterval:[2198,2206]},"hexDigit",[]]],["opt",{sourceInterval:[2208,2217]},["app",{sourceInterval:[2208,2216]},"hexDigit",[]]],["terminal",{sourceInterval:[2218,2221]},"}"]]],escapeChar_unicodeEscape:["define",{sourceInterval:[2250,2309]},null,[],["seq",{sourceInterval:[2250,2291]},["terminal",{sourceInterval:[2250,2255]},"\\u"],["app",{sourceInterval:[2256,2264]},"hexDigit",[]],["app",{sourceInterval:[2265,2273]},"hexDigit",[]],["app",{sourceInterval:[2274,2282]},"hexDigit",[]],["app",{sourceInterval:[2283,2291]},"hexDigit",[]]]],escapeChar_hexEscape:["define",{sourceInterval:[2316,2371]},null,[],["seq",{sourceInterval:[2316,2339]},["terminal",{sourceInterval:[2316,2321]},"\\x"],["app",{sourceInterval:[2322,2330]},"hexDigit",[]],["app",{sourceInterval:[2331,2339]},"hexDigit",[]]]],escapeChar:["define",{sourceInterval:[1664,2371]},"an escape sequence",[],["alt",{sourceInterval:[1703,2371]},["app",{sourceInterval:[1703,1709]},"escapeChar_backslash",[]],["app",{sourceInterval:[1765,1771]},"escapeChar_doubleQuote",[]],["app",{sourceInterval:[1829,1835]},"escapeChar_singleQuote",[]],["app",{sourceInterval:[1893,1898]},"escapeChar_backspace",[]],["app",{sourceInterval:[1955,1960]},"escapeChar_lineFeed",[]],["app",{sourceInterval:[2016,2021]},"escapeChar_carriageReturn",[]],["app",{sourceInterval:[2083,2088]},"escapeChar_tab",[]],["app",{sourceInterval:[2139,2221]},"escapeChar_unicodeCodePoint",[]],["app",{sourceInterval:[2250,2291]},"escapeChar_unicodeEscape",[]],["app",{sourceInterval:[2316,2339]},"escapeChar_hexEscape",[]]]],space:["extend",{sourceInterval:[2375,2394]},null,[],["app",{sourceInterval:[2387,2394]},"comment",[]]],comment_singleLine:["define",{sourceInterval:[2412,2458]},null,[],["seq",{sourceInterval:[2412,2443]},["terminal",{sourceInterval:[2412,2416]},"//"],["star",{sourceInterval:[2417,2429]},["seq",{sourceInterval:[2418,2427]},["not",{sourceInterval:[2418,2423]},["terminal",{sourceInterval:[2419,2423]},` `]],["app",{sourceInterval:[2424,2427]},"any",[]]]],["lookahead",{sourceInterval:[2430,2443]},["alt",{sourceInterval:[2432,2442]},["terminal",{sourceInterval:[2432,2436]},` `],["app",{sourceInterval:[2439,2442]},"end",[]]]]]],comment_multiLine:["define",{sourceInterval:[2465,2501]},null,[],["seq",{sourceInterval:[2465,2487]},["terminal",{sourceInterval:[2465,2469]},"/*"],["star",{sourceInterval:[2470,2482]},["seq",{sourceInterval:[2471,2480]},["not",{sourceInterval:[2471,2476]},["terminal",{sourceInterval:[2472,2476]},"*/"]],["app",{sourceInterval:[2477,2480]},"any",[]]]],["terminal",{sourceInterval:[2483,2487]},"*/"]]],comment:["define",{sourceInterval:[2398,2501]},null,[],["alt",{sourceInterval:[2412,2501]},["app",{sourceInterval:[2412,2443]},"comment_singleLine",[]],["app",{sourceInterval:[2465,2487]},"comment_multiLine",[]]]],tokens:["define",{sourceInterval:[2505,2520]},null,[],["star",{sourceInterval:[2514,2520]},["app",{sourceInterval:[2514,2519]},"token",[]]]],token:["define",{sourceInterval:[2524,2600]},null,[],["alt",{sourceInterval:[2532,2600]},["app",{sourceInterval:[2532,2540]},"caseName",[]],["app",{sourceInterval:[2543,2550]},"comment",[]],["app",{sourceInterval:[2553,2558]},"ident",[]],["app",{sourceInterval:[2561,2569]},"operator",[]],["app",{sourceInterval:[2572,2583]},"punctuation",[]],["app",{sourceInterval:[2586,2594]},"terminal",[]],["app",{sourceInterval:[2597,2600]},"any",[]]]],operator:["define",{sourceInterval:[2604,2669]},null,[],["alt",{sourceInterval:[2615,2669]},["terminal",{sourceInterval:[2615,2619]},"<:"],["terminal",{sourceInterval:[2622,2625]},"="],["terminal",{sourceInterval:[2628,2632]},":="],["terminal",{sourceInterval:[2635,2639]},"+="],["terminal",{sourceInterval:[2642,2645]},"*"],["terminal",{sourceInterval:[2648,2651]},"+"],["terminal",{sourceInterval:[2654,2657]},"?"],["terminal",{sourceInterval:[2660,2663]},"~"],["terminal",{sourceInterval:[2666,2669]},"&"]]],punctuation:["define",{sourceInterval:[2673,2709]},null,[],["alt",{sourceInterval:[2687,2709]},["terminal",{sourceInterval:[2687,2690]},"<"],["terminal",{sourceInterval:[2693,2696]},">"],["terminal",{sourceInterval:[2699,2702]},","],["terminal",{sourceInterval:[2705,2709]},"--"]]]}]),Ie=Object.create(g.prototype);function Je(r,e){for(const t in r)if(t===e)return!0;return!1}function gt(r,e,t){const n=new ce;let i,s,o,u=!1;return(t||ke).createSemantics().addOperation("visit",{Grammars(a){return a.children.map(c=>c.visit())},Grammar(a,c,l,p,h){const m=a.visit();i=n.newGrammar(m),c.child(0)&&c.child(0).visit(),p.children.map(b=>b.visit());const f=i.build();if(f.source=this.source.trimmed(),Je(e,m))throw $t(f);return e[m]=f,f},SuperGrammar(a,c){const l=c.visit();if(l==="null")i.withSuperGrammar(null);else{if(!e||!Je(e,l))throw Gt(l,e,c.source);i.withSuperGrammar(e[l])}},Rule_define(a,c,l,p,h){s=a.visit(),o=c.children.map(v=>v.visit())[0]||[],!i.defaultStartRule&&i.ensureSuperGrammar()!==j.ProtoBuiltInRules&&i.withDefaultStartRule(s);const m=h.visit(),f=l.children.map(v=>v.visit())[0],b=this.source.trimmed();return i.define(s,o,m,f,b)},Rule_override(a,c,l,p){s=a.visit(),o=c.children.map(f=>f.visit())[0]||[];const h=this.source.trimmed();i.ensureSuperGrammarRuleForOverriding(s,h),u=!0;const m=p.visit();return u=!1,i.override(s,o,m,null,h)},Rule_extend(a,c,l,p){s=a.visit(),o=c.children.map(f=>f.visit())[0]||[];const h=p.visit(),m=this.source.trimmed();return i.extend(s,o,h,null,m)},RuleBody(a,c){return n.alt(...c.visit()).withSource(this.source)},OverrideRuleBody(a,c){const l=c.visit(),p=l.indexOf(Ie);if(p>=0){const h=l.slice(0,p),m=l.slice(p+1);return m.forEach(f=>{if(f===Ie)throw Yt(f)}),new he(i.superGrammar,s,h,m).withSource(this.source)}else return n.alt(...l).withSource(this.source)},Formals(a,c,l){return c.visit()},Params(a,c,l){return c.visit()},Alt(a){return n.alt(...a.visit()).withSource(this.source)},TopLevelTerm_inline(a,c){const l=s+"_"+c.visit(),p=a.visit(),h=this.source.trimmed(),m=!(i.superGrammar&&i.superGrammar.rules[l]);u&&!m?i.override(l,o,p,null,h):i.define(l,o,p,null,h);const f=o.map(b=>n.app(b));return n.app(l,f).withSource(p.source)},OverrideTopLevelTerm_superSplice(a){return Ie},Seq(a){return n.seq(...a.children.map(c=>c.visit())).withSource(this.source)},Iter_star(a,c){return n.star(a.visit()).withSource(this.source)},Iter_plus(a,c){return n.plus(a.visit()).withSource(this.source)},Iter_opt(a,c){return n.opt(a.visit()).withSource(this.source)},Pred_not(a,c){return n.not(c.visit()).withSource(this.source)},Pred_lookahead(a,c){return n.lookahead(c.visit()).withSource(this.source)},Lex_lex(a,c){return n.lex(c.visit()).withSource(this.source)},Base_application(a,c){const l=c.children.map(p=>p.visit())[0]||[];return n.app(a.visit(),l).withSource(this.source)},Base_range(a,c,l){return n.range(a.visit(),l.visit()).withSource(this.source)},Base_terminal(a){return n.terminal(a.visit()).withSource(this.source)},Base_paren(a,c,l){return c.visit()},ruleDescr(a,c,l){return c.visit()},ruleDescrText(a){return this.sourceString.trim()},caseName(a,c,l,p,h){return l.visit()},name(a,c){return this.sourceString},nameFirst(a){},nameRest(a){},terminal(a,c,l){return c.children.map(p=>p.visit()).join("")},oneCharTerminal(a,c,l){return c.visit()},escapeChar(a){try{return it(this.sourceString)}catch(c){throw c instanceof RangeError&&c.message.startsWith("Invalid code point ")?Xt(a):c}},NonemptyListOf(a,c,l){return[a.visit()].concat(l.children.map(p=>p.visit()))},EmptyListOf(){return[]},_terminal(){return this.sourceString}})(r).visit()}const wr=Me(["grammar",{source:`OperationsAndAttributes { AttributeSignature = name OperationSignature = name Formals? Formals = "(" ListOf ")" name (a name) = nameFirst nameRest* nameFirst = "_" | letter nameRest = "_" | alnum }`},"OperationsAndAttributes",null,"AttributeSignature",{AttributeSignature:["define",{sourceInterval:[29,58]},null,[],["app",{sourceInterval:[54,58]},"name",[]]],OperationSignature:["define",{sourceInterval:[62,100]},null,[],["seq",{sourceInterval:[87,100]},["app",{sourceInterval:[87,91]},"name",[]],["opt",{sourceInterval:[92,100]},["app",{sourceInterval:[92,99]},"Formals",[]]]]],Formals:["define",{sourceInterval:[104,143]},null,[],["seq",{sourceInterval:[118,143]},["terminal",{sourceInterval:[118,121]},"("],["app",{sourceInterval:[122,139]},"ListOf",[["app",{sourceInterval:[129,133]},"name",[]],["terminal",{sourceInterval:[135,138]},","]]],["terminal",{sourceInterval:[140,143]},")"]]],name:["define",{sourceInterval:[147,187]},"a name",[],["seq",{sourceInterval:[168,187]},["app",{sourceInterval:[168,177]},"nameFirst",[]],["star",{sourceInterval:[178,187]},["app",{sourceInterval:[178,186]},"nameRest",[]]]]],nameFirst:["define",{sourceInterval:[191,223]},null,[],["alt",{sourceInterval:[207,223]},["terminal",{sourceInterval:[207,210]},"_"],["app",{sourceInterval:[217,223]},"letter",[]]]],nameRest:["define",{sourceInterval:[227,257]},null,[],["alt",{sourceInterval:[242,257]},["terminal",{sourceInterval:[242,245]},"_"],["app",{sourceInterval:[252,257]},"alnum",[]]]]}]);_r(j.BuiltInRules);Ar(wr);function _r(r){const e={empty(){return this.iteration()},nonEmpty(t,n,i){return this.iteration([t].concat(i.children))}};q.BuiltInSemantics=q.createSemantics(r,null).addOperation("asIteration",{emptyListOf:e.empty,nonemptyListOf:e.nonEmpty,EmptyListOf:e.empty,NonemptyListOf:e.nonEmpty})}function Ar(r){q.prototypeGrammarSemantics=r.createSemantics().addOperation("parse",{AttributeSignature(e){return{name:e.parse(),formals:[]}},OperationSignature(e,t){return{name:e.parse(),formals:t.children.map(n=>n.parse())[0]||[]}},Formals(e,t,n){return t.asIteration().children.map(i=>i.parse())},name(e,t){return this.sourceString}}),q.prototypeGrammar=r}function Or(r){let e=0;const t=[0],n=()=>t[t.length-1],i={},s=/( *).*(?:$|\r?\n|\r)/g;let o;for(;(o=s.exec(r))!=null;){const[u,a]=o;if(u.length===0)break;const c=a.length,l=n(),p=e+c;if(c>l)t.push(c),i[p]=1;else if(c1&&(i[e]=1-t.length),i}const vt="an indented block",yt="a dedent",Qe=1114111+1;class Rr extends me{constructor(e){super(e.input),this.state=e}_indentationAt(e){return this.state.userData[e]||0}atEnd(){return super.atEnd()&&this._indentationAt(this.pos)===0}next(){if(this._indentationAt(this.pos)!==0){this.examinedLength=Math.max(this.examinedLength,this.pos);return}return super.next()}nextCharCode(){return this._indentationAt(this.pos)!==0?(this.examinedLength=Math.max(this.examinedLength,this.pos),Qe):super.nextCharCode()}nextCodePoint(){return this._indentationAt(this.pos)!==0?(this.examinedLength=Math.max(this.examinedLength,this.pos),Qe):super.nextCodePoint()}}class Ze extends g{constructor(e=!0){super(),this.isIndent=e}allowsSkippingPrecedingSpace(){return!0}eval(e){const{inputStream:t}=e,n=e.userData;e.doNotMemoize=!0;const i=t.pos,s=this.isIndent?1:-1;return(n[i]||0)*s>0?(e.userData=Object.create(n),e.userData[i]-=s,e.pushBinding(new Y(0),i),!0):(e.processFailure(i,this),!1)}getArity(){return 1}_assertAllApplicationsAreValid(e,t){}_isNullable(e,t){return!1}assertChoicesHaveUniformArity(e){}assertIteratedExprsAreNotNullable(e){}introduceParams(e){return this}substituteParams(e){return this}toString(){return this.isIndent?"indent":"dedent"}toDisplayString(){return this.toString()}toFailure(e){const t=this.isIndent?vt:yt;return new $(this,t,"description")}}const Nr=new I("indent"),Pr=new I("dedent"),Lr=new he(Te,"any",[Nr,Pr],[]),Er=new ce().newGrammar("IndentationSensitive").withSuperGrammar(Te).define("indent",[],new Ze(!0),vt,void 0,!0).define("dedent",[],new Ze(!1),yt,void 0,!0).extend("any",[],Lr,"any character",void 0).build();Object.assign(Er,{_matchStateInitializer(r){r.userData=Or(r.input),r.inputStream=new Rr(r)},supportsIncrementalParsing:!1});j.initApplicationParser(ke,gt);const Cr=r=>!!r.constructor&&typeof r.constructor.isBuffer=="function"&&r.constructor.isBuffer(r);function Fr(r,e){const t=ke.match(r,"Grammars");if(t.failed())throw qt(t);return gt(t,e)}function jr(r,e){const t=Mr(r,e),n=Object.keys(t);if(n.length===0)throw new Error("Missing grammar definition");if(n.length>1){const i=t[n[1]].source;throw new Error(Ee(i.sourceString,i.startIdx)+"Found more than one grammar definition -- use ohm.grammars() instead.")}return t[n[0]]}function Mr(r,e){const t=Object.create(e||{});if(typeof r!="string")if(Cr(r))r=r.toString();else throw new TypeError("Expected string as first argument, got "+Pe(r));return Fr(r,t),t}function Tr(){return{install(r){const e=Object.create(r.Receiver,kr);Object.defineProperty(r.Core,"OperatorTable",d(e));function t(n){const i=It.match(n,"Program"),s=e.assignOperators,o=e.operators;return xt(i).toMessage(r,s,o)}return Object.defineProperty(r.Core.Message,"fromString",{value:t}),r}}}const kr={operators:{enumerable:!0,value:new Map([["?",0],["@",0],["@@",0],["**",1],["%",2],["*",2],["/",2],["+",3],["-",3],["<<",4],[">>",4],["<",5],["<=",5],[">",5],[">=",5],["!=",6],["==",6],["&",7],["^",8],["|",9],["&&",10],["and",10],["||",11],["or",11],["..",12],["%=",13],["&=",13],["*=",13],["+=",13],["-=",13],["/=",13],["<<=",13],[">>=",13],["^=",13],["|=",13],["return",14]])},assignOperators:{enumerable:!0,value:new Map([["::=","newSlot"],[":=","setSlot"],["=","updateSlot"]])}},It=jr(String.raw`Tu { Program = expression // messages expression = (message | sctpad)+ message = scpad* symbol scpad* arguments? -- single | brackets -- group brackets = "(" expression ")" -- round | "[" listOf "]" -- square | "{" listOf "}" -- curly arguments = "(" wcpad* listOf ")" argument = scpad* expression scpad* // symbols symbol = number | quote | identifier | operator identifier = (~("(" | ")" | "[" | "]" | "{" | "}" | "\"" | "," | ";" | space) alnum | "_")+ operator = (~("(" | ")" | "[" | "]" | "{" | "}" | "\"" | "," | ";" | space | alnum | "_") any)+ // quotes quote = "\"" ("\\\"" | ~"\"" any)* "\"" | "\"\"\"" (~"\"\"\"" any)* "\"\"\"" // spans terminator = separator* (";" | "\n") separator* separator = (~"\n" space) whitespace = " " | "\r" | "\t" | "\n" sctpad = (separator | comment | terminator) scpad = (separator | comment) wcpad = (whitespace | comment) // comments comment = "/*" (~"*/" any)* "*/" -- block | "//" (~"\n" any)* ("\n" | end) -- line | "#" (~"\n" any)* ("\n" | end) -- hash // numbers number = "0" caseInsensitive<"x"> (digit | "a".."f" | "A".."F")+ -- hex | digit* "." digit+ ("e" "-"? digit+)? -- exp | digit+ -- dec // characters comma = "," }`),xt=It.createSemantics();xt.addOperation("toMessage(Lobby, assigns, infixes)",{_terminal(){return null},_iter(...r){const{Lobby:e,assigns:t,infixes:n}=this.args;let i,s;for(const o of r){const u=o.toMessage(e,t,n);if(u&&!u.comment)if(i){if(u.isEndOfLine&&s.isEndOfLine){s.name===` `&&(s.name=u.name);continue}s.setNext(u),s=u.last}else{if(u.isEndOfLine)continue;i=u,s=i.last}}return i},Program(r){var h,m,f,b;const{Lobby:e,assigns:t,infixes:n}=this.args,i=Array.from(Object.keys(n)),s={macros:t,messagesByMacro:{}},o={allInfixes:i,priorities:n,messagesByPriority:{},groupEndSymbol:Symbol("groupEnd"),groupEndMessages:[]};let u=r.toMessage(e,s,o);const a=u.last;a.isEndOfLine&&a.name!==";"&&a.previous.setNext(null);for(const[v,S]of Object.entries(s.messagesByMacro))for(const x of S){const y=x.previous,B=x.next;let _=B.next;for(;_&&!(_!=null&&_.isEndOfLine);)_=_.next;if(!y)throw new Error("Missing assign name");if(y.isLiteral)throw new Error("Assign name must be a symbol");if(((h=y.arguments)==null?void 0:h.length)>0)throw new Error("Assign name must not have arguments");if(!B)throw new Error("Missing assign value");_&&((m=_.previous)==null||m.setNext(null));const fe=e.message();fe.name=y.name,fe.isLiteral=!0,y.setName(v),y.setArguments([fe,B]),y.setNext(_)}const c={};for(const[v,S]of n.entries())c[S]||(c[S]=[]),c[S].push(v);const l=Array.from(Object.keys(c)).map(v=>parseInt(v,10)),p=Array.from(Object.entries(o.messagesByPriority).map(([v,S])=>[parseInt(v,10),S])).sort((v,S)=>v[0]-S[0]);for(const[v,S]of p){const x=l.filter(y=>y>=v).flatMap(y=>c[y]);for(const y of S){const B=y.next;if(!B)continue;let _=B.next;for(;_&&!_.isEndOfLine&&_.name!==o.groupEndSymbol&&!x.includes(_.name);)_=_.next;_&&((f=_.previous)==null||f.setNext(null)),y.setArguments([B]),y.setNext(_)}}for(const v of o.groupEndMessages)(b=v.previous)==null||b.setNext(v.next);return u},expression(r){const{Lobby:e,assigns:t,infixes:n}=this.args;return r.toMessage(e,t,n)},message_single(r,e,t,n){var a,c;const{Lobby:i,assigns:s,infixes:o}=this.args,u=e.toMessage(i,s,o);if(n.sourceString)u.setArguments(n.toMessage(i,s,o));else{const l=u.name,p=s.macros.get(l);if(p)(a=s.messagesByMacro)[p]??(a[p]=[]),s.messagesByMacro[p].push(u);else{const h=o.priorities.get(l);typeof h<"u"&&((c=o.messagesByPriority)[h]??(c[h]=[]),o.messagesByPriority[h].push(u))}}return u},brackets_round(r,e,t){const{Lobby:n,assigns:i,infixes:s}=this.args,o=e.toMessage(n,i,s),u=n.message();return u.name=s.groupEndSymbol,u.isLiteral=!0,s.groupEndMessages.push(u),o.last.setNext(u),o},arguments(r,e,t,n){const{Lobby:i,assigns:s,infixes:o}=this.args,u=t.asIteration().children.map(a=>a.toMessage(i,s,o));if(u.length>0){const a=u[u.length-1].last;a.isEndOfLine&&a.name!==";"&&a.previous.setNext(null)}return u},argument(r,e,t){const{Lobby:n,assigns:i,infixes:s}=this.args;return e.toMessage(n,i,s)},identifier(r){const{Lobby:e}=this.args,t=e.message();t.name=r.sourceString;const{lineNum:n}=r.source.getLineAndColumn();return t.characterNumber=r.source.startIdx,t.lineNumber=n,t},operator(r){const{Lobby:e}=this.args,t=e.message();t.name=r.sourceString;const{lineNum:n}=r.source.getLineAndColumn();return t.characterNumber=r.source.startIdx,t.lineNumber=n,t},quote(r,e,t){const{Lobby:n}=this.args,i=n.message();r.sourceString==='"""'?i.name=e.sourceString:i.name=JSON.parse(`"${e.sourceString}"`),i.isLiteral=!0;const{lineNum:s}=e.source.getLineAndColumn();return i.characterNumber=e.source.startIdx,i.lineNumber=s,i},terminator(r,e,t){const{Lobby:n}=this.args,i=n.message();i.name=e.sourceString,i.isEndOfLine=!0;const{lineNum:s}=e.source.getLineAndColumn();return i.characterNumber=e.source.startIdx,i.lineNumber=s,i},comment_block(r,e,t){return{comment:"block",text:e.sourceString.replace(/^\s*\*(.*)/gm,"$1")}},comment_line(r,e,t){return{comment:"line",text:e.sourceString}},comment_hash(r,e,t){return{comment:"hash",text:e.sourceString}},number_hex(r,e,t){const{Lobby:n}=this.args,i=n.message();i.name=parseInt(t.sourceString,16),i.isLiteral=!0;const{lineNum:s}=r.source.getLineAndColumn();return i.characterNumber=r.source.startIdx,i.lineNumber=s,i},number_exp(r,e,t,n,i,s){const{Lobby:o}=this.args,u=o.message();u.name=parseFloat(`${r.sourceString||"0"}.${t.sourceString}${n.sourceString?`e${i.sourceString||""}${s.sourceString}`:""}`),u.isLiteral=!0;const{lineNum:a}=r.source.getLineAndColumn();return u.characterNumber=r.source.startIdx,u.lineNumber=a,u},number_dec(r){const{Lobby:e}=this.args,t=e.message();t.name=parseInt(r.sourceString,10),t.isLiteral=!0;const{lineNum:n}=r.source.getLineAndColumn();return t.characterNumber=r.source.startIdx,t.lineNumber=n,t}});function Dr(r){return{install(e,t){const n=(t==null?void 0:t.write)??r.console.log.bind(r.console);return Object.defineProperty(e.Receiver,"println",d(function(){var s;return n((((s=this==null?void 0:this.toString)==null?void 0:s.call(this))??this)+` `),this})),Object.defineProperty(e.Receiver,"print",d(function(){var s;return n(((s=this==null?void 0:this.toString)==null?void 0:s.call(this))??this),this})),Object.defineProperty(e.Receiver,"writeln",d(function(...s){const o=s.map(u=>{var a;return((a=u==null?void 0:u.toString)==null?void 0:a.call(u))??u}).join("");return n(o+` `),this})),Object.defineProperty(e.Receiver,"write",d(function(...s){const o=s.map(u=>{var a;return((a=u==null?void 0:u.toString)==null?void 0:a.call(u))??u}).join("");return n(o),this})),Object.defineProperty(e,"fetch",d(function(s,o){return r.fetch(s,o)})),e}}}function Br(r){return{install(e,t){const n=(t==null?void 0:t.write)??r.process.stdout.write.bind(r.process.stdout);return Object.defineProperty(e.Receiver,"println",d(function(){var s;return n((((s=this==null?void 0:this.toString)==null?void 0:s.call(this))??this)+` `),this})),Object.defineProperty(e.Receiver,"print",d(function(){var s;return n(((s=this==null?void 0:this.toString)==null?void 0:s.call(this))??this),this})),Object.defineProperty(e.Receiver,"writeln",d(function(...s){const o=s.map(u=>{var a;return((a=u==null?void 0:u.toString)==null?void 0:a.call(u))??u}).join("");return n(o+` `),this})),Object.defineProperty(e.Receiver,"write",d(function(...s){const o=s.map(u=>{var a;return((a=u==null?void 0:u.toString)==null?void 0:a.call(u))??u}).join("");return n(o),this})),Object.defineProperty(e,"fetch",d(function(s,o){return r.fetch(s,o)})),e}}}const qr=St().use(bt(se)).use(At(se)).use(Ft()).use(Tr()).use(typeof window>"u"?Br(global):Dr(window));exports.createEnvironment=qr;