ohm-js 17.3.0 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ohm-extras.cjs +51 -0
- package/dist/ohm-extras.js +51 -0
- package/dist/ohm.cjs +2 -1
- package/dist/ohm.cjs.map +1 -1
- package/dist/ohm.js +3 -2
- package/dist/ohm.min.js +1 -1
- package/extras/index.d.ts +7 -11
- package/extras/index.mjs +1 -0
- package/extras/recoverSourceOrder.js +48 -0
- package/package.json +1 -1
- package/src/pexprs-eval.js +1 -0
- package/src/version.js +1 -1
package/dist/ohm.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ohm={})}(this,(function(t){"use strict";function e(t){const e=t||"";return function(){throw new Error("this method "+e+" is abstract! (it has no implementation in class "+this.constructor.name+")")}}function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e,r){let n;Object.defineProperty(t,e,{get(){return n||(n=r.call(this)),n}})}function i(t,e){const r=[];for(;e-- >0;)r.push(t());return r}function s(t,e){return new Array(e+1).join(t)}function o(t,e){return i((()=>t),e)}function a(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];t.lastIndexOf(n)!==r&&e.indexOf(n)<0&&e.push(n)}return e}function u(t){const e=[];return t.forEach((t=>{e.indexOf(t)<0&&e.push(t)})),e}function c(t){const e=t[0];return e===e.toUpperCase()}function l(t){return!c(t)}function p(t,e,r){const n=r||" ";return t.length<e?s(n,e-t.length)+t:t}function h(){this.strings=[]}h.prototype.append=function(t){this.strings.push(t)},h.prototype.contents=function(){return this.strings.join("")};const m=t=>String.fromCodePoint(parseInt(t,16));function d(t){if("\\"!==t.charAt(0))return t;switch(t.charAt(1)){case"b":return"\b";case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case"v":return"\v";case"x":return m(t.slice(2,4));case"u":return"{"===t.charAt(2)?m(t.slice(3,-1)):m(t.slice(2,6));default:return t.charAt(1)}}function f(t){if(null==t)return String(t);const e=Object.prototype.toString.call(t);try{let r;return r=t.constructor&&t.constructor.name?t.constructor.name:0===e.indexOf("[object ")?e.slice(8,-1):typeof t,r+": "+JSON.stringify(String(t))}catch{return e}}function g(t,e="unexpected null value"){if(null==t)throw new Error(e);return t}var v=Object.freeze({__proto__:null,abstract:e,assert:r,defineLazyProperty:n,clone:function(t){return t?Object.assign({},t):t},repeatFn:i,repeatStr:s,repeat:o,getDuplicates:a,copyWithoutDuplicates:u,isSyntactic:c,isLexical:l,padLeft:p,StringBuffer:h,unescapeCodePoint:d,unexpectedObjToString:f,checkNotNull:g});const I=t=>new RegExp(String.raw`\p{${t}}`,"u"),y=Object.fromEntries(["Cc","Cf","Cn","Co","Cs","Ll","Lm","Lo","Lt","Lu","Mc","Me","Mn","Nd","Nl","No","Pc","Pd","Pe","Pf","Pi","Po","Ps","Sc","Sk","Sm","So","Zl","Zp","Zs"].map((t=>[t,I(t)])));y.Ltmo=/\p{Lt}|\p{Lm}|\p{Lo}/u;const x=Object.fromEntries(["XID_Start","XID_Continue","White_Space"].map((t=>[t,I(t)])));class S{constructor(){if(this.constructor===S)throw new Error("PExpr cannot be instantiated -- it's abstract")}withSource(t){return t&&(this.source=t.trimmed()),this}}const b=Object.create(S.prototype),_=Object.create(S.prototype);class w extends S{constructor(t){super(),this.obj=t}}class A extends S{constructor(t,e){super(),this.from=t,this.to=e,this.matchCodePoint=t.length>1||e.length>1}}class N extends S{constructor(t){super(),this.index=t}}class O extends S{constructor(t){super(),this.terms=t}}class R extends O{constructor(t,e,r){super([r,t.rules[e].body]),this.superGrammar=t,this.name=e,this.body=r}}class L extends O{constructor(t,e,r,n){const i=t.rules[e].body;super([...r,i,...n]),this.superGrammar=t,this.ruleName=e,this.expansionPos=r.length}}class P extends S{constructor(t){super(),this.factors=t}}class F extends S{constructor(t){super(),this.expr=t}}class E extends F{}class C extends F{}class T extends F{}E.prototype.operator="*",C.prototype.operator="+",T.prototype.operator="?",E.prototype.minNumMatches=0,C.prototype.minNumMatches=1,T.prototype.minNumMatches=0,E.prototype.maxNumMatches=Number.POSITIVE_INFINITY,C.prototype.maxNumMatches=Number.POSITIVE_INFINITY,T.prototype.maxNumMatches=1;class k extends S{constructor(t){super(),this.expr=t}}class D extends S{constructor(t){super(),this.expr=t}}class j extends S{constructor(t){super(),this.expr=t}}class M extends S{constructor(t,e=[]){super(),this.ruleName=t,this.args=e}isSyntactic(){return c(this.ruleName)}toMemoKey(){return this._memoKey||Object.defineProperty(this,"_memoKey",{value:this.toString()}),this._memoKey}}class G extends S{constructor(t){if(super(),this.categoryOrProp=t,t in y)this.pattern=y[t];else{if(!(t in x))throw new Error(`Invalid Unicode category or property name: ${JSON.stringify(t)}`);this.pattern=x[t]}}}function B(t,e){let r;return e?(r=new Error(e.getLineAndColumnMessage()+t),r.shortMessage=t,r.interval=e):r=new Error(t),r}function q(){return B("Interval sources don't match")}function U(t,e,r){return B("Rule "+t+" is not declared in grammar "+e,r)}function $(t,e,r,n){let i="Duplicate declaration for rule '"+t+"' in grammar '"+e+"'";return e!==r&&(i+=" (originally declared in '"+r+"')"),B(i,n)}function z(t,e,r,n){return B("Wrong number of parameters for rule "+t+" (expected "+e+", got "+r+")",n)}function K(t,e,r){return B("Duplicate parameter names in rule "+t+": "+e.join(", "),r)}function H(t,e){return B("Incorrect argument type: expected "+t,e.source)}function V(t,e){const r=e.length>0?e[e.length-1].args:[];let n="Nullable expression "+t.expr.substituteParams(r)+" is not allowed inside '"+t.operator+"' (possible infinite loop)";if(e.length>0){n+="\nApplication stack (most recent application last):\n"+e.map((t=>new M(t.ruleName,t.args))).join("\n")}return B(n,t.expr.source)}function W(t,e,r,n){return B("Rule "+t+" involves an alternation which has inconsistent arity (expected "+e+", got "+r+")",n.source)}function J(t){if(1===t.length)throw t[0];if(t.length>1)throw function(t){const e=t.map((t=>t.message));return B(["Errors:"].concat(e).join("\n- "),t[0].interval)}(t)}function Q(t,e,r){const n=t.length;return(t.slice(0,r)+e+t.slice(r+e.length)).substr(0,n)}function Z(...t){const e=this,{offset:n}=e,{repeatStr:i}=v,s=new h;s.append("Line "+e.lineNum+", col "+e.colNum+":\n");const o=function(t){let e=0;return t.map((t=>{const r=t.toString();return e=Math.max(e,r.length),r})).map((t=>p(t,e)))}([null==e.prevLine?0:e.lineNum-1,e.lineNum,null==e.nextLine?0:e.lineNum+1]),a=(t,e,r)=>{s.append(r+o[t]+" | "+e+"\n")};null!=e.prevLine&&a(0,e.prevLine," "),a(1,e.line,"> ");const u=e.line.length;let c=i(" ",u+1);for(let s=0;s<t.length;++s){let o=t[s][0],a=t[s][1];r(o>=0&&o<=a,"range start must be >= 0 and <= end");const l=n-e.colNum+1;o=Math.max(0,o-l),a=Math.min(a-l,u),c=Q(c,i("~",a-o),o)}const l=2+o[1].length+3;return s.append(i(" ",l)),c=Q(c,"^",e.colNum-1),s.append(c.replace(/ +$/,"")+"\n"),null!=e.nextLine&&a(2,e.nextLine," "),s.contents()}let X=[];function Y(t){X.push(t)}function tt(t,e){let r=1,n=1,i=0,s=0,o=null,a=null,u=-1;for(;i<e;){const e=t.charAt(i++);"\n"===e?(r++,n=1,u=s,s=i):"\r"!==e&&n++}let c=t.indexOf("\n",s);if(-1===c)c=t.length;else{const e=t.indexOf("\n",c+1);o=-1===e?t.slice(c):t.slice(c,e),o=o.replace(/^\r?\n/,"").replace(/\r$/,"")}u>=0&&(a=t.slice(u,s).replace(/\r?\n$/,""));return{offset:e,lineNum:r,colNum:n,line:t.slice(s,c).replace(/\r$/,""),prevLine:a,nextLine:o,toString:Z}}function et(t,e,...r){return tt(t,e).toString(...r)}const rt=(()=>{let t=0;return e=>""+e+t++})();class nt{constructor(t,e,r){Object.defineProperty(this,"_sourceString",{value:t,configurable:!1,enumerable:!1,writable:!1}),this.startIdx=e,this.endIdx=r}get sourceString(){return this._sourceString}get contents(){return void 0===this._contents&&(this._contents=this.sourceString.slice(this.startIdx,this.endIdx)),this._contents}get length(){return this.endIdx-this.startIdx}coverageWith(...t){return nt.coverage(...t,this)}collapsedLeft(){return new nt(this.sourceString,this.startIdx,this.startIdx)}collapsedRight(){return new nt(this.sourceString,this.endIdx,this.endIdx)}getLineAndColumn(){return tt(this.sourceString,this.startIdx)}getLineAndColumnMessage(){const t=[this.startIdx,this.endIdx];return et(this.sourceString,this.startIdx,t)}minus(t){if(this.sourceString!==t.sourceString)throw q();return this.startIdx===t.startIdx&&this.endIdx===t.endIdx?[]:this.startIdx<t.startIdx&&t.endIdx<this.endIdx?[new nt(this.sourceString,this.startIdx,t.startIdx),new nt(this.sourceString,t.endIdx,this.endIdx)]:this.startIdx<t.endIdx&&t.endIdx<this.endIdx?[new nt(this.sourceString,t.endIdx,this.endIdx)]:this.startIdx<t.startIdx&&t.startIdx<this.endIdx?[new nt(this.sourceString,this.startIdx,t.startIdx)]:[this]}relativeTo(t){if(this.sourceString!==t.sourceString)throw q();return r(this.startIdx>=t.startIdx&&this.endIdx<=t.endIdx,"other interval does not cover this one"),new nt(this.sourceString,this.startIdx-t.startIdx,this.endIdx-t.startIdx)}trimmed(){const{contents:t}=this,e=this.startIdx+t.match(/^\s*/)[0].length,r=this.endIdx-t.match(/\s*$/)[0].length;return new nt(this.sourceString,e,r)}subInterval(t,e){const r=this.startIdx+t;return new nt(this.sourceString,r,r+e)}}nt.coverage=function(t,...e){let{startIdx:r,endIdx:n}=t;for(const i of e){if(i.sourceString!==t.sourceString)throw q();r=Math.min(r,i.startIdx),n=Math.max(n,i.endIdx)}return new nt(t.sourceString,r,n)};class it{constructor(t){this.source=t,this.pos=0,this.examinedLength=0}atEnd(){const t=this.pos>=this.source.length;return this.examinedLength=Math.max(this.examinedLength,this.pos+1),t}next(){const t=this.source[this.pos++];return this.examinedLength=Math.max(this.examinedLength,this.pos),t}nextCharCode(){const t=this.next();return t&&t.charCodeAt(0)}nextCodePoint(){const t=this.source.slice(this.pos++).codePointAt(0);return t>65535&&(this.pos+=1),this.examinedLength=Math.max(this.examinedLength,this.pos),t}matchString(t,e){let r;if(e){for(r=0;r<t.length;r++){const e=this.next(),n=t[r];if(null==e||e.toUpperCase()!==n.toUpperCase())return!1}return!0}for(r=0;r<t.length;r++)if(this.next()!==t[r])return!1;return!0}sourceSlice(t,e){return this.source.slice(t,e)}interval(t,e){return new nt(this.source,t,e||this.pos)}}class st{constructor(t,e,r,i,s,o,a){this.matcher=t,this.input=e,this.startExpr=r,this._cst=i,this._cstOffset=s,this._rightmostFailurePosition=o,this._rightmostFailures=a,this.failed()&&(n(this,"message",(function(){const t="Expected "+this.getExpectedText();return et(this.input,this.getRightmostFailurePosition())+t})),n(this,"shortMessage",(function(){const t="expected "+this.getExpectedText(),e=tt(this.input,this.getRightmostFailurePosition());return"Line "+e.lineNum+", col "+e.colNum+": "+t})))}succeeded(){return!!this._cst}failed(){return!this.succeeded()}getRightmostFailurePosition(){return this._rightmostFailurePosition}getRightmostFailures(){if(!this._rightmostFailures){this.matcher.setInput(this.input);const t=this.matcher._match(this.startExpr,{tracing:!1,positionToRecordFailures:this.getRightmostFailurePosition()});this._rightmostFailures=t.getRightmostFailures()}return this._rightmostFailures}toString(){return this.succeeded()?"[match succeeded]":"[match failed at position "+this.getRightmostFailurePosition()+"]"}getExpectedText(){if(this.succeeded())throw new Error("cannot get expected text of a successful MatchResult");const t=new h;let e=this.getRightmostFailures();e=e.filter((t=>!t.isFluffy()));for(let r=0;r<e.length;r++)r>0&&(r===e.length-1?t.append(e.length>2?", or ":" or "):t.append(", ")),t.append(e[r].toString());return t.contents()}getInterval(){const t=this.getRightmostFailurePosition();return new nt(this.input,t,t)}}class ot{constructor(){this.applicationMemoKeyStack=[],this.memo={},this.maxExaminedLength=0,this.maxRightmostFailureOffset=-1,this.currentLeftRecursion=void 0}isActive(t){return this.applicationMemoKeyStack.indexOf(t.toMemoKey())>=0}enter(t){this.applicationMemoKeyStack.push(t.toMemoKey())}exit(){this.applicationMemoKeyStack.pop()}startLeftRecursion(t,e){e.isLeftRecursion=!0,e.headApplication=t,e.nextLeftRecursion=this.currentLeftRecursion,this.currentLeftRecursion=e;const{applicationMemoKeyStack:r}=this,n=r.indexOf(t.toMemoKey())+1,i=r.slice(n);e.isInvolved=function(t){return i.indexOf(t)>=0},e.updateInvolvedApplicationMemoKeys=function(){for(let t=n;t<r.length;t++){const e=r[t];this.isInvolved(e)||i.push(e)}}}endLeftRecursion(){this.currentLeftRecursion=this.currentLeftRecursion.nextLeftRecursion}shouldUseMemoizedResult(t){if(!t.isLeftRecursion)return!0;const{applicationMemoKeyStack:e}=this;for(let r=0;r<e.length;r++){const n=e[r];if(t.isInvolved(n))return!1}return!0}memoize(t,e){return this.memo[t]=e,this.maxExaminedLength=Math.max(this.maxExaminedLength,e.examinedLength),this.maxRightmostFailureOffset=Math.max(this.maxRightmostFailureOffset,e.rightmostFailureOffset),e}clearObsoleteEntries(t,e){if(t+this.maxExaminedLength<=e)return;const{memo:r}=this;this.maxExaminedLength=0,this.maxRightmostFailureOffset=-1,Object.keys(r).forEach((n=>{const i=r[n];t+i.examinedLength>e?delete r[n]:(this.maxExaminedLength=Math.max(this.maxExaminedLength,i.examinedLength),this.maxRightmostFailureOffset=Math.max(this.maxRightmostFailureOffset,i.rightmostFailureOffset))}))}}const at={succeeded:1,isRootNode:2,isImplicitSpaces:4,isMemoized:8,isHeadOfLeftRecursion:16,terminatesLR:32};function ut(t){return"string"==typeof t?t.replace(/ /g,"⋅").replace(/\t/g,"␉").replace(/\n/g,"␊").replace(/\r/g,"␍"):String(t)}class ct{constructor(t,e,r,n,i,s,o){this.input=t,this.pos=this.pos1=e,this.pos2=r,this.source=new nt(t,e,r),this.expr=n,this.bindings=s,this.children=o||[],this.terminatingLREntry=null,this._flags=i?at.succeeded:0}get displayString(){return this.expr.toDisplayString()}clone(){return this.cloneWithExpr(this.expr)}cloneWithExpr(t){const e=new ct(this.input,this.pos,this.pos2,t,this.succeeded,this.bindings,this.children);return e.isHeadOfLeftRecursion=this.isHeadOfLeftRecursion,e.isImplicitSpaces=this.isImplicitSpaces,e.isMemoized=this.isMemoized,e.isRootNode=this.isRootNode,e.terminatesLR=this.terminatesLR,e.terminatingLREntry=this.terminatingLREntry,e}recordLRTermination(t,e){this.terminatingLREntry=new ct(this.input,this.pos,this.pos2,this.expr,!1,[e],[t]),this.terminatingLREntry.terminatesLR=!0}walk(t,e){let r=t;function n(t,i,s){let o=!0;r.enter&&r.enter.call(e,t,i,s)===ct.prototype.SKIP&&(o=!1),o&&(t.children.forEach((e=>{n(e,t,s+1)})),r.exit&&r.exit.call(e,t,i,s))}"function"==typeof r&&(r={enter:r}),this.isRootNode?this.children.forEach((t=>{n(t,null,0)})):n(this,null,0)}toString(){const t=new h;return this.walk(((e,r,n)=>{if(!e)return this.SKIP;if("Alt"!==e.expr.constructor.name){if(t.append(function(t,e,r){const n=ut(t.slice(e,e+r));return n.length<r?n+o(" ",r-n.length).join(""):n}(e.input,e.pos,10)+o(" ",2*n+1).join("")),t.append((e.succeeded?"✓":"✗")+" "+e.displayString),e.isHeadOfLeftRecursion&&t.append(" (LR)"),e.succeeded){const r=ut(e.source.contents);t.append(" ⇒ "),t.append("string"==typeof r?'"'+r+'"':r)}t.append("\n")}})),t.contents()}}let lt,pt;ct.prototype.SKIP={},Object.keys(at).forEach((t=>{const e=at[t];Object.defineProperty(ct.prototype,t,{get(){return!!(this._flags&e)},set(t){t?this._flags|=e:this._flags&=~e}})})),S.prototype.allowsSkippingPrecedingSpace=e("allowsSkippingPrecedingSpace"),b.allowsSkippingPrecedingSpace=_.allowsSkippingPrecedingSpace=M.prototype.allowsSkippingPrecedingSpace=w.prototype.allowsSkippingPrecedingSpace=A.prototype.allowsSkippingPrecedingSpace=G.prototype.allowsSkippingPrecedingSpace=function(){return!0},O.prototype.allowsSkippingPrecedingSpace=F.prototype.allowsSkippingPrecedingSpace=j.prototype.allowsSkippingPrecedingSpace=D.prototype.allowsSkippingPrecedingSpace=k.prototype.allowsSkippingPrecedingSpace=N.prototype.allowsSkippingPrecedingSpace=P.prototype.allowsSkippingPrecedingSpace=function(){return!1},Y((t=>{lt=t})),S.prototype.assertAllApplicationsAreValid=function(t,e){pt=0,this._assertAllApplicationsAreValid(t,e)},S.prototype._assertAllApplicationsAreValid=e("_assertAllApplicationsAreValid"),b._assertAllApplicationsAreValid=_._assertAllApplicationsAreValid=w.prototype._assertAllApplicationsAreValid=A.prototype._assertAllApplicationsAreValid=N.prototype._assertAllApplicationsAreValid=G.prototype._assertAllApplicationsAreValid=function(t,e){},j.prototype._assertAllApplicationsAreValid=function(t,e){pt++,this.expr._assertAllApplicationsAreValid(t,e),pt--},O.prototype._assertAllApplicationsAreValid=function(t,e){for(let r=0;r<this.terms.length;r++)this.terms[r]._assertAllApplicationsAreValid(t,e)},P.prototype._assertAllApplicationsAreValid=function(t,e){for(let r=0;r<this.factors.length;r++)this.factors[r]._assertAllApplicationsAreValid(t,e)},F.prototype._assertAllApplicationsAreValid=k.prototype._assertAllApplicationsAreValid=D.prototype._assertAllApplicationsAreValid=function(t,e){this.expr._assertAllApplicationsAreValid(t,e)},M.prototype._assertAllApplicationsAreValid=function(t,e,r=!1){const n=e.rules[this.ruleName],i=c(t)&&0===pt;if(!n)throw U(this.ruleName,e.name,this.source);if(!r&&c(this.ruleName)&&!i)throw function(t,e){return B("Cannot apply syntactic rule "+t+" from here (inside a lexical context)",e.source)}(this.ruleName,this);const s=this.args.length,o=n.formals.length;if(s!==o)throw function(t,e,r,n){return B("Wrong number of arguments for rule "+t+" (expected "+e+", got "+r+")",n)}(this.ruleName,o,s,this.source);const a=lt&&n===lt.rules.applySyntactic;if(lt&&n===lt.rules.caseInsensitive&&!(this.args[0]instanceof w))throw H('a Terminal (e.g. "abc")',this.args[0]);if(a){const t=this.args[0];if(!(t instanceof M))throw H("a syntactic rule application",t);if(!c(t.ruleName))throw function(t){const{ruleName:e}=t;return B(`applySyntactic is for syntactic rules, but '${e}' is a lexical rule. NOTE: A _syntactic rule_ is a rule whose name begins with a capital letter. See https://ohmjs.org/d/svl for more details.`,t.source)}(t);if(i)throw B("applySyntactic is not required here (in a syntactic context)",this.source)}this.args.forEach((r=>{if(r._assertAllApplicationsAreValid(t,e,a),1!==r.getArity())throw function(t,e){return B("Invalid parameter to rule "+t+": "+e+" has arity "+e.getArity()+", but parameter expressions must have arity 1",e.source)}(this.ruleName,r)}))},S.prototype.assertChoicesHaveUniformArity=e("assertChoicesHaveUniformArity"),b.assertChoicesHaveUniformArity=_.assertChoicesHaveUniformArity=w.prototype.assertChoicesHaveUniformArity=A.prototype.assertChoicesHaveUniformArity=N.prototype.assertChoicesHaveUniformArity=j.prototype.assertChoicesHaveUniformArity=G.prototype.assertChoicesHaveUniformArity=function(t){},O.prototype.assertChoicesHaveUniformArity=function(t){if(0===this.terms.length)return;const e=this.terms[0].getArity();for(let r=0;r<this.terms.length;r++){const n=this.terms[r];n.assertChoicesHaveUniformArity();const i=n.getArity();if(e!==i)throw W(t,e,i,n)}},R.prototype.assertChoicesHaveUniformArity=function(t){const e=this.terms[0].getArity(),r=this.terms[1].getArity();if(e!==r)throw W(t,r,e,this.terms[0])},P.prototype.assertChoicesHaveUniformArity=function(t){for(let e=0;e<this.factors.length;e++)this.factors[e].assertChoicesHaveUniformArity(t)},F.prototype.assertChoicesHaveUniformArity=function(t){this.expr.assertChoicesHaveUniformArity(t)},k.prototype.assertChoicesHaveUniformArity=function(t){},D.prototype.assertChoicesHaveUniformArity=function(t){this.expr.assertChoicesHaveUniformArity(t)},M.prototype.assertChoicesHaveUniformArity=function(t){},S.prototype.assertIteratedExprsAreNotNullable=e("assertIteratedExprsAreNotNullable"),b.assertIteratedExprsAreNotNullable=_.assertIteratedExprsAreNotNullable=w.prototype.assertIteratedExprsAreNotNullable=A.prototype.assertIteratedExprsAreNotNullable=N.prototype.assertIteratedExprsAreNotNullable=G.prototype.assertIteratedExprsAreNotNullable=function(t){},O.prototype.assertIteratedExprsAreNotNullable=function(t){for(let e=0;e<this.terms.length;e++)this.terms[e].assertIteratedExprsAreNotNullable(t)},P.prototype.assertIteratedExprsAreNotNullable=function(t){for(let e=0;e<this.factors.length;e++)this.factors[e].assertIteratedExprsAreNotNullable(t)},F.prototype.assertIteratedExprsAreNotNullable=function(t){if(this.expr.assertIteratedExprsAreNotNullable(t),this.expr.isNullable(t))throw V(this,[])},T.prototype.assertIteratedExprsAreNotNullable=k.prototype.assertIteratedExprsAreNotNullable=D.prototype.assertIteratedExprsAreNotNullable=j.prototype.assertIteratedExprsAreNotNullable=function(t){this.expr.assertIteratedExprsAreNotNullable(t)},M.prototype.assertIteratedExprsAreNotNullable=function(t){this.args.forEach((e=>{e.assertIteratedExprsAreNotNullable(t)}))};class ht{constructor(t){this.matchLength=t}get ctorName(){throw new Error("subclass responsibility")}numChildren(){return this.children?this.children.length:0}childAt(t){if(this.children)return this.children[t]}indexOfChild(t){return this.children.indexOf(t)}hasChildren(){return this.numChildren()>0}hasNoChildren(){return!this.hasChildren()}onlyChild(){if(1!==this.numChildren())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(t){const e=this.indexOfChild(t);if(e<0)throw new Error("Node.childBefore() called w/ an argument that is not a child");if(0===e)throw new Error("cannot get child before first child");return this.childAt(e-1)}childAfter(t){const e=this.indexOfChild(t);if(e<0)throw new Error("Node.childAfter() called w/ an argument that is not a child");if(e===this.numChildren()-1)throw new Error("cannot get child after last child");return this.childAt(e+1)}isTerminal(){return!1}isNonterminal(){return!1}isIteration(){return!1}isOptional(){return!1}}class mt extends ht{get ctorName(){return"_terminal"}isTerminal(){return!0}get primitiveValue(){throw new Error("The `primitiveValue` property was removed in Ohm v17.")}}class dt extends ht{constructor(t,e,r,n){super(n),this.ruleName=t,this.children=e,this.childOffsets=r}get ctorName(){return this.ruleName}isNonterminal(){return!0}isLexical(){return l(this.ctorName)}isSyntactic(){return c(this.ctorName)}}class ft extends ht{constructor(t,e,r,n){super(r),this.children=t,this.childOffsets=e,this.optional=n}get ctorName(){return"_iter"}isIteration(){return!0}isOptional(){return this.optional}}function gt(t,e){const r={};if(t.source&&e){const n=t.source.relativeTo(e);r.sourceInterval=[n.startIdx,n.endIdx]}return r}function vt(t){return/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(t)}function It(t){const e=Object.create(null);t.forEach((t=>{e[t]=(e[t]||0)+1})),Object.keys(e).forEach((r=>{if(e[r]<=1)return;let n=1;t.forEach(((e,i)=>{e===r&&(t[i]=e+"_"+n++)}))}))}S.prototype.eval=e("eval"),b.eval=function(t){const{inputStream:e}=t,r=e.pos,n=e.nextCodePoint();return void 0!==n?(t.pushBinding(new mt(String.fromCodePoint(n).length),r),!0):(t.processFailure(r,this),!1)},_.eval=function(t){const{inputStream:e}=t,r=e.pos;return e.atEnd()?(t.pushBinding(new mt(0),r),!0):(t.processFailure(r,this),!1)},w.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;return e.matchString(this.obj)?(t.pushBinding(new mt(this.obj.length),r),!0):(t.processFailure(r,this),!1)},A.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=this.matchCodePoint?e.nextCodePoint():e.nextCharCode();return void 0!==n&&this.from.codePointAt(0)<=n&&n<=this.to.codePointAt(0)?(t.pushBinding(new mt(String.fromCodePoint(n).length),r),!0):(t.processFailure(r,this),!1)},N.prototype.eval=function(t){return t.eval(t.currentApplication().args[this.index])},j.prototype.eval=function(t){t.enterLexifiedContext();const e=t.eval(this.expr);return t.exitLexifiedContext(),e},O.prototype.eval=function(t){for(let e=0;e<this.terms.length;e++)if(t.eval(this.terms[e]))return!0;return!1},P.prototype.eval=function(t){for(let e=0;e<this.factors.length;e++){const r=this.factors[e];if(!t.eval(r))return!1}return!0},F.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=this.getArity(),i=[],s=[];for(;i.length<n;)i.push([]),s.push([]);let o,a=0,u=r;for(;a<this.maxNumMatches&&t.eval(this.expr);){if(e.pos===u)throw V(this,t._applicationStack);u=e.pos,a++;const r=t._bindings.splice(t._bindings.length-n,n),c=t._bindingOffsets.splice(t._bindingOffsets.length-n,n);for(o=0;o<r.length;o++)i[o].push(r[o]),s[o].push(c[o])}if(a<this.minNumMatches)return!1;let c=t.posToOffset(r),l=0;if(a>0){const t=i[n-1],e=s[n-1],r=e[e.length-1]+t[t.length-1].matchLength;c=s[0][0],l=r-c}const p=this instanceof T;for(o=0;o<i.length;o++)t._bindings.push(new ft(i[o],s[o],l,p)),t._bindingOffsets.push(c);return!0},k.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;t.pushFailuresInfo();const n=t.eval(this.expr);return t.popFailuresInfo(),n?(t.processFailure(r,this),!1):(e.pos=r,!0)},D.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;return!!t.eval(this.expr)&&(e.pos=r,!0)},M.prototype.eval=function(t){const e=t.currentApplication(),r=e?e.args:[],n=this.substituteParams(r),i=t.getCurrentPosInfo();if(i.isActive(n))return n.handleCycle(t);const s=n.toMemoKey(),o=i.memo[s];if(o&&i.shouldUseMemoizedResult(o)){if(t.hasNecessaryInfo(o))return t.useMemoizedResult(t.inputStream.pos,o);delete i.memo[s]}return n.reallyEval(t)},M.prototype.handleCycle=function(t){const e=t.getCurrentPosInfo(),{currentLeftRecursion:r}=e,n=this.toMemoKey();let i=e.memo[n];return r&&r.headApplication.toMemoKey()===n?i.updateInvolvedApplicationMemoKeys():i||(i=e.memoize(n,{matchLength:0,examinedLength:0,value:!1,rightmostFailureOffset:-1}),e.startLeftRecursion(this,i)),t.useMemoizedResult(t.inputStream.pos,i)},M.prototype.reallyEval=function(t){const{inputStream:e}=t,n=e.pos,i=t.getCurrentPosInfo(),s=t.grammar.rules[this.ruleName],{body:o}=s,{description:a}=s;t.enterApplication(i,this),a&&t.pushFailuresInfo();const u=e.examinedLength;e.examinedLength=0;let c=this.evalOnce(o,t);const l=i.currentLeftRecursion,p=this.toMemoKey(),h=l&&l.headApplication.toMemoKey()===p;let m;t.doNotMemoize?t.doNotMemoize=!1:h?(c=this.growSeedResult(o,t,n,l,c),i.endLeftRecursion(),m=l,m.examinedLength=e.examinedLength-n,m.rightmostFailureOffset=t._getRightmostFailureOffset(),i.memoize(p,m)):l&&l.isInvolved(p)||(m=i.memoize(p,{matchLength:e.pos-n,examinedLength:e.examinedLength-n,value:c,failuresAtRightmostPosition:t.cloneRecordedFailures(),rightmostFailureOffset:t._getRightmostFailureOffset()}));const d=!!c;if(a&&(t.popFailuresInfo(),d||t.processFailure(n,this),m&&(m.failuresAtRightmostPosition=t.cloneRecordedFailures())),t.isTracing()&&m){const e=t.getTraceEntry(n,this,d,d?[c]:[]);h&&(r(null!=e.terminatingLREntry||!d),e.isHeadOfLeftRecursion=!0),m.traceEntry=e}return e.examinedLength=Math.max(e.examinedLength,u),t.exitApplication(i,c),d},M.prototype.evalOnce=function(t,e){const{inputStream:r}=e,n=r.pos;if(e.eval(t)){const i=t.getArity(),s=e._bindings.splice(e._bindings.length-i,i),o=e._bindingOffsets.splice(e._bindingOffsets.length-i,i),a=r.pos-n;return new dt(this.ruleName,s,o,a)}return!1},M.prototype.growSeedResult=function(t,e,r,n,i){if(!i)return!1;const{inputStream:s}=e;for(;;){if(n.matchLength=s.pos-r,n.value=i,n.failuresAtRightmostPosition=e.cloneRecordedFailures(),e.isTracing()){const t=e.trace[e.trace.length-1];n.traceEntry=new ct(e.input,r,s.pos,this,!0,[i],[t.clone()])}if(s.pos=r,i=this.evalOnce(t,e),s.pos-r<=n.matchLength)break;e.isTracing()&&e.trace.splice(-2,1)}return e.isTracing()&&n.traceEntry.recordLRTermination(e.trace.pop(),i),s.pos=r+n.matchLength,n.value},G.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=e.nextCodePoint();if(void 0!==n&&n<=1114111){const e=String.fromCodePoint(n);if(this.pattern.test(e))return t.pushBinding(new mt(e.length),r),!0}return t.processFailure(r,this),!1},S.prototype.getArity=e("getArity"),b.getArity=_.getArity=w.prototype.getArity=A.prototype.getArity=N.prototype.getArity=M.prototype.getArity=G.prototype.getArity=function(){return 1},O.prototype.getArity=function(){return 0===this.terms.length?0:this.terms[0].getArity()},P.prototype.getArity=function(){let t=0;for(let e=0;e<this.factors.length;e++)t+=this.factors[e].getArity();return t},F.prototype.getArity=function(){return this.expr.getArity()},k.prototype.getArity=function(){return 0},D.prototype.getArity=j.prototype.getArity=function(){return this.expr.getArity()},S.prototype.outputRecipe=e("outputRecipe"),b.outputRecipe=function(t,e){return["any",gt(this,e)]},_.outputRecipe=function(t,e){return["end",gt(this,e)]},w.prototype.outputRecipe=function(t,e){return["terminal",gt(this,e),this.obj]},A.prototype.outputRecipe=function(t,e){return["range",gt(this,e),this.from,this.to]},N.prototype.outputRecipe=function(t,e){return["param",gt(this,e),this.index]},O.prototype.outputRecipe=function(t,e){return["alt",gt(this,e)].concat(this.terms.map((r=>r.outputRecipe(t,e))))},R.prototype.outputRecipe=function(t,e){return this.terms[0].outputRecipe(t,e)},L.prototype.outputRecipe=function(t,e){const r=this.terms.slice(0,this.expansionPos),n=this.terms.slice(this.expansionPos+1);return["splice",gt(this,e),r.map((r=>r.outputRecipe(t,e))),n.map((r=>r.outputRecipe(t,e)))]},P.prototype.outputRecipe=function(t,e){return["seq",gt(this,e)].concat(this.factors.map((r=>r.outputRecipe(t,e))))},E.prototype.outputRecipe=C.prototype.outputRecipe=T.prototype.outputRecipe=k.prototype.outputRecipe=D.prototype.outputRecipe=j.prototype.outputRecipe=function(t,e){return[this.constructor.name.toLowerCase(),gt(this,e),this.expr.outputRecipe(t,e)]},M.prototype.outputRecipe=function(t,e){return["app",gt(this,e),this.ruleName,this.args.map((r=>r.outputRecipe(t,e)))]},G.prototype.outputRecipe=function(t,e){return["unicodeChar",gt(this,e),this.categoryOrProp]},S.prototype.introduceParams=e("introduceParams"),b.introduceParams=_.introduceParams=w.prototype.introduceParams=A.prototype.introduceParams=N.prototype.introduceParams=G.prototype.introduceParams=function(t){return this},O.prototype.introduceParams=function(t){return this.terms.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},P.prototype.introduceParams=function(t){return this.factors.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},F.prototype.introduceParams=k.prototype.introduceParams=D.prototype.introduceParams=j.prototype.introduceParams=function(t){return this.expr=this.expr.introduceParams(t),this},M.prototype.introduceParams=function(t){const e=t.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 N(e).withSource(this.source)}return this.args.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},S.prototype.isNullable=function(t){return this._isNullable(t,Object.create(null))},S.prototype._isNullable=e("_isNullable"),b._isNullable=A.prototype._isNullable=N.prototype._isNullable=C.prototype._isNullable=G.prototype._isNullable=function(t,e){return!1},_._isNullable=function(t,e){return!0},w.prototype._isNullable=function(t,e){return"string"==typeof this.obj&&""===this.obj},O.prototype._isNullable=function(t,e){return 0===this.terms.length||this.terms.some((r=>r._isNullable(t,e)))},P.prototype._isNullable=function(t,e){return this.factors.every((r=>r._isNullable(t,e)))},E.prototype._isNullable=T.prototype._isNullable=k.prototype._isNullable=D.prototype._isNullable=function(t,e){return!0},j.prototype._isNullable=function(t,e){return this.expr._isNullable(t,e)},M.prototype._isNullable=function(t,e){const r=this.toMemoKey();if(!Object.prototype.hasOwnProperty.call(e,r)){const{body:n}=t.rules[this.ruleName],i=n.substituteParams(this.args);e[r]=!1,e[r]=i._isNullable(t,e)}return e[r]},S.prototype.substituteParams=e("substituteParams"),b.substituteParams=_.substituteParams=w.prototype.substituteParams=A.prototype.substituteParams=G.prototype.substituteParams=function(t){return this},N.prototype.substituteParams=function(t){return g(t[this.index])},O.prototype.substituteParams=function(t){return new O(this.terms.map((e=>e.substituteParams(t))))},P.prototype.substituteParams=function(t){return new P(this.factors.map((e=>e.substituteParams(t))))},F.prototype.substituteParams=k.prototype.substituteParams=D.prototype.substituteParams=j.prototype.substituteParams=function(t){return new this.constructor(this.expr.substituteParams(t))},M.prototype.substituteParams=function(t){if(0===this.args.length)return this;{const e=this.args.map((e=>e.substituteParams(t)));return new M(this.ruleName,e)}},S.prototype.toArgumentNameList=e("toArgumentNameList"),b.toArgumentNameList=function(t,e){return["any"]},_.toArgumentNameList=function(t,e){return["end"]},w.prototype.toArgumentNameList=function(t,e){return"string"==typeof this.obj&&/^[_a-zA-Z0-9]+$/.test(this.obj)?["_"+this.obj]:["$"+t]},A.prototype.toArgumentNameList=function(t,e){let r=this.from+"_to_"+this.to;return vt(r)||(r="_"+r),vt(r)||(r="$"+t),[r]},O.prototype.toArgumentNameList=function(t,e){const r=this.terms.map((e=>e.toArgumentNameList(t,!0))),n=[],i=r[0].length;for(let t=0;t<i;t++){const e=[];for(let n=0;n<this.terms.length;n++)e.push(r[n][t]);const i=u(e);n.push(i.join("_or_"))}return e||It(n),n},P.prototype.toArgumentNameList=function(t,e){let r=[];return this.factors.forEach((e=>{const n=e.toArgumentNameList(t,!0);r=r.concat(n),t+=n.length})),e||It(r),r},F.prototype.toArgumentNameList=function(t,e){const r=this.expr.toArgumentNameList(t,e).map((t=>"s"===t[t.length-1]?t+"es":t+"s"));return e||It(r),r},T.prototype.toArgumentNameList=function(t,e){return this.expr.toArgumentNameList(t,e).map((t=>"opt"+t[0].toUpperCase()+t.slice(1)))},k.prototype.toArgumentNameList=function(t,e){return[]},D.prototype.toArgumentNameList=j.prototype.toArgumentNameList=function(t,e){return this.expr.toArgumentNameList(t,e)},M.prototype.toArgumentNameList=function(t,e){return[this.ruleName]},G.prototype.toArgumentNameList=function(t,e){return["$"+t]},N.prototype.toArgumentNameList=function(t,e){return["param"+this.index]},S.prototype.toDisplayString=e("toDisplayString"),O.prototype.toDisplayString=P.prototype.toDisplayString=function(){return this.source?this.source.trimmed().contents:"["+this.constructor.name+"]"},b.toDisplayString=_.toDisplayString=F.prototype.toDisplayString=k.prototype.toDisplayString=D.prototype.toDisplayString=j.prototype.toDisplayString=w.prototype.toDisplayString=A.prototype.toDisplayString=N.prototype.toDisplayString=function(){return this.toString()},M.prototype.toDisplayString=function(){if(this.args.length>0){const t=this.args.map((t=>t.toDisplayString()));return this.ruleName+"<"+t.join(",")+">"}return this.ruleName},G.prototype.toDisplayString=function(){return"Unicode ["+this.categoryOrProp+"] character"};class yt{constructor(t,e,r){if(!function(t){return"description"===t||"string"===t||"code"===t}(r))throw new Error("invalid Failure type: "+r);this.pexpr=t,this.text=e,this.type=r,this.fluffy=!1}getPExpr(){return this.pexpr}getText(){return this.text}getType(){return this.type}isDescription(){return"description"===this.type}isStringTerminal(){return"string"===this.type}isCode(){return"code"===this.type}isFluffy(){return this.fluffy}makeFluffy(){this.fluffy=!0}clearFluffy(){this.fluffy=!1}subsumes(t){return this.getText()===t.getText()&&this.type===t.type&&(!this.isFluffy()||this.isFluffy()&&t.isFluffy())}toString(){return"string"===this.type?JSON.stringify(this.getText()):this.getText()}clone(){const t=new yt(this.pexpr,this.text,this.type);return this.isFluffy()&&t.makeFluffy(),t}toKey(){return this.toString()+"#"+this.type}}S.prototype.toFailure=e("toFailure"),b.toFailure=function(t){return new yt(this,"any object","description")},_.toFailure=function(t){return new yt(this,"end of input","description")},w.prototype.toFailure=function(t){return new yt(this,this.obj,"string")},A.prototype.toFailure=function(t){return new yt(this,JSON.stringify(this.from)+".."+JSON.stringify(this.to),"code")},k.prototype.toFailure=function(t){const e=this.expr===b?"nothing":"not "+this.expr.toFailure(t);return new yt(this,e,"description")},D.prototype.toFailure=function(t){return this.expr.toFailure(t)},M.prototype.toFailure=function(t){let{description:e}=t.rules[this.ruleName];if(!e){e=(/^[aeiouAEIOU]/.test(this.ruleName)?"an":"a")+" "+this.ruleName}return new yt(this,e,"description")},G.prototype.toFailure=function(t){return new yt(this,"a Unicode ["+this.categoryOrProp+"] character","description")},O.prototype.toFailure=function(t){const e="("+this.terms.map((e=>e.toFailure(t))).join(" or ")+")";return new yt(this,e,"description")},P.prototype.toFailure=function(t){const e="("+this.factors.map((e=>e.toFailure(t))).join(" ")+")";return new yt(this,e,"description")},F.prototype.toFailure=function(t){const e="("+this.expr.toFailure(t)+this.operator+")";return new yt(this,e,"description")},S.prototype.toString=e("toString"),b.toString=function(){return"any"},_.toString=function(){return"end"},w.prototype.toString=function(){return JSON.stringify(this.obj)},A.prototype.toString=function(){return JSON.stringify(this.from)+".."+JSON.stringify(this.to)},N.prototype.toString=function(){return"$"+this.index},j.prototype.toString=function(){return"#("+this.expr.toString()+")"},O.prototype.toString=function(){return 1===this.terms.length?this.terms[0].toString():"("+this.terms.map((t=>t.toString())).join(" | ")+")"},P.prototype.toString=function(){return 1===this.factors.length?this.factors[0].toString():"("+this.factors.map((t=>t.toString())).join(" ")+")"},F.prototype.toString=function(){return this.expr+this.operator},k.prototype.toString=function(){return"~"+this.expr},D.prototype.toString=function(){return"&"+this.expr},M.prototype.toString=function(){if(this.args.length>0){const t=this.args.map((t=>t.toString()));return this.ruleName+"<"+t.join(",")+">"}return this.ruleName},G.prototype.toString=function(){return"\\p{"+this.categoryOrProp+"}"};class xt extends S{constructor(t){super(),this.obj=t}_getString(t){const e=t.currentApplication().args[this.obj.index];return r(e instanceof w,"expected a Terminal expression"),e.obj}allowsSkippingPrecedingSpace(){return!0}eval(t){const{inputStream:e}=t,r=e.pos,n=this._getString(t);return e.matchString(n,!0)?(t.pushBinding(new mt(n.length),r),!0):(t.processFailure(r,this),!1)}getArity(){return 1}substituteParams(t){return new xt(this.obj.substituteParams(t))}toDisplayString(){return this.obj.toDisplayString()+" (case-insensitive)"}toFailure(t){return new yt(this,this.obj.toFailure(t)+" (case-insensitive)","description")}_isNullable(t,e){return this.obj._isNullable(t,e)}}var St=Object.freeze({__proto__:null,CaseInsensitiveTerminal:xt,PExpr:S,any:b,end:_,Terminal:w,Range:A,Param:N,Alt:O,Extend:R,Splice:L,Seq:P,Iter:F,Star:E,Plus:C,Opt:T,Not:k,Lookahead:D,Lex:j,Apply:M,UnicodeChar:G});let bt;Y((t=>{bt=t.rules.applySyntactic.body}));const _t=new M("spaces");class wt{constructor(t,e,r){this.matcher=t,this.startExpr=e,this.grammar=t.grammar,this.input=t.getInput(),this.inputStream=new it(this.input),this.memoTable=t._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=[],void 0!==r&&(this.positionToRecordFailures=r,this.recordedFailures=Object.create(null))}posToOffset(t){return t-this._posStack[this._posStack.length-1]}enterApplication(t,e){this._posStack.push(this.inputStream.pos),this._applicationStack.push(e),this.inLexifiedContextStack.push(!1),t.enter(e),this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this.rightmostFailurePosition=-1}exitApplication(t,e){const r=this._posStack.pop();this._applicationStack.pop(),this.inLexifiedContextStack.pop(),t.exit(),this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,this._rightmostFailurePositionStack.pop()),e&&this.pushBinding(e,r)}enterLexifiedContext(){this.inLexifiedContextStack.push(!0)}exitLexifiedContext(){this.inLexifiedContextStack.pop()}currentApplication(){return this._applicationStack[this._applicationStack.length-1]}inSyntacticContext(){const t=this.currentApplication();return t?t.isSyntactic()&&!this.inLexifiedContext():this.startExpr.factors[0].isSyntactic()}inLexifiedContext(){return this.inLexifiedContextStack[this.inLexifiedContextStack.length-1]}skipSpaces(){return this.pushFailuresInfo(),this.eval(_t),this.popBinding(),this.popFailuresInfo(),this.inputStream.pos}skipSpacesIfInSyntacticContext(){return this.inSyntacticContext()?this.skipSpaces():this.inputStream.pos}maybeSkipSpacesBefore(t){return t.allowsSkippingPrecedingSpace()&&t!==_t?this.skipSpacesIfInSyntacticContext():this.inputStream.pos}pushBinding(t,e){this._bindings.push(t),this._bindingOffsets.push(this.posToOffset(e))}popBinding(){this._bindings.pop(),this._bindingOffsets.pop()}numBindings(){return this._bindings.length}truncateBindings(t){for(;this._bindings.length>t;)this.popBinding()}getCurrentPosInfo(){return this.getPosInfo(this.inputStream.pos)}getPosInfo(t){let e=this.memoTable[t];return e||(e=this.memoTable[t]=new ot),e}processFailure(t,e){if(this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,t),this.recordedFailures&&t===this.positionToRecordFailures){const t=this.currentApplication();t&&(e=e.substituteParams(t.args)),this.recordFailure(e.toFailure(this.grammar),!1)}}recordFailure(t,e){const r=t.toKey();this.recordedFailures[r]?this.recordedFailures[r].isFluffy()&&!t.isFluffy()&&this.recordedFailures[r].clearFluffy():this.recordedFailures[r]=e?t.clone():t}recordFailures(t,e){Object.keys(t).forEach((r=>{this.recordFailure(t[r],e)}))}cloneRecordedFailures(){if(!this.recordedFailures)return;const t=Object.create(null);return Object.keys(this.recordedFailures).forEach((e=>{t[e]=this.recordedFailures[e].clone()})),t}getRightmostFailurePosition(){return this.rightmostFailurePosition}_getRightmostFailureOffset(){return this.rightmostFailurePosition>=0?this.posToOffset(this.rightmostFailurePosition):-1}getMemoizedTraceEntry(t,e){const r=this.memoTable[t];if(r&&e instanceof M){const t=r.memo[e.toMemoKey()];if(t&&t.traceEntry){const r=t.traceEntry.cloneWithExpr(e);return r.isMemoized=!0,r}}return null}getTraceEntry(t,e,r,n){if(e instanceof M){const t=this.currentApplication(),r=t?t.args:[];e=e.substituteParams(r)}return this.getMemoizedTraceEntry(t,e)||new ct(this.input,t,this.inputStream.pos,e,r,n,this.trace)}isTracing(){return!!this.trace}hasNecessaryInfo(t){return!(this.trace&&!t.traceEntry)&&(!this.recordedFailures||this.inputStream.pos+t.rightmostFailureOffset!==this.positionToRecordFailures||!!t.failuresAtRightmostPosition)}useMemoizedResult(t,e){this.trace&&this.trace.push(e.traceEntry);const r=this.inputStream.pos+e.rightmostFailureOffset;return this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,r),this.recordedFailures&&this.positionToRecordFailures===r&&e.failuresAtRightmostPosition&&this.recordFailures(e.failuresAtRightmostPosition,!0),this.inputStream.examinedLength=Math.max(this.inputStream.examinedLength,e.examinedLength+t),!!e.value&&(this.inputStream.pos+=e.matchLength,this.pushBinding(e.value,t),!0)}eval(t){const{inputStream:e}=this,r=this._bindings.length,n=this.userData;let i;this.recordedFailures&&(i=this.recordedFailures,this.recordedFailures=Object.create(null));const s=e.pos,o=this.maybeSkipSpacesBefore(t);let a;this.trace&&(a=this.trace,this.trace=[]);const u=t.eval(this);if(this.trace){const e=this._bindings.slice(r),n=this.getTraceEntry(o,t,u,e);n.isImplicitSpaces=t===_t,n.isRootNode=t===this.startExpr,a.push(n),this.trace=a}return u?this.recordedFailures&&e.pos===this.positionToRecordFailures&&Object.keys(this.recordedFailures).forEach((t=>{this.recordedFailures[t].makeFluffy()})):(e.pos=s,this.truncateBindings(r),this.userData=n),this.recordedFailures&&this.recordFailures(i,!1),t===bt&&this.skipSpaces(),u}getMatchResult(){let t;this.grammar._setUpMatchState(this),this.eval(this.startExpr),this.recordedFailures&&(t=Object.keys(this.recordedFailures).map((t=>this.recordedFailures[t])));const e=this._bindings[0];return e&&(e.grammar=this.grammar),new st(this.matcher,this.input,this.startExpr,e,this._bindingOffsets[0],this.rightmostFailurePosition,t)}getTrace(){this.trace=[];const t=this.getMatchResult(),e=this.trace[this.trace.length-1];return e.result=t,e}pushFailuresInfo(){this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this._recordedFailuresStack.push(this.recordedFailures)}popFailuresInfo(){this.rightmostFailurePosition=this._rightmostFailurePositionStack.pop(),this.recordedFailures=this._recordedFailuresStack.pop()}}class At{constructor(t){this.grammar=t,this._memoTable=[],this._input="",this._isMemoTableStale=!1}_resetMemoTable(){this._memoTable=[],this._isMemoTableStale=!1}getInput(){return this._input}setInput(t){return this._input!==t&&this.replaceInputRange(0,this._input.length,t),this}replaceInputRange(t,e,r){const n=this._input,i=this._memoTable;if(t<0||t>n.length||e<0||e>n.length||t>e)throw new Error("Invalid indices: "+t+" and "+e);this._input=n.slice(0,t)+r+n.slice(e),this._input!==n&&i.length>0&&(this._isMemoTableStale=!0);const s=i.slice(e);i.length=t;for(let t=0;t<r.length;t++)i.push(void 0);for(const t of s)i.push(t);for(let e=0;e<t;e++){const r=i[e];r&&r.clearObsoleteEntries(e,t)}return this}match(t,e={incremental:!0}){return this._match(this._getStartExpr(t),{incremental:e.incremental,tracing:!1})}trace(t,e={incremental:!0}){return this._match(this._getStartExpr(t),{incremental:e.incremental,tracing:!0})}_match(t,e={}){const r={tracing:!1,incremental:!0,positionToRecordFailures:void 0,...e};if(r.incremental){if(this._isMemoTableStale&&!this.grammar.supportsIncrementalParsing)throw function(t){return B(`Grammar '${t.name}' does not support incremental parsing`)}(this.grammar)}else this._resetMemoTable();const n=new wt(this,t,r.positionToRecordFailures);return r.tracing?n.getTrace():n.getMatchResult()}_getStartExpr(t){const e=t||this.grammar.defaultStartRule;if(!e)throw new Error("Missing start rule argument -- the grammar has no default start rule.");const r=this.grammar.parseApplication(e);return new P([r,_])}}const Nt=[],Ot=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class Rt{constructor(t,e,n){this._node=t,this.source=e,this._baseInterval=n,t.isNonterminal()&&r(e===n),this._childWrappers=[]}_forgetMemoizedResultFor(t){delete this._node[this._semantics.attributeKeys[t]],this.children.forEach((e=>{e._forgetMemoizedResultFor(t)}))}child(t){if(!(0<=t&&t<this._node.numChildren()))return;let e=this._childWrappers[t];if(!e){const r=this._node.childAt(t),n=this._node.childOffsets[t],i=this._baseInterval.subInterval(n,r.matchLength),s=r.isNonterminal()?i:this._baseInterval;e=this._childWrappers[t]=this._semantics.wrap(r,i,s)}return e}_children(){for(let t=0;t<this._node.numChildren();t++)this.child(t);return this._childWrappers}isIteration(){return this._node.isIteration()}isTerminal(){return this._node.isTerminal()}isNonterminal(){return this._node.isNonterminal()}isSyntactic(){return this.isNonterminal()&&this._node.isSyntactic()}isLexical(){return this.isNonterminal()&&this._node.isLexical()}isOptional(){return this._node.isOptional()}iteration(t){const e=t||[],r=e.map((t=>t._node)),n=new ft(r,[],-1,!1),i=this._semantics.wrap(n,null,null);return i._childWrappers=e,i}get children(){return this._children()}get ctorName(){return this._node.ctorName}get numChildren(){return this._node.numChildren()}get sourceString(){return this.source.contents}}class Lt{constructor(t,e){const r=this;if(this.grammar=t,this.checkedActionDicts=!1,this.Wrapper=class extends(e?e.Wrapper:Rt){constructor(t,e,n){super(t,e,n),r.checkActionDictsIfHaventAlready(),this._semantics=r}toString(){return"[semantics wrapper for "+r.grammar.name+"]"}},this.super=e,e){if(!t.equals(this.super.grammar)&&!t._inheritsFrom(this.super.grammar))throw new Error("Cannot extend a semantics for grammar '"+this.super.grammar.name+"' for use with grammar '"+t.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 t in this.attributes)Object.defineProperty(this.attributeKeys,t,{value:rt(t)})}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 t;for(t in this.operations)this.operations[t].checkActionDict(this.grammar);for(t in this.attributes)this.attributes[t].checkActionDict(this.grammar)}toRecipe(t){function e(t){return t.super!==Lt.BuiltInSemantics._getSemantics()}let r="(function(g) {\n";if(e(this)){r+=" var semantics = "+this.super.toRecipe(!0)+"(g";const t=this.super.grammar;let e=this.grammar;for(;e!==t;)r+=".superGrammar",e=e.superGrammar;r+=");\n",r+=" return g.extendSemantics(semantics)"}else r+=" return g.createSemantics()";return["Operation","Attribute"].forEach((t=>{const n=this[t.toLowerCase()+"s"];Object.keys(n).forEach((i=>{const{actionDict:s,formals:o,builtInDefault:a}=n[i];let u,c=i;o.length>0&&(c+="("+o.join(", ")+")"),u=e(this)&&this.super[t.toLowerCase()+"s"][i]?"extend"+t:"add"+t,r+="\n ."+u+"("+JSON.stringify(c)+", {";const l=[];Object.keys(s).forEach((t=>{if(s[t]!==a){let e=s[t].toString().trim();e=e.replace(/^.*\(/,"function("),l.push("\n "+JSON.stringify(t)+": "+e)}})),r+=l.join(",")+"\n })"}))})),r+=";\n })",t||(r="(function() {\n var grammar = this.fromRecipe("+this.grammar.toRecipe()+");\n var semantics = "+r+"(grammar);\n return semantics;\n});\n"),r}addOperationOrAttribute(t,e,r){const n=t+"s",i=Pt(e,t),{name:s}=i,{formals:o}=i;this.assertNewName(s,t);const a=function(t,e,r){return function(...n){const i=(this._semantics.operations[e]||this._semantics.attributes[e]).formals.map((t=>this.args[t]));if(this.isIteration()||1!==n.length)throw function(t,e,r,n){let i=n.slice(0,-1).map((t=>{const e=" "+t[0].name+" > "+t[1];return 3===t.length?e+" for '"+t[2]+"'":e})).join("\n");i+="\n "+e+" > "+t;let s="";"_iter"===t&&(s=["\nNOTE: as of Ohm v16, there is no default action for iteration nodes — see "," https://ohmjs.org/d/dsa for details."].join("\n"));const o=B([`Missing semantic action for '${t}' in ${r} '${e}'.${s}`,"Action stack (most recent call last):",i].join("\n"));return o.name="missingSemanticAction",o}(this.ctorName,e,t,Nt);return r.apply(n[0],i)}}(t,s,l),u={_default:a};Object.keys(r).forEach((t=>{u[t]=r[t]}));const c="operation"===t?new Ft(s,o,u,a):new Et(s,u,a);function l(...e){const r=this._semantics[n][s];if(arguments.length!==r.formals.length)throw new Error("Invalid number of arguments passed to "+s+" "+t+" (expected "+r.formals.length+", got "+arguments.length+")");const i=Object.create(null);for(const[t,n]of Object.entries(e)){i[r.formals[t]]=n}const o=this.args;this.args=i;const a=r.execute(this._semantics,this);return this.args=o,a}c.checkActionDict(this.grammar),this[n][s]=c,"operation"===t?(this.Wrapper.prototype[s]=l,this.Wrapper.prototype[s].toString=function(){return"["+s+" operation]"}):(Object.defineProperty(this.Wrapper.prototype,s,{get:l,configurable:!0}),Object.defineProperty(this.attributeKeys,s,{value:rt(s)}))}extendOperationOrAttribute(t,e,r){const n=t+"s";if(Pt(e,"attribute"),!this.super||!(e in this.super[n]))throw new Error("Cannot extend "+t+" '"+e+"': did not inherit an "+t+" with that name");if(Ot(this[n],e))throw new Error("Cannot extend "+t+" '"+e+"' again");const i=this[n][e].formals,s=this[n][e].actionDict,o=Object.create(s);Object.keys(r).forEach((t=>{o[t]=r[t]})),this[n][e]="operation"===t?new Ft(e,i,o):new Et(e,o),this[n][e].checkActionDict(this.grammar)}assertNewName(t,e){if(Ot(Rt.prototype,t))throw new Error("Cannot add "+e+" '"+t+"': that's a reserved name");if(t in this.operations)throw new Error("Cannot add "+e+" '"+t+"': an operation with that name already exists");if(t in this.attributes)throw new Error("Cannot add "+e+" '"+t+"': an attribute with that name already exists")}wrap(t,e,r){const n=r||e;return t instanceof this.Wrapper?t:new this.Wrapper(t,e,n)}}function Pt(t,e){if(!Lt.prototypeGrammar)return r(-1===t.indexOf("(")),{name:t,formals:[]};const n=Lt.prototypeGrammar.match(t,"operation"===e?"OperationSignature":"AttributeSignature");if(n.failed())throw new Error(n.message);return Lt.prototypeGrammarSemantics(n).parse()}Lt.createSemantics=function(t,e){const r=new Lt(t,void 0!==e?e:Lt.BuiltInSemantics._getSemantics()),n=function(e){if(!(e instanceof st))throw new TypeError("Semantics expected a MatchResult, but got "+f(e));if(e.failed())throw new TypeError("cannot apply Semantics to "+e.toString());const n=e._cst;if(n.grammar!==t)throw new Error("Cannot use a MatchResult from grammar '"+n.grammar.name+"' with a semantics for '"+t.name+"'");const i=new it(e.input);return r.wrap(n,i.interval(e._cstOffset,e.input.length))};return n.addOperation=function(t,e){return r.addOperationOrAttribute("operation",t,e),n},n.extendOperation=function(t,e){return r.extendOperationOrAttribute("operation",t,e),n},n.addAttribute=function(t,e){return r.addOperationOrAttribute("attribute",t,e),n},n.extendAttribute=function(t,e){return r.extendOperationOrAttribute("attribute",t,e),n},n._getActionDict=function(e){const n=r.operations[e]||r.attributes[e];if(!n)throw new Error('"'+e+'" is not a valid operation or attribute name in this semantics for "'+t.name+'"');return n.actionDict},n._remove=function(t){let e;return t in r.operations?(e=r.operations[t],delete r.operations[t]):t in r.attributes&&(e=r.attributes[t],delete r.attributes[t]),delete r.Wrapper.prototype[t],e},n.getOperationNames=function(){return Object.keys(r.operations)},n.getAttributeNames=function(){return Object.keys(r.attributes)},n.getGrammar=function(){return r.grammar},n.toRecipe=function(t){return r.toRecipe(t)},n.toString=r.toString.bind(r),n._getSemantics=function(){return r},n};class Ft{constructor(t,e,r,n){this.name=t,this.formals=e,this.actionDict=r,this.builtInDefault=n}checkActionDict(t){t._checkTopDownActionDict(this.typeName,this.name,this.actionDict)}execute(t,e){try{const{ctorName:t}=e._node;let r=this.actionDict[t];return r?(Nt.push([this,t]),r.apply(e,e._children())):e.isNonterminal()&&(r=this.actionDict._nonterminal,r)?(Nt.push([this,"_nonterminal",t]),r.apply(e,e._children())):(Nt.push([this,"default action",t]),this.actionDict._default.apply(e,e._children()))}finally{Nt.pop()}}}Ft.prototype.typeName="operation";class Et extends Ft{constructor(t,e,r){super(t,[],e,r)}execute(t,e){const r=e._node,n=t.attributeKeys[this.name];return Ot(r,n)||(r[n]=Ft.prototype.execute.call(this,t,e)),r[n]}}Et.prototype.typeName="attribute";const Ct=["_iter","_terminal","_nonterminal","_default"];function Tt(t){return Object.keys(t.rules).sort().map((e=>t.rules[e]))}let kt,Dt;class jt{constructor(t,e,r,n){if(this.name=t,this.superGrammar=e,this.rules=r,n){if(!(n in r))throw new Error("Invalid start rule: '"+n+"' is not a rule in grammar '"+t+"'");this.defaultStartRule=n}this._matchStateInitializer=void 0,this.supportsIncrementalParsing=!0}matcher(){return new At(this)}isBuiltIn(){return this===jt.ProtoBuiltInRules||this===jt.BuiltInRules}equals(t){if(this===t)return!0;if(null==t||this.name!==t.name||this.defaultStartRule!==t.defaultStartRule||this.superGrammar!==t.superGrammar&&!this.superGrammar.equals(t.superGrammar))return!1;const e=Tt(this),r=Tt(t);return e.length===r.length&&e.every(((t,e)=>t.description===r[e].description&&t.formals.join(",")===r[e].formals.join(",")&&t.body.toString()===r[e].body.toString()))}match(t,e){const r=this.matcher();return r.replaceInputRange(0,0,t),r.match(e)}trace(t,e){const r=this.matcher();return r.replaceInputRange(0,0,t),r.trace(e)}createSemantics(){return Lt.createSemantics(this)}extendSemantics(t){return Lt.createSemantics(this,t._getSemantics())}_checkTopDownActionDict(t,e,r){const n=[];for(const t in r){const e=r[t];if(!Ct.includes(t)&&!(t in this.rules)){n.push(`'${t}' is not a valid semantic action for '${this.name}'`);continue}if("function"!=typeof e){n.push(`'${t}' must be a function in an action dictionary for '${this.name}'`);continue}const i=e.length,s=this._topDownActionArity(t);if(i!==s){let e;e="_iter"===t||"_nonterminal"===t?`it should use a rest parameter, e.g. \`${t}(...children) {}\`. NOTE: this is new in Ohm v16 — see https://ohmjs.org/d/ati for details.`:`expected ${s}, got ${i}`,n.push(`Semantic action '${t}' has the wrong arity: ${e}`)}}if(n.length>0){const r=n.map((t=>"- "+t)),i=new Error([`Found errors in the action dictionary of the '${e}' ${t}:`,...r].join("\n"));throw i.problems=n,i}}_topDownActionArity(t){return Ct.includes(t)?0:this.rules[t].body.getArity()}_inheritsFrom(t){let e=this.superGrammar;for(;e;){if(e.equals(t,!0))return!0;e=e.superGrammar}return!1}toRecipe(t=void 0){const e={};this.source&&(e.source=this.source.contents);let r=null;this.defaultStartRule&&(r=this.defaultStartRule);const n={};Object.keys(this.rules).forEach((t=>{const e=this.rules[t],{body:r}=e,i=!this.superGrammar||!this.superGrammar.rules[t];let s;s=i?"define":r instanceof R?"extend":"override";const o={};if(e.source&&this.source){const t=e.source.relativeTo(this.source);o.sourceInterval=[t.startIdx,t.endIdx]}const a=i?e.description:null,u=r.outputRecipe(e.formals,this.source);n[t]=[s,o,a,e.formals,u]}));let i="null";t?i=t:this.superGrammar&&!this.superGrammar.isBuiltIn()&&(i=this.superGrammar.toRecipe());const s=[...["grammar",e,this.name].map(JSON.stringify),i,...[r,n].map(JSON.stringify)];return`[${s.join(",")}]`.replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}toOperationActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}toAttributeActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}_toOperationOrAttributeActionDictionaryTemplate(){const t=new h;t.append("{");let e=!0;for(const r in this.rules){const{body:n}=this.rules[r];e?e=!1:t.append(","),t.append("\n"),t.append(" "),this.addSemanticActionTemplate(r,n,t)}return t.append("\n}"),t.contents()}addSemanticActionTemplate(t,e,r){r.append(t),r.append(": function(");const n=this._topDownActionArity(t);r.append(o("_",n).join(", ")),r.append(") {\n"),r.append(" }")}parseApplication(t){let e;if(-1===t.indexOf("<"))e=new M(t);else{const r=kt.match(t,"Base_application");e=Dt(r,{})}if(!(e.ruleName in this.rules))throw U(e.ruleName,this.name);const{formals:r}=this.rules[e.ruleName];if(r.length!==e.args.length){const{source:t}=this.rules[e.ruleName];throw z(e.ruleName,r.length,e.args.length,t)}return e}_setUpMatchState(t){this._matchStateInitializer&&this._matchStateInitializer(t)}}jt.ProtoBuiltInRules=new jt("ProtoBuiltInRules",void 0,{any:{body:b,formals:[],description:"any character",primitive:!0},end:{body:_,formals:[],description:"end of input",primitive:!0},caseInsensitive:{body:new xt(new N(0)),formals:["str"],primitive:!0},lower:{body:new G("Ll"),formals:[],description:"a lowercase letter",primitive:!0},upper:{body:new G("Lu"),formals:[],description:"an uppercase letter",primitive:!0},unicodeLtmo:{body:new G("Ltmo"),formals:[],description:"a Unicode character in Lt, Lm, or Lo",primitive:!0},spaces:{body:new E(new M("space")),formals:[]},space:{body:new A("\0"," "),formals:[],description:"a space"}}),jt.initApplicationParser=function(t,e){kt=t,Dt=e};class Mt{constructor(t){this.name=t}sourceInterval(t,e){return this.source.subInterval(t,e-t)}ensureSuperGrammar(){return this.superGrammar||this.withSuperGrammar("BuiltInRules"===this.name?jt.ProtoBuiltInRules:jt.BuiltInRules),this.superGrammar}ensureSuperGrammarRuleForOverriding(t,e){const r=this.ensureSuperGrammar().rules[t];if(!r)throw n=t,i=this.superGrammar.name,B("Cannot override rule "+n+" because it is not declared in "+i,e);var n,i;return r}installOverriddenOrExtendedRule(t,e,r,n){const i=a(e);if(i.length>0)throw K(t,i,n);const s=this.ensureSuperGrammar().rules[t],o=s.formals,u=o?o.length:0;if(e.length!==u)throw z(t,u,e.length,n);return this.install(t,e,r,s.description,n)}install(t,e,r,n,i,s=!1){return this.rules[t]={body:r.introduceParams(e),formals:e,description:n,source:i,primitive:s},this}withSuperGrammar(t){if(this.superGrammar)throw new Error("the super grammar of a GrammarDecl cannot be set more than once");return this.superGrammar=t,this.rules=Object.create(t.rules),t.isBuiltIn()||(this.defaultStartRule=t.defaultStartRule),this}withDefaultStartRule(t){return this.defaultStartRule=t,this}withSource(t){return this.source=new it(t).interval(0,t.length),this}build(){const t=new jt(this.name,this.ensureSuperGrammar(),this.rules,this.defaultStartRule);t._matchStateInitializer=t.superGrammar._matchStateInitializer,t.supportsIncrementalParsing=t.superGrammar.supportsIncrementalParsing;const e=[];let r=!1;return Object.keys(t.rules).forEach((n=>{const{body:i}=t.rules[n];try{i.assertChoicesHaveUniformArity(n)}catch(t){e.push(t)}try{i.assertAllApplicationsAreValid(n,t)}catch(t){e.push(t),r=!0}})),r||Object.keys(t.rules).forEach((r=>{const{body:n}=t.rules[r];try{n.assertIteratedExprsAreNotNullable(t,[])}catch(t){e.push(t)}})),e.length>0&&J(e),this.source&&(t.source=this.source),t}define(t,e,r,n,i,s){if(this.ensureSuperGrammar(),this.superGrammar.rules[t])throw $(t,this.name,this.superGrammar.name,i);if(this.rules[t])throw $(t,this.name,this.name,i);const o=a(e);if(o.length>0)throw K(t,o,i);return this.install(t,e,r,n,i,s)}override(t,e,r,n,i){return this.ensureSuperGrammarRuleForOverriding(t,i),this.installOverriddenOrExtendedRule(t,e,r,i),this}extend(t,e,r,n,i){if(!this.ensureSuperGrammar().rules[t])throw s=t,o=this.superGrammar.name,B("Cannot extend rule "+s+" because it is not declared in "+o,i);var s,o;const a=new R(this.superGrammar,t,r);return a.source=r.source,this.installOverriddenOrExtendedRule(t,e,a,i),this}}class Gt{constructor(){this.currentDecl=null,this.currentRuleName=null}newGrammar(t){return new Mt(t)}grammar(t,e,r,n,i){const s=new Mt(e);return r&&s.withSuperGrammar(r instanceof jt?r:this.fromRecipe(r)),n&&s.withDefaultStartRule(n),t&&t.source&&s.withSource(t.source),this.currentDecl=s,Object.keys(i).forEach((t=>{this.currentRuleName=t;const e=i[t],r=e[0],n=e[1],o=e[2],a=e[3],u=this.fromRecipe(e[4]);let c;s.source&&n&&n.sourceInterval&&(c=s.source.subInterval(n.sourceInterval[0],n.sourceInterval[1]-n.sourceInterval[0])),s[r](t,a,u,o,c)})),this.currentRuleName=this.currentDecl=null,s.build()}terminal(t){return new w(t)}range(t,e){return new A(t,e)}param(t){return new N(t)}alt(...t){let e=[];for(let r of t)r instanceof S||(r=this.fromRecipe(r)),r instanceof O?e=e.concat(r.terms):e.push(r);return 1===e.length?e[0]:new O(e)}seq(...t){let e=[];for(let r of t)r instanceof S||(r=this.fromRecipe(r)),r instanceof P?e=e.concat(r.factors):e.push(r);return 1===e.length?e[0]:new P(e)}star(t){return t instanceof S||(t=this.fromRecipe(t)),new E(t)}plus(t){return t instanceof S||(t=this.fromRecipe(t)),new C(t)}opt(t){return t instanceof S||(t=this.fromRecipe(t)),new T(t)}not(t){return t instanceof S||(t=this.fromRecipe(t)),new k(t)}lookahead(t){return t instanceof S||(t=this.fromRecipe(t)),new D(t)}lex(t){return t instanceof S||(t=this.fromRecipe(t)),new j(t)}app(t,e){return e&&e.length>0&&(e=e.map((function(t){return t instanceof S?t:this.fromRecipe(t)}),this)),new M(t,e)}splice(t,e){return new L(this.currentDecl.superGrammar,this.currentRuleName,t.map((t=>this.fromRecipe(t))),e.map((t=>this.fromRecipe(t))))}fromRecipe(t){const e="grammar"===t[0]?t.slice(1):t.slice(2),r=this[t[0]](...e),n=t[1];return n&&n.sourceInterval&&this.currentDecl&&r.withSource(this.currentDecl.sourceInterval(...n.sourceInterval)),r}}function Bt(t){return"function"==typeof t?t.call(new Gt):("string"==typeof t&&(t=JSON.parse(t)),(new Gt).fromRecipe(t))}var qt=Bt(["grammar",{source:'BuiltInRules {\n\n alnum (an alpha-numeric character)\n = letter\n | digit\n\n letter (a letter)\n = lower\n | upper\n | unicodeLtmo\n\n digit (a digit)\n = "0".."9"\n\n hexDigit (a hexadecimal digit)\n = digit\n | "a".."f"\n | "A".."F"\n\n ListOf<elem, sep>\n = NonemptyListOf<elem, sep>\n | EmptyListOf<elem, sep>\n\n NonemptyListOf<elem, sep>\n = elem (sep elem)*\n\n EmptyListOf<elem, sep>\n = /* nothing */\n\n listOf<elem, sep>\n = nonemptyListOf<elem, sep>\n | emptyListOf<elem, sep>\n\n nonemptyListOf<elem, sep>\n = elem (sep elem)*\n\n emptyListOf<elem, sep>\n = /* nothing */\n\n // Allows a syntactic rule application within a lexical context.\n applySyntactic<app> = app\n}'},"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]]}]);jt.BuiltInRules=qt,function(t){X.forEach((e=>{e(t)})),X=null}(jt.BuiltInRules);var Ut=Bt(["grammar",{source:'Ohm {\n\n Grammars\n = Grammar*\n\n Grammar\n = ident SuperGrammar? "{" Rule* "}"\n\n SuperGrammar\n = "<:" ident\n\n Rule\n = ident Formals? ruleDescr? "=" RuleBody -- define\n | ident Formals? ":=" OverrideRuleBody -- override\n | ident Formals? "+=" RuleBody -- extend\n\n RuleBody\n = "|"? NonemptyListOf<TopLevelTerm, "|">\n\n TopLevelTerm\n = Seq caseName -- inline\n | Seq\n\n OverrideRuleBody\n = "|"? NonemptyListOf<OverrideTopLevelTerm, "|">\n\n OverrideTopLevelTerm\n = "..." -- superSplice\n | TopLevelTerm\n\n Formals\n = "<" ListOf<ident, ","> ">"\n\n Params\n = "<" ListOf<Seq, ","> ">"\n\n Alt\n = NonemptyListOf<Seq, "|">\n\n Seq\n = Iter*\n\n Iter\n = Pred "*" -- star\n | Pred "+" -- plus\n | Pred "?" -- opt\n | Pred\n\n Pred\n = "~" Lex -- not\n | "&" Lex -- lookahead\n | Lex\n\n Lex\n = "#" Base -- lex\n | Base\n\n Base\n = ident Params? ~(ruleDescr? "=" | ":=" | "+=") -- application\n | oneCharTerminal ".." oneCharTerminal -- range\n | terminal -- terminal\n | "(" Alt ")" -- paren\n\n ruleDescr (a rule description)\n = "(" ruleDescrText ")"\n\n ruleDescrText\n = (~")" any)*\n\n caseName\n = "--" (~"\\n" space)* name (~"\\n" space)* ("\\n" | &"}")\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n ident (an identifier)\n = name\n\n terminal\n = "\\"" terminalChar* "\\""\n\n oneCharTerminal\n = "\\"" terminalChar "\\""\n\n terminalChar\n = escapeChar\n | ~"\\\\" ~"\\"" ~"\\n" "\\u{0}".."\\u{10FFFF}"\n\n escapeChar (an escape sequence)\n = "\\\\\\\\" -- backslash\n | "\\\\\\"" -- doubleQuote\n | "\\\\\\\'" -- singleQuote\n | "\\\\b" -- backspace\n | "\\\\n" -- lineFeed\n | "\\\\r" -- carriageReturn\n | "\\\\t" -- tab\n | "\\\\u{" hexDigit hexDigit? hexDigit?\n hexDigit? hexDigit? hexDigit? "}" -- unicodeCodePoint\n | "\\\\u" hexDigit hexDigit hexDigit hexDigit -- unicodeEscape\n | "\\\\x" hexDigit hexDigit -- hexEscape\n\n space\n += comment\n\n comment\n = "//" (~"\\n" any)* &("\\n" | end) -- singleLine\n | "/*" (~"*/" any)* "*/" -- multiLine\n\n tokens = token*\n\n token = caseName | comment | ident | operator | punctuation | terminal | any\n\n operator = "<:" | "=" | ":=" | "+=" | "*" | "+" | "?" | "~" | "&"\n\n punctuation = "<" | ">" | "," | "--"\n}'},"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]},"\n"]],["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]},"\n"]],["app",{sourceInterval:[1317,1322]},"space",[]]]],["alt",{sourceInterval:[1326,1337]},["terminal",{sourceInterval:[1326,1330]},"\n"],["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]},"\n"]],["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]},"\n"]],["app",{sourceInterval:[2424,2427]},"any",[]]]],["lookahead",{sourceInterval:[2430,2443]},["alt",{sourceInterval:[2432,2442]},["terminal",{sourceInterval:[2432,2436]},"\n"],["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]},"--"]]]}]);const $t=Object.create(S.prototype);function zt(t,e){for(const r in t)if(r===e)return!0;return!1}function Kt(t,e,n){const i=new Gt;let s,o,a,u=!1;const c=(n||Ut).createSemantics().addOperation("visit",{Grammars:t=>t.children.map((t=>t.visit())),Grammar(t,r,n,o,a){const u=t.visit();s=i.newGrammar(u),r.child(0)&&r.child(0).visit(),o.children.map((t=>t.visit()));const c=s.build();if(c.source=this.source.trimmed(),zt(e,u))throw function(t){return B("Grammar "+t.name+" is already declared in this namespace")}(c);return e[u]=c,c},SuperGrammar(t,r){const n=r.visit();if("null"===n)s.withSuperGrammar(null);else{if(!e||!zt(e,n))throw function(t,e,r){return B(e?`Grammar ${t} is not declared in namespace '${e}'`:"Undeclared grammar "+t,r)}(n,e,r.source);s.withSuperGrammar(e[n])}},Rule_define(t,e,r,n,i){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[],s.defaultStartRule||s.ensureSuperGrammar()===jt.ProtoBuiltInRules||s.withDefaultStartRule(o);const u=i.visit(),c=r.children.map((t=>t.visit()))[0],l=this.source.trimmed();return s.define(o,a,u,c,l)},Rule_override(t,e,r,n){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[];const i=this.source.trimmed();s.ensureSuperGrammarRuleForOverriding(o,i),u=!0;const c=n.visit();return u=!1,s.override(o,a,c,null,i)},Rule_extend(t,e,r,n){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[];const i=n.visit(),u=this.source.trimmed();return s.extend(o,a,i,null,u)},RuleBody(t,e){return i.alt(...e.visit()).withSource(this.source)},OverrideRuleBody(t,e){const r=e.visit(),n=r.indexOf($t);if(n>=0){const t=r.slice(0,n),e=r.slice(n+1);return e.forEach((t=>{if(t===$t)throw B("'...' can appear at most once in a rule body",t.source)})),new L(s.superGrammar,o,t,e).withSource(this.source)}return i.alt(...r).withSource(this.source)},Formals:(t,e,r)=>e.visit(),Params:(t,e,r)=>e.visit(),Alt(t){return i.alt(...t.visit()).withSource(this.source)},TopLevelTerm_inline(t,e){const r=o+"_"+e.visit(),n=t.visit(),c=this.source.trimmed(),l=!(s.superGrammar&&s.superGrammar.rules[r]);u&&!l?s.override(r,a,n,null,c):s.define(r,a,n,null,c);const p=a.map((t=>i.app(t)));return i.app(r,p).withSource(n.source)},OverrideTopLevelTerm_superSplice:t=>$t,Seq(t){return i.seq(...t.children.map((t=>t.visit()))).withSource(this.source)},Iter_star(t,e){return i.star(t.visit()).withSource(this.source)},Iter_plus(t,e){return i.plus(t.visit()).withSource(this.source)},Iter_opt(t,e){return i.opt(t.visit()).withSource(this.source)},Pred_not(t,e){return i.not(e.visit()).withSource(this.source)},Pred_lookahead(t,e){return i.lookahead(e.visit()).withSource(this.source)},Lex_lex(t,e){return i.lex(e.visit()).withSource(this.source)},Base_application(t,e){const r=e.children.map((t=>t.visit()))[0]||[];return i.app(t.visit(),r).withSource(this.source)},Base_range(t,e,r){return i.range(t.visit(),r.visit()).withSource(this.source)},Base_terminal(t){return i.terminal(t.visit()).withSource(this.source)},Base_paren:(t,e,r)=>e.visit(),ruleDescr:(t,e,r)=>e.visit(),ruleDescrText(t){return this.sourceString.trim()},caseName:(t,e,r,n,i)=>r.visit(),name(t,e){return this.sourceString},nameFirst(t){},nameRest(t){},terminal:(t,e,r)=>e.children.map((t=>t.visit())).join(""),oneCharTerminal:(t,e,r)=>e.visit(),escapeChar(t){try{return d(this.sourceString)}catch(e){if(e instanceof RangeError&&e.message.startsWith("Invalid code point "))throw function(t){const e=t._node;r(e&&e.isNonterminal()&&"escapeChar_unicodeCodePoint"===e.ctorName);const n=t.children.slice(1,-1).map((t=>t.source)),i=n[0].coverageWith(...n.slice(1));return B(`U+${i.contents} is not a valid Unicode code point`,i)}(t);throw e}},NonemptyListOf:(t,e,r)=>[t.visit()].concat(r.children.map((t=>t.visit()))),EmptyListOf:()=>[],_terminal(){return this.sourceString}});return c(t).visit()}var Ht=Bt(["grammar",{source:'OperationsAndAttributes {\n\n AttributeSignature =\n name\n\n OperationSignature =\n name Formals?\n\n Formals\n = "(" ListOf<name, ","> ")"\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n}'},"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",[]]]]}]);!function(t){const e={empty(){return this.iteration()},nonEmpty(t,e,r){return this.iteration([t].concat(r.children))},self(...t){return this}};Lt.BuiltInSemantics=Lt.createSemantics(t,null).addOperation("asIteration",{emptyListOf:e.empty,nonemptyListOf:e.nonEmpty,EmptyListOf:e.empty,NonemptyListOf:e.nonEmpty,_iter:e.self})}(jt.BuiltInRules),function(t){Lt.prototypeGrammarSemantics=t.createSemantics().addOperation("parse",{AttributeSignature:t=>({name:t.parse(),formals:[]}),OperationSignature:(t,e)=>({name:t.parse(),formals:e.children.map((t=>t.parse()))[0]||[]}),Formals:(t,e,r)=>e.asIteration().children.map((t=>t.parse())),name(t,e){return this.sourceString}}),Lt.prototypeGrammar=t}(Ht);const Vt="an indented block",Wt="a dedent",Jt=1114112;class Qt extends it{constructor(t){super(t.input),this.state=t}_indentationAt(t){return this.state.userData[t]||0}atEnd(){return super.atEnd()&&0===this._indentationAt(this.pos)}next(){if(0===this._indentationAt(this.pos))return super.next();this.examinedLength=Math.max(this.examinedLength,this.pos)}nextCharCode(){return 0!==this._indentationAt(this.pos)?(this.examinedLength=Math.max(this.examinedLength,this.pos),Jt):super.nextCharCode()}nextCodePoint(){return 0!==this._indentationAt(this.pos)?(this.examinedLength=Math.max(this.examinedLength,this.pos),Jt):super.nextCodePoint()}}class Zt extends S{constructor(t=!0){super(),this.isIndent=t}allowsSkippingPrecedingSpace(){return!0}eval(t){const{inputStream:e}=t,r=t.userData;t.doNotMemoize=!0;const n=e.pos,i=this.isIndent?1:-1;return(r[n]||0)*i>0?(t.userData=Object.create(r),t.userData[n]-=i,t.pushBinding(new mt(0),n),!0):(t.processFailure(n,this),!1)}getArity(){return 1}_assertAllApplicationsAreValid(t,e){}_isNullable(t,e){return!1}assertChoicesHaveUniformArity(t){}assertIteratedExprsAreNotNullable(t){}introduceParams(t){return this}substituteParams(t){return this}toString(){return this.isIndent?"indent":"dedent"}toDisplayString(){return this.toString()}toFailure(t){const e=this.isIndent?Vt:Wt;return new yt(this,e,"description")}}const Xt=new M("indent"),Yt=new M("dedent"),te=new L(qt,"any",[Xt,Yt],[]),ee=(new Gt).newGrammar("IndentationSensitive").withSuperGrammar(qt).define("indent",[],new Zt(!0),Vt,void 0,!0).define("dedent",[],new Zt(!1),Wt,void 0,!0).extend("any",[],te,"any character",void 0).build();Object.assign(ee,{_matchStateInitializer(t){t.userData=function(t){let e=0;const r=[0],n=()=>r[r.length-1],i={},s=/( *).*(?:$|\r?\n|\r)/g;let o;for(;null!=(o=s.exec(t));){const[t,s]=o;if(0===t.length)break;const a=s.length,u=n(),c=e+a;if(a>u)r.push(a),i[c]=1;else if(a<u){const t=r.length;for(;n()!==a;)r.pop();i[c]=-1*(t-r.length)}e+=t.length}return r.length>1&&(i[e]=1-r.length),i}(t.input),t.inputStream=new Qt(t)},supportsIncrementalParsing:!1});jt.initApplicationParser(Ut,Kt);function re(t,e){const r=Ut.match(t,"Grammars");if(r.failed())throw function(t){const e=new Error;return Object.defineProperty(e,"message",{enumerable:!0,get:()=>t.message}),Object.defineProperty(e,"shortMessage",{enumerable:!0,get:()=>"Expected "+t.getExpectedText()}),e.interval=t.getInterval(),e}(r);return Kt(r,e)}function ne(t,e){const r=Object.create(e||{});if("string"!=typeof t){if(!(n=t).constructor||"function"!=typeof n.constructor.isBuffer||!n.constructor.isBuffer(n))throw new TypeError("Expected string as first argument, got "+f(t));t=t.toString()}var n;return re(t,r),r}t.ExperimentalIndentationSensitive=ee,t._buildGrammar=Kt,t.grammar=function(t,e){const r=ne(t,e),n=Object.keys(r);if(0===n.length)throw new Error("Missing grammar definition");if(n.length>1){const t=r[n[1]].source;throw new Error(et(t.sourceString,t.startIdx)+"Found more than one grammar definition -- use ohm.grammars() instead.")}return r[n[0]]},t.grammars=ne,t.makeRecipe=Bt,t.ohmGrammar=Ut,t.pexprs=St,t.version="17.3.0",Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ohm={})}(this,(function(t){"use strict";function e(t){const e=t||"";return function(){throw new Error("this method "+e+" is abstract! (it has no implementation in class "+this.constructor.name+")")}}function r(t,e){if(!t)throw new Error(e||"Assertion failed")}function n(t,e,r){let n;Object.defineProperty(t,e,{get(){return n||(n=r.call(this)),n}})}function i(t,e){const r=[];for(;e-- >0;)r.push(t());return r}function s(t,e){return new Array(e+1).join(t)}function o(t,e){return i((()=>t),e)}function a(t){const e=[];for(let r=0;r<t.length;r++){const n=t[r];t.lastIndexOf(n)!==r&&e.indexOf(n)<0&&e.push(n)}return e}function u(t){const e=[];return t.forEach((t=>{e.indexOf(t)<0&&e.push(t)})),e}function c(t){const e=t[0];return e===e.toUpperCase()}function l(t){return!c(t)}function p(t,e,r){const n=r||" ";return t.length<e?s(n,e-t.length)+t:t}function h(){this.strings=[]}h.prototype.append=function(t){this.strings.push(t)},h.prototype.contents=function(){return this.strings.join("")};const m=t=>String.fromCodePoint(parseInt(t,16));function d(t){if("\\"!==t.charAt(0))return t;switch(t.charAt(1)){case"b":return"\b";case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case"v":return"\v";case"x":return m(t.slice(2,4));case"u":return"{"===t.charAt(2)?m(t.slice(3,-1)):m(t.slice(2,6));default:return t.charAt(1)}}function f(t){if(null==t)return String(t);const e=Object.prototype.toString.call(t);try{let r;return r=t.constructor&&t.constructor.name?t.constructor.name:0===e.indexOf("[object ")?e.slice(8,-1):typeof t,r+": "+JSON.stringify(String(t))}catch{return e}}function g(t,e="unexpected null value"){if(null==t)throw new Error(e);return t}var v=Object.freeze({__proto__:null,abstract:e,assert:r,defineLazyProperty:n,clone:function(t){return t?Object.assign({},t):t},repeatFn:i,repeatStr:s,repeat:o,getDuplicates:a,copyWithoutDuplicates:u,isSyntactic:c,isLexical:l,padLeft:p,StringBuffer:h,unescapeCodePoint:d,unexpectedObjToString:f,checkNotNull:g});const I=t=>new RegExp(String.raw`\p{${t}}`,"u"),y=Object.fromEntries(["Cc","Cf","Cn","Co","Cs","Ll","Lm","Lo","Lt","Lu","Mc","Me","Mn","Nd","Nl","No","Pc","Pd","Pe","Pf","Pi","Po","Ps","Sc","Sk","Sm","So","Zl","Zp","Zs"].map((t=>[t,I(t)])));y.Ltmo=/\p{Lt}|\p{Lm}|\p{Lo}/u;const x=Object.fromEntries(["XID_Start","XID_Continue","White_Space"].map((t=>[t,I(t)])));class S{constructor(){if(this.constructor===S)throw new Error("PExpr cannot be instantiated -- it's abstract")}withSource(t){return t&&(this.source=t.trimmed()),this}}const b=Object.create(S.prototype),_=Object.create(S.prototype);class w extends S{constructor(t){super(),this.obj=t}}class A extends S{constructor(t,e){super(),this.from=t,this.to=e,this.matchCodePoint=t.length>1||e.length>1}}class O extends S{constructor(t){super(),this.index=t}}class N extends S{constructor(t){super(),this.terms=t}}class R extends N{constructor(t,e,r){super([r,t.rules[e].body]),this.superGrammar=t,this.name=e,this.body=r}}class L extends N{constructor(t,e,r,n){const i=t.rules[e].body;super([...r,i,...n]),this.superGrammar=t,this.ruleName=e,this.expansionPos=r.length}}class P extends S{constructor(t){super(),this.factors=t}}class F extends S{constructor(t){super(),this.expr=t}}class E extends F{}class C extends F{}class T extends F{}E.prototype.operator="*",C.prototype.operator="+",T.prototype.operator="?",E.prototype.minNumMatches=0,C.prototype.minNumMatches=1,T.prototype.minNumMatches=0,E.prototype.maxNumMatches=Number.POSITIVE_INFINITY,C.prototype.maxNumMatches=Number.POSITIVE_INFINITY,T.prototype.maxNumMatches=1;class k extends S{constructor(t){super(),this.expr=t}}class D extends S{constructor(t){super(),this.expr=t}}class j extends S{constructor(t){super(),this.expr=t}}class M extends S{constructor(t,e=[]){super(),this.ruleName=t,this.args=e}isSyntactic(){return c(this.ruleName)}toMemoKey(){return this._memoKey||Object.defineProperty(this,"_memoKey",{value:this.toString()}),this._memoKey}}class G extends S{constructor(t){if(super(),this.categoryOrProp=t,t in y)this.pattern=y[t];else{if(!(t in x))throw new Error(`Invalid Unicode category or property name: ${JSON.stringify(t)}`);this.pattern=x[t]}}}function B(t,e){let r;return e?(r=new Error(e.getLineAndColumnMessage()+t),r.shortMessage=t,r.interval=e):r=new Error(t),r}function q(){return B("Interval sources don't match")}function U(t,e,r){return B("Rule "+t+" is not declared in grammar "+e,r)}function $(t,e,r,n){let i="Duplicate declaration for rule '"+t+"' in grammar '"+e+"'";return e!==r&&(i+=" (originally declared in '"+r+"')"),B(i,n)}function z(t,e,r,n){return B("Wrong number of parameters for rule "+t+" (expected "+e+", got "+r+")",n)}function K(t,e,r){return B("Duplicate parameter names in rule "+t+": "+e.join(", "),r)}function H(t,e){return B("Incorrect argument type: expected "+t,e.source)}function V(t,e){const r=e.length>0?e[e.length-1].args:[];let n="Nullable expression "+t.expr.substituteParams(r)+" is not allowed inside '"+t.operator+"' (possible infinite loop)";if(e.length>0){n+="\nApplication stack (most recent application last):\n"+e.map((t=>new M(t.ruleName,t.args))).join("\n")}return B(n,t.expr.source)}function W(t,e,r,n){return B("Rule "+t+" involves an alternation which has inconsistent arity (expected "+e+", got "+r+")",n.source)}function J(t){if(1===t.length)throw t[0];if(t.length>1)throw function(t){const e=t.map((t=>t.message));return B(["Errors:"].concat(e).join("\n- "),t[0].interval)}(t)}function Q(t,e,r){const n=t.length;return(t.slice(0,r)+e+t.slice(r+e.length)).substr(0,n)}function Z(...t){const e=this,{offset:n}=e,{repeatStr:i}=v,s=new h;s.append("Line "+e.lineNum+", col "+e.colNum+":\n");const o=function(t){let e=0;return t.map((t=>{const r=t.toString();return e=Math.max(e,r.length),r})).map((t=>p(t,e)))}([null==e.prevLine?0:e.lineNum-1,e.lineNum,null==e.nextLine?0:e.lineNum+1]),a=(t,e,r)=>{s.append(r+o[t]+" | "+e+"\n")};null!=e.prevLine&&a(0,e.prevLine," "),a(1,e.line,"> ");const u=e.line.length;let c=i(" ",u+1);for(let s=0;s<t.length;++s){let o=t[s][0],a=t[s][1];r(o>=0&&o<=a,"range start must be >= 0 and <= end");const l=n-e.colNum+1;o=Math.max(0,o-l),a=Math.min(a-l,u),c=Q(c,i("~",a-o),o)}const l=2+o[1].length+3;return s.append(i(" ",l)),c=Q(c,"^",e.colNum-1),s.append(c.replace(/ +$/,"")+"\n"),null!=e.nextLine&&a(2,e.nextLine," "),s.contents()}let X=[];function Y(t){X.push(t)}function tt(t,e){let r=1,n=1,i=0,s=0,o=null,a=null,u=-1;for(;i<e;){const e=t.charAt(i++);"\n"===e?(r++,n=1,u=s,s=i):"\r"!==e&&n++}let c=t.indexOf("\n",s);if(-1===c)c=t.length;else{const e=t.indexOf("\n",c+1);o=-1===e?t.slice(c):t.slice(c,e),o=o.replace(/^\r?\n/,"").replace(/\r$/,"")}u>=0&&(a=t.slice(u,s).replace(/\r?\n$/,""));return{offset:e,lineNum:r,colNum:n,line:t.slice(s,c).replace(/\r$/,""),prevLine:a,nextLine:o,toString:Z}}function et(t,e,...r){return tt(t,e).toString(...r)}const rt=(()=>{let t=0;return e=>""+e+t++})();class nt{constructor(t,e,r){Object.defineProperty(this,"_sourceString",{value:t,configurable:!1,enumerable:!1,writable:!1}),this.startIdx=e,this.endIdx=r}get sourceString(){return this._sourceString}get contents(){return void 0===this._contents&&(this._contents=this.sourceString.slice(this.startIdx,this.endIdx)),this._contents}get length(){return this.endIdx-this.startIdx}coverageWith(...t){return nt.coverage(...t,this)}collapsedLeft(){return new nt(this.sourceString,this.startIdx,this.startIdx)}collapsedRight(){return new nt(this.sourceString,this.endIdx,this.endIdx)}getLineAndColumn(){return tt(this.sourceString,this.startIdx)}getLineAndColumnMessage(){const t=[this.startIdx,this.endIdx];return et(this.sourceString,this.startIdx,t)}minus(t){if(this.sourceString!==t.sourceString)throw q();return this.startIdx===t.startIdx&&this.endIdx===t.endIdx?[]:this.startIdx<t.startIdx&&t.endIdx<this.endIdx?[new nt(this.sourceString,this.startIdx,t.startIdx),new nt(this.sourceString,t.endIdx,this.endIdx)]:this.startIdx<t.endIdx&&t.endIdx<this.endIdx?[new nt(this.sourceString,t.endIdx,this.endIdx)]:this.startIdx<t.startIdx&&t.startIdx<this.endIdx?[new nt(this.sourceString,this.startIdx,t.startIdx)]:[this]}relativeTo(t){if(this.sourceString!==t.sourceString)throw q();return r(this.startIdx>=t.startIdx&&this.endIdx<=t.endIdx,"other interval does not cover this one"),new nt(this.sourceString,this.startIdx-t.startIdx,this.endIdx-t.startIdx)}trimmed(){const{contents:t}=this,e=this.startIdx+t.match(/^\s*/)[0].length,r=this.endIdx-t.match(/\s*$/)[0].length;return new nt(this.sourceString,e,r)}subInterval(t,e){const r=this.startIdx+t;return new nt(this.sourceString,r,r+e)}}nt.coverage=function(t,...e){let{startIdx:r,endIdx:n}=t;for(const i of e){if(i.sourceString!==t.sourceString)throw q();r=Math.min(r,i.startIdx),n=Math.max(n,i.endIdx)}return new nt(t.sourceString,r,n)};class it{constructor(t){this.source=t,this.pos=0,this.examinedLength=0}atEnd(){const t=this.pos>=this.source.length;return this.examinedLength=Math.max(this.examinedLength,this.pos+1),t}next(){const t=this.source[this.pos++];return this.examinedLength=Math.max(this.examinedLength,this.pos),t}nextCharCode(){const t=this.next();return t&&t.charCodeAt(0)}nextCodePoint(){const t=this.source.slice(this.pos++).codePointAt(0);return t>65535&&(this.pos+=1),this.examinedLength=Math.max(this.examinedLength,this.pos),t}matchString(t,e){let r;if(e){for(r=0;r<t.length;r++){const e=this.next(),n=t[r];if(null==e||e.toUpperCase()!==n.toUpperCase())return!1}return!0}for(r=0;r<t.length;r++)if(this.next()!==t[r])return!1;return!0}sourceSlice(t,e){return this.source.slice(t,e)}interval(t,e){return new nt(this.source,t,e||this.pos)}}class st{constructor(t,e,r,i,s,o,a){this.matcher=t,this.input=e,this.startExpr=r,this._cst=i,this._cstOffset=s,this._rightmostFailurePosition=o,this._rightmostFailures=a,this.failed()&&(n(this,"message",(function(){const t="Expected "+this.getExpectedText();return et(this.input,this.getRightmostFailurePosition())+t})),n(this,"shortMessage",(function(){const t="expected "+this.getExpectedText(),e=tt(this.input,this.getRightmostFailurePosition());return"Line "+e.lineNum+", col "+e.colNum+": "+t})))}succeeded(){return!!this._cst}failed(){return!this.succeeded()}getRightmostFailurePosition(){return this._rightmostFailurePosition}getRightmostFailures(){if(!this._rightmostFailures){this.matcher.setInput(this.input);const t=this.matcher._match(this.startExpr,{tracing:!1,positionToRecordFailures:this.getRightmostFailurePosition()});this._rightmostFailures=t.getRightmostFailures()}return this._rightmostFailures}toString(){return this.succeeded()?"[match succeeded]":"[match failed at position "+this.getRightmostFailurePosition()+"]"}getExpectedText(){if(this.succeeded())throw new Error("cannot get expected text of a successful MatchResult");const t=new h;let e=this.getRightmostFailures();e=e.filter((t=>!t.isFluffy()));for(let r=0;r<e.length;r++)r>0&&(r===e.length-1?t.append(e.length>2?", or ":" or "):t.append(", ")),t.append(e[r].toString());return t.contents()}getInterval(){const t=this.getRightmostFailurePosition();return new nt(this.input,t,t)}}class ot{constructor(){this.applicationMemoKeyStack=[],this.memo={},this.maxExaminedLength=0,this.maxRightmostFailureOffset=-1,this.currentLeftRecursion=void 0}isActive(t){return this.applicationMemoKeyStack.indexOf(t.toMemoKey())>=0}enter(t){this.applicationMemoKeyStack.push(t.toMemoKey())}exit(){this.applicationMemoKeyStack.pop()}startLeftRecursion(t,e){e.isLeftRecursion=!0,e.headApplication=t,e.nextLeftRecursion=this.currentLeftRecursion,this.currentLeftRecursion=e;const{applicationMemoKeyStack:r}=this,n=r.indexOf(t.toMemoKey())+1,i=r.slice(n);e.isInvolved=function(t){return i.indexOf(t)>=0},e.updateInvolvedApplicationMemoKeys=function(){for(let t=n;t<r.length;t++){const e=r[t];this.isInvolved(e)||i.push(e)}}}endLeftRecursion(){this.currentLeftRecursion=this.currentLeftRecursion.nextLeftRecursion}shouldUseMemoizedResult(t){if(!t.isLeftRecursion)return!0;const{applicationMemoKeyStack:e}=this;for(let r=0;r<e.length;r++){const n=e[r];if(t.isInvolved(n))return!1}return!0}memoize(t,e){return this.memo[t]=e,this.maxExaminedLength=Math.max(this.maxExaminedLength,e.examinedLength),this.maxRightmostFailureOffset=Math.max(this.maxRightmostFailureOffset,e.rightmostFailureOffset),e}clearObsoleteEntries(t,e){if(t+this.maxExaminedLength<=e)return;const{memo:r}=this;this.maxExaminedLength=0,this.maxRightmostFailureOffset=-1,Object.keys(r).forEach((n=>{const i=r[n];t+i.examinedLength>e?delete r[n]:(this.maxExaminedLength=Math.max(this.maxExaminedLength,i.examinedLength),this.maxRightmostFailureOffset=Math.max(this.maxRightmostFailureOffset,i.rightmostFailureOffset))}))}}const at={succeeded:1,isRootNode:2,isImplicitSpaces:4,isMemoized:8,isHeadOfLeftRecursion:16,terminatesLR:32};function ut(t){return"string"==typeof t?t.replace(/ /g,"⋅").replace(/\t/g,"␉").replace(/\n/g,"␊").replace(/\r/g,"␍"):String(t)}class ct{constructor(t,e,r,n,i,s,o){this.input=t,this.pos=this.pos1=e,this.pos2=r,this.source=new nt(t,e,r),this.expr=n,this.bindings=s,this.children=o||[],this.terminatingLREntry=null,this._flags=i?at.succeeded:0}get displayString(){return this.expr.toDisplayString()}clone(){return this.cloneWithExpr(this.expr)}cloneWithExpr(t){const e=new ct(this.input,this.pos,this.pos2,t,this.succeeded,this.bindings,this.children);return e.isHeadOfLeftRecursion=this.isHeadOfLeftRecursion,e.isImplicitSpaces=this.isImplicitSpaces,e.isMemoized=this.isMemoized,e.isRootNode=this.isRootNode,e.terminatesLR=this.terminatesLR,e.terminatingLREntry=this.terminatingLREntry,e}recordLRTermination(t,e){this.terminatingLREntry=new ct(this.input,this.pos,this.pos2,this.expr,!1,[e],[t]),this.terminatingLREntry.terminatesLR=!0}walk(t,e){let r=t;function n(t,i,s){let o=!0;r.enter&&r.enter.call(e,t,i,s)===ct.prototype.SKIP&&(o=!1),o&&(t.children.forEach((e=>{n(e,t,s+1)})),r.exit&&r.exit.call(e,t,i,s))}"function"==typeof r&&(r={enter:r}),this.isRootNode?this.children.forEach((t=>{n(t,null,0)})):n(this,null,0)}toString(){const t=new h;return this.walk(((e,r,n)=>{if(!e)return this.SKIP;if("Alt"!==e.expr.constructor.name){if(t.append(function(t,e,r){const n=ut(t.slice(e,e+r));return n.length<r?n+o(" ",r-n.length).join(""):n}(e.input,e.pos,10)+o(" ",2*n+1).join("")),t.append((e.succeeded?"✓":"✗")+" "+e.displayString),e.isHeadOfLeftRecursion&&t.append(" (LR)"),e.succeeded){const r=ut(e.source.contents);t.append(" ⇒ "),t.append("string"==typeof r?'"'+r+'"':r)}t.append("\n")}})),t.contents()}}let lt,pt;ct.prototype.SKIP={},Object.keys(at).forEach((t=>{const e=at[t];Object.defineProperty(ct.prototype,t,{get(){return!!(this._flags&e)},set(t){t?this._flags|=e:this._flags&=~e}})})),S.prototype.allowsSkippingPrecedingSpace=e("allowsSkippingPrecedingSpace"),b.allowsSkippingPrecedingSpace=_.allowsSkippingPrecedingSpace=M.prototype.allowsSkippingPrecedingSpace=w.prototype.allowsSkippingPrecedingSpace=A.prototype.allowsSkippingPrecedingSpace=G.prototype.allowsSkippingPrecedingSpace=function(){return!0},N.prototype.allowsSkippingPrecedingSpace=F.prototype.allowsSkippingPrecedingSpace=j.prototype.allowsSkippingPrecedingSpace=D.prototype.allowsSkippingPrecedingSpace=k.prototype.allowsSkippingPrecedingSpace=O.prototype.allowsSkippingPrecedingSpace=P.prototype.allowsSkippingPrecedingSpace=function(){return!1},Y((t=>{lt=t})),S.prototype.assertAllApplicationsAreValid=function(t,e){pt=0,this._assertAllApplicationsAreValid(t,e)},S.prototype._assertAllApplicationsAreValid=e("_assertAllApplicationsAreValid"),b._assertAllApplicationsAreValid=_._assertAllApplicationsAreValid=w.prototype._assertAllApplicationsAreValid=A.prototype._assertAllApplicationsAreValid=O.prototype._assertAllApplicationsAreValid=G.prototype._assertAllApplicationsAreValid=function(t,e){},j.prototype._assertAllApplicationsAreValid=function(t,e){pt++,this.expr._assertAllApplicationsAreValid(t,e),pt--},N.prototype._assertAllApplicationsAreValid=function(t,e){for(let r=0;r<this.terms.length;r++)this.terms[r]._assertAllApplicationsAreValid(t,e)},P.prototype._assertAllApplicationsAreValid=function(t,e){for(let r=0;r<this.factors.length;r++)this.factors[r]._assertAllApplicationsAreValid(t,e)},F.prototype._assertAllApplicationsAreValid=k.prototype._assertAllApplicationsAreValid=D.prototype._assertAllApplicationsAreValid=function(t,e){this.expr._assertAllApplicationsAreValid(t,e)},M.prototype._assertAllApplicationsAreValid=function(t,e,r=!1){const n=e.rules[this.ruleName],i=c(t)&&0===pt;if(!n)throw U(this.ruleName,e.name,this.source);if(!r&&c(this.ruleName)&&!i)throw function(t,e){return B("Cannot apply syntactic rule "+t+" from here (inside a lexical context)",e.source)}(this.ruleName,this);const s=this.args.length,o=n.formals.length;if(s!==o)throw function(t,e,r,n){return B("Wrong number of arguments for rule "+t+" (expected "+e+", got "+r+")",n)}(this.ruleName,o,s,this.source);const a=lt&&n===lt.rules.applySyntactic;if(lt&&n===lt.rules.caseInsensitive&&!(this.args[0]instanceof w))throw H('a Terminal (e.g. "abc")',this.args[0]);if(a){const t=this.args[0];if(!(t instanceof M))throw H("a syntactic rule application",t);if(!c(t.ruleName))throw function(t){const{ruleName:e}=t;return B(`applySyntactic is for syntactic rules, but '${e}' is a lexical rule. NOTE: A _syntactic rule_ is a rule whose name begins with a capital letter. See https://ohmjs.org/d/svl for more details.`,t.source)}(t);if(i)throw B("applySyntactic is not required here (in a syntactic context)",this.source)}this.args.forEach((r=>{if(r._assertAllApplicationsAreValid(t,e,a),1!==r.getArity())throw function(t,e){return B("Invalid parameter to rule "+t+": "+e+" has arity "+e.getArity()+", but parameter expressions must have arity 1",e.source)}(this.ruleName,r)}))},S.prototype.assertChoicesHaveUniformArity=e("assertChoicesHaveUniformArity"),b.assertChoicesHaveUniformArity=_.assertChoicesHaveUniformArity=w.prototype.assertChoicesHaveUniformArity=A.prototype.assertChoicesHaveUniformArity=O.prototype.assertChoicesHaveUniformArity=j.prototype.assertChoicesHaveUniformArity=G.prototype.assertChoicesHaveUniformArity=function(t){},N.prototype.assertChoicesHaveUniformArity=function(t){if(0===this.terms.length)return;const e=this.terms[0].getArity();for(let r=0;r<this.terms.length;r++){const n=this.terms[r];n.assertChoicesHaveUniformArity();const i=n.getArity();if(e!==i)throw W(t,e,i,n)}},R.prototype.assertChoicesHaveUniformArity=function(t){const e=this.terms[0].getArity(),r=this.terms[1].getArity();if(e!==r)throw W(t,r,e,this.terms[0])},P.prototype.assertChoicesHaveUniformArity=function(t){for(let e=0;e<this.factors.length;e++)this.factors[e].assertChoicesHaveUniformArity(t)},F.prototype.assertChoicesHaveUniformArity=function(t){this.expr.assertChoicesHaveUniformArity(t)},k.prototype.assertChoicesHaveUniformArity=function(t){},D.prototype.assertChoicesHaveUniformArity=function(t){this.expr.assertChoicesHaveUniformArity(t)},M.prototype.assertChoicesHaveUniformArity=function(t){},S.prototype.assertIteratedExprsAreNotNullable=e("assertIteratedExprsAreNotNullable"),b.assertIteratedExprsAreNotNullable=_.assertIteratedExprsAreNotNullable=w.prototype.assertIteratedExprsAreNotNullable=A.prototype.assertIteratedExprsAreNotNullable=O.prototype.assertIteratedExprsAreNotNullable=G.prototype.assertIteratedExprsAreNotNullable=function(t){},N.prototype.assertIteratedExprsAreNotNullable=function(t){for(let e=0;e<this.terms.length;e++)this.terms[e].assertIteratedExprsAreNotNullable(t)},P.prototype.assertIteratedExprsAreNotNullable=function(t){for(let e=0;e<this.factors.length;e++)this.factors[e].assertIteratedExprsAreNotNullable(t)},F.prototype.assertIteratedExprsAreNotNullable=function(t){if(this.expr.assertIteratedExprsAreNotNullable(t),this.expr.isNullable(t))throw V(this,[])},T.prototype.assertIteratedExprsAreNotNullable=k.prototype.assertIteratedExprsAreNotNullable=D.prototype.assertIteratedExprsAreNotNullable=j.prototype.assertIteratedExprsAreNotNullable=function(t){this.expr.assertIteratedExprsAreNotNullable(t)},M.prototype.assertIteratedExprsAreNotNullable=function(t){this.args.forEach((e=>{e.assertIteratedExprsAreNotNullable(t)}))};class ht{constructor(t){this.matchLength=t}get ctorName(){throw new Error("subclass responsibility")}numChildren(){return this.children?this.children.length:0}childAt(t){if(this.children)return this.children[t]}indexOfChild(t){return this.children.indexOf(t)}hasChildren(){return this.numChildren()>0}hasNoChildren(){return!this.hasChildren()}onlyChild(){if(1!==this.numChildren())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(t){const e=this.indexOfChild(t);if(e<0)throw new Error("Node.childBefore() called w/ an argument that is not a child");if(0===e)throw new Error("cannot get child before first child");return this.childAt(e-1)}childAfter(t){const e=this.indexOfChild(t);if(e<0)throw new Error("Node.childAfter() called w/ an argument that is not a child");if(e===this.numChildren()-1)throw new Error("cannot get child after last child");return this.childAt(e+1)}isTerminal(){return!1}isNonterminal(){return!1}isIteration(){return!1}isOptional(){return!1}}class mt extends ht{get ctorName(){return"_terminal"}isTerminal(){return!0}get primitiveValue(){throw new Error("The `primitiveValue` property was removed in Ohm v17.")}}class dt extends ht{constructor(t,e,r,n){super(n),this.ruleName=t,this.children=e,this.childOffsets=r}get ctorName(){return this.ruleName}isNonterminal(){return!0}isLexical(){return l(this.ctorName)}isSyntactic(){return c(this.ctorName)}}class ft extends ht{constructor(t,e,r,n){super(r),this.children=t,this.childOffsets=e,this.optional=n}get ctorName(){return"_iter"}isIteration(){return!0}isOptional(){return this.optional}}function gt(t,e){const r={};if(t.source&&e){const n=t.source.relativeTo(e);r.sourceInterval=[n.startIdx,n.endIdx]}return r}function vt(t){return/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(t)}function It(t){const e=Object.create(null);t.forEach((t=>{e[t]=(e[t]||0)+1})),Object.keys(e).forEach((r=>{if(e[r]<=1)return;let n=1;t.forEach(((e,i)=>{e===r&&(t[i]=e+"_"+n++)}))}))}S.prototype.eval=e("eval"),b.eval=function(t){const{inputStream:e}=t,r=e.pos,n=e.nextCodePoint();return void 0!==n?(t.pushBinding(new mt(String.fromCodePoint(n).length),r),!0):(t.processFailure(r,this),!1)},_.eval=function(t){const{inputStream:e}=t,r=e.pos;return e.atEnd()?(t.pushBinding(new mt(0),r),!0):(t.processFailure(r,this),!1)},w.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;return e.matchString(this.obj)?(t.pushBinding(new mt(this.obj.length),r),!0):(t.processFailure(r,this),!1)},A.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=this.matchCodePoint?e.nextCodePoint():e.nextCharCode();return void 0!==n&&this.from.codePointAt(0)<=n&&n<=this.to.codePointAt(0)?(t.pushBinding(new mt(String.fromCodePoint(n).length),r),!0):(t.processFailure(r,this),!1)},O.prototype.eval=function(t){return t.eval(t.currentApplication().args[this.index])},j.prototype.eval=function(t){t.enterLexifiedContext();const e=t.eval(this.expr);return t.exitLexifiedContext(),e},N.prototype.eval=function(t){for(let e=0;e<this.terms.length;e++)if(t.eval(this.terms[e]))return!0;return!1},P.prototype.eval=function(t){for(let e=0;e<this.factors.length;e++){const r=this.factors[e];if(!t.eval(r))return!1}return!0},F.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=this.getArity(),i=[],s=[];for(;i.length<n;)i.push([]),s.push([]);let o,a=0,u=r;for(;a<this.maxNumMatches&&t.eval(this.expr);){if(e.pos===u)throw V(this,t._applicationStack);u=e.pos,a++;const r=t._bindings.splice(t._bindings.length-n,n),c=t._bindingOffsets.splice(t._bindingOffsets.length-n,n);for(o=0;o<r.length;o++)i[o].push(r[o]),s[o].push(c[o])}if(a<this.minNumMatches)return!1;let c=t.posToOffset(r),l=0;if(a>0){const t=i[n-1],e=s[n-1],r=e[e.length-1]+t[t.length-1].matchLength;c=s[0][0],l=r-c}const p=this instanceof T;for(o=0;o<i.length;o++)t._bindings.push(new ft(i[o],s[o],l,p)),t._bindingOffsets.push(c);return!0},k.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;t.pushFailuresInfo();const n=t.eval(this.expr);return t.popFailuresInfo(),n?(t.processFailure(r,this),!1):(e.pos=r,!0)},D.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos;return!!t.eval(this.expr)&&(e.pos=r,!0)},M.prototype.eval=function(t){const e=t.currentApplication(),r=e?e.args:[],n=this.substituteParams(r),i=t.getCurrentPosInfo();if(i.isActive(n))return n.handleCycle(t);const s=n.toMemoKey(),o=i.memo[s];if(o&&i.shouldUseMemoizedResult(o)){if(t.hasNecessaryInfo(o))return t.useMemoizedResult(t.inputStream.pos,o);delete i.memo[s]}return n.reallyEval(t)},M.prototype.handleCycle=function(t){const e=t.getCurrentPosInfo(),{currentLeftRecursion:r}=e,n=this.toMemoKey();let i=e.memo[n];return r&&r.headApplication.toMemoKey()===n?i.updateInvolvedApplicationMemoKeys():i||(i=e.memoize(n,{matchLength:0,examinedLength:0,value:!1,rightmostFailureOffset:-1}),e.startLeftRecursion(this,i)),t.useMemoizedResult(t.inputStream.pos,i)},M.prototype.reallyEval=function(t){const{inputStream:e}=t,n=e.pos,i=t.getCurrentPosInfo(),s=t.grammar.rules[this.ruleName],{body:o}=s,{description:a}=s;t.enterApplication(i,this),a&&t.pushFailuresInfo();const u=e.examinedLength;e.examinedLength=0;let c=this.evalOnce(o,t);const l=i.currentLeftRecursion,p=this.toMemoKey(),h=l&&l.headApplication.toMemoKey()===p;let m;t.doNotMemoize?t.doNotMemoize=!1:h?(c=this.growSeedResult(o,t,n,l,c),i.endLeftRecursion(),m=l,m.examinedLength=e.examinedLength-n,m.rightmostFailureOffset=t._getRightmostFailureOffset(),i.memoize(p,m)):l&&l.isInvolved(p)||(m=i.memoize(p,{matchLength:e.pos-n,examinedLength:e.examinedLength-n,value:c,failuresAtRightmostPosition:t.cloneRecordedFailures(),rightmostFailureOffset:t._getRightmostFailureOffset()}));const d=!!c;if(a&&(t.popFailuresInfo(),d||t.processFailure(n,this),m&&(m.failuresAtRightmostPosition=t.cloneRecordedFailures(),m.rightmostFailureOffset=t._getRightmostFailureOffset())),t.isTracing()&&m){const e=t.getTraceEntry(n,this,d,d?[c]:[]);h&&(r(null!=e.terminatingLREntry||!d),e.isHeadOfLeftRecursion=!0),m.traceEntry=e}return e.examinedLength=Math.max(e.examinedLength,u),t.exitApplication(i,c),d},M.prototype.evalOnce=function(t,e){const{inputStream:r}=e,n=r.pos;if(e.eval(t)){const i=t.getArity(),s=e._bindings.splice(e._bindings.length-i,i),o=e._bindingOffsets.splice(e._bindingOffsets.length-i,i),a=r.pos-n;return new dt(this.ruleName,s,o,a)}return!1},M.prototype.growSeedResult=function(t,e,r,n,i){if(!i)return!1;const{inputStream:s}=e;for(;;){if(n.matchLength=s.pos-r,n.value=i,n.failuresAtRightmostPosition=e.cloneRecordedFailures(),e.isTracing()){const t=e.trace[e.trace.length-1];n.traceEntry=new ct(e.input,r,s.pos,this,!0,[i],[t.clone()])}if(s.pos=r,i=this.evalOnce(t,e),s.pos-r<=n.matchLength)break;e.isTracing()&&e.trace.splice(-2,1)}return e.isTracing()&&n.traceEntry.recordLRTermination(e.trace.pop(),i),s.pos=r+n.matchLength,n.value},G.prototype.eval=function(t){const{inputStream:e}=t,r=e.pos,n=e.nextCodePoint();if(void 0!==n&&n<=1114111){const e=String.fromCodePoint(n);if(this.pattern.test(e))return t.pushBinding(new mt(e.length),r),!0}return t.processFailure(r,this),!1},S.prototype.getArity=e("getArity"),b.getArity=_.getArity=w.prototype.getArity=A.prototype.getArity=O.prototype.getArity=M.prototype.getArity=G.prototype.getArity=function(){return 1},N.prototype.getArity=function(){return 0===this.terms.length?0:this.terms[0].getArity()},P.prototype.getArity=function(){let t=0;for(let e=0;e<this.factors.length;e++)t+=this.factors[e].getArity();return t},F.prototype.getArity=function(){return this.expr.getArity()},k.prototype.getArity=function(){return 0},D.prototype.getArity=j.prototype.getArity=function(){return this.expr.getArity()},S.prototype.outputRecipe=e("outputRecipe"),b.outputRecipe=function(t,e){return["any",gt(this,e)]},_.outputRecipe=function(t,e){return["end",gt(this,e)]},w.prototype.outputRecipe=function(t,e){return["terminal",gt(this,e),this.obj]},A.prototype.outputRecipe=function(t,e){return["range",gt(this,e),this.from,this.to]},O.prototype.outputRecipe=function(t,e){return["param",gt(this,e),this.index]},N.prototype.outputRecipe=function(t,e){return["alt",gt(this,e)].concat(this.terms.map((r=>r.outputRecipe(t,e))))},R.prototype.outputRecipe=function(t,e){return this.terms[0].outputRecipe(t,e)},L.prototype.outputRecipe=function(t,e){const r=this.terms.slice(0,this.expansionPos),n=this.terms.slice(this.expansionPos+1);return["splice",gt(this,e),r.map((r=>r.outputRecipe(t,e))),n.map((r=>r.outputRecipe(t,e)))]},P.prototype.outputRecipe=function(t,e){return["seq",gt(this,e)].concat(this.factors.map((r=>r.outputRecipe(t,e))))},E.prototype.outputRecipe=C.prototype.outputRecipe=T.prototype.outputRecipe=k.prototype.outputRecipe=D.prototype.outputRecipe=j.prototype.outputRecipe=function(t,e){return[this.constructor.name.toLowerCase(),gt(this,e),this.expr.outputRecipe(t,e)]},M.prototype.outputRecipe=function(t,e){return["app",gt(this,e),this.ruleName,this.args.map((r=>r.outputRecipe(t,e)))]},G.prototype.outputRecipe=function(t,e){return["unicodeChar",gt(this,e),this.categoryOrProp]},S.prototype.introduceParams=e("introduceParams"),b.introduceParams=_.introduceParams=w.prototype.introduceParams=A.prototype.introduceParams=O.prototype.introduceParams=G.prototype.introduceParams=function(t){return this},N.prototype.introduceParams=function(t){return this.terms.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},P.prototype.introduceParams=function(t){return this.factors.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},F.prototype.introduceParams=k.prototype.introduceParams=D.prototype.introduceParams=j.prototype.introduceParams=function(t){return this.expr=this.expr.introduceParams(t),this},M.prototype.introduceParams=function(t){const e=t.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 O(e).withSource(this.source)}return this.args.forEach(((e,r,n)=>{n[r]=e.introduceParams(t)})),this},S.prototype.isNullable=function(t){return this._isNullable(t,Object.create(null))},S.prototype._isNullable=e("_isNullable"),b._isNullable=A.prototype._isNullable=O.prototype._isNullable=C.prototype._isNullable=G.prototype._isNullable=function(t,e){return!1},_._isNullable=function(t,e){return!0},w.prototype._isNullable=function(t,e){return"string"==typeof this.obj&&""===this.obj},N.prototype._isNullable=function(t,e){return 0===this.terms.length||this.terms.some((r=>r._isNullable(t,e)))},P.prototype._isNullable=function(t,e){return this.factors.every((r=>r._isNullable(t,e)))},E.prototype._isNullable=T.prototype._isNullable=k.prototype._isNullable=D.prototype._isNullable=function(t,e){return!0},j.prototype._isNullable=function(t,e){return this.expr._isNullable(t,e)},M.prototype._isNullable=function(t,e){const r=this.toMemoKey();if(!Object.prototype.hasOwnProperty.call(e,r)){const{body:n}=t.rules[this.ruleName],i=n.substituteParams(this.args);e[r]=!1,e[r]=i._isNullable(t,e)}return e[r]},S.prototype.substituteParams=e("substituteParams"),b.substituteParams=_.substituteParams=w.prototype.substituteParams=A.prototype.substituteParams=G.prototype.substituteParams=function(t){return this},O.prototype.substituteParams=function(t){return g(t[this.index])},N.prototype.substituteParams=function(t){return new N(this.terms.map((e=>e.substituteParams(t))))},P.prototype.substituteParams=function(t){return new P(this.factors.map((e=>e.substituteParams(t))))},F.prototype.substituteParams=k.prototype.substituteParams=D.prototype.substituteParams=j.prototype.substituteParams=function(t){return new this.constructor(this.expr.substituteParams(t))},M.prototype.substituteParams=function(t){if(0===this.args.length)return this;{const e=this.args.map((e=>e.substituteParams(t)));return new M(this.ruleName,e)}},S.prototype.toArgumentNameList=e("toArgumentNameList"),b.toArgumentNameList=function(t,e){return["any"]},_.toArgumentNameList=function(t,e){return["end"]},w.prototype.toArgumentNameList=function(t,e){return"string"==typeof this.obj&&/^[_a-zA-Z0-9]+$/.test(this.obj)?["_"+this.obj]:["$"+t]},A.prototype.toArgumentNameList=function(t,e){let r=this.from+"_to_"+this.to;return vt(r)||(r="_"+r),vt(r)||(r="$"+t),[r]},N.prototype.toArgumentNameList=function(t,e){const r=this.terms.map((e=>e.toArgumentNameList(t,!0))),n=[],i=r[0].length;for(let t=0;t<i;t++){const e=[];for(let n=0;n<this.terms.length;n++)e.push(r[n][t]);const i=u(e);n.push(i.join("_or_"))}return e||It(n),n},P.prototype.toArgumentNameList=function(t,e){let r=[];return this.factors.forEach((e=>{const n=e.toArgumentNameList(t,!0);r=r.concat(n),t+=n.length})),e||It(r),r},F.prototype.toArgumentNameList=function(t,e){const r=this.expr.toArgumentNameList(t,e).map((t=>"s"===t[t.length-1]?t+"es":t+"s"));return e||It(r),r},T.prototype.toArgumentNameList=function(t,e){return this.expr.toArgumentNameList(t,e).map((t=>"opt"+t[0].toUpperCase()+t.slice(1)))},k.prototype.toArgumentNameList=function(t,e){return[]},D.prototype.toArgumentNameList=j.prototype.toArgumentNameList=function(t,e){return this.expr.toArgumentNameList(t,e)},M.prototype.toArgumentNameList=function(t,e){return[this.ruleName]},G.prototype.toArgumentNameList=function(t,e){return["$"+t]},O.prototype.toArgumentNameList=function(t,e){return["param"+this.index]},S.prototype.toDisplayString=e("toDisplayString"),N.prototype.toDisplayString=P.prototype.toDisplayString=function(){return this.source?this.source.trimmed().contents:"["+this.constructor.name+"]"},b.toDisplayString=_.toDisplayString=F.prototype.toDisplayString=k.prototype.toDisplayString=D.prototype.toDisplayString=j.prototype.toDisplayString=w.prototype.toDisplayString=A.prototype.toDisplayString=O.prototype.toDisplayString=function(){return this.toString()},M.prototype.toDisplayString=function(){if(this.args.length>0){const t=this.args.map((t=>t.toDisplayString()));return this.ruleName+"<"+t.join(",")+">"}return this.ruleName},G.prototype.toDisplayString=function(){return"Unicode ["+this.categoryOrProp+"] character"};class yt{constructor(t,e,r){if(!function(t){return"description"===t||"string"===t||"code"===t}(r))throw new Error("invalid Failure type: "+r);this.pexpr=t,this.text=e,this.type=r,this.fluffy=!1}getPExpr(){return this.pexpr}getText(){return this.text}getType(){return this.type}isDescription(){return"description"===this.type}isStringTerminal(){return"string"===this.type}isCode(){return"code"===this.type}isFluffy(){return this.fluffy}makeFluffy(){this.fluffy=!0}clearFluffy(){this.fluffy=!1}subsumes(t){return this.getText()===t.getText()&&this.type===t.type&&(!this.isFluffy()||this.isFluffy()&&t.isFluffy())}toString(){return"string"===this.type?JSON.stringify(this.getText()):this.getText()}clone(){const t=new yt(this.pexpr,this.text,this.type);return this.isFluffy()&&t.makeFluffy(),t}toKey(){return this.toString()+"#"+this.type}}S.prototype.toFailure=e("toFailure"),b.toFailure=function(t){return new yt(this,"any object","description")},_.toFailure=function(t){return new yt(this,"end of input","description")},w.prototype.toFailure=function(t){return new yt(this,this.obj,"string")},A.prototype.toFailure=function(t){return new yt(this,JSON.stringify(this.from)+".."+JSON.stringify(this.to),"code")},k.prototype.toFailure=function(t){const e=this.expr===b?"nothing":"not "+this.expr.toFailure(t);return new yt(this,e,"description")},D.prototype.toFailure=function(t){return this.expr.toFailure(t)},M.prototype.toFailure=function(t){let{description:e}=t.rules[this.ruleName];if(!e){e=(/^[aeiouAEIOU]/.test(this.ruleName)?"an":"a")+" "+this.ruleName}return new yt(this,e,"description")},G.prototype.toFailure=function(t){return new yt(this,"a Unicode ["+this.categoryOrProp+"] character","description")},N.prototype.toFailure=function(t){const e="("+this.terms.map((e=>e.toFailure(t))).join(" or ")+")";return new yt(this,e,"description")},P.prototype.toFailure=function(t){const e="("+this.factors.map((e=>e.toFailure(t))).join(" ")+")";return new yt(this,e,"description")},F.prototype.toFailure=function(t){const e="("+this.expr.toFailure(t)+this.operator+")";return new yt(this,e,"description")},S.prototype.toString=e("toString"),b.toString=function(){return"any"},_.toString=function(){return"end"},w.prototype.toString=function(){return JSON.stringify(this.obj)},A.prototype.toString=function(){return JSON.stringify(this.from)+".."+JSON.stringify(this.to)},O.prototype.toString=function(){return"$"+this.index},j.prototype.toString=function(){return"#("+this.expr.toString()+")"},N.prototype.toString=function(){return 1===this.terms.length?this.terms[0].toString():"("+this.terms.map((t=>t.toString())).join(" | ")+")"},P.prototype.toString=function(){return 1===this.factors.length?this.factors[0].toString():"("+this.factors.map((t=>t.toString())).join(" ")+")"},F.prototype.toString=function(){return this.expr+this.operator},k.prototype.toString=function(){return"~"+this.expr},D.prototype.toString=function(){return"&"+this.expr},M.prototype.toString=function(){if(this.args.length>0){const t=this.args.map((t=>t.toString()));return this.ruleName+"<"+t.join(",")+">"}return this.ruleName},G.prototype.toString=function(){return"\\p{"+this.categoryOrProp+"}"};class xt extends S{constructor(t){super(),this.obj=t}_getString(t){const e=t.currentApplication().args[this.obj.index];return r(e instanceof w,"expected a Terminal expression"),e.obj}allowsSkippingPrecedingSpace(){return!0}eval(t){const{inputStream:e}=t,r=e.pos,n=this._getString(t);return e.matchString(n,!0)?(t.pushBinding(new mt(n.length),r),!0):(t.processFailure(r,this),!1)}getArity(){return 1}substituteParams(t){return new xt(this.obj.substituteParams(t))}toDisplayString(){return this.obj.toDisplayString()+" (case-insensitive)"}toFailure(t){return new yt(this,this.obj.toFailure(t)+" (case-insensitive)","description")}_isNullable(t,e){return this.obj._isNullable(t,e)}}var St=Object.freeze({__proto__:null,CaseInsensitiveTerminal:xt,PExpr:S,any:b,end:_,Terminal:w,Range:A,Param:O,Alt:N,Extend:R,Splice:L,Seq:P,Iter:F,Star:E,Plus:C,Opt:T,Not:k,Lookahead:D,Lex:j,Apply:M,UnicodeChar:G});let bt;Y((t=>{bt=t.rules.applySyntactic.body}));const _t=new M("spaces");class wt{constructor(t,e,r){this.matcher=t,this.startExpr=e,this.grammar=t.grammar,this.input=t.getInput(),this.inputStream=new it(this.input),this.memoTable=t._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=[],void 0!==r&&(this.positionToRecordFailures=r,this.recordedFailures=Object.create(null))}posToOffset(t){return t-this._posStack[this._posStack.length-1]}enterApplication(t,e){this._posStack.push(this.inputStream.pos),this._applicationStack.push(e),this.inLexifiedContextStack.push(!1),t.enter(e),this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this.rightmostFailurePosition=-1}exitApplication(t,e){const r=this._posStack.pop();this._applicationStack.pop(),this.inLexifiedContextStack.pop(),t.exit(),this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,this._rightmostFailurePositionStack.pop()),e&&this.pushBinding(e,r)}enterLexifiedContext(){this.inLexifiedContextStack.push(!0)}exitLexifiedContext(){this.inLexifiedContextStack.pop()}currentApplication(){return this._applicationStack[this._applicationStack.length-1]}inSyntacticContext(){const t=this.currentApplication();return t?t.isSyntactic()&&!this.inLexifiedContext():this.startExpr.factors[0].isSyntactic()}inLexifiedContext(){return this.inLexifiedContextStack[this.inLexifiedContextStack.length-1]}skipSpaces(){return this.pushFailuresInfo(),this.eval(_t),this.popBinding(),this.popFailuresInfo(),this.inputStream.pos}skipSpacesIfInSyntacticContext(){return this.inSyntacticContext()?this.skipSpaces():this.inputStream.pos}maybeSkipSpacesBefore(t){return t.allowsSkippingPrecedingSpace()&&t!==_t?this.skipSpacesIfInSyntacticContext():this.inputStream.pos}pushBinding(t,e){this._bindings.push(t),this._bindingOffsets.push(this.posToOffset(e))}popBinding(){this._bindings.pop(),this._bindingOffsets.pop()}numBindings(){return this._bindings.length}truncateBindings(t){for(;this._bindings.length>t;)this.popBinding()}getCurrentPosInfo(){return this.getPosInfo(this.inputStream.pos)}getPosInfo(t){let e=this.memoTable[t];return e||(e=this.memoTable[t]=new ot),e}processFailure(t,e){if(this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,t),this.recordedFailures&&t===this.positionToRecordFailures){const t=this.currentApplication();t&&(e=e.substituteParams(t.args)),this.recordFailure(e.toFailure(this.grammar),!1)}}recordFailure(t,e){const r=t.toKey();this.recordedFailures[r]?this.recordedFailures[r].isFluffy()&&!t.isFluffy()&&this.recordedFailures[r].clearFluffy():this.recordedFailures[r]=e?t.clone():t}recordFailures(t,e){Object.keys(t).forEach((r=>{this.recordFailure(t[r],e)}))}cloneRecordedFailures(){if(!this.recordedFailures)return;const t=Object.create(null);return Object.keys(this.recordedFailures).forEach((e=>{t[e]=this.recordedFailures[e].clone()})),t}getRightmostFailurePosition(){return this.rightmostFailurePosition}_getRightmostFailureOffset(){return this.rightmostFailurePosition>=0?this.posToOffset(this.rightmostFailurePosition):-1}getMemoizedTraceEntry(t,e){const r=this.memoTable[t];if(r&&e instanceof M){const t=r.memo[e.toMemoKey()];if(t&&t.traceEntry){const r=t.traceEntry.cloneWithExpr(e);return r.isMemoized=!0,r}}return null}getTraceEntry(t,e,r,n){if(e instanceof M){const t=this.currentApplication(),r=t?t.args:[];e=e.substituteParams(r)}return this.getMemoizedTraceEntry(t,e)||new ct(this.input,t,this.inputStream.pos,e,r,n,this.trace)}isTracing(){return!!this.trace}hasNecessaryInfo(t){return!(this.trace&&!t.traceEntry)&&(!this.recordedFailures||this.inputStream.pos+t.rightmostFailureOffset!==this.positionToRecordFailures||!!t.failuresAtRightmostPosition)}useMemoizedResult(t,e){this.trace&&this.trace.push(e.traceEntry);const r=this.inputStream.pos+e.rightmostFailureOffset;return this.rightmostFailurePosition=Math.max(this.rightmostFailurePosition,r),this.recordedFailures&&this.positionToRecordFailures===r&&e.failuresAtRightmostPosition&&this.recordFailures(e.failuresAtRightmostPosition,!0),this.inputStream.examinedLength=Math.max(this.inputStream.examinedLength,e.examinedLength+t),!!e.value&&(this.inputStream.pos+=e.matchLength,this.pushBinding(e.value,t),!0)}eval(t){const{inputStream:e}=this,r=this._bindings.length,n=this.userData;let i;this.recordedFailures&&(i=this.recordedFailures,this.recordedFailures=Object.create(null));const s=e.pos,o=this.maybeSkipSpacesBefore(t);let a;this.trace&&(a=this.trace,this.trace=[]);const u=t.eval(this);if(this.trace){const e=this._bindings.slice(r),n=this.getTraceEntry(o,t,u,e);n.isImplicitSpaces=t===_t,n.isRootNode=t===this.startExpr,a.push(n),this.trace=a}return u?this.recordedFailures&&e.pos===this.positionToRecordFailures&&Object.keys(this.recordedFailures).forEach((t=>{this.recordedFailures[t].makeFluffy()})):(e.pos=s,this.truncateBindings(r),this.userData=n),this.recordedFailures&&this.recordFailures(i,!1),t===bt&&this.skipSpaces(),u}getMatchResult(){let t;this.grammar._setUpMatchState(this),this.eval(this.startExpr),this.recordedFailures&&(t=Object.keys(this.recordedFailures).map((t=>this.recordedFailures[t])));const e=this._bindings[0];return e&&(e.grammar=this.grammar),new st(this.matcher,this.input,this.startExpr,e,this._bindingOffsets[0],this.rightmostFailurePosition,t)}getTrace(){this.trace=[];const t=this.getMatchResult(),e=this.trace[this.trace.length-1];return e.result=t,e}pushFailuresInfo(){this._rightmostFailurePositionStack.push(this.rightmostFailurePosition),this._recordedFailuresStack.push(this.recordedFailures)}popFailuresInfo(){this.rightmostFailurePosition=this._rightmostFailurePositionStack.pop(),this.recordedFailures=this._recordedFailuresStack.pop()}}class At{constructor(t){this.grammar=t,this._memoTable=[],this._input="",this._isMemoTableStale=!1}_resetMemoTable(){this._memoTable=[],this._isMemoTableStale=!1}getInput(){return this._input}setInput(t){return this._input!==t&&this.replaceInputRange(0,this._input.length,t),this}replaceInputRange(t,e,r){const n=this._input,i=this._memoTable;if(t<0||t>n.length||e<0||e>n.length||t>e)throw new Error("Invalid indices: "+t+" and "+e);this._input=n.slice(0,t)+r+n.slice(e),this._input!==n&&i.length>0&&(this._isMemoTableStale=!0);const s=i.slice(e);i.length=t;for(let t=0;t<r.length;t++)i.push(void 0);for(const t of s)i.push(t);for(let e=0;e<t;e++){const r=i[e];r&&r.clearObsoleteEntries(e,t)}return this}match(t,e={incremental:!0}){return this._match(this._getStartExpr(t),{incremental:e.incremental,tracing:!1})}trace(t,e={incremental:!0}){return this._match(this._getStartExpr(t),{incremental:e.incremental,tracing:!0})}_match(t,e={}){const r={tracing:!1,incremental:!0,positionToRecordFailures:void 0,...e};if(r.incremental){if(this._isMemoTableStale&&!this.grammar.supportsIncrementalParsing)throw function(t){return B(`Grammar '${t.name}' does not support incremental parsing`)}(this.grammar)}else this._resetMemoTable();const n=new wt(this,t,r.positionToRecordFailures);return r.tracing?n.getTrace():n.getMatchResult()}_getStartExpr(t){const e=t||this.grammar.defaultStartRule;if(!e)throw new Error("Missing start rule argument -- the grammar has no default start rule.");const r=this.grammar.parseApplication(e);return new P([r,_])}}const Ot=[],Nt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);class Rt{constructor(t,e,n){this._node=t,this.source=e,this._baseInterval=n,t.isNonterminal()&&r(e===n),this._childWrappers=[]}_forgetMemoizedResultFor(t){delete this._node[this._semantics.attributeKeys[t]],this.children.forEach((e=>{e._forgetMemoizedResultFor(t)}))}child(t){if(!(0<=t&&t<this._node.numChildren()))return;let e=this._childWrappers[t];if(!e){const r=this._node.childAt(t),n=this._node.childOffsets[t],i=this._baseInterval.subInterval(n,r.matchLength),s=r.isNonterminal()?i:this._baseInterval;e=this._childWrappers[t]=this._semantics.wrap(r,i,s)}return e}_children(){for(let t=0;t<this._node.numChildren();t++)this.child(t);return this._childWrappers}isIteration(){return this._node.isIteration()}isTerminal(){return this._node.isTerminal()}isNonterminal(){return this._node.isNonterminal()}isSyntactic(){return this.isNonterminal()&&this._node.isSyntactic()}isLexical(){return this.isNonterminal()&&this._node.isLexical()}isOptional(){return this._node.isOptional()}iteration(t){const e=t||[],r=e.map((t=>t._node)),n=new ft(r,[],-1,!1),i=this._semantics.wrap(n,null,null);return i._childWrappers=e,i}get children(){return this._children()}get ctorName(){return this._node.ctorName}get numChildren(){return this._node.numChildren()}get sourceString(){return this.source.contents}}class Lt{constructor(t,e){const r=this;if(this.grammar=t,this.checkedActionDicts=!1,this.Wrapper=class extends(e?e.Wrapper:Rt){constructor(t,e,n){super(t,e,n),r.checkActionDictsIfHaventAlready(),this._semantics=r}toString(){return"[semantics wrapper for "+r.grammar.name+"]"}},this.super=e,e){if(!t.equals(this.super.grammar)&&!t._inheritsFrom(this.super.grammar))throw new Error("Cannot extend a semantics for grammar '"+this.super.grammar.name+"' for use with grammar '"+t.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 t in this.attributes)Object.defineProperty(this.attributeKeys,t,{value:rt(t)})}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 t;for(t in this.operations)this.operations[t].checkActionDict(this.grammar);for(t in this.attributes)this.attributes[t].checkActionDict(this.grammar)}toRecipe(t){function e(t){return t.super!==Lt.BuiltInSemantics._getSemantics()}let r="(function(g) {\n";if(e(this)){r+=" var semantics = "+this.super.toRecipe(!0)+"(g";const t=this.super.grammar;let e=this.grammar;for(;e!==t;)r+=".superGrammar",e=e.superGrammar;r+=");\n",r+=" return g.extendSemantics(semantics)"}else r+=" return g.createSemantics()";return["Operation","Attribute"].forEach((t=>{const n=this[t.toLowerCase()+"s"];Object.keys(n).forEach((i=>{const{actionDict:s,formals:o,builtInDefault:a}=n[i];let u,c=i;o.length>0&&(c+="("+o.join(", ")+")"),u=e(this)&&this.super[t.toLowerCase()+"s"][i]?"extend"+t:"add"+t,r+="\n ."+u+"("+JSON.stringify(c)+", {";const l=[];Object.keys(s).forEach((t=>{if(s[t]!==a){let e=s[t].toString().trim();e=e.replace(/^.*\(/,"function("),l.push("\n "+JSON.stringify(t)+": "+e)}})),r+=l.join(",")+"\n })"}))})),r+=";\n })",t||(r="(function() {\n var grammar = this.fromRecipe("+this.grammar.toRecipe()+");\n var semantics = "+r+"(grammar);\n return semantics;\n});\n"),r}addOperationOrAttribute(t,e,r){const n=t+"s",i=Pt(e,t),{name:s}=i,{formals:o}=i;this.assertNewName(s,t);const a=function(t,e,r){return function(...n){const i=(this._semantics.operations[e]||this._semantics.attributes[e]).formals.map((t=>this.args[t]));if(this.isIteration()||1!==n.length)throw function(t,e,r,n){let i=n.slice(0,-1).map((t=>{const e=" "+t[0].name+" > "+t[1];return 3===t.length?e+" for '"+t[2]+"'":e})).join("\n");i+="\n "+e+" > "+t;let s="";"_iter"===t&&(s=["\nNOTE: as of Ohm v16, there is no default action for iteration nodes — see "," https://ohmjs.org/d/dsa for details."].join("\n"));const o=B([`Missing semantic action for '${t}' in ${r} '${e}'.${s}`,"Action stack (most recent call last):",i].join("\n"));return o.name="missingSemanticAction",o}(this.ctorName,e,t,Ot);return r.apply(n[0],i)}}(t,s,l),u={_default:a};Object.keys(r).forEach((t=>{u[t]=r[t]}));const c="operation"===t?new Ft(s,o,u,a):new Et(s,u,a);function l(...e){const r=this._semantics[n][s];if(arguments.length!==r.formals.length)throw new Error("Invalid number of arguments passed to "+s+" "+t+" (expected "+r.formals.length+", got "+arguments.length+")");const i=Object.create(null);for(const[t,n]of Object.entries(e)){i[r.formals[t]]=n}const o=this.args;this.args=i;const a=r.execute(this._semantics,this);return this.args=o,a}c.checkActionDict(this.grammar),this[n][s]=c,"operation"===t?(this.Wrapper.prototype[s]=l,this.Wrapper.prototype[s].toString=function(){return"["+s+" operation]"}):(Object.defineProperty(this.Wrapper.prototype,s,{get:l,configurable:!0}),Object.defineProperty(this.attributeKeys,s,{value:rt(s)}))}extendOperationOrAttribute(t,e,r){const n=t+"s";if(Pt(e,"attribute"),!this.super||!(e in this.super[n]))throw new Error("Cannot extend "+t+" '"+e+"': did not inherit an "+t+" with that name");if(Nt(this[n],e))throw new Error("Cannot extend "+t+" '"+e+"' again");const i=this[n][e].formals,s=this[n][e].actionDict,o=Object.create(s);Object.keys(r).forEach((t=>{o[t]=r[t]})),this[n][e]="operation"===t?new Ft(e,i,o):new Et(e,o),this[n][e].checkActionDict(this.grammar)}assertNewName(t,e){if(Nt(Rt.prototype,t))throw new Error("Cannot add "+e+" '"+t+"': that's a reserved name");if(t in this.operations)throw new Error("Cannot add "+e+" '"+t+"': an operation with that name already exists");if(t in this.attributes)throw new Error("Cannot add "+e+" '"+t+"': an attribute with that name already exists")}wrap(t,e,r){const n=r||e;return t instanceof this.Wrapper?t:new this.Wrapper(t,e,n)}}function Pt(t,e){if(!Lt.prototypeGrammar)return r(-1===t.indexOf("(")),{name:t,formals:[]};const n=Lt.prototypeGrammar.match(t,"operation"===e?"OperationSignature":"AttributeSignature");if(n.failed())throw new Error(n.message);return Lt.prototypeGrammarSemantics(n).parse()}Lt.createSemantics=function(t,e){const r=new Lt(t,void 0!==e?e:Lt.BuiltInSemantics._getSemantics()),n=function(e){if(!(e instanceof st))throw new TypeError("Semantics expected a MatchResult, but got "+f(e));if(e.failed())throw new TypeError("cannot apply Semantics to "+e.toString());const n=e._cst;if(n.grammar!==t)throw new Error("Cannot use a MatchResult from grammar '"+n.grammar.name+"' with a semantics for '"+t.name+"'");const i=new it(e.input);return r.wrap(n,i.interval(e._cstOffset,e.input.length))};return n.addOperation=function(t,e){return r.addOperationOrAttribute("operation",t,e),n},n.extendOperation=function(t,e){return r.extendOperationOrAttribute("operation",t,e),n},n.addAttribute=function(t,e){return r.addOperationOrAttribute("attribute",t,e),n},n.extendAttribute=function(t,e){return r.extendOperationOrAttribute("attribute",t,e),n},n._getActionDict=function(e){const n=r.operations[e]||r.attributes[e];if(!n)throw new Error('"'+e+'" is not a valid operation or attribute name in this semantics for "'+t.name+'"');return n.actionDict},n._remove=function(t){let e;return t in r.operations?(e=r.operations[t],delete r.operations[t]):t in r.attributes&&(e=r.attributes[t],delete r.attributes[t]),delete r.Wrapper.prototype[t],e},n.getOperationNames=function(){return Object.keys(r.operations)},n.getAttributeNames=function(){return Object.keys(r.attributes)},n.getGrammar=function(){return r.grammar},n.toRecipe=function(t){return r.toRecipe(t)},n.toString=r.toString.bind(r),n._getSemantics=function(){return r},n};class Ft{constructor(t,e,r,n){this.name=t,this.formals=e,this.actionDict=r,this.builtInDefault=n}checkActionDict(t){t._checkTopDownActionDict(this.typeName,this.name,this.actionDict)}execute(t,e){try{const{ctorName:t}=e._node;let r=this.actionDict[t];return r?(Ot.push([this,t]),r.apply(e,e._children())):e.isNonterminal()&&(r=this.actionDict._nonterminal,r)?(Ot.push([this,"_nonterminal",t]),r.apply(e,e._children())):(Ot.push([this,"default action",t]),this.actionDict._default.apply(e,e._children()))}finally{Ot.pop()}}}Ft.prototype.typeName="operation";class Et extends Ft{constructor(t,e,r){super(t,[],e,r)}execute(t,e){const r=e._node,n=t.attributeKeys[this.name];return Nt(r,n)||(r[n]=Ft.prototype.execute.call(this,t,e)),r[n]}}Et.prototype.typeName="attribute";const Ct=["_iter","_terminal","_nonterminal","_default"];function Tt(t){return Object.keys(t.rules).sort().map((e=>t.rules[e]))}let kt,Dt;class jt{constructor(t,e,r,n){if(this.name=t,this.superGrammar=e,this.rules=r,n){if(!(n in r))throw new Error("Invalid start rule: '"+n+"' is not a rule in grammar '"+t+"'");this.defaultStartRule=n}this._matchStateInitializer=void 0,this.supportsIncrementalParsing=!0}matcher(){return new At(this)}isBuiltIn(){return this===jt.ProtoBuiltInRules||this===jt.BuiltInRules}equals(t){if(this===t)return!0;if(null==t||this.name!==t.name||this.defaultStartRule!==t.defaultStartRule||this.superGrammar!==t.superGrammar&&!this.superGrammar.equals(t.superGrammar))return!1;const e=Tt(this),r=Tt(t);return e.length===r.length&&e.every(((t,e)=>t.description===r[e].description&&t.formals.join(",")===r[e].formals.join(",")&&t.body.toString()===r[e].body.toString()))}match(t,e){const r=this.matcher();return r.replaceInputRange(0,0,t),r.match(e)}trace(t,e){const r=this.matcher();return r.replaceInputRange(0,0,t),r.trace(e)}createSemantics(){return Lt.createSemantics(this)}extendSemantics(t){return Lt.createSemantics(this,t._getSemantics())}_checkTopDownActionDict(t,e,r){const n=[];for(const t in r){const e=r[t];if(!Ct.includes(t)&&!(t in this.rules)){n.push(`'${t}' is not a valid semantic action for '${this.name}'`);continue}if("function"!=typeof e){n.push(`'${t}' must be a function in an action dictionary for '${this.name}'`);continue}const i=e.length,s=this._topDownActionArity(t);if(i!==s){let e;e="_iter"===t||"_nonterminal"===t?`it should use a rest parameter, e.g. \`${t}(...children) {}\`. NOTE: this is new in Ohm v16 — see https://ohmjs.org/d/ati for details.`:`expected ${s}, got ${i}`,n.push(`Semantic action '${t}' has the wrong arity: ${e}`)}}if(n.length>0){const r=n.map((t=>"- "+t)),i=new Error([`Found errors in the action dictionary of the '${e}' ${t}:`,...r].join("\n"));throw i.problems=n,i}}_topDownActionArity(t){return Ct.includes(t)?0:this.rules[t].body.getArity()}_inheritsFrom(t){let e=this.superGrammar;for(;e;){if(e.equals(t,!0))return!0;e=e.superGrammar}return!1}toRecipe(t=void 0){const e={};this.source&&(e.source=this.source.contents);let r=null;this.defaultStartRule&&(r=this.defaultStartRule);const n={};Object.keys(this.rules).forEach((t=>{const e=this.rules[t],{body:r}=e,i=!this.superGrammar||!this.superGrammar.rules[t];let s;s=i?"define":r instanceof R?"extend":"override";const o={};if(e.source&&this.source){const t=e.source.relativeTo(this.source);o.sourceInterval=[t.startIdx,t.endIdx]}const a=i?e.description:null,u=r.outputRecipe(e.formals,this.source);n[t]=[s,o,a,e.formals,u]}));let i="null";t?i=t:this.superGrammar&&!this.superGrammar.isBuiltIn()&&(i=this.superGrammar.toRecipe());const s=[...["grammar",e,this.name].map(JSON.stringify),i,...[r,n].map(JSON.stringify)];return`[${s.join(",")}]`.replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029")}toOperationActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}toAttributeActionDictionaryTemplate(){return this._toOperationOrAttributeActionDictionaryTemplate()}_toOperationOrAttributeActionDictionaryTemplate(){const t=new h;t.append("{");let e=!0;for(const r in this.rules){const{body:n}=this.rules[r];e?e=!1:t.append(","),t.append("\n"),t.append(" "),this.addSemanticActionTemplate(r,n,t)}return t.append("\n}"),t.contents()}addSemanticActionTemplate(t,e,r){r.append(t),r.append(": function(");const n=this._topDownActionArity(t);r.append(o("_",n).join(", ")),r.append(") {\n"),r.append(" }")}parseApplication(t){let e;if(-1===t.indexOf("<"))e=new M(t);else{const r=kt.match(t,"Base_application");e=Dt(r,{})}if(!(e.ruleName in this.rules))throw U(e.ruleName,this.name);const{formals:r}=this.rules[e.ruleName];if(r.length!==e.args.length){const{source:t}=this.rules[e.ruleName];throw z(e.ruleName,r.length,e.args.length,t)}return e}_setUpMatchState(t){this._matchStateInitializer&&this._matchStateInitializer(t)}}jt.ProtoBuiltInRules=new jt("ProtoBuiltInRules",void 0,{any:{body:b,formals:[],description:"any character",primitive:!0},end:{body:_,formals:[],description:"end of input",primitive:!0},caseInsensitive:{body:new xt(new O(0)),formals:["str"],primitive:!0},lower:{body:new G("Ll"),formals:[],description:"a lowercase letter",primitive:!0},upper:{body:new G("Lu"),formals:[],description:"an uppercase letter",primitive:!0},unicodeLtmo:{body:new G("Ltmo"),formals:[],description:"a Unicode character in Lt, Lm, or Lo",primitive:!0},spaces:{body:new E(new M("space")),formals:[]},space:{body:new A("\0"," "),formals:[],description:"a space"}}),jt.initApplicationParser=function(t,e){kt=t,Dt=e};class Mt{constructor(t){this.name=t}sourceInterval(t,e){return this.source.subInterval(t,e-t)}ensureSuperGrammar(){return this.superGrammar||this.withSuperGrammar("BuiltInRules"===this.name?jt.ProtoBuiltInRules:jt.BuiltInRules),this.superGrammar}ensureSuperGrammarRuleForOverriding(t,e){const r=this.ensureSuperGrammar().rules[t];if(!r)throw n=t,i=this.superGrammar.name,B("Cannot override rule "+n+" because it is not declared in "+i,e);var n,i;return r}installOverriddenOrExtendedRule(t,e,r,n){const i=a(e);if(i.length>0)throw K(t,i,n);const s=this.ensureSuperGrammar().rules[t],o=s.formals,u=o?o.length:0;if(e.length!==u)throw z(t,u,e.length,n);return this.install(t,e,r,s.description,n)}install(t,e,r,n,i,s=!1){return this.rules[t]={body:r.introduceParams(e),formals:e,description:n,source:i,primitive:s},this}withSuperGrammar(t){if(this.superGrammar)throw new Error("the super grammar of a GrammarDecl cannot be set more than once");return this.superGrammar=t,this.rules=Object.create(t.rules),t.isBuiltIn()||(this.defaultStartRule=t.defaultStartRule),this}withDefaultStartRule(t){return this.defaultStartRule=t,this}withSource(t){return this.source=new it(t).interval(0,t.length),this}build(){const t=new jt(this.name,this.ensureSuperGrammar(),this.rules,this.defaultStartRule);t._matchStateInitializer=t.superGrammar._matchStateInitializer,t.supportsIncrementalParsing=t.superGrammar.supportsIncrementalParsing;const e=[];let r=!1;return Object.keys(t.rules).forEach((n=>{const{body:i}=t.rules[n];try{i.assertChoicesHaveUniformArity(n)}catch(t){e.push(t)}try{i.assertAllApplicationsAreValid(n,t)}catch(t){e.push(t),r=!0}})),r||Object.keys(t.rules).forEach((r=>{const{body:n}=t.rules[r];try{n.assertIteratedExprsAreNotNullable(t,[])}catch(t){e.push(t)}})),e.length>0&&J(e),this.source&&(t.source=this.source),t}define(t,e,r,n,i,s){if(this.ensureSuperGrammar(),this.superGrammar.rules[t])throw $(t,this.name,this.superGrammar.name,i);if(this.rules[t])throw $(t,this.name,this.name,i);const o=a(e);if(o.length>0)throw K(t,o,i);return this.install(t,e,r,n,i,s)}override(t,e,r,n,i){return this.ensureSuperGrammarRuleForOverriding(t,i),this.installOverriddenOrExtendedRule(t,e,r,i),this}extend(t,e,r,n,i){if(!this.ensureSuperGrammar().rules[t])throw s=t,o=this.superGrammar.name,B("Cannot extend rule "+s+" because it is not declared in "+o,i);var s,o;const a=new R(this.superGrammar,t,r);return a.source=r.source,this.installOverriddenOrExtendedRule(t,e,a,i),this}}class Gt{constructor(){this.currentDecl=null,this.currentRuleName=null}newGrammar(t){return new Mt(t)}grammar(t,e,r,n,i){const s=new Mt(e);return r&&s.withSuperGrammar(r instanceof jt?r:this.fromRecipe(r)),n&&s.withDefaultStartRule(n),t&&t.source&&s.withSource(t.source),this.currentDecl=s,Object.keys(i).forEach((t=>{this.currentRuleName=t;const e=i[t],r=e[0],n=e[1],o=e[2],a=e[3],u=this.fromRecipe(e[4]);let c;s.source&&n&&n.sourceInterval&&(c=s.source.subInterval(n.sourceInterval[0],n.sourceInterval[1]-n.sourceInterval[0])),s[r](t,a,u,o,c)})),this.currentRuleName=this.currentDecl=null,s.build()}terminal(t){return new w(t)}range(t,e){return new A(t,e)}param(t){return new O(t)}alt(...t){let e=[];for(let r of t)r instanceof S||(r=this.fromRecipe(r)),r instanceof N?e=e.concat(r.terms):e.push(r);return 1===e.length?e[0]:new N(e)}seq(...t){let e=[];for(let r of t)r instanceof S||(r=this.fromRecipe(r)),r instanceof P?e=e.concat(r.factors):e.push(r);return 1===e.length?e[0]:new P(e)}star(t){return t instanceof S||(t=this.fromRecipe(t)),new E(t)}plus(t){return t instanceof S||(t=this.fromRecipe(t)),new C(t)}opt(t){return t instanceof S||(t=this.fromRecipe(t)),new T(t)}not(t){return t instanceof S||(t=this.fromRecipe(t)),new k(t)}lookahead(t){return t instanceof S||(t=this.fromRecipe(t)),new D(t)}lex(t){return t instanceof S||(t=this.fromRecipe(t)),new j(t)}app(t,e){return e&&e.length>0&&(e=e.map((function(t){return t instanceof S?t:this.fromRecipe(t)}),this)),new M(t,e)}splice(t,e){return new L(this.currentDecl.superGrammar,this.currentRuleName,t.map((t=>this.fromRecipe(t))),e.map((t=>this.fromRecipe(t))))}fromRecipe(t){const e="grammar"===t[0]?t.slice(1):t.slice(2),r=this[t[0]](...e),n=t[1];return n&&n.sourceInterval&&this.currentDecl&&r.withSource(this.currentDecl.sourceInterval(...n.sourceInterval)),r}}function Bt(t){return"function"==typeof t?t.call(new Gt):("string"==typeof t&&(t=JSON.parse(t)),(new Gt).fromRecipe(t))}var qt=Bt(["grammar",{source:'BuiltInRules {\n\n alnum (an alpha-numeric character)\n = letter\n | digit\n\n letter (a letter)\n = lower\n | upper\n | unicodeLtmo\n\n digit (a digit)\n = "0".."9"\n\n hexDigit (a hexadecimal digit)\n = digit\n | "a".."f"\n | "A".."F"\n\n ListOf<elem, sep>\n = NonemptyListOf<elem, sep>\n | EmptyListOf<elem, sep>\n\n NonemptyListOf<elem, sep>\n = elem (sep elem)*\n\n EmptyListOf<elem, sep>\n = /* nothing */\n\n listOf<elem, sep>\n = nonemptyListOf<elem, sep>\n | emptyListOf<elem, sep>\n\n nonemptyListOf<elem, sep>\n = elem (sep elem)*\n\n emptyListOf<elem, sep>\n = /* nothing */\n\n // Allows a syntactic rule application within a lexical context.\n applySyntactic<app> = app\n}'},"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]]}]);jt.BuiltInRules=qt,function(t){X.forEach((e=>{e(t)})),X=null}(jt.BuiltInRules);var Ut=Bt(["grammar",{source:'Ohm {\n\n Grammars\n = Grammar*\n\n Grammar\n = ident SuperGrammar? "{" Rule* "}"\n\n SuperGrammar\n = "<:" ident\n\n Rule\n = ident Formals? ruleDescr? "=" RuleBody -- define\n | ident Formals? ":=" OverrideRuleBody -- override\n | ident Formals? "+=" RuleBody -- extend\n\n RuleBody\n = "|"? NonemptyListOf<TopLevelTerm, "|">\n\n TopLevelTerm\n = Seq caseName -- inline\n | Seq\n\n OverrideRuleBody\n = "|"? NonemptyListOf<OverrideTopLevelTerm, "|">\n\n OverrideTopLevelTerm\n = "..." -- superSplice\n | TopLevelTerm\n\n Formals\n = "<" ListOf<ident, ","> ">"\n\n Params\n = "<" ListOf<Seq, ","> ">"\n\n Alt\n = NonemptyListOf<Seq, "|">\n\n Seq\n = Iter*\n\n Iter\n = Pred "*" -- star\n | Pred "+" -- plus\n | Pred "?" -- opt\n | Pred\n\n Pred\n = "~" Lex -- not\n | "&" Lex -- lookahead\n | Lex\n\n Lex\n = "#" Base -- lex\n | Base\n\n Base\n = ident Params? ~(ruleDescr? "=" | ":=" | "+=") -- application\n | oneCharTerminal ".." oneCharTerminal -- range\n | terminal -- terminal\n | "(" Alt ")" -- paren\n\n ruleDescr (a rule description)\n = "(" ruleDescrText ")"\n\n ruleDescrText\n = (~")" any)*\n\n caseName\n = "--" (~"\\n" space)* name (~"\\n" space)* ("\\n" | &"}")\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n ident (an identifier)\n = name\n\n terminal\n = "\\"" terminalChar* "\\""\n\n oneCharTerminal\n = "\\"" terminalChar "\\""\n\n terminalChar\n = escapeChar\n | ~"\\\\" ~"\\"" ~"\\n" "\\u{0}".."\\u{10FFFF}"\n\n escapeChar (an escape sequence)\n = "\\\\\\\\" -- backslash\n | "\\\\\\"" -- doubleQuote\n | "\\\\\\\'" -- singleQuote\n | "\\\\b" -- backspace\n | "\\\\n" -- lineFeed\n | "\\\\r" -- carriageReturn\n | "\\\\t" -- tab\n | "\\\\u{" hexDigit hexDigit? hexDigit?\n hexDigit? hexDigit? hexDigit? "}" -- unicodeCodePoint\n | "\\\\u" hexDigit hexDigit hexDigit hexDigit -- unicodeEscape\n | "\\\\x" hexDigit hexDigit -- hexEscape\n\n space\n += comment\n\n comment\n = "//" (~"\\n" any)* &("\\n" | end) -- singleLine\n | "/*" (~"*/" any)* "*/" -- multiLine\n\n tokens = token*\n\n token = caseName | comment | ident | operator | punctuation | terminal | any\n\n operator = "<:" | "=" | ":=" | "+=" | "*" | "+" | "?" | "~" | "&"\n\n punctuation = "<" | ">" | "," | "--"\n}'},"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]},"\n"]],["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]},"\n"]],["app",{sourceInterval:[1317,1322]},"space",[]]]],["alt",{sourceInterval:[1326,1337]},["terminal",{sourceInterval:[1326,1330]},"\n"],["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]},"\n"]],["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]},"\n"]],["app",{sourceInterval:[2424,2427]},"any",[]]]],["lookahead",{sourceInterval:[2430,2443]},["alt",{sourceInterval:[2432,2442]},["terminal",{sourceInterval:[2432,2436]},"\n"],["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]},"--"]]]}]);const $t=Object.create(S.prototype);function zt(t,e){for(const r in t)if(r===e)return!0;return!1}function Kt(t,e,n){const i=new Gt;let s,o,a,u=!1;const c=(n||Ut).createSemantics().addOperation("visit",{Grammars:t=>t.children.map((t=>t.visit())),Grammar(t,r,n,o,a){const u=t.visit();s=i.newGrammar(u),r.child(0)&&r.child(0).visit(),o.children.map((t=>t.visit()));const c=s.build();if(c.source=this.source.trimmed(),zt(e,u))throw function(t){return B("Grammar "+t.name+" is already declared in this namespace")}(c);return e[u]=c,c},SuperGrammar(t,r){const n=r.visit();if("null"===n)s.withSuperGrammar(null);else{if(!e||!zt(e,n))throw function(t,e,r){return B(e?`Grammar ${t} is not declared in namespace '${e}'`:"Undeclared grammar "+t,r)}(n,e,r.source);s.withSuperGrammar(e[n])}},Rule_define(t,e,r,n,i){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[],s.defaultStartRule||s.ensureSuperGrammar()===jt.ProtoBuiltInRules||s.withDefaultStartRule(o);const u=i.visit(),c=r.children.map((t=>t.visit()))[0],l=this.source.trimmed();return s.define(o,a,u,c,l)},Rule_override(t,e,r,n){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[];const i=this.source.trimmed();s.ensureSuperGrammarRuleForOverriding(o,i),u=!0;const c=n.visit();return u=!1,s.override(o,a,c,null,i)},Rule_extend(t,e,r,n){o=t.visit(),a=e.children.map((t=>t.visit()))[0]||[];const i=n.visit(),u=this.source.trimmed();return s.extend(o,a,i,null,u)},RuleBody(t,e){return i.alt(...e.visit()).withSource(this.source)},OverrideRuleBody(t,e){const r=e.visit(),n=r.indexOf($t);if(n>=0){const t=r.slice(0,n),e=r.slice(n+1);return e.forEach((t=>{if(t===$t)throw B("'...' can appear at most once in a rule body",t.source)})),new L(s.superGrammar,o,t,e).withSource(this.source)}return i.alt(...r).withSource(this.source)},Formals:(t,e,r)=>e.visit(),Params:(t,e,r)=>e.visit(),Alt(t){return i.alt(...t.visit()).withSource(this.source)},TopLevelTerm_inline(t,e){const r=o+"_"+e.visit(),n=t.visit(),c=this.source.trimmed(),l=!(s.superGrammar&&s.superGrammar.rules[r]);u&&!l?s.override(r,a,n,null,c):s.define(r,a,n,null,c);const p=a.map((t=>i.app(t)));return i.app(r,p).withSource(n.source)},OverrideTopLevelTerm_superSplice:t=>$t,Seq(t){return i.seq(...t.children.map((t=>t.visit()))).withSource(this.source)},Iter_star(t,e){return i.star(t.visit()).withSource(this.source)},Iter_plus(t,e){return i.plus(t.visit()).withSource(this.source)},Iter_opt(t,e){return i.opt(t.visit()).withSource(this.source)},Pred_not(t,e){return i.not(e.visit()).withSource(this.source)},Pred_lookahead(t,e){return i.lookahead(e.visit()).withSource(this.source)},Lex_lex(t,e){return i.lex(e.visit()).withSource(this.source)},Base_application(t,e){const r=e.children.map((t=>t.visit()))[0]||[];return i.app(t.visit(),r).withSource(this.source)},Base_range(t,e,r){return i.range(t.visit(),r.visit()).withSource(this.source)},Base_terminal(t){return i.terminal(t.visit()).withSource(this.source)},Base_paren:(t,e,r)=>e.visit(),ruleDescr:(t,e,r)=>e.visit(),ruleDescrText(t){return this.sourceString.trim()},caseName:(t,e,r,n,i)=>r.visit(),name(t,e){return this.sourceString},nameFirst(t){},nameRest(t){},terminal:(t,e,r)=>e.children.map((t=>t.visit())).join(""),oneCharTerminal:(t,e,r)=>e.visit(),escapeChar(t){try{return d(this.sourceString)}catch(e){if(e instanceof RangeError&&e.message.startsWith("Invalid code point "))throw function(t){const e=t._node;r(e&&e.isNonterminal()&&"escapeChar_unicodeCodePoint"===e.ctorName);const n=t.children.slice(1,-1).map((t=>t.source)),i=n[0].coverageWith(...n.slice(1));return B(`U+${i.contents} is not a valid Unicode code point`,i)}(t);throw e}},NonemptyListOf:(t,e,r)=>[t.visit()].concat(r.children.map((t=>t.visit()))),EmptyListOf:()=>[],_terminal(){return this.sourceString}});return c(t).visit()}var Ht=Bt(["grammar",{source:'OperationsAndAttributes {\n\n AttributeSignature =\n name\n\n OperationSignature =\n name Formals?\n\n Formals\n = "(" ListOf<name, ","> ")"\n\n name (a name)\n = nameFirst nameRest*\n\n nameFirst\n = "_"\n | letter\n\n nameRest\n = "_"\n | alnum\n\n}'},"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",[]]]]}]);!function(t){const e={empty(){return this.iteration()},nonEmpty(t,e,r){return this.iteration([t].concat(r.children))},self(...t){return this}};Lt.BuiltInSemantics=Lt.createSemantics(t,null).addOperation("asIteration",{emptyListOf:e.empty,nonemptyListOf:e.nonEmpty,EmptyListOf:e.empty,NonemptyListOf:e.nonEmpty,_iter:e.self})}(jt.BuiltInRules),function(t){Lt.prototypeGrammarSemantics=t.createSemantics().addOperation("parse",{AttributeSignature:t=>({name:t.parse(),formals:[]}),OperationSignature:(t,e)=>({name:t.parse(),formals:e.children.map((t=>t.parse()))[0]||[]}),Formals:(t,e,r)=>e.asIteration().children.map((t=>t.parse())),name(t,e){return this.sourceString}}),Lt.prototypeGrammar=t}(Ht);const Vt="an indented block",Wt="a dedent",Jt=1114112;class Qt extends it{constructor(t){super(t.input),this.state=t}_indentationAt(t){return this.state.userData[t]||0}atEnd(){return super.atEnd()&&0===this._indentationAt(this.pos)}next(){if(0===this._indentationAt(this.pos))return super.next();this.examinedLength=Math.max(this.examinedLength,this.pos)}nextCharCode(){return 0!==this._indentationAt(this.pos)?(this.examinedLength=Math.max(this.examinedLength,this.pos),Jt):super.nextCharCode()}nextCodePoint(){return 0!==this._indentationAt(this.pos)?(this.examinedLength=Math.max(this.examinedLength,this.pos),Jt):super.nextCodePoint()}}class Zt extends S{constructor(t=!0){super(),this.isIndent=t}allowsSkippingPrecedingSpace(){return!0}eval(t){const{inputStream:e}=t,r=t.userData;t.doNotMemoize=!0;const n=e.pos,i=this.isIndent?1:-1;return(r[n]||0)*i>0?(t.userData=Object.create(r),t.userData[n]-=i,t.pushBinding(new mt(0),n),!0):(t.processFailure(n,this),!1)}getArity(){return 1}_assertAllApplicationsAreValid(t,e){}_isNullable(t,e){return!1}assertChoicesHaveUniformArity(t){}assertIteratedExprsAreNotNullable(t){}introduceParams(t){return this}substituteParams(t){return this}toString(){return this.isIndent?"indent":"dedent"}toDisplayString(){return this.toString()}toFailure(t){const e=this.isIndent?Vt:Wt;return new yt(this,e,"description")}}const Xt=new M("indent"),Yt=new M("dedent"),te=new L(qt,"any",[Xt,Yt],[]),ee=(new Gt).newGrammar("IndentationSensitive").withSuperGrammar(qt).define("indent",[],new Zt(!0),Vt,void 0,!0).define("dedent",[],new Zt(!1),Wt,void 0,!0).extend("any",[],te,"any character",void 0).build();Object.assign(ee,{_matchStateInitializer(t){t.userData=function(t){let e=0;const r=[0],n=()=>r[r.length-1],i={},s=/( *).*(?:$|\r?\n|\r)/g;let o;for(;null!=(o=s.exec(t));){const[t,s]=o;if(0===t.length)break;const a=s.length,u=n(),c=e+a;if(a>u)r.push(a),i[c]=1;else if(a<u){const t=r.length;for(;n()!==a;)r.pop();i[c]=-1*(t-r.length)}e+=t.length}return r.length>1&&(i[e]=1-r.length),i}(t.input),t.inputStream=new Qt(t)},supportsIncrementalParsing:!1});jt.initApplicationParser(Ut,Kt);function re(t,e){const r=Ut.match(t,"Grammars");if(r.failed())throw function(t){const e=new Error;return Object.defineProperty(e,"message",{enumerable:!0,get:()=>t.message}),Object.defineProperty(e,"shortMessage",{enumerable:!0,get:()=>"Expected "+t.getExpectedText()}),e.interval=t.getInterval(),e}(r);return Kt(r,e)}function ne(t,e){const r=Object.create(e||{});if("string"!=typeof t){if(!(n=t).constructor||"function"!=typeof n.constructor.isBuffer||!n.constructor.isBuffer(n))throw new TypeError("Expected string as first argument, got "+f(t));t=t.toString()}var n;return re(t,r),r}t.ExperimentalIndentationSensitive=ee,t._buildGrammar=Kt,t.grammar=function(t,e){const r=ne(t,e),n=Object.keys(r);if(0===n.length)throw new Error("Missing grammar definition");if(n.length>1){const t=r[n[1]].source;throw new Error(et(t.sourceString,t.startIdx)+"Found more than one grammar definition -- use ohm.grammars() instead.")}return r[n[0]]},t.grammars=ne,t.makeRecipe=Bt,t.ohmGrammar=Ut,t.pexprs=St,t.version="17.4.0",Object.defineProperty(t,"__esModule",{value:!0})}));
|
package/extras/index.d.ts
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type {MatchResult,
|
|
2
|
-
|
|
3
|
-
interface LineAndColumnInfo {
|
|
4
|
-
offset: number;
|
|
5
|
-
lineNumber: number;
|
|
6
|
-
colNum: number;
|
|
7
|
-
line: string;
|
|
8
|
-
prevLine: string;
|
|
9
|
-
nextLine: string;
|
|
10
|
-
toString(...ranges: number[][]): string;
|
|
11
|
-
}
|
|
1
|
+
import type {Grammar, LineAndColumnInfo, MatchResult, Node, Semantics} from '../index.d.ts';
|
|
12
2
|
|
|
13
3
|
export function toAST(matchResult: MatchResult, mapping?: {}): {};
|
|
14
4
|
export function semanticsForToAST(g: Grammar): Semantics;
|
|
@@ -44,3 +34,9 @@ interface Example {
|
|
|
44
34
|
* `//- "shouldn't match"`. The examples text is a JSON string.
|
|
45
35
|
*/
|
|
46
36
|
export function extractExamples(grammarsDef: string): [Example];
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
Given an array of nodes, return a new array where (a) all iter nodes are replaced by
|
|
40
|
+
their children, and (b) nodes appear in the correct source order.
|
|
41
|
+
*/
|
|
42
|
+
export function recoverSourceOrder(nodes: Node[]): Node[];
|
package/extras/index.mjs
CHANGED
|
@@ -2,3 +2,4 @@ export {getLineAndColumnMessage, getLineAndColumn} from '../src/util.js';
|
|
|
2
2
|
export {VisitorFamily} from './VisitorFamily.js';
|
|
3
3
|
export {semanticsForToAST, toAST} from './semantics-toAST.js';
|
|
4
4
|
export {extractExamples} from './extractExamples.js';
|
|
5
|
+
export {recoverSourceOrder} from './recoverSourceOrder.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
To find iter nodes that are derived from the same repetition expression, we
|
|
3
|
+
look for adjacent iter nodes that have the same source interval and the same
|
|
4
|
+
number of children.
|
|
5
|
+
|
|
6
|
+
A few things to note:
|
|
7
|
+
- The children of `*` and `+` nodes can't be nullable, so the associated iter
|
|
8
|
+
nodes always consume some input, and therefore consecutive nodes that have
|
|
9
|
+
the same interval must come from the same repetition expression.
|
|
10
|
+
- We *could* mistake `a? b?` for (a b)?`, if neither of them comsume any input.
|
|
11
|
+
However, for the purposes of this module, those two cases are equivalent
|
|
12
|
+
anyways, since we only care about finding the correct order of the non-iter
|
|
13
|
+
nodes, and both interpretations yield the same order.
|
|
14
|
+
*/
|
|
15
|
+
const isIterSibling = (refNode, n) => {
|
|
16
|
+
return (
|
|
17
|
+
n.isIteration() &&
|
|
18
|
+
n.source.startIdx === refNode.source.startIdx &&
|
|
19
|
+
n.source.endIdx === refNode.source.endIdx &&
|
|
20
|
+
n.children.length === refNode.children.length
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function recoverSourceOrder(nodes, depth = 0) {
|
|
25
|
+
const ans = [];
|
|
26
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
27
|
+
const n = nodes[i];
|
|
28
|
+
if (!n.isIteration()) {
|
|
29
|
+
ans.push(n);
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// We found an iter node, now find its siblings.
|
|
34
|
+
const siblings = [n];
|
|
35
|
+
// Find the first node that's *not* part of the current list.
|
|
36
|
+
for (let j = i + 1; j < nodes.length && isIterSibling(n, nodes[j]); j++) {
|
|
37
|
+
siblings.push(nodes[j]);
|
|
38
|
+
i = j;
|
|
39
|
+
}
|
|
40
|
+
const cousins = [];
|
|
41
|
+
const numRows = siblings[0].children.length;
|
|
42
|
+
for (let row = 0; row < numRows; row++) {
|
|
43
|
+
cousins.push(...siblings.map(sib => sib.children[row]));
|
|
44
|
+
}
|
|
45
|
+
ans.push(...recoverSourceOrder(cousins, depth + 1));
|
|
46
|
+
}
|
|
47
|
+
return ans;
|
|
48
|
+
}
|