3
QF>]                 @   sr   d dl Z e jdkZe jdkZer4e jZd dlmZ nd dlmZ G dd deZG dd deZ	G d	d
 d
Z
dS )    N      )UserListc               @   sP   e Zd Zg fddZdd Zer(dd Zdd Zd	d
 ZdddZ	dddZ
dS )ASTc             C   s   t || _tj| | d S )N)internkindr   __init__)selfr   Zkids r
   M/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/spark_parser/ast.pyr      s    
zAST.__init__c             C   s   | j || S )N)data)r	   lowhighr
   r
   r   __getslice__   s    zAST.__getslice__c             C   s
   | j | S )N)r   )r	   ir
   r
   r   __getitem__   s    zAST.__getitem__c             C   s0   t |tr"| j|jko tj| |S | j|kS d S )N)
isinstancer   r   r   __eq__)r	   or
   r
   r   r      s    
z
AST.__eq__c             C   s
   t | jS )N)hashr   )r	   r
   r
   r   __hash__    s    zAST.__hash__ c             C   s   | j |d S )N)	__repr1__)r	   indentr
   r
   r   __repr__#   s    zAST.__repr__Nc             C   s   t | j}|d k	rd||f }d}t| dkrB|dt|  7 }d}|| }|d7 }d}xp| D ]h}t|dr|r||j||}q|j|d }n&|r|d|t |f  }n|t | }|d	| 7 }|d7 }q\W |S )
Nz%d. %sF   z (%d)Tz  r   r   
)strr   lenhasattrr   )r	   r   ZsibNumrvZenumerate_childrenr   nodechildr
   r
   r   r   &   s*    


zAST.__repr1__)r   )N)__name__
__module____qualname__r   r   PYTHON37r   r   r   r   r   r
   r
   r
   r   r      s   
r   c               @   s   e Zd ZdS )#GenericASTTraversalPruningExceptionN)r#   r$   r%   r
   r
   r
   r   r'   A   s   r'   c               @   sD   e Zd ZdZdd Zdd Zdd Zdd	d
ZdddZdd Z	dS )GenericASTTraversala  
    GenericASTTraversal is a Visitor pattern according to Design Patterns.  For
    each node it attempts to invoke the method n_<node type>, falling
    back onto the default() method if the n_* can't be found.  The preorder
    traversal also looks for an exit hook named n_<node type>_exit (no default
    routine is called if it's not found).  To prematurely halt traversal
    of a subtree, call the prune() method -- this only makes sense for a
    preorder traversal.  Node type is determined via the typestring() method.
    c             C   s
   || _ d S )N)ast)r	   r)   r
   r
   r   r   N   s    zGenericASTTraversal.__init__c             C   s   |j S )N)r   )r	   r!   r
   r
   r   
typestringQ   s    zGenericASTTraversal.typestringc             C   s   t d S )N)r'   )r	   r
   r
   r   pruneT   s    zGenericASTTraversal.pruneNc             C   s   |dkr| j }y:d| j| }t| |r<t| |}|| n
| j| W n tk
r\   dS X x|D ]}| j| qdW |d }t| |rt| |}|| dS )a  Walk the tree in roughly 'preorder' (a bit of a lie explained below).
        For each node with typestring name *name* if the
        node has a method called n_*name*, call that before walking
        children. If there is no method define, call a
        self.default(node) instead. Subclasses of GenericASTTtraversal
        ill probably want to override this method.

        If the node has a method called *name*_exit, that is called
        after all children have been called.

        In typical use a node with children can call "preorder" in any
        order it wants which may skip children or order then in ways
        other than first to last.  In fact, this this happens.  So in
        this sense this function not strictly preorder.
        Nn__exit)r)   r*   r   getattrdefaultr'   preorder)r	   r!   namefunckidr
   r
   r   r0   W   s     





zGenericASTTraversal.preorderc             C   s   |dkr| j }yt|}W n tk
r2   d}Y nX |rPx|D ]}| j| q>W y:d| j| }t| |r~t| |}|| n
| j| W n tk
r   dS X |d }t| |rt| |}|| dS )a  Walk the tree in roughly 'postorder' (a bit of a lie
        explained below).

        For each node with typestring name *name* if the
        node has a method called n_*name*, call that before walking
        children. If there is no method define, call a
        self.default(node) instead. Subclasses of GenericASTTtraversal
        ill probably want to override this method.

        If the node has a method called *name*_exit, that is called
        after all children have been called.  So in this sense this
        function is a lie.

        In typical use a node with children can call "postorder" in
        any order it wants which may skip children or order then in
        ways other than first to last.  In fact, this this happens.
        Nr,   r-   )	r)   iter	TypeError	postorderr*   r   r.   r/   r'   )r	   r!   firstr3   r1   r2   r
   r
   r   r6   |   s*    






zGenericASTTraversal.postorderc             C   s   dS )zDefault action to take on an ASTNode. Our defualt is to do nothing.
        Subclasses will probably want to define this for other behavior.Nr
   )r	   r!   r
   r
   r   r/      s    zGenericASTTraversal.default)N)N)
r#   r$   r%   __doc__r   r*   r+   r0   r6   r/   r
   r
   r
   r   r(   D   s   	
%
-r(   )r   r   )r   r   )sysversion_infoZPYTHON3r&   r   collectionsr   r   BaseExceptionr'   r(   r
   r
   r
   r   <module>   s   

4