ó ^ bc@sdZdZddlZddlZddlmZdZiad„Zdefd„ƒYZ d e fd „ƒYZ d e fd „ƒYZ d „Z defd„ƒYZ de fd„ƒYZde fd„ƒYZde fd„ƒYZde fd„ƒYZd„ZdS(sÌ Python parse tree definitions. This is a very concrete parse tree; we need to keep every token and even the comments and whitespace between tokens. There's also a pattern matching implementation here. s#Guido van Rossum iÿÿÿÿN(tStringIOiÿÿÿcCshtsXddlm}x?|jjƒD]+\}}t|ƒtkr&|t|tpropertyRARBRCRDRFtsyst version_infoRJ(((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR s6            tNodecBsªeZdZdddd„Zd„Zd„ZejdkrHeZ nd„Z d„Z d„Z d „Z d „Zd „ZeeeƒZd „Zd „Zd„ZRS(s+Concrete implementation for interior nodes.cCs¦|dkst|ƒ‚||_t|ƒ|_x;|jD]0}|jdksatt|ƒƒ‚||_q:W|dk r†||_n|r™||_n d|_dS(sð Initializer. Takes a type constant (a symbol number >= 256), a sequence of child nodes, and an optional context keyword argument. As a side effect, the parent pointers of the children are updated. iN( RRR*R,R&R'treprR#tfixers_applied(RRR,tcontextR#RUR4((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt__init__ós  !    cCs#d|jjt|jƒ|jfS(s)Return a canonical string representation.s %s(%s, %r)(RRKR RR,(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt__repr__ s  cCsdjtt|jƒƒS(sk Return a pretty string representation. This reproduces the input source exactly. u(tjointmapRHR,(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt __unicode__siicCs"|j|jf|j|jfkS(sCompare two nodes for equality.(RR,(RR((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRscCs5t|jg|jD]}|jƒ^qd|jƒS(s$Return a cloned (deep) copy of self.RU(RSRR,RRU(RR4((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR!s+ccs9x-|jD]"}x|jƒD] }|VqWq W|VdS(s*Return a post-order iterator for the tree.N(R,R(RR@R9((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR&s ccs9|Vx-|jD]"}x|jƒD] }|Vq"WqWdS(s)Return a pre-order iterator for the tree.N(R,R(RR@R9((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR-scCs|js dS|jdjS(sO The whitespace and comments preceding this node in the input. ti(R,R#(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt_prefix_getter4s cCs |jr||jd_ndS(Ni(R,R#(RR#((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt_prefix_setter<s cCs4||_d|j|_||j|<|jƒdS(s… Equivalent to 'node.children[i] = child'. This method also sets the child's parent attribute appropriately. N(R&R'R,R0(RR=R@((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt set_childBs  cCs*||_|jj||ƒ|jƒdS(s‹ Equivalent to 'node.children.insert(i, child)'. This method also sets the child's parent attribute appropriately. N(R&R,tinsertR0(RR=R@((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt insert_childLs cCs'||_|jj|ƒ|jƒdS(sˆ Equivalent to 'node.children.append(child)'. This method also sets the child's parent attribute appropriately. N(R&R,R/R0(RR@((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyt append_childUs N(ii(RKRLRMR'RWRXR[RQRRRJRRRRR]R^RPR#R_RaRb(((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRSïs$           R7cBsªeZdZdZdZdZddgd„Zd„Zd„Z e j dkrZe Z nd„Z d„Zd „Zd „Zd „Zd „Zd „ZeeeƒZRS(s'Concrete implementation for leaf nodes.R\icCsŠd|kodkns(t|ƒ‚|dk rR|\|_\|_|_n||_||_|dk r|||_n||_dS(s— Initializer. Takes a type constant (a token number < 256), a string value, and an optional context keyword argument. iiN(RR't_prefixR8tcolumnRtvalueRU(RRReRVR#RU((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRWhs (     cCsd|jj|j|jfS(s)Return a canonical string representation.s %s(%r, %r)(RRKRRe(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRX{s cCs|jt|jƒS(sk Return a pretty string representation. This reproduces the input source exactly. (R#RHRe(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR[sicCs"|j|jf|j|jfkS(sCompare two nodes for equality.(RRe(RR((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRŒscCs4t|j|j|j|j|jffd|jƒS(s$Return a cloned (deep) copy of self.RU(R7RReR#R8RdRU(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRsccs |VdS(N((R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRC–sccs |VdS(s*Return a post-order iterator for the tree.N((R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR™sccs |VdS(s)Return a pre-order iterator for the tree.N((R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRscCs|jS(sP The whitespace and comments preceding this token in the input. (Rc(R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR]¡scCs|jƒ||_dS(N(R0Rc(RR#((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR^§s N(ii(RKRLRMRcR8RdR'RWRXR[RQRRRJRRRCRRR]R^RPR#(((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyR7_s&           cCsk|\}}}}|s'||jkrTt|ƒdkrA|dSt||d|ƒSt||d|ƒSdS(sõ Convert raw node information to a Node or Leaf instance. This is passed to the parser driver which calls it whenever a reduction of a grammar rule produces a new complete node, so that the tree is build strictly bottom-up. iiRVN(t number2symboltlenRSR7(tgrtraw_nodeRReRVR,((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pytconvert­s t BasePatterncBs\eZdZdZdZdZd„Zd„Zd„Z dd„Z dd„Z d„Z RS(s” A pattern is a tree matching pattern. It looks for a specific node type (token or symbol), and optionally for a specific content. This is an abstract base class. There are three concrete subclasses: - LeafPattern matches a single leaf node; - NodePattern matches a single node (usually non-leaf); - WildcardPattern matches a sequence of nodes of variable length. cOs%|tk stdƒ‚tj|ƒS(s>Constructor that prevents BasePattern from being instantiated.sCannot instantiate BasePattern(RkRRR(RRR((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRÕscCsht|jƒ|j|jg}x!|rA|ddkrA|d=q!Wd|jjdjtt |ƒƒfS(Niÿÿÿÿs%s(%s)s, ( R RtcontentR R'RRKRYRZRT(RR((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRXÚs cCs|S(sŒ A subclass can define this as a hook for optimizations. Returns either self or another node with the same effect. ((R((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pytoptimizeàscCs§|jdk r%|j|jkr%tS|jdk r~d}|dk rOi}n|j||ƒsetS|r~|j|ƒq~n|dk r£|jr£|||j= 256). If the type is None this matches *any* single node (leaf or not), except if content is not None, in which it only matches non-leaf nodes that also match the content pattern. The content, if not None, must be a sequence of Patterns that must match the node's children exactly. If the content is given, the type must not be None. If a name is given, the matching node is stored in the results dict under that key. iN(R'RR)RwRTR*R<RktWildcardPatternR.t wildcardsRRlR (RRRlR R=titem((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRWFs  " !  cCsÊ|jrhxXt|j|jƒD]A\}}|t|jƒkr|dk r\|j|ƒntSqWtSt|jƒt|jƒkrŠtSx9t |j|jƒD]"\}}|j ||ƒs tSq WtS(s„ Match the pattern's content to the node's children. This assumes the node type matches and self.content is not None. Returns True if it matches, False if not. If results is not None, it must be a dict which will be updated with the nodes matching named subpatterns. When returning False, the results dict may still be updated. N( RzRuRlR,RgR'RoR.R+tzipRr(RR9RptcRqt subpatternR@((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRncs " "N(RKRLR+RzR'RWRn(((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRxBsRycBsheZdZd ded d„Zd„Zd d„Zd d„Zd„Z d„Z d„Z d „Z RS( s A wildcard pattern can match zero or more nodes. This has all the flexibility needed to implement patterns like: .* .+ .? .{m,n} (a b c | d e | f) (...)* (...)+ (...)? (...){m,n} except it always uses non-greedy matching. icCsÒd|ko"|ko"tkns9t||fƒ‚|dk rªttt|ƒƒ}t|ƒsxtt|ƒƒ‚x/|D]$}t|ƒstt|ƒƒ‚qWn||_||_||_ ||_ dS(sÏ Initializer. Args: content: optional sequence of subsequences of patterns; if absent, matches one node; if present, each subsequence is an alternative [*] min: optional minimum number of times to match, default 0 max: optional maximum number of times to match, default HUGE name: optional name assigned to this match [*] Thus, if content is [[a, b, c], [d, e], [f, g, h]] this is equivalent to (a b c | d e | f g h); if content is None, this is equivalent to '.' in regular expression terms. The min and max parameters work as follows: min=0, max=maxint: .* min=1, max=maxint: .+ min=0, max=1: .? min=1, max=1: . If content is not None, replace the dot with the parenthesized list of alternatives, e.g. (a b c | d e | f g h)* iN( tHUGERR'ttupleRZRgRTRltmintmaxR (RRlRR‚R talt((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRWs9  %   cCs/d}|jdk rWt|jƒdkrWt|jdƒdkrW|jdd}n|jdkr¿|jdkr¿|jdkr”td|jƒS|dk r¿|j|jkr¿|jƒSn|jdkr+t|t ƒr+|jdkr+|j|jkr+t |j|j|j|j|j|jƒS|S(s+Optimize certain stacked wildcard patterns.iiR N( R'RlRgRR‚RxR RmR)Ry(RR~((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRm°s . !    cCs|j|g|ƒS(s'Does this pattern exactly match a node?(Rt(RR9Rp((s3/opt/alt/python27/lib64/python2.7/lib2to3/pytree.pyRrÃscCsuxn|j|ƒD]]\}}|t|ƒkr|dk ri|j|ƒ|jrit|ƒ||j s"   ÏpN V,=¼#