o ?Og@sj dZddlZddlZddlmZddlmZddlmZGddde Z Gd d d e Z ia d d Z dS) z+George Boutsioukis N) defaultdict)pytree) reduce_treec@seZdZ eZddZdS)BMNodecCs"i|_g|_ttj|_d|_dS)N)transition_tablefixersnextrcountidcontentselfr:/opt/alt/python310/lib64/python3.10/lib2to3/btm_matcher.py__init__s  zBMNode.__init__N)__name__ __module__ __qualname__ itertoolsr rrrrrrs rc@s6eZdZ ddZddZddZddZd d Zd S) BottomMatchercCs0t|_t|_|jg|_g|_td|_dS)NZRefactoringTool) setmatchrrootZnodesr loggingZ getLoggerZloggerrrrrrs  zBottomMatcher.__init__cCsJ |j|t|j}|}|j||jd}|D]}|j|qdS)Nstart)r appendrZ pattern_treeZget_linear_subpatternaddr)rfixerZtreeZlinear match_nodesZ match_noderrr add_fixer%s  zBottomMatcher.add_fixerc Cs |s|gSt|dtr1g}|dD]}|j||d}|D]}|||dd|qq|S|d|jvrCt}||j|d<n|j|d}|ddr]|j|dd|d}|S|g}|S)Nrrr) isinstancetuplerextendrr)rpatternrr!Z alternativeZ end_nodesendZ next_noderrrr1s(  zBottomMatcher.addc Cs |j}tt}|D]l}|}|rvd|_|jD]}t|tjr(|jdkr(d|_nq|j dkr2|j}n|j }||j vrM|j |}|j D] }|| |qBn$|j}|j durZ|j jrZn||j vrq|j |}|j D] }|| |qg|j }|sq |S)NT;Fr)rrlistZ was_checkedchildrenr#rZLeafvaluetyperr rparent) rZleavesZcurrent_ac_nodeZresultsZleafZcurrent_ast_nodechildZ node_tokenr rrrrunSsB         "zBottomMatcher.runcs, tdfdd|jtddS)Nz digraph g{csZ|jD]%}|j|}td|j|jt|t|jf|dkr&t|j|qdS)Nz%d -> %d [label=%s] //%sr)rkeysprintr type_reprstrr r )ZnodeZ subnode_keyZsubnode print_noderrr5s   z*BottomMatcher.print_ac..print_node})r1rrrr4rprint_acs    zBottomMatcher.print_acN)rrrrr"rr/r7rrrrrs " 8rcCsDtsddlm}|jD]\}}t|tkr|t|<q t||S)Nr)python_symbols) _type_reprsZpygramr8__dict__itemsr,int setdefault)Ztype_numr8namevalrrrr2s   r2) __author__rr collectionsrrrZ btm_utilsrobjectrrr9r2rrrrs