
    `N`                     v    d Z ddlZddlmZ ddlmZ  G d de          Zej        fdZ	 G d d	e          Z
dS )
a  Generic visitor pattern for pytrees.

The lib2to3 parser produces a "pytree" - syntax tree consisting of Node
and Leaf types. This module implements a visitor pattern for such trees.

It also exports a basic "dumping" visitor that dumps a textual representation of
a pytree into a stream.

  PyTreeVisitor: a generic visitor pattern fo pytrees.
  PyTreeDumper: a configurable "dumper" for displaying pytrees.
  DumpPyTree(): a convenience function to dump a pytree.
    N)pytree)pytree_utilsc                   $    e Zd ZdZd Zd Zd ZdS )PyTreeVisitora  Visitor pattern for pytree trees.

  Methods named Visit_XXX will be invoked when a node with type XXX is
  encountered in the tree. The type is either a token type (for Leaf nodes) or
  grammar symbols (for Node nodes). The return value of Visit_XXX methods is
  ignored by the visitor.

  Visitors can modify node contents but must not change the tree structure
  (e.g. add/remove children and move nodes around).

  This is a very common visitor pattern in Python code; it's also used in the
  Python standard library ast module for providing AST visitors.

  Note: this makes names that aren't style conformant, so such visitor methods
  need to be marked with # pylint: disable=invalid-name We don't have a choice
  here, because lib2to3 nodes have under_separated names.

  For more complex behavior, the visit, DefaultNodeVisit and DefaultLeafVisit
  methods can be overridden. Don't forget to invoke DefaultNodeVisit for nodes
  that may have children - otherwise the children will not be visited.
  c                 6   d                     t          j        |                    }t          | |          r t	          | |          |           dS t          |t          j                  r|                     |           dS | 	                    |           dS )zVisit a node.z	Visit_{0}N)
formatr   NodeNamehasattrgetattr
isinstancer   LeafDefaultLeafVisitDefaultNodeVisit)selfnodemethods      ;lib/python3.11/site-packages/yapf/yapflib/pytree_visitor.pyVisitzPyTreeVisitor.Visit9   s     5d ; ;<<FtV $gdFD!!!!!	D&+	&	& $d#####d#####    c                 D    |j         D ]}|                     |           dS )zDefault visitor for Node: visits the node's children depth-first.

    This method is invoked when no specific visitor for the node is defined.

    Arguments:
      node: the node to visit
    N)childrenr   )r   r   childs      r   r   zPyTreeVisitor.DefaultNodeVisitE   s4       
jj r   c                     dS )zDefault visitor for Leaf: no-op.

    This method is invoked when no specific visitor for the leaf is defined.

    Arguments:
      leaf: the leaf to visit
    N r   leafs     r   r   zPyTreeVisitor.DefaultLeafVisitP   s	     	Dr   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   "   sK         ,
$ 
$ 
$	 	 		 	 	 	 	r   r   c                 N    t          |          }|                    |            dS )az  Convenience function for dumping a given pytree.

  This function presents a very minimal interface. For more configurability (for
  example, controlling how specific node types are displayed), use PyTreeDumper
  directly.

  Arguments:
    tree: the tree to dump.
    target_stream: the stream to dump the tree to. A file-like object. By
      default will dump into stdout.
  N)PyTreeDumperr   )treetarget_streamdumpers      r   
DumpPyTreer&   [   s)     &&&,,tr   c                   B     e Zd ZdZej        fdZd Z fdZd Z	 xZ
S )r"   zVVisitor that dumps the tree to a stream.

  Implements the PyTreeVisitor interface.
  c                 "    || _         d| _        dS )zCreate a tree dumper.

    Arguments:
      target_stream: the stream to dump the tree to. A file-like object. By
        default will dump into stdout.
    r   N)_target_stream_current_indent)r   r$   s     r   __init__zPyTreeDumper.__init__q   s     (DDr   c                 r    | j                             d                    d| j        z  |                     d S )Nz{0}{1}
 )r)   writer   r*   )r   ss     r   _DumpStringzPyTreeDumper._DumpString{   s7    j//d6J0JANNOOOOOr   c                     |                      t          j        |                     | xj        dz  c_        t	          t
          |                               |           | xj        dz  c_        d S )N   )r0   r   DumpNodeToStringr*   superr"   r   )r   r   	__class__s     r   r   zPyTreeDumper.DefaultNodeVisit~   sp     	\2488999A	,..t444Ar   c                 T    |                      t          j        |                     d S )N)r0   r   r3   r   s     r   r   zPyTreeDumper.DefaultLeafVisit   s'    \248899999r   )r   r   r   r    sysstdoutr+   r0   r   r   __classcell__)r5   s   @r   r"   r"   k   s~         
 $':    P P P    : : : : : : :r   r"   )r    r7   lib2to3r   yapf.yapflibr   objectr   r8   r&   r"   r   r   r   <module>r=      s     


       % % % % % %6	 6	 6	 6	 6	F 6	 6	 6	r $':     : : : : := : : : : :r   