f ž _ô5c@sdddlmZmZmZGdd„dejƒZGdd„deƒZGdd„deƒZGdd „d eƒZ dd d „Z d S)é)ÚgrammarÚtokenÚtokenizec@s eZdZdS)Ú PgenGrammarN)Ú__name__Ú __module__Ú __qualname__©rrú+/usr/lib64/python3.10/lib2to3/pgen2/pgen.pyrsrc@s eZdZd&dd„Zdd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd'd d!„Zd"d#„Zd$d%„ZdS)(ÚParserGeneratorNcCsld}|durt|ƒ}|j}||_||_t |j¡|_| ¡|  ¡\|_ |_ |durZ|ƒi|_ |  ¡dS©N)ZopenZcloseÚfilenameÚstreamrZgenerate_tokensZreadlineÚ generatorÚgettokenÚparseÚdfasÚ startsymbolÚfirstÚ addfirstsets)Úselfr r Z close_streamrrr Ú__init__ szParserGenerator.__init__c Cstƒ}t|j ¡ƒ}| ¡| |j¡| d|j¡|D]&}dt|j ƒ}||j |<||j |<q:|D] }|j|}g}|D]`}g}t |j   ¡ƒD]$\} } | | || ¡| | ¡f¡q’|jrÒ| d| |¡f¡| |¡q||j |¡|| ||¡f|j|j |<qf|j |j|_|S)Néi)rÚlistrÚkeysÚsortZremoverZinsertÚlenÚ symbol2numberZ number2symbolÚsortedÚarcsÚitemsÚappendÚ make_labelÚindexÚisfinalÚstatesÚ make_firstÚstart) rÚcÚnamesÚnameÚiÚdfar$ÚstaterÚlabelÚnextrrr Ú make_grammars.      zParserGenerator.make_grammarcCs4|j|}i}t|ƒD]}| ||¡}d||<q|S©Nr)rrr!)rr'r)Zrawfirstrr-Úilabelrrr r%4s     zParserGenerator.make_firstcCst|jƒ}|d ¡r–||jvrX||jvr4|j|S|j |j|df¡||j|<|Stt|dƒ}||jvrx|j|S|j |df¡||j|<|St |ƒ}|d ¡rÞ||j vr¾|j |S|j tj |f¡||j |<|St j |}||jvrü|j|S|j |df¡||j|<|S©Nr)rZlabelsZisalpharZ symbol2labelr ZgetattrrZtokensZevalZkeywordsÚNAMErZopmap)rr'r-r1ZitokenÚvaluerrr r!=s6                  zParserGenerator.make_labelcCs8t|j ¡ƒ}| ¡|D]}||jvr| |¡qdSr )rrrrrÚ calcfirst)rr(r)rrr rks  zParserGenerator.addfirstsetsc Csþ|j|}d|j|<|d}i}i}|j ¡D]x\}}||jvr’||jvrj|j|}|dur~td|ƒ‚n| |¡|j|}| |¡|||<q.d||<|di||<q.i} | ¡D]:\}} | D],} | | vrätd|| || | fƒ‚|| | <qÀq´||j|<dS)Nrzrecursion for rule %rrzArule %s is ambiguous; %s is in the first sets of %s as well as %s)rrrrZ ValueErrorr5Zupdate) rr)r+r,ZtotalsetZ overlapcheckr-r.ZfsetZinverseZitsfirstZsymbolrrr r5ss4         þ zParserGenerator.calcfirstc Cs i}d}|jtjkr˜|jtjkr*| ¡q| tj¡}| tjd¡| ¡\}}| tj¡|  ||¡}t |ƒ}|  |¡t |ƒ}|||<|dur|}q||fS)Nz:) ÚtyperZ ENDMARKERZNEWLINErÚexpectr3ÚOPÚ parse_rhsÚmake_dfarÚ simplify_dfa) rrrr)ÚaÚzr+ZoldlenZnewlenrrr r‘s"        zParserGenerator.parsec s¾‡fdd„}‡fdd„‰t||ƒ|ƒg}|D]Œ}i}|jD].}|jD]"\}} |durDˆ| | |i¡ƒqDq:t| ¡ƒD]@\}} |D]} | j| kr‚qªq‚t| |ƒ} | | ¡| | |¡qvq,|S)Ncsi}ˆ||ƒ|Sr r)r,Úbase©Ú addclosurerr Úclosure°s z)ParserGenerator.make_dfa..closurecs:||vr dSd||<|jD]\}}|durˆ||ƒqdSr0©r)r,r>r-r.r?rr r@´s z,ParserGenerator.make_dfa..addclosure)ÚDFAStateÚnfasetrZ setdefaultrrr Úaddarc) rr&ÚfinishrAr$r,rZnfastater-r.rDZstrr?r r:©s"      zParserGenerator.make_dfac Csštd|ƒ|g}t|ƒD]|\}}td|||ur2dp4dƒ|jD]T\}}||vrZ| |¡} nt|ƒ} | |¡|dur‚td| ƒq>td|| fƒq>qdS)NzDump of NFA forú Stateú(final)Úz -> %dú %s -> %d)ÚprintÚ enumeraterr"rr ) rr)r&rFZtodor*r,r-r.Újrrr Údump_nfaÍs   zParserGenerator.dump_nfacCsdtd|ƒt|ƒD]L\}}td||jr*dp,dƒt|j ¡ƒD]\}}td|| |¡fƒq>qdS)NzDump of DFA forrGrHrIrJ)rKrLr#rrrr")rr)r+r*r,r-r.rrr Údump_dfaÝs  zParserGenerator.dump_dfacCspd}|rld}t|ƒD]T\}}t|dt|ƒƒD]8}||}||kr.||=|D]}| ||¡qLd}qq.qqdS)NTFr)rLZrangerÚ unifystate)rr+Zchangesr*Zstate_irMZstate_jr,rrr r;äszParserGenerator.simplify_dfacCsz| ¡\}}|jdkr||fStƒ}tƒ}| |¡| |¡|jdkrr| ¡| ¡\}}| |¡| |¡q>||fS)Nz|)Ú parse_altr4ÚNFAStaterEr)rr<r=ZaaZzzrrr r9ùs        zParserGenerator.parse_rhscCsL| ¡\}}|jdvs(|jtjtjfvrD| ¡\}}| |¡|}q ||fS)N)ú(ú[)Ú parse_itemr4r6rr3ÚSTRINGrE)rr<Zbr'Zdrrr rQ s  ÿ  zParserGenerator.parse_altcCsŠ|jdkr>| ¡| ¡\}}| tjd¡| |¡||fS| ¡\}}|j}|dvr`||fS| ¡| |¡|dkr‚||fS||fS)NrTz])ú+Z*rW)r4rr9r7rr8rEÚ parse_atom)rr<r=r4rrr rUs     zParserGenerator.parse_itemcCs†|jdkr4| ¡| ¡\}}| tjd¡||fS|jtjtjfvrpt ƒ}t ƒ}|  ||j¡| ¡||fS|  d|j|j¡dS)NrSz)z+expected (...) or NAME or STRING, got %s/%s) r4rr9r7rr8r6r3rVrRrEÚ raise_error)rr<r=rrr rX(s  ÿzParserGenerator.parse_atomcCsD|j|ks|dur2|j|kr2| d|||j|j¡|j}| ¡|S)Nzexpected %s/%s, got %s/%s)r6r4rYr)rr6r4rrr r79s ÿzParserGenerator.expectcCsFt|jƒ}|dtjtjfvr*t|jƒ}q |\|_|_|_|_|_ dSr2) r.rrZCOMMENTZNLr6r4ZbeginÚendÚline)rZtuprrr rAs  zParserGenerator.gettokenc Gs^|r8z ||}Wn&d |gttt|ƒƒ¡}Yn0t||j|jd|jd|jfƒ‚dS)Nz rr)ZjoinrZmapZstrZ SyntaxErrorr rZr[)rZmsgZargsrrr rYHs   ÿzParserGenerator.raise_errorr r )rrrrr/r%r!rr5rr:rNrOr;r9rQrUrXr7rrYrrrr r s$  .$  r c@seZdZdd„Zddd„ZdS)rRcCs g|_dSr rB)rrrr rSszNFAState.__init__NcCs|j ||f¡dSr )rr ©rr.r-rrr rEVszNFAState.addarcr )rrrrrErrrr rRQsrRc@s0eZdZdd„Zdd„Zdd„Zdd„Zd Zd S) rCcCs||_||v|_i|_dSr )rDr#r)rrDZfinalrrr r]s zDFAState.__init__cCs||j|<dSr rBr\rrr rEeszDFAState.addarccCs*|j ¡D]\}}||ur ||j|<q dSr )rr)rZoldZnewr-r.rrr rPkszDFAState.unifystatecCsT|j|jkrdSt|jƒt|jƒkr(dS|j ¡D]\}}||j |¡ur2dSdS)NFT)r#rrrZget)rZotherr-r.rrr Ú__eq__ps zDFAState.__eq__N)rrrrrErPr]Z__hash__rrrr rC[s rCú Grammar.txtcCst|ƒ}| ¡Sr )r r/)r Zprrr Úgenerate_grammar€sr_N)r^) rIrrrZGrammarrZobjectr rRrCr_rrrr ZsI %