ofc@sdZdZddlZddlZddlmZmZmZmZm Z m Z ddl m Z ddl m Z ejjejjedZd efd YZd Zd efd YZiejd6ejd6ejd6dd6ZdZdZdZdS(sPattern compiler. The grammer is taken from PatternGrammar.txt. The compiler compiles a pattern to a pytree.*Pattern instance. s#Guido van Rossum iNi(tdrivertliteralsttokenttokenizetparsetgrammar(tpytree(tpygramsPatternGrammar.txttPatternSyntaxErrorcBseZRS((t__name__t __module__(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyRsc cswttjtjtjf}tjtj|j}x7|D]/}|\}}}}}||kr@|Vq@q@WdS(s6Tokenizes a string suppressing significant whitespace.N( tsetRtNEWLINEtINDENTtDEDENTRtgenerate_tokenstStringIOtreadline( tinputtskipttokenst quintuplettypetvaluetstarttendt line_text((s'/usr/lib64/python2.7/lib2to3/patcomp.pyttokenize_wrapper!s   tPatternCompilercBsAeZedZeedZdZddZdZ RS(cCs^tj||_tj|j|_tj|_tj|_ tj |jdt |_dS(s^Initializer. Takes an optional alternative filename for the pattern grammar. tconvertN( Rt load_grammarRRtSymbolstsymstpython_grammart pygrammartpython_symbolstpysymstDrivertpattern_convert(tselft grammar_file((s'/usr/lib64/python2.7/lib2to3/patcomp.pyt__init__-s   cCs}t|}y|jj|d|}Wn(tjk rR}tt|nX|rl|j||fS|j|SdS(s=Compiles a pattern string to a nested pytree.*Pattern object.tdebugN(RRt parse_tokensRt ParseErrorRtstrt compile_node(R'RR*t with_treeRtrootte((s'/usr/lib64/python2.7/lib2to3/patcomp.pytcompile_pattern8s c Cs|j|jjkr%|jd}n|j|jjkrg|jdddD]}|j|^qQ}t|dkr|dStjg|D]}|g^qdddd}|j S|j|jj kr=g|jD]}|j|^q}t|dkr|dStj|gdddd}|j S|j|jj kr|j |jd}tj |}|j S|j|jjkstd}|j} t| dkr| djtjkr| dj}| d} nd} t| dkr5| dj|jjkr5| d} | d } n|j | | }| dk r| j|jjksnt| j} | d} | jtjkrd} tj}n| jtjkrd} tj}n| jtjkrQ| djtjkstt| d kst|j| d} }t| d kr]|j| d}q]n ts]t| dksu|dkr|j }tj|ggd| d|}qn|dk r||_n|j S( sXCompiles a node, recursively. This is one big switch on the node type. iNiitmintmaxiii(ii(RR tMatchertchildrent AlternativesR.tlenRtWildcardPatterntoptimizet Alternativet NegatedUnitt compile_basictNegatedPatterntUnittAssertionErrortNoneRtEQUALRtRepeatertSTARtHUGEtPLUStLBRACEtRBRACEtget_inttFalsetname(R'tnodetchtaltstatptunitstpatternRKtnodestrepeatR6tchildR3R4((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR.Dsh21 %   (  +         '  cCst|dkst|d}|jtjkrbttj|j}t j t ||S|jtj krp|j}|j r|tkrtd|n|drtdnt j t|S|dkrd}nF|jds-t|j|d}|dkr-td|q-n|drW|j|djdg}nd}t j||Sns|jdkr|j|dS|jd kr|dkst|j|d}t j|ggd dd dStst|dS( NiisInvalid token: %rsCan't have details for tokentanyt_sInvalid symbol: %rt(t[R3R4(R8R@RRtSTRINGtunicodeRt evalStringRRt LeafPatternt_type_of_literaltNAMEtisuppert TOKEN_MAPRRAt startswithtgetattrR$R.R6t NodePatternR9RJ(R'RSRTRLRRtcontentt subpattern((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR=s<          cCs%|jtjkstt|jS(N(RRtNUMBERR@tintR(R'RL((s'/usr/lib64/python2.7/lib2to3/patcomp.pyRIsN( R R t_PATTERN_GRAMMAR_FILER)RJR2R.RAR=RI(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR+s   G #R_RZRgtTOKENcCs9|djrtjS|tjkr1tj|SdSdS(Ni(tisalphaRR_RtopmapRA(R((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR^s  cCsW|\}}}}|s'||jkr=tj||d|Stj||d|SdS(s9Converts raw node information to a Node or Leaf instance.tcontextN(t number2symbolRtNodetLeaf(Rt raw_node_infoRRRmR6((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR&scCstj|S(N(RR2(RR((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR2s( t__doc__t __author__tosRtpgen2RRRRRRtRRtpathtjointdirnamet__file__Rit ExceptionRRtobjectRR_RZRgRARaR^R&R2(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyt s$  .