"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e,r=require("lezer");function s(t,e,r,s){if("a"===r&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!s:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?s:"a"===r?s.call(t):s?s.value:e.get(t)}function c(t,e,r,s,c){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!c)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!c:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?c.call(t,r):c?c.value=r:e.set(t,r),r}function i(t){return t>96&&t<103||t>47&&t<58}"function"==typeof SuppressedError&&SuppressedError;class a{}class h extends r.ExternalTokenizer{constructor(){super(((e,r,c)=>{if(r.start>=e.length)return;let i=0;return c.dialectEnabled(Term.Dialect_tex)&&(i|=1),c.dialectEnabled(Term.Dialect_etex)&&(i|=2),c.dialectEnabled(Term.Dialect_pdftex)&&(i|=4),c.dialectEnabled(Term.Dialect_xetex)&&(i|=8),c.dialectEnabled(Term.Dialect_latex)&&(i|=16),c.dialectEnabled(Term.Dialect_directives)&&(i|=1024),s(this,t,"f").buf=e,s(this,t,"f").loc=r.start,s(this,t,"f").chr=e.get(s(this,t,"f").loc++),s(this,t,"f").tok=r,s(this,t,"f").stk=c,s(this,t,"f").ctx=c.context,s(this,t,"f").dct=i,this.getNext()}),{contextual:!0}),t.set(this,new a),e.set(this,2),this.nextIsDirective=()=>!0,this.nextIsMathShift=()=>3===s(this,t,"f").ctx.catcode(s(this,t,"f").buf.get(s(this,t,"f").loc))}getNext(){switch(s(this,t,"f").cmd=s(this,t,"f").ctx.catcode(s(this,t,"f").chr),s(this,t,"f").cmd){case 1:s(this,t,"f").tok.accept(1,s(this,t,"f").loc);break;case 2:s(this,t,"f").tok.accept(2,s(this,t,"f").loc);break;case 4:s(this,t,"f").tok.accept(3,s(this,t,"f").loc);break;case 5:s(this,t,"f").tok.accept(4,s(this,t,"f").loc);break;case 8:s(this,t,"f").tok.accept(6,s(this,t,"f").loc);break;case 9:s(this,t,"f").tok.accept(7,s(this,t,"f").loc);break;case 10:s(this,t,"f").tok.accept(29,s(this,t,"f").loc);break;case 11:s(this,t,"f").tok.accept(30,s(this,t,"f").loc);break;case 13:s(this,t,"f").tok.accept(8,s(this,t,"f").loc);break;case 12:s(this,t,"f").tok.accept(31,s(this,t,"f").loc);break;case 6:s(this,t,"f").tok.accept(28,s(this,t,"f").loc);break;case 15:s(this,t,"f").tok.accept(9,s(this,t,"f").loc);break;case 3:if(this.nextIsMathShift()){s(this,t,"f").loc+=1,s(this,t,"f").tok.accept(4===s(this,t,"f").ctx.groupType?14:13,s(this,t,"f").loc);break}s(this,t,"f").tok.accept(3===s(this,t,"f").ctx.groupType?12:11,s(this,t,"f").loc);break;case 0:this.scanControlSequence(),s(this,t,"f").tok.accept(s(this,t,"f").ctx.command(s(this,t,"f").cs),s(this,t,"f").loc);break;case 14:if((1024&s(this,t,"f").dct)>0&&this.nextIsDirective()){this.scanComment(),s(this,t,"f").tok.accept(32,s(this,t,"f").loc);break}this.scanComment(),s(this,t,"f").tok.accept(10,s(this,t,"f").loc);break;case 7:if(this.nextIsExpandedCharacter()){this.scanExpandedCharacter(),s(this,t,"f").loc+=s(this,e,"f"),this.getNext();break}s(this,t,"f").tok.accept(5,s(this,t,"f").loc);break;default:throw new Error("Unknown character")}}scanControlSequence(){if(s(this,t,"f").loc>=s(this,t,"f").buf.length)return;s(this,t,"f").chr=s(this,t,"f").buf.get(s(this,t,"f").loc++),s(this,t,"f").cmd=s(this,t,"f").ctx.catcode(s(this,t,"f").chr);const r=[s(this,t,"f").chr];if(7===s(this,t,"f").cmd&&this.nextIsExpandedCharacter()&&(this.scanExpandedCharacter(),s(this,t,"f").loc+=s(this,e,"f"),s(this,t,"f").cmd=s(this,t,"f").ctx.catcode(s(this,t,"f").chr),r[0]=s(this,t,"f").chr),11===s(this,t,"f").cmd){do{s(this,t,"f").chr=s(this,t,"f").buf.get(s(this,t,"f").loc++),s(this,t,"f").cmd=s(this,t,"f").ctx.catcode(s(this,t,"f").chr),r.push(s(this,t,"f").chr),7===s(this,t,"f").cmd&&this.nextIsExpandedCharacter()&&(this.scanExpandedCharacter(),s(this,t,"f").cmd=s(this,t,"f").ctx.catcode(s(this,t,"f").chr),11===s(this,t,"f").cmd&&(r.push(s(this,t,"f").chr),s(this,t,"f").loc+=s(this,e,"f")))}while(11===s(this,t,"f").cmd);s(this,t,"f").loc-=1,r.pop(),s(this,t,"f").cs=String.fromCodePoint(...r)}else s(this,t,"f").cs=String.fromCodePoint(...r)}scanExpandedCharacter(){if(c(this,e,2,"f"),s(this,t,"f").chr=s(this,t,"f").buf.get(s(this,t,"f").loc+1),i(s(this,t,"f").chr)){const r=s(this,t,"f").buf.get(s(this,t,"f").loc+2);if(i(r))return c(this,e,s(this,e,"f")+1,"f"),void(s(this,t,"f").chr=parseInt(`0x${String.fromCharCode(s(this,t,"f").chr,r)}`,16))}s(this,t,"f").chr=s(this,t,"f").chr<64?s(this,t,"f").chr+64:s(this,t,"f").chr-64}scanComment(){do{s(this,t,"f").chr=s(this,t,"f").buf.get(s(this,t,"f").loc++)}while(s(this,t,"f").chr>-1&&5!==s(this,t,"f").ctx.catcode(s(this,t,"f").chr))}nextIsExpandedCharacter(){if(7!==s(this,t,"f").ctx.catcode(s(this,t,"f").buf.get(s(this,t,"f").loc)))return!1;const e=s(this,t,"f").buf.get(s(this,t,"f").loc+1);return e>0&&e<128}}t=new WeakMap,e=new WeakMap;class o{static deserialize(t){const e=new o(null),[r,s]=JSON.parse(t.replaceAll("",',"').replaceAll("",",{").replaceAll("","}]").replaceAll("",'":[').replaceAll("\0",',{"'));return e.value=r,Object.entries(s).forEach((([t,r])=>{e.children[t]=o.deserialize(JSON.stringify(r))})),e}static serialize(t){return`[${JSON.stringify(t.value)},{${Object.entries(t.children).reduce(((t,[e,r])=>r?`${t}"${e}":${o.serialize(r)},`:t),"").slice(0,-1)}}]`.replaceAll(',{"',"\0").replaceAll('":[',"").replaceAll("}]","").replaceAll(",{","").replaceAll(',"',"")}constructor(t){this.value=t,this.children={}}insert(t,e){let r=this;for(let e=t.length-1;e>-1;e--)void 0===r.children[t[e]]&&(r.children[t[e]]=new o(r.value)),r=r.children[t[e]];r.value=e}lookup(t){let e=this;for(let r=t.length-1;r>-1;r--)if(e=e.children[t[r]],void 0===e)return;return e.value}clone(){const t=new o(this.value);return Object.entries(this.children).forEach((([e,r])=>{t.children[e]=r.clone()})),t}}const n=[];class l{static clone(t){const e=new l(t.groupType,t.depth,t.parent);return Object.assign(e.eqtb.catcode,t.eqtb.catcode),e.eqtb.commands=t.eqtb.commands.clone(),e}constructor(t,e=0,r=null){this.groupType=t,this.depth=e,this.parent=r,this.eqtb={catcode:[],commands:new o([-1,0])}}get hash(){var t;let e,r;return this.depth in n||([e,r]=null!==(t=n[this.depth-1])&&void 0!==t?t:[1,1],n[this.depth]=[5*e,8191*r]),[e,r]=n[this.depth],((this.parent?this.parent.hash:0)+this.groupType*e+this.hashEQTB()*r)%(Math.pow(2,19)-1)}hashEQTB(){var t;let e,r=17,s=0;for(let c=0;c>>4*t)*r,s%=8191}return s}catcode(t,e){switch(!0){case t>=262144&&t<917504:throw new RangeError("Unicode point is valid, but unassigned");case t>1114111:throw new RangeError("Unicode point is invalid");case t<0:return-1;case t>917503:t-=655360}const r=Math.floor(t/8),s=t%8*4;let c=this.eqtb.catcode[r];for(let t=this.parent;null!==t&&void 0===c;t=t.parent)c=t.eqtb.catcode[r];if(void 0===e)return void 0===c?12:(c&15<>>s;const i=l.clone(this);return i.eqtb.catcode[r]=((null!=c?c:3435973836)&~(15<>>0)+(e<>>0)+(e<t.catcode(e,r)}),O=Object.freeze({__proto__:null,catcodeDirective:u});class m extends r.ContextTracker{constructor(){super({start:new f,hash:t=>t.hash,shift:(t,e,r,s)=>this.handleTerm(t,e,r,s),reduce:(t,e,r,s)=>this.handleTerm(t,e,r,s)})}handleTerm(t,e,r,s){var c;switch(e){case 1:return new l(1,t.depth+1,t);case 18:return new l(2,t.depth+1,t);case 11:return new l(3,t.depth+1,t);case 13:return new l(4,t.depth+1,t);case 2:case 19:case 12:case 14:return null!==(c=t.parent)&&void 0!==c?c:t;case 24:{const e=r.read(s.ruleStart+2,s.pos).trim();for(const r of Object.values(O)){const s=r.exec(e,t);if(null!==s&&(t=s,!r.fallthrough))break}break}}return t}}const Q=new m,g=new h,b={__proto__:null,0:85,1:85,2:85,3:85,4:85,5:85,6:85,7:85,8:85,9:87},_=r.Parser.deserialize({version:13,states:"SWOVQQOOOPaQQOUQrlOOQQUQrnUQrnOPhQQOUQrmOPoQQOUQsTOPvQQOUQsUOOQQUQrpUQrpOOQQUQrqUQrqOOQQUQrrUQrrOP}QROUQrsOOQQUQrtUQrtOOQQUQsSUQsSOOQQUQruUQruQVQQOOOOQQZdhWZdhWOQVQQOZdhWOOQQUQroUQroOOQQZdhXZdhXOPhQQOZdhXOOQQZdhoZdhoOQ^QQOZdhoOOQQZdhpZdhpOQeQQOZdhpOOQQUQsVUQsVOOQQUQrvUQrvOQlQROZdh_OOQQ[tes[tesOOQQ`v]r`v]rOOQQ`v]s`v]sOOQQ`v^Z`v^ZOOQQ`v^[`v^[OOQQ[tet[tet",stateData:"S_~OYOS~OPPORZOSZOTZOUZOVZOWZOXZOZSO]TOlXOmZOnZOoZOpYOqVOrWOsQO~OQ^O~PVOt`O~PVO[cO~PVO^eO~PVOzgO{gO~OQkO~PVO[mO~PVO^nO~PVOzgO{gOPgaRgaSgaTgaUgaVgaWgaXgaZga]gakgalgamgangaogapgaqgargasgaQgatga[ga^ga~Op~",goto:"QuzPPPPPPPPPPPPPPPP{{PXPe{{{{{PkQRPPPPPPPPPPPQXQeQeQqeZOPRST]_bdfeROPRST]_bdfQaRRlbQ]OQ_PQbRQdSQfTZj]_bdfQiXRoie[OPRST]_bdfeUOPRST]_bdfThXi",nodeNames:"⚠ left_brace right_brace tab_mark car_ret sup_mark sub_mark ignore active_char invalid_char comment left_math_shift right_math_shift left_double_math_shift right_double_math_shift Document SimpleGroup SemiSimpleGroup begingroup endgroup MathShiftGroup control_sequence primitive macro_parameter directive",maxTerm:43,context:Q,nodeProps:[[r.NodeProp.closedBy,1,"right_brace",11,"right_math_shift",13,"right_double_math_shift",18,"endgroup"],[r.NodeProp.openedBy,2,"left_brace",12,"left_math_shift",14,"left_double_math_shift",19,"begingroup"]],skippedNodes:[0,10],repeatNodeCount:2,tokenData:"RORO",tokenizers:[0,g],topRules:{Document:[0,15]},dialects:{directives:197,tex:0,etex:0,pdftex:0,xetex:0,latex:0},specialized:[{term:31,get:t=>b[t]||-1}],tokenPrec:0,termNames:{0:"⚠",1:"left_brace",2:"right_brace",3:"tab_mark",4:"car_ret",5:"sup_mark",6:"sub_mark",7:"ignore",8:"active_char",9:"invalid_char",10:"line_comment",11:"left_math_shift",12:"right_math_shift",13:"left_double_math_shift",14:"right_double_math_shift",15:"@top",16:"SimpleGroup",17:"SemiSimpleGroup",18:"begingroup",19:"endgroup",20:"MathShiftGroup",21:"control_sequence",22:"primitive",23:"macro_parameter",24:"directive",25:"statement+",26:"dec_digit+",27:"␄",28:"mac_param",29:"spacer",30:"letter",31:"other_char",32:"directive_comment",33:"control_sequence_token",34:"primitive_token",35:"begingroup_token",36:"endgroup_token",37:"%mainskip",38:"statement",39:"ordinary_math_mode",40:"display_math_mode",41:"dec_digit",42:'other_char/"0"',43:'other_char/"9"'}});exports.default=_;