3 \&@sxddlmZddlmZmZddlmZmZeZeZ ej Z eZ dZ dZdZGdddeZdd d Zd d Zd dZdS))pytree)grammartoken)pattern_symbolspython_symbolsc@s6eZdZd ddZddZddZdd Zd d ZdS) MinNodeNcCs.||_||_g|_d|_d|_g|_g|_dS)NF)typenamechildrenleafparent alternativesgroup)selfr r r)/usr/lib64/python3.6/lib2to3/btm_utils.py__init__szMinNode.__init__cCst|jdt|jS)N )strr r )rrrr__repr__szMinNode.__repr__cCs|}g}x|r|jtkr`|jj|t|jt|jkrTt|jg}g|_|j}q n |j}d}P|jtkr|j j|t|j t|jkrt |j }g|_ |j}q n |j}d}P|jt j kr|j r|j|j n |j|j|j}q W|S)N)r TYPE_ALTERNATIVESrappendlenr tupler TYPE_GROUPrget_characteristic_subpattern token_labelsNAMEr )rnodesubprrr leaf_to_root!s8        zMinNode.leaf_to_rootcCs&x |jD]}|j}|r |Sq WdS)N)leavesr")rlr!rrrget_linear_subpatternKszMinNode.get_linear_subpatternccs.x|jD]}|jEdHqW|js*|VdS)N)r r#)rchildrrrr#`s zMinNode.leaves)NN)__name__ __module__ __qualname__rrr"r%r#rrrrr s  *r Nc Csd}|jtjkr|jd}|jtjkrt|jdkrFt|jd|}nJttd}x>|jD]4}|jj |drnqXt||}|dk rX|jj |qXWn|jtj krt|jdkrtt d}x(|jD]}t||}|r|jj |qW|jsd}nt|jd|}n|jtj krt|jdtjrH|jdjdkrHt|jd|St|jdtjrn|jdjdkst|jdkrt|jddr|jdjdkrdSd}d}d}d }d} d } xn|jD]d}|jtjkrd }|}n*|jtjkrd}|} n|jtjkr |}t|dr|jd krd} qW| rb|jd} t| drl| jdkrl|jd } n |jd} | jtjkr| jd krttd}n4tt| jrttt| jd}nttt| jd}n\| jtjkr | jjd } | tkrtt| d}nttj| d}n| jtjkr$t||}|rZ| jdjdkrBd}n| jdjdkrVnt|r|dk rx8|jddD]&}t||}|dk rz|jj |qzW|r||_|S)Nr)r r([valueTF=rany')r r *+)r symsZMatcherr Z Alternativesr reduce_treer rindexrZ AlternativerZUnit isinstancerZLeafr-hasattrZDetailsZRepeaterrrTYPE_ANYgetattrpysymsSTRINGstriptokensNotImplementedErrorr) r rZnew_noder&Zreducedr Z details_nodeZalternatives_nodeZ has_repeaterZ repeater_nodeZhas_variable_nameZ name_leafr rrrr5gs                     r5cst|ts|St|dkr"|dSg}g}dddddgg}dxl|D]d}tt|d d rFtt|fd d r~|j|qFtt|fd d r|j|qF|j|qFW|r|}n|r|}n|r|}t|td S)Nrr*inforifnotNonez[]().,:cSs t|tkS)N)r r)xrrrsz/get_characteristic_subpattern..cst|to|kS)N)r7r)rE) common_charsrrrFscst|to|kS)N)r7r)rE) common_namesrrrFs)key)r7listrr/rec_testrmax)Z subpatternsZsubpatterns_with_namesZsubpatterns_with_common_namesZsubpatterns_with_common_chars subpatternr)rGrHrrs2     rccs<x6|D].}t|ttfr*t||EdHq||VqWdS)N)r7rJrrK)ZsequenceZ test_funcrErrrrKs rKr3)N)rZpgen2rrZpygramrrr4r;Zopmapr>rr9rrobjectr r5rrKrrrrs W %