import "./cljs_env.js";
shadow$provide.module$node_modules$$lezer$lr$dist$index_cjs=function(global,require,module,exports){function decodeArray(input,Type=Uint16Array){if("string"!=typeof input)return input;let array=null;for(let pos=0,out=0;pos<input.length;){let value=0;for(;;){var next=input.charCodeAt(pos++);let stop=!1;if(126==next){value=65535;break}92<=next&&next--;34<=next&&next--;next-=32;46<=next&&(next-=46,stop=!0);value+=next;if(stop)break;value*=46}array?array[out++]=value:array=new Type(value)}return array}
function cutAt(tree,pos,side){let cursor=tree.cursor(common.IterMode.IncludeAnonymous);for(cursor.moveTo(pos);;)if(0>side?!cursor.childBefore(pos):!cursor.childAfter(pos))for(;;){if((0>side?cursor.to<pos:cursor.from>pos)&&!cursor.type.isError)return 0>side?Math.max(0,Math.min(cursor.to-1,pos-25)):Math.min(tree.length,Math.max(cursor.from+1,pos+25));if(0>side?cursor.prevSibling():cursor.nextSibling())break;if(!cursor.parent())return 0>side?0:tree.length}}function pushStackDedup(stack,newStacks){for(let i=
0;i<newStacks.length;i++){let other=newStacks[i];if(other.pos==stack.pos&&other.sameState(stack)){newStacks[i].score<stack.score&&(newStacks[i]=stack);return}}newStacks.push(stack)}function pair(data,off){return data[off]|data[off+1]<<16}function findOffset(data,start,term){for(let i=start,next;65535!=(next=data[i]);i++)if(next==term)return i-start;return-1}function findFinished(stacks){let best=null;for(let stack of stacks)stacks=stack.p.stoppedAt,(stack.pos==stack.p.stream.end||null!=stacks&&stack.pos>
stacks)&&stack.p.parser.stateFlag(stack.state,2)&&(!best||best.score<stack.score)&&(best=stack);return best}function getSpecializer(spec){if(spec.external){let mask=spec.extend?1:0;return(value,stack)=>spec.external(value,stack)<<1|mask}return spec.get}global=require("module$node_modules$process$browser");"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var common=require("module$node_modules$$lezer$common$dist$index_cjs");class Stack{constructor(p,stack,state,reducePos,pos,score,
buffer,bufferBase,curContext,lookAhead=0,parent){this.p=p;this.stack=stack;this.state=state;this.reducePos=reducePos;this.pos=pos;this.score=score;this.buffer=buffer;this.bufferBase=bufferBase;this.curContext=curContext;this.lookAhead=lookAhead;this.parent=parent}toString(){return`[${this.stack.filter((_,i)=>0==i%3).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(p,state,pos=0){let cx=p.parser.context;return new Stack(p,[],state,pos,pos,0,[],0,cx?new StackContext(cx,
cx.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(state,start){this.stack.push(this.state,start,this.bufferBase+this.buffer.length);this.state=state}reduce(action){var depth=action>>19;let type=action&65535,{parser}=this.p;var dPrec=parser.dynamicPrecedence(type);dPrec&&(this.score+=dPrec);if(0==depth)this.pushState(parser.getGoto(this.state,type,!0),this.reducePos),type<parser.minRepeatTerm&&this.storeNode(type,this.reducePos,this.reducePos,4,!0),
this.reduceContext(type,this.reducePos);else{depth=this.stack.length-3*(depth-1)-(action&262144?6:0);dPrec=this.stack[depth-2];var count=this.bufferBase+this.buffer.length-this.stack[depth-1];if(type<parser.minRepeatTerm||action&131072){let pos=parser.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(type,dPrec,pos,count+4,!0)}for(this.state=action&262144?this.stack[depth]:parser.getGoto(this.stack[depth-3],type,!0);this.stack.length>depth;)this.stack.pop();this.reduceContext(type,dPrec)}}storeNode(term,
start,end,size=4,isReduce=!1){if(0==term&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let cur=this,top=this.buffer.length;0==top&&cur.parent&&(top=cur.bufferBase-cur.parent.bufferBase,cur=cur.parent);if(0<top&&0==cur.buffer[top-4]&&-1<cur.buffer[top-1]){if(start==end)return;if(cur.buffer[top-2]>=start){cur.buffer[top-2]=end;return}}}if(isReduce&&this.pos!=end){isReduce=this.buffer.length;if(0<isReduce&&0!=this.buffer[isReduce-4])for(;0<isReduce&&this.buffer[isReduce-
2]>end;)this.buffer[isReduce]=this.buffer[isReduce-4],this.buffer[isReduce+1]=this.buffer[isReduce-3],this.buffer[isReduce+2]=this.buffer[isReduce-2],this.buffer[isReduce+3]=this.buffer[isReduce-1],isReduce-=4,4<size&&(size-=4);this.buffer[isReduce]=term;this.buffer[isReduce+1]=start;this.buffer[isReduce+2]=end;this.buffer[isReduce+3]=size}else this.buffer.push(term,start,end,size)}shift(action,next,nextEnd){let start=this.pos;if(action&131072)this.pushState(action&65535,this.pos);else if(0==(action&
262144)){let {parser}=this.p;if(nextEnd>this.pos||next<=parser.maxNode)this.pos=nextEnd,parser.stateFlag(action,1)||(this.reducePos=nextEnd);this.pushState(action,start);this.shiftContext(next,start);next<=parser.maxNode&&this.buffer.push(next,start,nextEnd,4)}else this.pos=nextEnd,this.shiftContext(next,start),next<=this.p.parser.maxNode&&this.buffer.push(next,start,nextEnd,4)}apply(action,next,nextEnd){action&65536?this.reduce(action):this.shift(action,next,nextEnd)}useNode(value,next){let index=
this.p.reused.length-1;if(0>index||this.p.reused[index]!=value)this.p.reused.push(value),index++;let start=this.pos;this.reducePos=this.pos=start+value.length;this.pushState(next,start);this.buffer.push(index,start,this.reducePos,-1);this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,value,this,this.p.stream.reset(this.pos-value.length)))}split(){let parent=this;for(var off=parent.buffer.length;0<off&&parent.buffer[off-2]>parent.reducePos;)off-=4;let buffer=
parent.buffer.slice(off);for(off=parent.bufferBase+off;parent&&off==parent.bufferBase;)parent=parent.parent;return new Stack(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,buffer,off,this.curContext,this.lookAhead,parent)}recoverByDelete(next,nextEnd){let isNode=next<=this.p.parser.maxNode;isNode&&this.storeNode(next,this.pos,nextEnd,4);this.storeNode(0,this.pos,nextEnd,isNode?8:4);this.pos=this.reducePos=nextEnd;this.score-=190}canShift(term){for(let sim=new SimulatedStack(this);;){let action=
this.p.parser.stateSlot(sim.state,4)||this.p.parser.hasAction(sim.state,term);if(0==(action&65536))return!0;if(0==action)return!1;sim.reduce(action)}}recoverByInsert(next){if(300<=this.stack.length)return[];let nextStates=this.p.parser.nextStates(this.state);if(8<nextStates.length||120<=this.stack.length){var best=[];for(let i=0,s;i<nextStates.length;i+=2)(s=nextStates[i+1])!=this.state&&this.p.parser.hasAction(s,next)&&best.push(nextStates[i],s);if(120>this.stack.length)for(next=0;8>best.length&&
next<nextStates.length;next+=2){let s=nextStates[next+1];best.some((v,i)=>i&1&&v==s)||best.push(nextStates[next],s)}nextStates=best}best=[];for(next=0;next<nextStates.length&&4>best.length;next+=2){let s=nextStates[next+1];if(s==this.state)continue;let stack=this.split();stack.pushState(s,this.pos);stack.storeNode(0,stack.pos,stack.pos,4,!0);stack.shiftContext(nextStates[next],this.pos);stack.score-=200;best.push(stack)}return best}forceReduce(){let reduce=this.p.parser.stateSlot(this.state,5);if(0==
(reduce&65536))return!1;let {parser}=this.p;if(!parser.validAction(this.state,reduce)){let target=this.stack.length-3*(reduce>>19);if(0>target||0>parser.getGoto(this.stack[target],reduce&65535,!1))return!1;this.storeNode(0,this.reducePos,this.reducePos,4,!0);this.score-=100}this.reducePos=this.pos;this.reduce(reduce);return!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(3!=this.stack.length)return!1;
let {parser}=this.p;return 65535==parser.data[parser.stateSlot(this.state,1)]&&!parser.stateSlot(this.state,4)}restart(){this.state=this.stack[0];this.stack.length=0}sameState(other){if(this.state!=other.state||this.stack.length!=other.stack.length)return!1;for(let i=0;i<this.stack.length;i+=3)if(this.stack[i]!=other.stack[i])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(dialectID){return this.p.parser.dialect.flags[dialectID]}shiftContext(term,start){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,
term,this,this.p.stream.reset(start)))}reduceContext(term,start){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,term,this,this.p.stream.reset(start)))}emitContext(){let last=this.buffer.length-1;(0>last||-3!=this.buffer[last])&&this.buffer.push(this.curContext.hash,this.reducePos,this.reducePos,-3)}emitLookAhead(){let last=this.buffer.length-1;(0>last||-4!=this.buffer[last])&&this.buffer.push(this.lookAhead,this.reducePos,this.reducePos,-4)}updateContext(context){context!=
this.curContext.context&&(context=new StackContext(this.curContext.tracker,context),context.hash!=this.curContext.hash&&this.emitContext(),this.curContext=context)}setLookAhead(lookAhead){lookAhead>this.lookAhead&&(this.emitLookAhead(),this.lookAhead=lookAhead)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext();0<this.lookAhead&&this.emitLookAhead()}}class StackContext{constructor(tracker,context){this.tracker=tracker;this.context=context;this.hash=tracker.strict?tracker.hash(context):
0}}var Recover$jscomp$0;(function(Recover){Recover[Recover.Insert=200]="Insert";Recover[Recover.Delete=190]="Delete";Recover[Recover.Reduce=100]="Reduce";Recover[Recover.MaxNext=4]="MaxNext";Recover[Recover.MaxInsertStackDepth=300]="MaxInsertStackDepth";Recover[Recover.DampenInsertStackDepth=120]="DampenInsertStackDepth"})(Recover$jscomp$0||(Recover$jscomp$0={}));class SimulatedStack{constructor(start){this.start=start;this.state=start.state;this.stack=start.stack;this.base=this.stack.length}reduce(action){let term=
action&65535;action>>=19;0==action?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0),this.base+=3):this.base-=3*(action-1);this.state=this.start.p.parser.getGoto(this.stack[this.base-3],term,!0)}}class StackBufferCursor{constructor(stack,pos,index){this.stack=stack;this.pos=pos;this.index=index;this.buffer=stack.buffer;0==this.index&&this.maybeNext()}static create(stack,pos=stack.bufferBase+stack.buffer.length){return new StackBufferCursor(stack,pos,pos-
stack.bufferBase)}maybeNext(){let next=this.stack.parent;null!=next&&(this.index=this.stack.bufferBase-next.bufferBase,this.stack=next,this.buffer=next.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;0==this.index&&this.maybeNext()}fork(){return new StackBufferCursor(this.stack,this.pos,this.index)}}class CachedToken{constructor(){this.extended=
this.end=this.value=this.start=-1;this.context=this.mask=this.lookAhead=0}}const nullToken=new CachedToken;class InputStream{constructor(input,ranges){this.input=input;this.ranges=ranges;this.chunk="";this.chunkOff=0;this.chunk2="";this.chunk2Pos=0;this.next=-1;this.token=nullToken;this.rangeIndex=0;this.pos=this.chunkPos=ranges[0].from;this.range=ranges[0];this.end=ranges[ranges.length-1].to;this.readNext()}resolveOffset(offset,assoc){let range=this.range,index=this.rangeIndex;for(offset=this.pos+
offset;offset<range.from;){if(!index)return null;var next=this.ranges[--index];offset-=range.from-next.to;range=next}for(;0>assoc?offset>range.to:offset>=range.to;){if(index==this.ranges.length-1)return null;next=this.ranges[++index];offset+=next.from-range.to;range=next}return offset}clipPos(pos){if(pos>=this.range.from&&pos<this.range.to)return pos;for(let range of this.ranges)if(range.to>pos)return Math.max(pos,range.from);return this.end}peek(offset){var idx=this.chunkOff+offset;if(0<=idx&&idx<
this.chunk.length)offset=this.pos+offset,idx=this.chunk.charCodeAt(idx);else{offset=this.resolveOffset(offset,1);if(null==offset)return-1;if(offset>=this.chunk2Pos&&offset<this.chunk2Pos+this.chunk2.length)idx=this.chunk2.charCodeAt(offset-this.chunk2Pos);else{idx=this.rangeIndex;let range=this.range;for(;range.to<=offset;)range=this.ranges[++idx];this.chunk2=this.input.chunk(this.chunk2Pos=offset);offset+this.chunk2.length>range.to&&(this.chunk2=this.chunk2.slice(0,range.to-offset));idx=this.chunk2.charCodeAt(0)}}offset>=
this.token.lookAhead&&(this.token.lookAhead=offset+1);return idx}acceptToken(token,endOffset=0){endOffset=endOffset?this.resolveOffset(endOffset,-1):this.pos;if(null==endOffset||endOffset<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=token;this.token.end=endOffset}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let {chunk,chunkPos}=this;this.chunk=this.chunk2;this.chunkPos=this.chunk2Pos;this.chunk2=chunk;this.chunk2Pos=chunkPos;
this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk;this.chunk2Pos=this.chunkPos;let nextChunk=this.input.chunk(this.pos);this.chunk=this.pos+nextChunk.length>this.range.to?nextChunk.slice(0,this.range.to-this.pos):nextChunk;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(n=1){for(this.chunkOff+=n;this.pos+n>=this.range.to;){if(this.rangeIndex==
this.ranges.length-1)return this.setDone();n-=this.range.to-this.pos;this.range=this.ranges[++this.rangeIndex];this.pos=this.range.from}this.pos+=n;this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1);return this.readNext()}setDone(){this.pos=this.chunkPos=this.end;this.range=this.ranges[this.rangeIndex=this.ranges.length-1];this.chunk="";return this.next=-1}reset(pos,token){token?(this.token=token,token.start=pos,token.lookAhead=pos+1,token.value=token.extended=-1):this.token=nullToken;
if(this.pos!=pos){this.pos=pos;if(pos==this.end)return this.setDone(),this;for(;pos<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;pos>=this.range.to;)this.range=this.ranges[++this.rangeIndex];pos>=this.chunkPos&&pos<this.chunkPos+this.chunk.length?this.chunkOff=pos-this.chunkPos:(this.chunk="",this.chunkOff=0);this.readNext()}return this}read(from,to){if(from>=this.chunkPos&&to<=this.chunkPos+this.chunk.length)return this.chunk.slice(from-this.chunkPos,to-this.chunkPos);if(from>=
this.chunk2Pos&&to<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(from-this.chunk2Pos,to-this.chunk2Pos);if(from>=this.range.from&&to<=this.range.to)return this.input.read(from,to);let result="";for(let r of this.ranges){if(r.from>=to)break;r.to>from&&(result+=this.input.read(Math.max(r.from,from),Math.min(r.to,to)))}return result}}class TokenGroup{constructor(data,id){this.data=data;this.id=id}token(input,stack){var data=this.data,state=0;let groupMask=1<<this.id;({parser:stack}=stack.p);
let {dialect}=stack;a:for(;0!=(groupMask&data[state]);){let accEnd=data[state+1];for(var i=state+3;i<accEnd;i+=2)if(0<(data[i+1]&groupMask)){var term=data[i];if(dialect.allows(term)&&(-1==input.token.value||input.token.value==term||stack.overrides(term,input.token.value))){input.acceptToken(term);break}}i=input.next;term=0;state=data[state+2];if(0>input.next&&state>term&&65535==data[accEnd+3*state-3]){state=data[accEnd+3*state-1];continue a}for(;term<state;){let mid=term+state>>1,index=accEnd+mid+
(mid<<1),to=data[index+1];if(i<data[index])state=mid;else if(i>=to)term=mid+1;else{state=data[index+2];input.advance();continue a}}break}}}TokenGroup.prototype.contextual=TokenGroup.prototype.fallback=TokenGroup.prototype.extend=!1;class ExternalTokenizer{constructor(token,options={}){this.token=token;this.contextual=!!options.contextual;this.fallback=!!options.fallback;this.extend=!!options.extend}}const verbose="undefined"!=typeof global&&global.env&&/\bparse\b/.test(global.env.LOG);let stackIDs=
null;var Safety;(function(Safety){Safety[Safety.Margin=25]="Margin"})(Safety||(Safety={}));class FragmentCursor{constructor(fragments,nodeSet){this.fragments=fragments;this.nodeSet=nodeSet;this.i=0;this.fragment=null;this.safeTo=this.safeFrom=-1;this.trees=[];this.start=[];this.index=[];this.nextFragment()}nextFragment(){let fr=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(fr){this.safeFrom=fr.openStart?cutAt(fr.tree,fr.from+fr.offset,1)-fr.offset:fr.from;for(this.safeTo=
fr.openEnd?cutAt(fr.tree,fr.to+fr.offset,-1)-fr.offset:fr.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(fr.tree);this.start.push(-fr.offset);this.index.push(0);this.nextStart=this.safeFrom}else this.nextStart=1E9}nodeAt(pos){if(pos<this.nextStart)return null;for(;this.fragment&&this.safeTo<=pos;)this.nextFragment();if(!this.fragment)return null;for(;;){let last=this.trees.length-1;if(0>last)return this.nextFragment(),null;var top=this.trees[last],index=this.index[last];
if(index==top.children.length){this.trees.pop();this.start.pop();this.index.pop();continue}let next=top.children[index];top=this.start[last]+top.positions[index];if(top>pos)return this.nextStart=top,null;if(next instanceof common.Tree){if(top==pos){if(top<this.safeFrom)return null;index=top+next.length;if(index<=this.safeTo){let lookAhead=next.prop(common.NodeProp.lookAhead);if(!lookAhead||index+lookAhead<this.fragment.to)return next}}this.index[last]++;top+next.length>=Math.max(this.safeFrom,pos)&&
(this.trees.push(next),this.start.push(top),this.index.push(0))}else this.index[last]++,this.nextStart=top+next.length}}}class TokenCache{constructor(parser,stream){this.stream=stream;this.tokens=[];this.mainToken=null;this.actions=[];this.tokens=parser.tokenizers.map(_=>new CachedToken)}getActions(stack){let actionIndex=0,main=null;var {parser}=stack.p;let {tokenizers}=parser;parser=parser.stateSlot(stack.state,3);let context=stack.curContext?stack.curContext.hash:0,lookAhead=0;for(let i=0;i<tokenizers.length;i++){if(0==
(1<<i&parser))continue;let tokenizer=tokenizers[i],token=this.tokens[i];if(!main||tokenizer.fallback){if(tokenizer.contextual||token.start!=stack.pos||token.mask!=parser||token.context!=context)this.updateCachedToken(token,tokenizer,stack),token.mask=parser,token.context=context;token.lookAhead>token.end+25&&(lookAhead=Math.max(token.lookAhead,lookAhead));if(0!=token.value){let startIndex=actionIndex;-1<token.extended&&(actionIndex=this.addActions(stack,token.extended,token.end,actionIndex));actionIndex=
this.addActions(stack,token.value,token.end,actionIndex);if(!tokenizer.extend&&(main=token,actionIndex>startIndex))break}}}for(;this.actions.length>actionIndex;)this.actions.pop();lookAhead&&stack.setLookAhead(lookAhead);main||stack.pos!=this.stream.end||(main=new CachedToken,main.value=stack.p.parser.eofTerm,main.start=main.end=stack.pos,this.addActions(stack,main.value,main.end,actionIndex));this.mainToken=main;return this.actions}getMainToken(stack){if(this.mainToken)return this.mainToken;let main=
new CachedToken,{pos,p}=stack;main.start=pos;main.end=Math.min(pos+1,p.stream.end);main.value=pos==p.stream.end?p.parser.eofTerm:0;return main}updateCachedToken(token,tokenizer,stack){var start=this.stream.clipPos(stack.pos);tokenizer.token(this.stream.reset(start,token),stack);if(-1<token.value)for({parser:tokenizer}=stack.p,start=0;start<tokenizer.specialized.length;start++){if(tokenizer.specialized[start]==token.value){let result=tokenizer.specializers[start](this.stream.read(token.start,token.end),
stack);if(0<=result&&stack.p.parser.dialect.allows(result>>1)){0==(result&1)?token.value=result>>1:token.extended=result>>1;break}}}else token.value=0,token.end=this.stream.clipPos(start+1)}putAction(action,token,end,index){for(let i=0;i<index;i+=3)if(this.actions[i]==action)return index;this.actions[index++]=action;this.actions[index++]=token;this.actions[index++]=end;return index}addActions(stack,token,end,index){let {state}=stack;({parser:stack}=stack.p);let {data}=stack;for(let set=0;2>set;set++)for(let i=
stack.stateSlot(state,set?2:1);;i+=3){if(65535==data[i])if(1==data[i+1])i=pair(data,i+2);else{0==index&&2==data[i+1]&&(index=this.putAction(pair(data,i+2),token,end,index));break}data[i]==token&&(index=this.putAction(pair(data,i+1),token,end,index))}return index}}var Rec$jscomp$0;(function(Rec){Rec[Rec.Distance=5]="Distance";Rec[Rec.MaxRemainingPerStep=3]="MaxRemainingPerStep";Rec[Rec.MinBufferLengthPrune=500]="MinBufferLengthPrune";Rec[Rec.ForceReduceLimit=10]="ForceReduceLimit";Rec[Rec.CutDepth=
15E3]="CutDepth";Rec[Rec.CutTo=9E3]="CutTo"})(Rec$jscomp$0||(Rec$jscomp$0={}));class Parse{constructor(parser,input,fragments,ranges){this.parser=parser;this.input=input;this.ranges=ranges;this.recovering=0;this.nextStackID=9812;this.minStackPos=0;this.reused=[];this.stoppedAt=null;this.stream=new InputStream(input,ranges);this.tokens=new TokenCache(parser,this.stream);this.topTerm=parser.top[1];({from:input}=ranges[0]);this.stacks=[Stack.start(this,parser.top[0],input)];this.fragments=fragments.length&&
this.stream.end-input>4*parser.bufferLength?new FragmentCursor(fragments,parser.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){var stacks=this.stacks;let pos=this.minStackPos,newStacks=this.stacks=[];for(var i=0;i<stacks.length;i++)for(var stack=stacks[i];;){this.tokens.mainToken=null;if(stack.pos>pos)newStacks.push(stack);else if(this.advanceStack(stack,newStacks,stacks))continue;else{if(!stopped){var stopped=[];var stoppedTokens=[]}stopped.push(stack);stack=this.tokens.getMainToken(stack);
stoppedTokens.push(stack.value,stack.end)}break}if(!newStacks.length){if(stacks=stopped&&findFinished(stopped))return this.stackToTree(stacks);if(this.parser.strict)throw verbose&&stopped&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+pos);this.recovering||(this.recovering=5)}if(this.recovering&&stopped&&(stopped=null!=this.stoppedAt&&stopped[0].pos>this.stoppedAt?stopped[0]:this.runRecovery(stopped,
stoppedTokens,newStacks)))return this.stackToTree(stopped.forceAll());if(this.recovering){stopped=1==this.recovering?1:3*this.recovering;if(newStacks.length>stopped)for(newStacks.sort((a,b)=>b.score-a.score);newStacks.length>stopped;)newStacks.pop();newStacks.some(s=>s.reducePos>pos)&&this.recovering--}else if(1<newStacks.length)a:for(stopped=0;stopped<newStacks.length-1;stopped++)for(stoppedTokens=newStacks[stopped],stacks=stopped+1;stacks<newStacks.length;stacks++)if(i=newStacks[stacks],stoppedTokens.sameState(i)||
500<stoppedTokens.buffer.length&&500<i.buffer.length)if(0<(stoppedTokens.score-i.score||stoppedTokens.buffer.length-i.buffer.length))newStacks.splice(stacks--,1);else{newStacks.splice(stopped--,1);continue a}this.minStackPos=newStacks[0].pos;for(stopped=1;stopped<newStacks.length;stopped++)newStacks[stopped].pos<this.minStackPos&&(this.minStackPos=newStacks[stopped].pos);return null}stopAt(pos){if(null!=this.stoppedAt&&this.stoppedAt<pos)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=
pos}advanceStack(stack,stacks,split){let start=stack.pos,{parser}=this,base=verbose?this.stackID(stack)+" -\x3e ":"";if(null!=this.stoppedAt&&start>this.stoppedAt)return stack.forceReduce()?stack:null;if(this.fragments){var strictCx=stack.curContext&&stack.curContext.tracker.strict,cxHash=strictCx?stack.curContext.hash:0;for(var cached=this.fragments.nodeAt(start);cached;){var match=this.parser.nodeSet.types[cached.type.id]==cached.type?parser.getGoto(stack.state,cached.type.id):-1;if(-1<match&&cached.length&&
(!strictCx||(cached.prop(common.NodeProp.contextHash)||0)==cxHash))return stack.useNode(cached,match),verbose&&console.log(base+this.stackID(stack)+` (via reuse of ${parser.getName(cached.type.id)})`),!0;if(!(cached instanceof common.Tree)||0==cached.children.length||0<cached.positions[0])break;match=cached.children[0];if(match instanceof common.Tree&&0==cached.positions[0])cached=match;else break}}strictCx=parser.stateSlot(stack.state,4);if(0<strictCx)return stack.reduce(strictCx),verbose&&console.log(base+
this.stackID(stack)+` (via always-reduce ${parser.getName(strictCx&65535)})`),!0;if(15E3<=stack.stack.length)for(;9E3<stack.stack.length&&stack.forceReduce(););strictCx=this.tokens.getActions(stack);for(cxHash=0;cxHash<strictCx.length;){cached=strictCx[cxHash++];match=strictCx[cxHash++];let end=strictCx[cxHash++],last=cxHash==strictCx.length||!split,localStack=last?stack:stack.split();localStack.apply(cached,match,end);verbose&&console.log(base+this.stackID(localStack)+` (via ${0==(cached&65536)?
"shift":`reduce of ${parser.getName(cached&65535)}`} for ${parser.getName(match)} @ ${start}${localStack==stack?"":", split"})`);if(last)return!0;localStack.pos>start?stacks.push(localStack):split.push(localStack)}return!1}advanceFully(stack,newStacks){let pos=stack.pos;for(;;){if(!this.advanceStack(stack,null,null))return!1;if(stack.pos>pos)return pushStackDedup(stack,newStacks),!0}}runRecovery(stacks,tokens,newStacks){let finished=null,restarted=!1;for(let i=0;i<stacks.length;i++){let stack=stacks[i],
token=tokens[i<<1],tokenEnd=tokens[(i<<1)+1],base=verbose?this.stackID(stack)+" -\x3e ":"";if(stack.deadEnd){if(restarted)continue;restarted=!0;stack.restart();verbose&&console.log(base+this.stackID(stack)+" (restarted)");if(this.advanceFully(stack,newStacks))continue}let force=stack.split(),forceBase=base;for(let j=0;force.forceReduce()&&10>j;j++){verbose&&console.log(forceBase+this.stackID(force)+" (via force-reduce)");if(this.advanceFully(force,newStacks))break;verbose&&(forceBase=this.stackID(force)+
" -\x3e ")}for(let insert of stack.recoverByInsert(token))verbose&&console.log(base+this.stackID(insert)+" (via recover-insert)"),this.advanceFully(insert,newStacks);if(this.stream.end>stack.pos)tokenEnd==stack.pos&&(tokenEnd++,token=0),stack.recoverByDelete(token,tokenEnd),verbose&&console.log(base+this.stackID(stack)+` (via recover-delete ${this.parser.getName(token)})`),pushStackDedup(stack,newStacks);else if(!finished||finished.score<stack.score)finished=stack}return finished}stackToTree(stack){stack.close();
return common.Tree.build({buffer:StackBufferCursor.create(stack),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:stack.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(stack){let id=(stackIDs||(stackIDs=new WeakMap)).get(stack);id||stackIDs.set(stack,id=String.fromCodePoint(this.nextStackID++));return id+stack}}class Dialect{constructor(source,flags,disabled){this.source=source;this.flags=
flags;this.disabled=disabled}allows(term){return!this.disabled||0==this.disabled[term]}}const id$jscomp$1=x=>x;class ContextTracker{constructor(spec){this.start=spec.start;this.shift=spec.shift||id$jscomp$1;this.reduce=spec.reduce||id$jscomp$1;this.reuse=spec.reuse||id$jscomp$1;this.hash=spec.hash||(()=>0);this.strict=!1!==spec.strict}}class LRParser extends common.Parser{constructor(spec){function setProp(nodeID,prop,value){nodeProps[nodeID].push([prop,prop.deserialize(String(value))])}super();this.wrappers=
[];if(14!=spec.version)throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);var nodeNames=spec.nodeNames.split(" ");this.minRepeatTerm=nodeNames.length;for(var i$jscomp$0=0;i$jscomp$0<spec.repeatNodeCount;i$jscomp$0++)nodeNames.push("");let topTerms=Object.keys(spec.topRules).map(r=>spec.topRules[r][1]),nodeProps=[];for(i$jscomp$0=0;i$jscomp$0<nodeNames.length;i$jscomp$0++)nodeProps.push([]);if(spec.nodeProps)for(let propSpec of spec.nodeProps){i$jscomp$0=
propSpec[0];"string"==typeof i$jscomp$0&&(i$jscomp$0=common.NodeProp[i$jscomp$0]);for(let i=1;i<propSpec.length;){var next=propSpec[i++];if(0<=next)setProp(next,i$jscomp$0,propSpec[i++]);else{let value=propSpec[i+-next];for(next=-next;0<next;next--)setProp(propSpec[i++],i$jscomp$0,value);i++}}}this.nodeSet=new common.NodeSet(nodeNames.map((name,i)=>common.NodeType.define({name:i>=this.minRepeatTerm?void 0:name,id:i,props:nodeProps[i],top:-1<topTerms.indexOf(i),error:0==i,skipped:spec.skippedNodes&&
-1<spec.skippedNodes.indexOf(i)})));spec.propSources&&(this.nodeSet=this.nodeSet.extend(...spec.propSources));this.strict=!1;this.bufferLength=common.DefaultBufferLength;let tokenArray=decodeArray(spec.tokenData);this.context=spec.context;this.specializerSpecs=spec.specialized||[];this.specialized=new Uint16Array(this.specializerSpecs.length);for(nodeNames=0;nodeNames<this.specializerSpecs.length;nodeNames++)this.specialized[nodeNames]=this.specializerSpecs[nodeNames].term;this.specializers=this.specializerSpecs.map(getSpecializer);
this.states=decodeArray(spec.states,Uint32Array);this.data=decodeArray(spec.stateData);this.goto=decodeArray(spec.goto);this.maxTerm=spec.maxTerm;this.tokenizers=spec.tokenizers.map(value=>"number"==typeof value?new TokenGroup(tokenArray,value):value);this.topRules=spec.topRules;this.dialects=spec.dialects||{};this.dynamicPrecedences=spec.dynamicPrecedences||null;this.tokenPrecTable=spec.tokenPrec;this.termNames=spec.termNames||null;this.maxNode=this.nodeSet.types.length-1;this.dialect=this.parseDialect();
this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(input,fragments,ranges){let parse=new Parse(this,input,fragments,ranges);for(let w of this.wrappers)parse=w(parse,input,fragments,ranges);return parse}getGoto(state,term,loose=!1){let table=this.goto;if(term>=table[0])return-1;for(term=table[term+1];;){var groupTag=table[term++];let last=groupTag&1,target=table[term++];if(last&&loose)return target;for(groupTag=term+(groupTag>>1);term<groupTag;term++)if(table[term]==state)return target;
if(last)return-1}}hasAction(state,terminal){let data=this.data;for(let set=0;2>set;set++)for(let i=this.stateSlot(state,set?2:1),next;;i+=3){if(65535==(next=data[i]))if(1==data[i+1])next=data[i=pair(data,i+2)];else{if(2==data[i+1])return pair(data,i+2);break}if(next==terminal||0==next)return pair(data,i+1)}return 0}stateSlot(state,slot){return this.states[6*state+slot]}stateFlag(state,flag){return 0<(this.stateSlot(state,0)&flag)}validAction(state,action){if(action==this.stateSlot(state,4))return!0;
for(state=this.stateSlot(state,1);;state+=3){if(65535==this.data[state])if(1==this.data[state+1])state=pair(this.data,state+2);else return!1;if(action==pair(this.data,state+1))return!0}}nextStates(state){let result=[];for(state=this.stateSlot(state,1);;state+=3){if(65535==this.data[state])if(1==this.data[state+1])state=pair(this.data,state+2);else break;if(0==(this.data[state+2]&1)){let value=this.data[state+1];result.some((v,i)=>i&1&&v==value)||result.push(this.data[state],value)}}return result}overrides(token,
prev){prev=findOffset(this.data,this.tokenPrecTable,prev);return 0>prev||findOffset(this.data,this.tokenPrecTable,token)<prev}configure(config){let copy=Object.assign(Object.create(LRParser.prototype),this);config.props&&(copy.nodeSet=this.nodeSet.extend(...config.props));if(config.top){let info=this.topRules[config.top];if(!info)throw new RangeError(`Invalid top rule name ${config.top}`);copy.top=info}config.tokenizers&&(copy.tokenizers=this.tokenizers.map(t=>{let found=config.tokenizers.find(r=>
r.from==t);return found?found.to:t}));config.specializers&&(copy.specializers=this.specializers.slice(),copy.specializerSpecs=this.specializerSpecs.map((s,i)=>{var found=config.specializers.find(r=>r.from==s.external);if(!found)return s;found=Object.assign(Object.assign({},s),{external:found.to});copy.specializers[i]=getSpecializer(found);return found}));config.contextTracker&&(copy.context=config.contextTracker);config.dialect&&(copy.dialect=this.parseDialect(config.dialect));null!=config.strict&&
(copy.strict=config.strict);config.wrap&&(copy.wrappers=copy.wrappers.concat(config.wrap));null!=config.bufferLength&&(copy.bufferLength=config.bufferLength);return copy}hasWrappers(){return 0<this.wrappers.length}getName(term){return this.termNames?this.termNames[term]:String(term<=this.maxNode&&this.nodeSet.types[term].name||term)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(term){let prec=this.dynamicPrecedences;return null==prec?0:
prec[term]||0}parseDialect(dialect){let values=Object.keys(this.dialects),flags=values.map(()=>!1);if(dialect)for(var part of dialect.split(" ")){var id$jscomp$0=values.indexOf(part);0<=id$jscomp$0&&(flags[id$jscomp$0]=!0)}part=null;for(id$jscomp$0=0;id$jscomp$0<values.length;id$jscomp$0++)if(!flags[id$jscomp$0])for(let j=this.dialects[values[id$jscomp$0]],id;65535!=(id=this.data[j++]);)(part||(part=new Uint8Array(this.maxTerm+1)))[id]=1;return new Dialect(dialect,flags,part)}static deserialize(spec){return new LRParser(spec)}}
exports.ContextTracker=ContextTracker;exports.ExternalTokenizer=ExternalTokenizer;exports.InputStream=InputStream;exports.LRParser=LRParser;exports.Stack=Stack}
//# sourceMappingURL=module$node_modules$$lezer$lr$dist$index_cjs.js.map
