ó {fc@sådZdZddlZddlmZmZmZmZmZm Z ddl m Z ddl m Z de fd „ƒYZd „Zd efd „ƒYZiejd 6ejd6ejd6dd6Zd„Zd„Zd„ZdS(sPattern compiler. The grammar is taken from PatternGrammar.txt. The compiler compiles a pattern to a pytree.*Pattern instance. s#Guido van Rossum iÿÿÿÿNi(tdrivertliteralsttokenttokenizetparsetgrammar(tpytree(tpygramtPatternSyntaxErrorcBseZRS((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_wrappers   tPatternCompilercBsAeZdd„Zeed„Zd„Zdd„Zd„ZRS(cCs…|dkr'tj|_tj|_n'tj|ƒ|_tj|jƒ|_tj |_ tj |_ tj |jdtƒ|_dS(s^Initializer. Takes an optional alternative filename for the pattern grammar. tconvertN(tNoneRtpattern_grammarRtpattern_symbolstsymsRt load_grammartSymbolstpython_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_pattern7s cCsT|j|jjkr%|jd}n|j|jjkrÁg|jddd…D]}|j|ƒ^qQ}t|ƒdkr†|dStjg|D]}|g^q“ddddƒ}|j ƒS|j|jj kr=g|jD]}|j|ƒ^qà}t|ƒdkr|dStj|gddddƒ}|j ƒS|j|jj kr|j |jdƒ}tj |ƒ}|j ƒSd}|j} t| ƒdkrÒ| djtjkrÒ| dj}| d} nd} t| ƒdkr| dj|jjkr| d} | d } n|j | | ƒ}| dk r2| j} | d} | jtjkrod} tj}nx| jtjkr“d} tj}nT| jtjkrç|j| dƒ} }t| ƒd krç|j| dƒ}qçn| dksÿ|dkr2|j ƒ}tj|ggd| d|ƒ}q2n|dk rJ||_n|j ƒS( sXCompiles a node, recursively. This is one big switch on the node type. iNiitmintmaxiiÿÿÿÿi(RR!tMatchertchildrent AlternativesR1tlenRtWildcardPatterntoptimizet Alternativet NegatedUnitt compile_basictNegatedPatternRRtEQUALRtRepeatertSTARtHUGEtPLUStLBRACEtget_inttname(R*tnodetchtaltstatptunitstpatternRItnodestrepeatR9tchildR6R7((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR1Cs^21 %   (  +        '  cCs½|d}|jtjkrJttj|jƒƒ}tjt |ƒ|ƒS|jtj krX|j}|j ƒrº|t krt d|ƒ‚n|dr©t dƒ‚ntjt |ƒS|dkrÏd}nF|jdƒst|j|dƒ}|dkrt d|ƒ‚qn|dr?|j|djdƒg}nd}tj||ƒSna|jdkrx|j|dƒS|jd kr¹|j|dƒ}tj|ggd dd dƒSdS( NisInvalid token: %risCan't have details for tokentanyt_sInvalid symbol: %rt(t[R6R7(RRtSTRINGtunicodeRt evalStringRRt LeafPatternt_type_of_literaltNAMEtisuppert TOKEN_MAPRRt startswithtgetattrR'R1R9t NodePatternR<(R*RQRRRJRRtcontentt subpattern((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR@Šs8          cCs t|jƒS(N(tintR(R*RJ((s'/usr/lib64/python2.7/lib2to3/patcomp.pyRH­sN( R R RR,tFalseR5R1R@RH(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR&s   G #R]RXtNUMBERtTOKENcCs9|djƒrtjS|tjkr1tj|SdSdS(Ni(tisalphaRR]RtopmapR(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_infoRRRkR9((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR)ÂscCstƒj|ƒS(N(RR5(RP((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR5Ës(t__doc__t __author__Rtpgen2RRRRRRtRRt ExceptionRRtobjectRR]RXRgRR_R\R)R5(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyt s .