Ë
    ?d°  ã                   ór   — 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
y)
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 for 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y)Ú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                 ó  — dj                  t        j                  |«      «      }t        | |«      r t	        | |«      |«       yt        |t        j                  «      r| j                  |«       y| j                  |«       y)zVisit a node.z	Visit_{0}N)
Úformatr   ÚNodeNameÚhasattrÚgetattrÚ
isinstancer   ÚLeafÚDefaultLeafVisitÚDefaultNodeVisit)ÚselfÚnodeÚmethods      ú</usr/lib/python3/dist-packages/yapf/pytree/pytree_visitor.pyÚVisitzPyTreeVisitor.Visit9   sb   € à×Ñ¤× 5Ñ 5°dÓ ;Ó<€FÜˆtVÔà„gˆdFÓ˜DÕ!ä	Dœ&Ÿ+™+Ô	&Ø×Ñ˜dÕ#à×Ñ˜dÕ#ó    c                 óH   — |j                   D ]  }| j                  |«       Œ y)zÂDefault 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   s#   € ð —‘ò ˆØ
‡jjÕñr   c                  ó   — y)z¡Default 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   € ð 	r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   "   s   „ ñò,
$ò	ó	r   r   c                 ó<   — t        |«      }|j                  | «       y)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                   óL   ‡ — 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| _        y)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                 ót   — | j                   j                  dj                  d| j                  z  |«      «       y )Nz{0}{1}
ú )r)   Úwriter   r*   )r   Úss     r   Ú_DumpStringzPyTreeDumper._DumpString{   s.   € Ø×Ñ×Ñ˜j×/Ñ/°°d×6JÑ6JÑ0JÈAÓNÕOr   c                 óÈ   •— | j                  t        j                  |«      «       | xj                  dz  c_        t        t
        |   |«       | xj                  dz  c_        y )Né   )r0   r   ÚDumpNodeToStringr*   Úsuperr"   r   )r   r   Ú	__class__s     €r   r   zPyTreeDumper.DefaultNodeVisit~   sO   ø€ ð 	×Ñ”\×2Ñ2°4Ó8Ô9Ø×Ò˜AÑÕÜ	Œ,˜Ñ.¨tÔ4Ø×Ò˜AÑÖr   c                 óL   — | j                  t        j                  |«      «       y )N)r0   r   r3   r   s     r   r   zPyTreeDumper.DefaultLeafVisit†   s   € Ø×Ñ”\×2Ñ2°4Ó8Õ9r   )r   r   r   r    ÚsysÚstdoutr+   r0   r   r   Ú__classcell__)r5   s   @r   r"   r"   k   s&   ø„ ñð
 $'§:¡:ó òPôö:r   r"   )r    r7   Úlib2to3r   Úyapf.pytreer   Úobjectr   r8   r&   r"   r   r   r   ú<module>r=      s<   ðñó å å $ô6	Fô 6	ðr $'§:¡:ó ô :=õ :r   