UNPKG

@gdquest/gd-exercise

Version:

Core package that handles logic for the GDExercise project.

1 lines 90.6 kB
import"./chunk-2YCYAEJC.min.mjs";import{foldNodeProp as hi,foldInside as fi,indentNodeProp as ui,LRLanguage as ci,LanguageSupport as pi}from"@codemirror/language";var Ft=0,de=class{constructor(e,t){this.from=e,this.to=t}},T=class{constructor(e={}){this.id=Ft++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")})}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=W.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}};T.closedBy=new T({deserialize:r=>r.split(" ")});T.openedBy=new T({deserialize:r=>r.split(" ")});T.group=new T({deserialize:r=>r.split(" ")});T.contextHash=new T({perNode:!0});T.lookAhead=new T({perNode:!0});T.mounted=new T({perNode:!0});var Lt=Object.create(null),W=class r{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Lt,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new r(e.name||"",t,e.id,i);if(e.props){for(let n of e.props)if(Array.isArray(n)||(n=n(s)),n){if(n[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[n[0].id]=n[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(T.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(T.group),n=-1;n<(s?s.length:0);n++){let o=t[n<0?i.name:s[n]];if(o)return o}}}};W.none=new W("",Object.create(null),0,8);var Pe=class r{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let n of e){let o=n(i);o&&(s||(s=Object.assign({},i.props)),s[o[0].id]=o[1])}t.push(s?new W(i.name,s,i.id,i.flags):i)}return new r(t)}},ke=new WeakMap,mt=new WeakMap,A;(function(r){r[r.ExcludeBuffers=1]="ExcludeBuffers",r[r.IncludeAnonymous=2]="IncludeAnonymous",r[r.IgnoreMounts=4]="IgnoreMounts",r[r.IgnoreOverlays=8]="IgnoreOverlays"})(A||(A={}));var E=class r{constructor(e,t,i,s,n){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,n&&n.length){this.props=Object.create(null);for(let[o,l]of n)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=this.prop(T.mounted);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new he(this.topNode,e)}cursorAt(e,t=0,i=0){let s=ke.get(this)||this.topNode,n=new he(s);return n.moveTo(e,t),ke.set(this,n._tree),n}get topNode(){return new re(this,0,0,null)}resolve(e,t=0){let i=ae(ke.get(this)||this.topNode,e,t,!1);return ke.set(this,i),i}resolveInner(e,t=0){let i=ae(mt.get(this)||this.topNode,e,t,!0);return mt.set(this,i),i}iterate(e){let{enter:t,leave:i,from:s=0,to:n=this.length}=e,o=e.mode||0,l=(o&A.IncludeAnonymous)>0;for(let a=this.cursor(o|A.IncludeAnonymous);;){let h=!1;if(a.from<=n&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:Fe(W.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new r(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new r(W.none,t,i,s)))}static build(e){return Zt(e)}};E.empty=new E(W.none,[],[],0);var We=class r{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new r(this.buffer,this.index)}},ie=class r{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return W.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],n=s.name;if(/\W/.test(n)&&!s.isError&&(n=JSON.stringify(n)),e+=4,i==e)return n;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return n+"("+o.join(",")+")"}findChild(e,t,i,s,n){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(bt(n,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,n=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){n[a++]=s[l++],n[a++]=s[l++]-i;let h=n[a++]=s[l++]-i;n[a++]=s[l++]-e,o=Math.max(o,h)}return new r(n,o,this.set)}};function bt(r,e,t,i){switch(r){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function xt(r,e){let t=r.childBefore(e);for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(r=t,t=i.prevSibling):t=i}return r}function ae(r,e,t,i){for(var s;r.from==r.to||(t<1?r.from>=e:r.from>e)||(t>-1?r.to<=e:r.to<e);){let o=!i&&r instanceof re&&r.index<0?null:r.parent;if(!o)return r;r=o}let n=i?0:A.IgnoreOverlays;if(i)for(let o=r,l=o.parent;l;o=l,l=o.parent)o instanceof re&&o.index<0&&((s=l.enter(e,t,n))===null||s===void 0?void 0:s.from)!=o.from&&(r=l);for(;;){let o=r.enter(e,t,n);if(!o)return r;r=o}}var re=class r{constructor(e,t,i,s){this._tree=e,this.from=t,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,s,n=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let p=l[e],f=a[e]+o.from;if(bt(s,i,f,f+p.length)){if(p instanceof ie){if(n&A.ExcludeBuffers)continue;let b=p.findChild(0,p.buffer.length,t,i-f,s);if(b>-1)return new Oe(new Ge(o,p,e,f),null,b)}else if(n&A.IncludeAnonymous||!p.type.isAnonymous||je(p)){let b;if(!(n&A.IgnoreMounts)&&p.props&&(b=p.prop(T.mounted))&&!b.overlay)return new r(b.tree,f,e,o);let y=new r(p,f,e,o);return n&A.IncludeAnonymous||!y.type.isAnonymous?y:y.nextChild(t<0?p.children.length-1:0,t,i,s)}}}if(n&A.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}enter(e,t,i=0){let s;if(!(i&A.IgnoreOverlays)&&(s=this._tree.prop(T.mounted))&&s.overlay){let n=e-this.from;for(let{from:o,to:l}of s.overlay)if((t>0?o<=n:o<n)&&(t<0?l>=n:l>n))return new r(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}cursor(e=0){return new he(this,e)}get tree(){return this._tree}toTree(){return this._tree}resolve(e,t=0){return ae(this,e,t,!1)}resolveInner(e,t=0){return ae(this,e,t,!0)}enterUnfinishedNodesBefore(e){return xt(this,e)}getChild(e,t=null,i=null){let s=ve(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return ve(this,e,t,i)}toString(){return this._tree.toString()}get node(){return this}matchContext(e){return Te(this,e)}};function ve(r,e,t,i){let s=r.cursor(),n=[];if(!s.firstChild())return n;if(t!=null){for(;!s.type.is(t);)if(!s.nextSibling())return n}for(;;){if(i!=null&&s.type.is(i))return n;if(s.type.is(e)&&n.push(s.node),!s.nextSibling())return i==null?n:[]}}function Te(r,e,t=e.length-1){for(let i=r.parent;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}var Ge=class{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}},Oe=class r{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return n<0?null:new r(this.context,this,n)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}enter(e,t,i=0){if(i&A.ExcludeBuffers)return null;let{buffer:s}=this.context,n=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return n<0?null:new r(this.context,this,n)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new r(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new r(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}cursor(e=0){return new he(this,e)}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,n=i.buffer[this.index+3];if(n>s){let o=i.buffer[this.index+1];e.push(i.slice(s,n,o)),t.push(0)}return new E(this.type,e,t,this.to-this.from)}resolve(e,t=0){return ae(this,e,t,!1)}resolveInner(e,t=0){return ae(this,e,t,!0)}enterUnfinishedNodesBefore(e){return xt(this,e)}toString(){return this.context.buffer.childString(this.index)}getChild(e,t=null,i=null){let s=ve(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return ve(this,e,t,i)}get node(){return this}matchContext(e){return Te(this,e)}},he=class{get name(){return this.type.name}constructor(e,t=0){if(this.mode=t,this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,e instanceof re)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof re?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,n=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return n<0?!1:(this.stack.push(this.index),this.yieldBuf(n))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&A.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&A.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&A.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let n=0;n<this.index;n++)if(s.buffer.buffer[n+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let n=t+e,o=e<0?-1:i._tree.children.length;n!=o;n+=e){let l=i._tree.children[n];if(this.mode&A.IncludeAnonymous||l instanceof ie||!l.type.isAnonymous||je(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let s=this.index,n=this.stack.length;n>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=n+1;break e}s=this.stack[--n]}for(let s=i;s<this.stack.length;s++)t=new Oe(this.buffer,t,this.stack[s]);return this.bufferNode=new Oe(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;s&&t&&t(this),s=this.type.isAnonymous,!this.nextSibling();){if(!i)return;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return Te(this.node,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let s=e.length-1,n=this.stack.length-1;s>=0;n--){if(n<0)return Te(this.node,e,s);let o=i[t.buffer[this.stack[n]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}};function je(r){return r.children.some(e=>e instanceof ie||!e.type.isAnonymous||je(e))}function Zt(r){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=1024,reused:n=[],minRepeatType:o=i.types.length}=r,l=Array.isArray(t)?new We(t,t.length):t,a=i.types,h=0,p=0;function f(x,Q,u,m,w){let{id:g,start:d,end:k,size:v}=l,z=p;for(;v<0;)if(l.next(),v==-1){let N=n[g];u.push(N),m.push(d-x);return}else if(v==-3){h=g;return}else if(v==-4){p=g;return}else throw new RangeError(`Unrecognized record size: ${v}`);let q=a[g],_,U,ce=d-x;if(k-d<=s&&(U=I(l.pos-Q,w))){let N=new Uint16Array(U.size-U.skip),$=l.pos-U.size,R=N.length;for(;l.pos>$;)R=G(U.start,N,R);_=new ie(N,k-U.start,i),ce=U.start-x}else{let N=l.pos-v;l.next();let $=[],R=[],X=g>=o?g:-1,D=0,J=k;for(;l.pos>N;)X>=0&&l.id==X&&l.size>=0?(l.end<=J-s&&(y($,R,d,D,l.end,J,X,z),D=$.length,J=l.end),l.next()):f(d,N,$,R,X);if(X>=0&&D>0&&D<$.length&&y($,R,d,D,d,J,X,z),$.reverse(),R.reverse(),X>-1&&D>0){let pe=b(q);_=Fe(q,$,R,0,$.length,0,k-d,pe,pe)}else _=S(q,$,R,k-d,z-k)}u.push(_),m.push(ce)}function b(x){return(Q,u,m)=>{let w=0,g=Q.length-1,d,k;if(g>=0&&(d=Q[g])instanceof E){if(!g&&d.type==x&&d.length==m)return d;(k=d.prop(T.lookAhead))&&(w=u[g]+d.length+k)}return S(x,Q,u,m,w)}}function y(x,Q,u,m,w,g,d,k){let v=[],z=[];for(;x.length>m;)v.push(x.pop()),z.push(Q.pop()+u-w);x.push(S(i.types[d],v,z,g-w,k-g)),Q.push(w-u)}function S(x,Q,u,m,w=0,g){if(h){let d=[T.contextHash,h];g=g?[d].concat(g):[d]}if(w>25){let d=[T.lookAhead,w];g=g?[d].concat(g):[d]}return new E(x,Q,u,m,g)}function I(x,Q){let u=l.fork(),m=0,w=0,g=0,d=u.end-s,k={size:0,start:0,skip:0};e:for(let v=u.pos-x;u.pos>v;){let z=u.size;if(u.id==Q&&z>=0){k.size=m,k.start=w,k.skip=g,g+=4,m+=4,u.next();continue}let q=u.pos-z;if(z<0||q<v||u.start<d)break;let _=u.id>=o?4:0,U=u.start;for(u.next();u.pos>q;){if(u.size<0)if(u.size==-3)_+=4;else break e;else u.id>=o&&(_+=4);u.next()}w=U,m+=z,g+=_}return(Q<0||m==x)&&(k.size=m,k.start=w,k.skip=g),k.size>4?k:void 0}function G(x,Q,u){let{id:m,start:w,end:g,size:d}=l;if(l.next(),d>=0&&m<o){let k=u;if(d>4){let v=l.pos-(d-4);for(;l.pos>v;)u=G(x,Q,u)}Q[--u]=k,Q[--u]=g-x,Q[--u]=w-x,Q[--u]=m}else d==-3?h=m:d==-4&&(p=m);return u}let Y=[],B=[];for(;l.pos>0;)f(r.start||0,r.bufferStart||0,Y,B,-1);let P=(e=r.length)!==null&&e!==void 0?e:Y.length?B[0]+Y[0].length:0;return new E(a[r.topID],Y.reverse(),B.reverse(),P)}var gt=new WeakMap;function we(r,e){if(!r.isAnonymous||e instanceof ie||e.type!=r)return 1;let t=gt.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=r||!(i instanceof E)){t=1;break}t+=we(r,i)}gt.set(e,t)}return t}function Fe(r,e,t,i,s,n,o,l,a){let h=0;for(let S=i;S<s;S++)h+=we(r,e[S]);let p=Math.ceil(h*1.5/8),f=[],b=[];function y(S,I,G,Y,B){for(let P=G;P<Y;){let x=P,Q=I[P],u=we(r,S[P]);for(P++;P<Y;P++){let m=we(r,S[P]);if(u+m>=p)break;u+=m}if(P==x+1){if(u>p){let m=S[x];y(m.children,m.positions,0,m.children.length,I[x]+B);continue}f.push(S[x])}else{let m=I[P-1]+S[P-1].length-Q;f.push(Fe(r,S,I,x,P,Q,m,null,a))}b.push(Q+B-n)}}return y(e,t,i,s,0),(l||a)(f,b,o)}var ze=class{startParse(e,t,i){return typeof e=="string"&&(e=new Me(e)),i=i?i.length?i.map(s=>new de(s.from,s.to)):[new de(0,0)]:[new de(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let n=s.advance();if(n)return n}}},Me=class{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}};var Mi=new T({perNode:!0});var Je=class r{constructor(e,t,i,s,n,o,l,a,h,p=0,f){this.p=e,this.stack=t,this.state=i,this.reducePos=s,this.pos=n,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=h,this.lookAhead=p,this.parent=f}toString(){return`[${this.stack.filter((e,t)=>t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let s=e.parser.context;return new r(e,[],t,i,i,0,[],0,s?new $e(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,s=e&65535,{parser:n}=this.p,o=n.dynamicPrecedence(s);if(o&&(this.score+=o),i==0){this.pushState(n.getGoto(this.state,s,!0),this.reducePos),s<n.minRepeatTerm&&this.storeNode(s,this.reducePos,this.reducePos,4,!0),this.reduceContext(s,this.reducePos);return}let l=this.stack.length-(i-1)*3-(e&262144?6:0),a=l?this.stack[l-2]:this.p.ranges[0].from,h=this.reducePos-a;h>=2e3&&!(!((t=this.p.parser.nodeSet.types[s])===null||t===void 0)&&t.isAnonymous)&&(a==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=h):this.p.lastBigReductionSize<h&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=a,this.p.lastBigReductionSize=h));let p=l?this.stack[l-1]:0,f=this.bufferBase+this.buffer.length-p;if(s<n.minRepeatTerm||e&131072){let b=n.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(s,a,b,f+4,!0)}if(e&262144)this.state=this.stack[l];else{let b=this.stack[l-3];this.state=n.getGoto(b,s,!0)}for(;this.stack.length>l;)this.stack.pop();this.reduceContext(s,a)}storeNode(e,t,i,s=4,n=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(t==i)return;if(o.buffer[l-2]>=t){o.buffer[l-2]=i;return}}}if(!n||this.pos==i)this.buffer.push(e,t,i,s);else{let o=this.buffer.length;if(o>0&&this.buffer[o-4]!=0)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4);this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=s}}shift(e,t,i){let s=this.pos;if(e&131072)this.pushState(e&65535,this.pos);else if(e&262144)this.pos=i,this.shiftContext(t,s),t<=this.p.parser.maxNode&&this.buffer.push(t,s,i,4);else{let n=e,{parser:o}=this.p;(i>this.pos||t<=o.maxNode)&&(this.pos=i,o.stateFlag(n,1)||(this.reducePos=i)),this.pushState(n,s),this.shiftContext(t,s),t<=o.maxNode&&this.buffer.push(t,s,i,4)}}apply(e,t,i){e&65536?this.reduce(e):this.shift(e,t,i)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let s=this.pos;this.reducePos=this.pos=s+e.length,this.pushState(t,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),s=e.bufferBase+t;for(;e&&s==e.bufferBase;)e=e.parent;return new r(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new He(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if(!(i&65536))return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let s=[];for(let n=0,o;n<t.length;n+=2)(o=t[n+1])!=this.state&&this.p.parser.hasAction(o,e)&&s.push(t[n],o);if(this.stack.length<120)for(let n=0;s.length<8&&n<t.length;n+=2){let o=t[n+1];s.some((l,a)=>a&1&&l==o)||s.push(t[n],o)}t=s}let i=[];for(let s=0;s<t.length&&i.length<4;s+=2){let n=t[s+1];if(n==this.state)continue;let o=this.split();o.pushState(n,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[s],this.pos),o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if(!(t&65536))return!1;if(!e.validAction(this.state,t)){let i=t>>19,s=t&65535,n=this.stack.length-i*3;if(n<0||e.getGoto(this.stack[n],s,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(s,n)=>{if(!t.includes(s))return t.push(s),e.allActions(s,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-n;if(l>1){let a=o&65535,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],a,!1)>=0)return l<<19|65536|a}}else{let l=i(o,n+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new $e(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){e>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=e)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}},$e=class{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}},Qt;(function(r){r[r.Insert=200]="Insert",r[r.Delete=190]="Delete",r[r.Reduce=100]="Reduce",r[r.MaxNext=4]="MaxNext",r[r.MaxInsertStackDepth=300]="MaxInsertStackDepth",r[r.DampenInsertStackDepth=120]="DampenInsertStackDepth",r[r.MinBigReduction=2e3]="MinBigReduction"})(Qt||(Qt={}));var He=class{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=(i-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=s}},Ke=class r{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new r(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new r(this.stack,this.pos,this.index)}};function me(r,e=Uint16Array){if(typeof r!="string")return r;let t=null;for(let i=0,s=0;i<r.length;){let n=0;for(;;){let o=r.charCodeAt(i++),l=!1;if(o==126){n=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),n+=a,l)break;n*=46}t?t[s++]=n:t=new e(n)}return t}var fe=class{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}},St=new fe,et=class{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=St,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,s=this.rangeIndex,n=this.pos+e;for(;n<i.from;){if(!s)return null;let o=this.ranges[--s];n-=i.from-o.to,i=o}for(;t<0?n>i.to:n>=i.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];n+=o.from-i.to,i=o}return n}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,s;if(t>=0&&t<this.chunk.length)i=this.pos+e,s=this.chunk.charCodeAt(t);else{let n=this.resolveOffset(e,1);if(n==null)return-1;if(i=n,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),s=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),s}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=St,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let s of this.ranges){if(s.from>=t)break;s.to>e&&(i+=this.input.read(Math.max(s.from,e),Math.min(s.to,t)))}return i}},K=class{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;zt(this.data,e,t,this.id,i.data,i.tokenPrecTable)}};K.prototype.contextual=K.prototype.fallback=K.prototype.extend=!1;var tt=class{constructor(e,t,i){this.precTable=t,this.elseToken=i,this.data=typeof e=="string"?me(e):e}token(e,t){let i=e.pos,s=0;for(;;){let n=e.next<0,o=e.resolveOffset(1,1);if(zt(this.data,e,t,0,this.data,this.precTable),e.token.value>-1)break;if(this.elseToken==null)return;if(n||s++,o==null)break;e.reset(o,e.token)}s&&(e.reset(i,e.token),e.acceptToken(this.elseToken,s))}};tt.prototype.contextual=K.prototype.fallback=K.prototype.extend=!1;var ge=class{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}};function zt(r,e,t,i,s,n){let o=0,l=1<<i,{dialect:a}=t.p.parser;e:for(;l&r[o];){let h=r[o+1];for(let y=o+3;y<h;y+=2)if((r[y+1]&l)>0){let S=r[y];if(a.allows(S)&&(e.token.value==-1||e.token.value==S||Ht(S,e.token.value,s,n))){e.acceptToken(S);break}}let p=e.next,f=0,b=r[o+2];if(e.next<0&&b>f&&r[h+b*3-3]==65535&&r[h+b*3-3]==65535){o=r[h+b*3-1];continue e}for(;f<b;){let y=f+b>>1,S=h+y+(y<<1),I=r[S],G=r[S+1]||65536;if(p<I)b=y;else if(p>=G)f=y+1;else{o=r[S+2],e.advance();continue e}}break}}function yt(r,e,t){for(let i=e,s;(s=r[i])!=65535;i++)if(s==t)return i-e;return-1}function Ht(r,e,t,i){let s=yt(t,i,e);return s<0||yt(t,i,r)<s}var M=typeof process<"u"&&process.env&&/\bparse\b/.test(process.env.LOG),Le=null,kt;(function(r){r[r.Margin=25]="Margin"})(kt||(kt={}));function wt(r,e,t){let i=r.cursor(A.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(r.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:r.length}}var it=class{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?wt(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?wt(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],s=this.index[t];if(s==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let n=i.children[s],o=this.start[t]+i.positions[s];if(o>e)return this.nextStart=o,null;if(n instanceof E){if(o==e){if(o<this.safeFrom)return null;let l=o+n.length;if(l<=this.safeTo){let a=n.prop(T.lookAhead);if(!a||l+a<this.fragment.to)return n}}this.index[t]++,o+n.length>=Math.max(this.safeFrom,e)&&(this.trees.push(n),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+n.length}}},rt=class{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new fe)}getActions(e){let t=0,i=null,{parser:s}=e.p,{tokenizers:n}=s,o=s.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let h=0;h<n.length;h++){if(!(1<<h&o))continue;let p=n[h],f=this.tokens[h];if(!(i&&!p.fallback)&&((p.contextual||f.start!=e.pos||f.mask!=o||f.context!=l)&&(this.updateCachedToken(f,p,e),f.mask=o,f.context=l),f.lookAhead>f.end+25&&(a=Math.max(f.lookAhead,a)),f.value!=0)){let b=t;if(f.extended>-1&&(t=this.addActions(e,f.extended,f.end,t)),t=this.addActions(e,f.value,f.end,t),!p.extend&&(i=f,t>b))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new fe,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new fe,{pos:i,p:s}=e;return t.start=i,t.end=Math.min(i+1,s.stream.end),t.value=i==s.stream.end?s.parser.eofTerm:0,t}updateCachedToken(e,t,i){let s=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(s,e),i),e.value>-1){let{parser:n}=i.p;for(let o=0;o<n.specialized.length;o++)if(n.specialized[o]==e.value){let l=n.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){l&1?e.extended=l>>1:e.value=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(s+1)}putAction(e,t,i,s){for(let n=0;n<s;n+=3)if(this.actions[n]==e)return s;return this.actions[s++]=e,this.actions[s++]=t,this.actions[s++]=i,s}addActions(e,t,i,s){let{state:n}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let h=o.stateSlot(n,a?2:1);;h+=3){if(l[h]==65535)if(l[h+1]==1)h=H(l,h+2);else{s==0&&l[h+1]==2&&(s=this.putAction(H(l,h+2),t,i,s));break}l[h]==t&&(s=this.putAction(H(l,h+1),t,i,s))}return s}},Pt;(function(r){r[r.Distance=5]="Distance",r[r.MaxRemainingPerStep=3]="MaxRemainingPerStep",r[r.MinBufferLengthPrune=500]="MinBufferLengthPrune",r[r.ForceReduceLimit=10]="ForceReduceLimit",r[r.CutDepth=15e3]="CutDepth",r[r.CutTo=9e3]="CutTo",r[r.MaxLeftAssociativeReductionCount=300]="MaxLeftAssociativeReductionCount",r[r.MaxStackCount=12]="MaxStackCount"})(Pt||(Pt={}));var st=class{constructor(e,t,i,s){this.parser=e,this.input=t,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new et(t,s),this.tokens=new rt(e,this.stream),this.topTerm=e.top[1];let{from:n}=s[0];this.stacks=[Je.start(this,e.top[0],n)],this.fragments=i.length&&this.stream.end-n>e.bufferLength*4?new it(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],s,n;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{s||(s=[],n=[]),s.push(l);let a=this.tokens.getMainToken(l);n.push(a.value,a.end)}}break}}if(!i.length){let o=s&&Kt(s);if(o)return this.stackToTree(o);if(this.parser.strict)throw M&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,n,i);if(o)return this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,a)=>a.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let a=o+1;a<i.length;a++){let h=i[a];if(l.sameState(h)||l.buffer.length>500&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&i.splice(12,i.length-12)}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let s=e.pos,{parser:n}=this,o=M?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,p=h?e.curContext.hash:0;for(let f=this.fragments.nodeAt(s);f;){let b=this.parser.nodeSet.types[f.type.id]==f.type?n.getGoto(e.state,f.type.id):-1;if(b>-1&&f.length&&(!h||(f.prop(T.contextHash)||0)==p))return e.useNode(f,b),M&&console.log(o+this.stackID(e)+` (via reuse of ${n.getName(f.type.id)})`),!0;if(!(f instanceof E)||f.children.length==0||f.positions[0]>0)break;let y=f.children[0];if(y instanceof E&&f.positions[0]==0)f=y;else break}}let l=n.stateSlot(e.state,4);if(l>0)return e.reduce(l),M&&console.log(o+this.stackID(e)+` (via always-reduce ${n.getName(l&65535)})`),!0;if(e.stack.length>=15e3)for(;e.stack.length>9e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let h=0;h<a.length;){let p=a[h++],f=a[h++],b=a[h++],y=h==a.length||!i,S=y?e:e.split();if(S.apply(p,f,b),M&&console.log(o+this.stackID(S)+` (via ${p&65536?`reduce of ${n.getName(p&65535)}`:"shift"} for ${n.getName(f)} @ ${s}${S==e?"":", split"})`),y)return!0;S.pos>s?t.push(S):i.push(S)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return vt(e,t),!0}}runRecovery(e,t,i){let s=null,n=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],h=t[(o<<1)+1],p=M?this.stackID(l)+" -> ":"";if(l.deadEnd&&(n||(n=!0,l.restart(),M&&console.log(p+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let f=l.split(),b=p;for(let y=0;f.forceReduce()&&y<10&&(M&&console.log(b+this.stackID(f)+" (via force-reduce)"),!this.advanceFully(f,i));y++)M&&(b=this.stackID(f)+" -> ");for(let y of l.recoverByInsert(a))M&&console.log(p+this.stackID(y)+" (via recover-insert)"),this.advanceFully(y,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),M&&console.log(p+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),vt(l,i)):(!s||s.score<l.score)&&(s=l)}return s}stackToTree(e){return e.close(),E.build({buffer:Ke.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(Le||(Le=new WeakMap)).get(e);return t||Le.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}};function vt(r,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==r.pos&&i.sameState(r)){e[t].score<r.score&&(e[t]=r);return}}e.push(r)}var nt=class{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}},Ze=r=>r,Ce=class{constructor(e){this.start=e.start,this.shift=e.shift||Ze,this.reduce=e.reduce||Ze,this.reuse=e.reuse||Ze,this.hash=e.hash||(()=>0),this.strict=e.strict!==!1}},Ue=class r extends ze{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),s=[];for(let l=0;l<t.length;l++)s.push([]);function n(l,a,h){s[l].push([a,a.deserialize(String(h))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=T[a]);for(let h=1;h<l.length;){let p=l[h++];if(p>=0)n(p,a,l[h++]);else{let f=l[h+-p];for(let b=-p;b>0;b--)n(l[h++],a,f);h++}}}this.nodeSet=new Pe(t.map((l,a)=>W.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:s[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=1024;let o=me(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(Tt),this.states=me(e.states,Uint32Array),this.data=me(e.stateData),this.goto=me(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new K(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let s=new st(this,e,t,i);for(let n of this.wrappers)s=n(s,e,t,i);return s}getGoto(e,t,i=!1){let s=this.goto;if(t>=s[0])return-1;for(let n=s[t+1];;){let o=s[n++],l=o&1,a=s[n++];if(l&&i)return a;for(let h=n+(o>>1);n<h;n++)if(s[n]==e)return a;if(l)return-1}}hasAction(e,t){let i=this.data;for(let s=0;s<2;s++)for(let n=this.stateSlot(e,s?2:1),o;;n+=3){if((o=i[n])==65535)if(i[n+1]==1)o=i[n=H(i,n+2)];else{if(i[n+1]==2)return H(i,n+2);break}if(o==t||o==0)return H(i,n+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),s=i?t(i):void 0;for(let n=this.stateSlot(e,1);s==null;n+=3){if(this.data[n]==65535)if(this.data[n+1]==1)n=H(this.data,n+2);else break;s=t(H(this.data,n+1))}return s}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=H(this.data,i+2);else break;if(!(this.data[i+2]&1)){let s=this.data[i+1];t.some((n,o)=>o&1&&n==s)||t.push(this.data[i],s)}}return t}configure(e){let t=Object.assign(Object.create(r.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let s=e.tokenizers.find(n=>n.from==i);return s?s.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,s)=>{let n=e.specializers.find(l=>l.from==i.external);if(!n)return i;let o=Object.assign(Object.assign({},i),{external:n.to});return t.specializers[s]=Tt(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let n of e.split(" ")){let o=t.indexOf(n);o>=0&&(i[o]=!0)}let s=null;for(let n=0;n<t.length;n++)if(!i[n])for(let o=this.dialects[t[n]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new nt(e,i,s)}static deserialize(e){return new r(e)}};function H(r,e){return r[e]|r[e+1]<<16}function Kt(r){let e=null;for(let t of r){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function Tt(r){if(r.external){let e=r.extend?1:0;return(t,i)=>r.external(t,i)<<1|e}return r.get}var ei=0,Z=class r{constructor(e,t,i){this.set=e,this.base=t,this.modified=i,this.id=ei++}static define(e){if(e?.base)throw new Error("Can not derive from a modified tag");let t=new r([],null,[]);if(t.set.push(t),e)for(let i of e.set)t.set.push(i);return t}static defineModifier(){let e=new Ne;return t=>t.modified.indexOf(e)>-1?t:Ne.get(t.base||t,t.modified.concat(e).sort((i,s)=>i.id-s.id))}},ti=0,Ne=class r{constructor(){this.instances=[],this.id=ti++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&ii(t,l.modified));if(i)return i;let s=[],n=new Z(s,e,t);for(let l of t)l.instances.push(n);let o=ri(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(r.get(l,a));return n}};function ii(r,e){return r.length==e.length&&r.every((t,i)=>t==e[i])}function ri(r){let e=[[]];for(let t=0;t<r.length;t++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(r[t]));return e.sort((t,i)=>i.length-t.length)}function Ut(r){let e=Object.create(null);for(let t in r){let i=r[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let n=[],o=2,l=s;for(let f=0;;){if(l=="..."&&f>0&&f+3==s.length){o=1;break}let b=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!b)throw new RangeError("Invalid path: "+s);if(n.push(b[0]=="*"?"":b[0][0]=='"'?JSON.parse(b[0]):b[0]),f+=b[0].length,f==s.length)break;let y=s[f++];if(f==s.length&&y=="!"){o=0;break}if(y!="/")throw new RangeError("Invalid path: "+s);l=s.slice(f)}let a=n.length-1,h=n[a];if(!h)throw new RangeError("Invalid path: "+s);let p=new xe(i,o,a>0?n.slice(0,a):null);e[h]=p.sort(e[h])}}return si.add(e)}var si=new T,xe=class{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}};xe.empty=new xe([],2,null);function ni(r,e){let t=Object.create(null);for(let n of r)if(!Array.isArray(n.tag))t[n.tag.id]=n.class;else for(let o of n.tag)t[o.id]=n.class;let{scope:i,all:s=null}=e||{};return{style:n=>{let o=s;for(let l of n)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}var c=Z.define,Re=c(),ee=c(),$t=c(ee),Ct=c(ee),te=c(),Ae=c(te),ot=c(te),L=c(),se=c(L),j=c(),F=c(),lt=c(),be=c(lt),_e=c(),O={comment:Re,lineComment:c(Re),blockComment:c(Re),docComment:c(Re),name:ee,variableName:c(ee),typeName:$t,tagName:c($t),propertyName:Ct,attributeName:c(Ct),className:c(ee),labelName:c(ee),namespace:c(ee),macroName:c(ee),literal:te,string:Ae,docString:c(Ae),character:c(Ae),attributeValue:c(Ae),number:ot,integer:c(ot),float:c(ot),bool:c(te),regexp:c(te),escape:c(te),color:c(te),url:c(te),keyword:j,self:c(j),null:c(j),atom:c(j),unit:c(j),modifier:c(j),operatorKeyword:c(j),controlKeyword:c(j),definitionKeyword:c(j),moduleKeyword:c(j),operator:F,derefOperator:c(F),arithmeticOperator:c(F),logicOperator:c(F),bitwiseOperator:c(F),compareOperator:c(F),updateOperator:c(F),definitionOperator:c(F),typeOperator:c(F),controlOperator:c(F),punctuation:lt,separator:c(lt),bracket:be,angleBracket:c(be),squareBracket:c(be),paren:c(be),brace:c(be),content:L,heading:se,heading1:c(se),heading2:c(se),heading3:c(se),heading4:c(se),heading5:c(se),heading6:c(se),contentSeparator:c(L),list:c(L),quote:c(L),emphasis:c(L),strong:c(L),link:c(L),monospace:c(L),strikethrough:c(L),inserted:c(),deleted:c(),changed:c(),invalid:c(),meta:_e,documentMeta:c(_e),annotation:c(_e),processingInstruction:c(_e),definition:Z.defineModifier(),constant:Z.defineModifier(),function:Z.defineModifier(),standard:Z.defineModifier(),local:Z.defineModifier(),special:Z.defineModifier()},Ji=ni([{tag:O.link,class:"tok-link"},{tag:O.heading,class:"tok-heading"},{tag:O.emphasis,class:"tok-emphasis"},{tag:O.strong,class:"tok-strong"},{tag:O.keyword,class:"tok-keyword"},{tag:O.atom,class:"tok-atom"},{tag:O.bool,class:"tok-bool"},{tag:O.url,class:"tok-url"},{tag:O.labelName,class:"tok-labelName"},{tag:O.inserted,class:"tok-inserted"},{tag:O.deleted,class:"tok-deleted"},{tag:O.literal,class:"tok-literal"},{tag:O.string,class:"tok-string"},{tag:O.number,class:"tok-number"},{tag:[O.regexp,O.escape,O.special(O.string)],class:"tok-string2"},{tag:O.variableName,class:"tok-variableName"},{tag:O.local(O.variableName),class:"tok-variableName tok-local"},{tag:O.definition(O.variableName),class:"tok-variableName tok-definition"},{tag:O.special(O.variableName),class:"tok-variableName2"},{tag:O.definition(O.propertyName),class:"tok-propertyName tok-definition"},{tag:O.typeName,class:"tok-typeName"},{tag:O.namespace,class:"tok-namespace"},{tag:O.className,class:"tok-className"},{tag:O.macroName,class:"tok-macroName"},{tag:O.propertyName,class:"tok-propertyName"},{tag:O.operator,class:"tok-operator"},{tag:O.comment,class:"tok-comment"},{tag:O.meta,class:"tok-meta"},{tag:O.invalid,class:"tok-invalid"},{tag:O.punctuation,class:"tok-punctuation"}]);import{Annotation as er,StateEffect as tr,EditorSelection as ir,codePointAt as rr,codePointSize as sr,fromCodePoint as nr,Facet as or,combineConfig as lr,StateField as ar,Prec as hr,Text as fr,MapMode as ur,RangeValue as oi,Range