Ñò §ÚêLc@sdZdZddkZddkZddklZdZhad„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ÿÿÿcCsltpUddkl}xB|iiƒD]-\}}t|ƒtjo|t|\}}||jo%|djodS|ii|dSq(WdS(s¤ The node immediately preceding the invocant in their parent's children list. If the invocant does not have a previous sibling, it is None. iiN(R(R*R:R)(RR;R>((s&/usr/lib64/python2.6/lib2to3/pytree.pyt prev_siblingÈs   cCs"|i}|djodS|iS(s Return the string immediately following the invocant node. This is effectively equivalent to node.next_sibling.prefix uN(R?R*R"(Rtnext_sib((s&/usr/lib64/python2.6/lib2to3/pytree.pyt get_suffixØs  iicCst|ƒidƒS(Ntascii(tunicodetencode(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyt__str__ãsN((ii(t__name__t __module__t__doc__R*RR(R)R'R9RRt__hash__RRRRRR#R$R4R8R.R<tpropertyR?R@RBtsyst version_infoRF(((s&/usr/lib64/python2.6/lib2to3/pytree.pyR "s0          tNodecBs©eZdZddd„Zd„Zd„Zeidjo eZ nd„Z d„Z d„Z d „Z d „Zd „ZeeeƒZd „Zd „Zd„ZRS(s+Concrete implementation for interior nodes.cCsS||_t|ƒ|_x|iD]}||_q"W|dj o ||_ndS(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. N(RR&R)R(R*R"(RRR)tcontextR"R2((s&/usr/lib64/python2.6/lib2to3/pytree.pyt__init__ës    cCs#d|iit|iƒ|ifS(s)Return a canonical string representation.s %s(%s, %r)(RRGR RR)(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyt__repr__ýs  cCsditt|iƒƒS(sk Return a pretty string representation. This reproduces the input source exactly. u(tjointmapRDR)(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyt __unicode__siicCs"|i|if|i|ifjS(sCompare two nodes for equality.(RR)(RR((s&/usr/lib64/python2.6/lib2to3/pytree.pyRscCs4t|ig}|iD]}||iƒq~ƒS(s$Return a cloned (deep) copy of self.(RNRR)R(Rt_[1]R2((s&/usr/lib64/python2.6/lib2to3/pytree.pyRsccs9x-|iD]"}x|iƒD] }|VqWq W|VdS(s*Return a post-order iterator for the tree.N(R)R(RR>R7((s&/usr/lib64/python2.6/lib2to3/pytree.pyRs    ccs9|Vx-|iD]"}x|iƒD] }|Vq"WqWdS(s)Return a pre-order iterator for the tree.N(R)R(RR>R7((s&/usr/lib64/python2.6/lib2to3/pytree.pyRs   cCs|ipdS|idiS(sO The whitespace and comments preceding this node in the input. ti(R)R"(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyt_prefix_getter$s cCs"|io||id_ndS(Ni(R)R"(RR"((s&/usr/lib64/python2.6/lib2to3/pytree.pyt_prefix_setter,s cCs4||_d|i|_||i|<|iƒdS(s… Equivalent to 'node.children[i] = child'. This method also sets the child's parent attribute appropriately. N(R(R*R)R.(RR;R>((s&/usr/lib64/python2.6/lib2to3/pytree.pyt set_child2s  cCs*||_|ii||ƒ|iƒdS(s‹ Equivalent to 'node.children.insert(i, child)'. This method also sets the child's parent attribute appropriately. N(R(R)tinsertR.(RR;R>((s&/usr/lib64/python2.6/lib2to3/pytree.pyt insert_child<s cCs'||_|ii|ƒ|iƒdS(sˆ Equivalent to 'node.children.append(child)'. This method also sets the child's parent attribute appropriately. N(R(R)R-R.(RR>((s&/usr/lib64/python2.6/lib2to3/pytree.pyt append_childEs N(ii(RGRHRIR*RPRQRTRLRMRFRRRRRWRXRKR"RYR[R\(((s&/usr/lib64/python2.6/lib2to3/pytree.pyRNçs           R5cBs eZdZdZdZdZd d d„Zd„Zd„Z e i djo e Z nd„Z d„Zd „Zd „Zd „Zd „ZeeeƒZRS(s'Concrete implementation for leaf nodes.RVicCs\|dj o|\|_\|_|_n||_||_|dj o ||_ndS(s— Initializer. Takes a type constant (a token number < 256), a string value, and an optional context keyword argument. N(R*t_prefixR6tcolumnRtvalue(RRR_ROR"((s&/usr/lib64/python2.6/lib2to3/pytree.pyRPXs     cCsd|ii|i|ifS(s)Return a canonical string representation.s %s(%r, %r)(RRGRR_(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyRQgs cCs|it|iƒS(sk Return a pretty string representation. This reproduces the input source exactly. (R"RDR_(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyRTmsicCs"|i|if|i|ifjS(sCompare two nodes for equality.(RR_(RR((s&/usr/lib64/python2.6/lib2to3/pytree.pyRxscCs+t|i|i|i|i|iffƒS(s$Return a cloned (deep) copy of self.(R5RR_R"R6R^(R((s&/usr/lib64/python2.6/lib2to3/pytree.pyR|sccs |VdS(s*Return a post-order iterator for the tree.N((R((s&/usr/lib64/python2.6/lib2to3/pytree.pyRsccs |VdS(s)Return a pre-order iterator for the tree.N((R((s&/usr/lib64/python2.6/lib2to3/pytree.pyR…scCs|iS(sP The whitespace and comments preceding this token in the input. (R](R((s&/usr/lib64/python2.6/lib2to3/pytree.pyRW‰scCs|iƒ||_dS(N(R.R](RR"((s&/usr/lib64/python2.6/lib2to3/pytree.pyRXs N(ii(RGRHRIR]R6R^R*RPRQRTRLRMRFRRRRRWRXRKR"(((s&/usr/lib64/python2.6/lib2to3/pytree.pyR5Os          cCsp|\}}}}|p||ijo0t|ƒdjo |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. iiRON(t number2symboltlenRNR5(tgrtraw_nodeRR_ROR)((s&/usr/lib64/python2.6/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 ti|ƒS(s>Constructor that prevents BasePattern from being instantiated.(RR(RRR((s&/usr/lib64/python2.6/lib2to3/pytree.pyR½scCskt|iƒ|i|ig}x$|o|ddjo |d=q!Wd|iiditt |ƒƒfS(Niÿÿÿÿs%s(%s)s, ( R RtcontentR R*RRGRRRStrepr(RR((s&/usr/lib64/python2.6/lib2to3/pytree.pyRQÂ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((s&/usr/lib64/python2.6/lib2to3/pytree.pytoptimizeÈscCsµ|idj o|i|ijotS|idj oQd}|dj o h}n|i||ƒptS|o|i|ƒq‰n|dj o|io|||i= 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. N( R*R&R:R%tWildcardPatternR,t wildcardsRRfR (RRRfR R;titem((s&/usr/lib64/python2.6/lib2to3/pytree.pyRP.s      cCsÔ|iodx\t|i|iƒD]E\}}|t|iƒjo#|dj o|i|ƒntSq WtSt|iƒt|iƒjotSx;t |i|iƒD]$\}}|i ||ƒptSq¨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( RtRpRfR)RaR*RjR,R'tzipRm(RR7RktcRlt subpatternR>((s&/usr/lib64/python2.6/lib2to3/pytree.pyRiKs      N(RGRHR'RtR*RPRi(((s&/usr/lib64/python2.6/lib2to3/pytree.pyRr*sRscBsheZdZd 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_|dj o*ttt|ƒƒ}x|D]}q)Wn||_||_||_||_dS(sÏ Initializer. Args: content: optional sequence of subsequences of patterns; if absent, matches one node; if present, each subsequence is an alternative [*] min: optinal minumum number of times to match, default 0 max: optional maximum number of times tro 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)* N(R*ttupleRSRftmintmaxR (RRfRzR{R talt((s&/usr/lib64/python2.6/lib2to3/pytree.pyRPus    cCs@d}|idj oEt|iƒdjo/t|idƒdjo|idd}n|idjo`|idjoP|idjotd|iƒS|dj o|i|ijo |iƒSn|idjoat|t ƒoQ|idjoA|i|ijo.t |i|i|i|i|i|iƒS|S(s+Optimize certain stacked wildcard patterns.iiR N( R*RfRaRzR{RrR RhR%Rs(RRx((s&/usr/lib64/python2.6/lib2to3/pytree.pyRh˜s 0   #    cCs|i|g|ƒS(s'Does this pattern exactly match a node?(Ro(RR7Rk((s&/usr/lib64/python2.6/lib2to3/pytree.pyRm«scCs{xt|i|ƒD]c\}}|t|ƒjoD|dj o2|i|ƒ|iot|ƒ||i s"   ÅhF V,=¹#