html-lexer
Version:
An HTML5 lexer
2 lines (1 loc) • 8.32 kB
JavaScript
var wt=Object.defineProperty;var k=(n,f)=>wt(n,"name",{value:f,configurable:!0});function*Tt(n,f=1/0){for(;n<=f;)yield n++}k(Tt,"range");var Et=k((n,f=0)=>new Proxy({},{get:(y,E)=>(n[E]=f,f++)}),"intsInto"),Qe=console.log.bind(console),et,qt=(()=>{let[n,f,y,E,F,V,h,N,R,b,U,X,Y,_,J,K,C,$,g,O,A]=Tt(1);et=E;let G=k(c=>c===0?n:c===13?f:c===10?y:c===9||c===32?h:c===33?Y:c===34?F:c===35?R:c===38?b:c===39?V:c===45?_:c===47?C:48<=c&&c<=57?$:c===59?N:c===60?J:c===61?U:c===62?K:c===63?X:65<=c&&c<=70?g:c===88||c===120?A:71<=c&&c<=90?O:97<=c&&c<=102?g:102<=c&&c<=122?O:et,"eqClassFn"),W=new Uint8Array(127);for(let c=0,Rt=127;c<=Rt;c++)W[c]=G(c);return W})(),kt=0,Z={errorToken:kt},{data:Ct,rawtext:rt,rcdata:ot,plaintext:Vt,nulls:Bt,space:Lt,newline:st,ampersand:Nt,lt:vt,charRefDecimal:nt,charRefHex:ut,charRefNamed:yt,charRefLegacy:Ft,mDeclStart:Ot,commentStart:Pt,commentData:tt,commentEnd:It,bogusStart:it,bogusData:Mt,bogusEnd:Qt,startTagStart:Ut,endTagStart:Xt,tagEnd:$t,attributeSep:ct,attributeName:Gt,attributeAssign:Ht,valueStartApos:Yt,valueStartQuot:_t,valueEnd:Wt,unquoted:lt,squoted:jt,quoted:zt}=Et(Z,1),Zt=[];for(let n in Z)Zt[Z[n]]=n;var[ht,Jt,Kt,te,ee,ae,re,oe,se,ne,ue,mt,ie,dt,ft,ce,le,p,B,xt,me,v,I,x,a,r,o,s,m,d,l,e,de,fe,q,M,P,j,bt,xe,be,gt,D,T,S,ge,pe,Te,Q,he,z,H,Ae,De,pt,Se,Re,we,L]=Tt(1),Ee=0,qe={Main:ht,RcData:Jt,RawText:Kt,Plain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,t,t,T,T,T],[it,t,t,t,t,t,t,t,t,t,t,t,t,t,ie,t,t,t,t,S,S,S],[Ut,D,t,t,D,D,D,t,D,D,D,D,D,D,D,D,t,t,D,D,D,D],[Xt,T,t,t,T,T,T,t,T,T,T,T,T,T,T,T,t,t,T,T,T,T],[Ot,S,t,t,S,S,S,t,S,S,S,S,S,S,S,S,t,t,S,S,S,S],[rt,t,t,t,a,a,a,a,a,a,a,a,a,a,a,t,a,mt,a,a,a,a],[ot,t,t,t,r,r,r,r,r,r,r,r,r,r,r,t,r,mt,r,r,r,r],[Pt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[$t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[Qt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[It,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[Ht,t,H,H,t,t,t,H,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[_t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[Yt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[Wt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[yt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[nt,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[ut,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t],[st,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t]],Ve={eqClass:qt,defaultClass:et,tokens:Z,states:qe,table:Ce,initialState:ht,minAccepts:ke},At=Ve;var $e=console.log.bind(console),{defineProperties:Be}=Object,{eqClass:Le,defaultClass:Ne,tokens:u,states:i,initialState:He,table:Dt,minAccepts:St}=At,ve=0,ye=0,w=[];for(let n in u)w[u[n]]=n;w[u.unquoted]="attributeValueData";w[u.quoted]="attributeValueData";w[u.squoted]="attributeValueData";w[u.attributeSep]="tagSpace";w[u.valueStartApos]="attributeValueStart";w[u.valueStartQuot]="attributeValueStart";w[u.valueEnd]="attributeValueEnd";w[u.bogusStart]="commentStartBogus";w[u.bogusData]="commentData";w[u.bogusEnd]="commentEndBogus";w[u.lt]="lessThanSign";w[u.ampersand]="uncodedAmpersand";var at={};for(let n of w)at[n]=n;delete at.errorToken;delete at.mDeclStart;function Ye(n){let f="",y=!1,E=1,F=0,V=0,h=0,N=0,R=0,b=i.Main,U=0,X="";return Be(this,{position:{get:J},write:{value:Y,hidden:!0},end:{value:_,hidden:!0},parse:{value:_,hidden:!0}});function Y(C){f+=C;let $=f.length;for(;R<$;){let g=b,O=b<St?ve:b;do{let A=f.charCodeAt(R++);g=Dt[g][A<=122?Le[A]:Ne],St<=g&&(O=g,N=R),(A===13||A===10)&&(F=R,E+=V!==13),V=A}while(g&&R<$);if(N<f.length||y)K(Dt[O][0],h,N);else{R=N=h;break}}f=f.substr(N),h=R=N=0}function _(C=""){y=!0,Y(C),n.end()}function J(){return{line:E,column:R-F}}function K(C,$,g){switch(C){case ye:{let A=`Lexer error at line ${E}:${R-F}`;throw new SyntaxError(A)}break;case u.startTagStart:{let A=f.substring(h+1,g);return U=C,X=A.toLowerCase(),n.write(["startTagStart","<"]),n.write(["tagName",A]),b=i.BeforeAttribute,h=R=g}case u.endTagStart:{let A=f.substring(h+2,g);return U=C,b===i.Main||X===A.toLowerCase()?b=i.BeforeAttribute:b===i.RcData?u.rcdata:u.rawtext,n.write(["endTagStart","</"]),n.write(["tagName",A]),h=R=g}case u.mDeclStart:return b=i.Bogus,n.write([w[u.bogusStart],"<!"]),n.write([w[u.bogusData],f.substring(h+2,g)]),h=R=g;case u.tagEnd:{b=U===u.startTagStart&&Fe[X]||i.Main;let G=f[g-2]==="/"?"tagEndAutoclose":"tagEnd";return n.write([G,f.substring(h,g)]),h=R=g}case u.charRefNamed:case u.charRefLegacy:{let A=f[g],G=Ie(f.substring(h,g),b,A);for(let W of G)n.write(W);return h=R=g}case u.attributeSep:b=i.BeforeAttribute;break;case u.attributeName:b=i.BeforeAssign;break;case u.attributeAssign:b=i.BeforeValue;break;case u.valueStartQuot:b=i.ValueQuoted;break;case u.valueStartApos:b=i.ValueAposed;break;case u.valueEnd:b=i.BeforeAttribute;break;case u.unquoted:b=i.ValueUnquoted;break;case u.commentStart:b=i.BeforeCommentData;break;case u.commentData:b=i.InCommentData;break;case u.commentEnd:b=i.Main;break;case u.bogusStart:b=i.Bogus;break;case u.bogusData:b=i.Bogus;break;case u.bogusEnd:b=i.Main;break}let O=w[C];n.write([O,f.substring(h,g)]),h=R=g}}k(Ye,"Lexer");var Fe={style:i.RawText,script:i.RawText,xmp:i.RawText,iframe:i.RawText,noembed:i.RawText,noframes:i.RawText,textarea:i.RcData,title:i.RcData,plaintext:i.PlainText},Oe=/^&([AEIOUYaeiouy]?acute|[AEIOUaeiou](?:grave|circ|uml)|y?uml|[ANOano]tilde|[Aa]ring|[Oo]slash|[Cc]?cedil|brvbar|curren|divide|frac(?:12|14|34)|iquest|middot|plusmn|(?:AE|ae|sz)lig|[lr]aquo|iexcl|micro|pound|THORN|thorn|times|COPY|copy|cent|macr|nbsp|ord[fm]|para|QUOT|quot|sect|sup[123]|AMP|amp|ETH|eth|REG|reg|deg|not|shy|yen|GT|gt|LT|lt)(;|.*)$/,Pe=/^&(?:copysr|centerdot|divideontimes|[gl]t(?:quest|dot|cir|cc)|[gl]trPar|gtr(?:dot|less|eqqless|eqless|approx|arr|sim)|ltr(?:i|if|ie|mes)|ltlarr|lthree|notin(?:dot|E|v[abc])?|notni(?:v[abc])?|parallel|times(?:bar|d|b));$/;function Ie(n,f,y){if(Pe.test(n))return[["charRefNamed",n]];let E=Oe.exec(n),F=n[n.length-1]===";",V=f===i.Main?"data":f===i.RcData?"rcdata":"attributeValueData";if(!E)return F?[["charRefNamed",n]]:[[V,n]];if(E[2]===";")return[["charRefNamed","&"+E[1]+";"]];let h=f===i.BeforeValue||f===i.ValueQuoted||f===i.ValueAposed||f===i.ValueUnquoted;return E[2]===""?!h||y!=="="?[["charRefLegacy",n]]:[[V,n]]:h?[[V,n]]:[["charRefLegacy","&"+E[1]],[V,E[2]]]}k(Ie,"splitCharRef");export{At as DFA,Ye as Lexer,at as tokenTypes};