PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  oY&@sdZddlmZddlmZmZddlmZmZeZ eZ ej Z eZ dZdZdZGdddeZd d d Zd d ZddZd S)z0Utility functions used by the btm_matcher module)pytree)grammartoken)pattern_symbolspython_symbolsc@sXeZdZdZddddZddZddZd d Zd d ZdS) MinNodezThis class serves as an intermediate representation of the pattern tree during the conversion to sets of leaf-to-root subpatternsNcCsC||_||_g|_d|_d|_g|_g|_dS)NF)typenamechildrenleafparent alternativesgroup)selfr r r(/opt/python35/lib/python3.5/btm_utils.py__init__s      zMinNode.__init__cCst|jdt|jS)N )strr r )rrrr__repr__szMinNode.__repr__cCsO|}g}x<|rJ|jtkr|jj|t|jt|jkr|t|jg}g|_|j}qn|j}d}P|jtkr|j j|t|j t|jkrt |j }g|_ |j}qn|j}d}P|jt j kr.|j r.|j|j n|j|j|j}qW|S)zInternal method. Returns a characteristic path of the pattern tree. This method must be run for all leaves until the linear subpatterns are merged into a singleN)r TYPE_ALTERNATIVESrappendlenr tupler TYPE_GROUPrget_characteristic_subpattern token_labelsNAMEr )rnodesubprrr leaf_to_root!s8        zMinNode.leaf_to_rootcCs1x*|jD]}|j}|r |Sq WdS)aDrives the leaf_to_root method. The reason that leaf_to_root must be run multiple times is because we need to reject 'group' matches; for example the alternative form (a | b c) creates a group [b c] that needs to be matched. Since matching multiple linear patterns overcomes the automaton's capabilities, leaf_to_root merges each group into a single choice based on 'characteristic'ity, i.e. (a|b c) -> (a|b) if b more characteristic than c Returns: The most 'characteristic'(as defined by get_characteristic_subpattern) path for the compiled pattern tree. N)leavesr")rlr!rrrget_linear_subpatternKs zMinNode.get_linear_subpatternccs5x |jD]}|jEdHq W|js1|VdS)z-Generator that returns the leaves of the treeN)r r#)rchildrrrr#`s zMinNode.leaves) __name__ __module__ __qualname____doc__rrr"r%r#rrrrr s   * r Nc Csd}|jtjkr%|jd}|jtjkrt|jdkret|jd|}qtdt}xa|jD]J}|jj |drq~t||}|dk r~|jj |q~Wn |jtj krit|jdkrPtdt }x6|jD]+}t||}|r|jj |qW|jsfd}qt|jd|}no|jtj krt|jdtjr|jdjdkrt|jd|St|jdtjr|jdjdks.t|jdkr2t|jddr2|jdjdkr2dSd }d}d}d }d} d } x|jD]}|jtjkrd }|}n9|jtjkrd }|} n|jtjkr|}t|dr`|jd kr`d } q`W| r)|jd} t| dr6| jdkr6|jd } n |jd} | jtjkr| jd kritdt}q9tt| jrtdtt| j}q9tdtt| j}n| jtjkr| jjd} | tkrtdt| }q9tdtjd| }n!| jtjkr9t||}|r}| jdjdkr^d}n| jdjdkrwnt|r|dk rxF|jddD]1}t||}|dk r|jj |qW|r||_|S)z Internal function. Reduces a compiled pattern tree to an intermediate representation suitable for feeding the automaton. This also trims off any optional pattern elements(like [a], a*). Nrr r([valueTF=rany'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 rrrr6gs             r6cs/t|ts|St|dkr-|dSg}g}dddddgg}dx|D]}tt|d d ratt|fd d r|j|qatt|fd d r|j|qa|j|qaW|r|}n|r|}n |r|}t|d tS)zPicks the most characteristic from a list of linear patterns Current order used is: names > common_names > common_chars rr+inforifnotNonez[]().,:cSst|tkS)N)r r)xrrrsz/get_characteristic_subpattern..cst|to|kS)N)r8r)rF) common_charsrrrGscst|to|kS)N)r8r)rF) common_namesrrrGskey)r8listrr0rec_testrmax)Z subpatternsZsubpatterns_with_namesZsubpatterns_with_common_namesZsubpatterns_with_common_chars subpatternr)rHrIrrs2     rccsJxC|D];}t|ttfr7t||EdHq||VqWdS)zPTests test_func on all items of sequence and items of included sub-iterablesN)r8rKrrL)ZsequenceZ test_funcrFrrrrLs rLr4)r*rZpgen2rrZpygramrrr5r<Zopmapr?rr:rrobjectr r6rrLrrrrs W %