ó o”þfc@sdZdZddlZddlZddlmZmZmZmZm Z m Z ddl m Z ddl m Z ejjejjeƒdƒZd efd „ƒYZd „Zd efd „ƒYZiejd6ejd6ejd6dd6Zd„Zd„Zd„ZdS(sPattern compiler. The grammer is taken from PatternGrammar.txt. The compiler compiles a pattern to a pytree.*Pattern instance. s#Guido van Rossum iÿÿÿÿNi(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   tPatternCompilercBsAeZed„Zeed„Zd„Zdd„Zd„Z 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 CsT|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 AlternativesR.tlenRtWildcardPatterntoptimizet Alternativet NegatedUnitt compile_basictNegatedPatterntNoneRtEQUALRtRepeatertSTARtHUGEtPLUStLBRACEtget_inttname(R'tnodetchtaltstatptunitstpatternRGtnodestrepeatR6tchildR3R4((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR.Ds^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[R3R4(RRtSTRINGtunicodeRt evalStringRRt LeafPatternt_type_of_literaltNAMEtisuppert TOKEN_MAPRR?t startswithtgetattrR$R.R6t NodePatternR9(R'RORPRHRRtcontentt subpattern((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR=‹s8          cCs t|jƒS(N(tintR(R'RH((s'/usr/lib64/python2.7/lib2to3/patcomp.pyRF®sN( R R t_PATTERN_GRAMMAR_FILER)tFalseR2R.R?R=RF(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR+s   G #R[RVtNUMBERtTOKENcCs9|djƒrtjS|tjkr1tj|SdSdS(Ni(tisalphaRR[RtopmapR?(R((s'/usr/lib64/python2.7/lib2to3/patcomp.pyRZº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_infoRRRjR6((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR&ÃscCstƒj|ƒS(N(RR2(RN((s'/usr/lib64/python2.7/lib2to3/patcomp.pyR2Ìs( t__doc__t __author__tosRtpgen2RRRRRRtRRtpathtjointdirnamet__file__Rdt ExceptionRRtobjectRR[RVRfR?R]RZR&R2(((s'/usr/lib64/python2.7/lib2to3/patcomp.pyt s$  .  ‰