
    ":h3                         d Z ddlmZ ddlmZmZ ddlmZmZ  G d de	      Z
 G d d	e
      Z G d
 de      Z G d de	e      Zd Zy)zNodes that make up parse trees

Parsing spits out a tree of these, which you can then tell to walk itself and
spit out a useful value. Or you can walk it yourself; the structural attributes
are public.

    )
isfunction)version_infoexc_info   )VisitationErrorUndefinedLabelc                   h    e Zd ZdZg dZddZed        Zd Zed        Z	ddZ
d	 Zd
 Zd ZddZy)Nodea  A parse tree node

    Consider these immutable once constructed. As a side effect of a
    memory-saving strategy in the cache, multiple references to a single
    ``Node`` might be returned in a single parse tree. So, if you start
    messing with one, you'll see surprising parallel changes pop up elsewhere.

    My philosophy is that parse trees (and their nodes) should be
    representation-agnostic. That is, they shouldn't get all mixed up with what
    the final rendered form of a wiki page (or the intermediate representation
    of a programming language, or whatever) is going to be: you should be able
    to parse once and render several representations from the tree, one after
    another.

    expr	full_textstartendchildrenNc                 R    || _         || _        || _        || _        |xs g | _        y Nr   )selfr   r   r   r   r   s         e/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/static_dependencies/parsimonious/nodes.py__init__zNode.__init__(   s)    	"
 B    c                 .    | j                   j                  S r   )r   namer   s    r   	expr_namezNode.expr_name/   s     yy~~r   c                 ,    t        | j                        S )zSupport looping over my children and doing tuple unpacks on me.

        It can be very handy to unpack nodes in arg lists; see
        :class:`PegVisitor` for an example.

        )iterr   r   s    r   __iter__zNode.__iter__4   s     DMM""r   c                 H    | j                   | j                  | j                   S )z"Return the text this node matched.)r   r   r   r   s    r   textz	Node.text=   s     ~~djj22r   c                     d }d| j                   j                  | j                  rd| j                  z  ndd| j                  d|| u rdndg}| D ])  }|j	                   ||j                  |                   + d	j                  |      S )
zReturn a unicode, pretty-printed representation of me.

        :arg error: The node to highlight because an error occurred there

        c                 N    dj                  d | j                         D              S )N
c              3   &   K   | ]	  }d |z     yw)z    N ).0lines     r   	<genexpr>z0Node.prettily.<locals>.indent.<locals>.<genexpr>M   s     KftmKs   )join
splitlines)r   s    r   indentzNode.prettily.<locals>.indentL   s    99K9JKKKr   <z called "%s" z matching "z">z  <-- *** We were here. ***)errorr"   )	__class____name__r   r   appendprettilyr(   )r   r-   r*   retns        r   r1   zNode.prettilyD   s    	L NN##15^dnn,RGII-2d])B	D E
  	8AJJvajjuj567	8yy~r   c                 "    | j                         S )z6Return a compact, human-readable representation of me.)r1   r   s    r   __str__zNode.__str__W   s    }}r   c                 8   t        |t              st        S | j                  |j                  k(  xrj | j                  |j                  k(  xrO | j
                  |j
                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S )z>Support by-value deep comparison with other nodes for testing.)
isinstancer
   NotImplementedr   r   r   r   r   r   others     r   __eq__zNode.__eq__[   s    %&!!		UZZ' 0%//10

ekk)0 EII%0 /		1r   c                     | |k(   S r   r$   r9   s     r   __ne__zNode.__ne__f   s    5=  r   c                    |rd| j                   z  gng }|j                  | j                  j                  d| j                  d| j
                  d| j                  | j                  r<ddj                  | j                  D cg c]  }|j                  d       c}      z  ndd		       d
j                  |      S c c}w )zNReturn a bit of code (though not an expression) that will recreate
        me.zs = %r(z, s, z, z, children=[%s]F)	top_levelr,   )r"   )
r   r0   r.   r/   r   r   r   r   r(   __repr__)r   r@   r2   cs       r   rB   zNode.__repr__i   s    
 .7x$..()B

NN##IIJJHH }} YYT]]K

U
3KLM"$%& 	' yy~ Ls   B?r   )T)r/   
__module____qualname____doc__	__slots__r   propertyr   r   r   r1   r5   r;   r=   rB   r$   r   r   r
   r
      sY    "I'  # 3 3&	1!r   r
   c                       e Zd ZdZdgZy)	RegexNodezNode returned from a ``Regex`` expression

    Grants access to the ``re.Match`` object, in case you want to access
    capturing groups, etc.

    matchN)r/   rD   rE   rF   rG   r$   r   r   rJ   rJ   z   s     	Ir   rJ   c                        e Zd Z fdZ xZS )RuleDecoratorMetac                 P   d |j                         D cg c]  \  }}t        |d      rt        |      r|  }}}|rKddlm} |j                  t        d   dk  rd nd 	        |d
j                  fd|D                    |d<   t        t        | +  | |||      S c c}}w )Nc                 2    | j                  d      r| dd S | S )z/Remove any leading "visit_" from a method name.visit_   N)
startswith)r   s    r   unvisitz*RuleDecoratorMeta.__new__.<locals>.unvisit   s    #x848BdBr   _ruler   )Grammarr      c                 .    | j                   j                  S r   )	func_codeco_firstlinenoxs    r   <lambda>z+RuleDecoratorMeta.__new__.<locals>.<lambda>   s    (B(B r   c                 .    | j                   j                  S r   )__code__rY   rZ   s    r   r\   z+RuleDecoratorMeta.__new__.<locals>.<lambda>   s    

(A(A r   )keyr"   c              3   x   K   | ]1  }d j                   |j                        |j                         3 yw)z{name} = {expr})r   r   N)formatr/   rT   )r%   mrS   s     r   r'   z,RuleDecoratorMeta.__new__.<locals>.<genexpr>   s<      , ,22

8K89 3 A ,s   7:grammar)itemshasattrr   rc   rU   sortr   r(   superrM   __new__)
	metaclassr   bases	namespacekvmethodsrU   rS   r.   s
           @r   rh   zRuleDecoratorMeta.__new__   s    	C "+!2 :A1g&:a=  : :(LL ,Q! 3 CA  D $+		 ,#*, ,$-Ii  &((14	 J	K:s   #B")r/   rD   rE   rh   __classcell__)r.   s   @r   rM   rM      s    K Kr   rM   c                   @    e Zd ZdZdZdZd Zd Zd
dZd
dZ	d Z
d	 Zy)NodeVisitora}  A shell for writing things that turn parse trees into something useful

    Performs a depth-first traversal of an AST. Subclass this, add methods for
    each expr you care about, instantiate, and call
    ``visit(top_node_of_parse_tree)``. It'll return the useful stuff. This API
    is very similar to that of ``ast.NodeVisitor``.

    These could easily all be static methods, but that would add at least as
    much weirdness at the call site as the ``()`` for instantiation. And this
    way, we support subclasses that require state: options, for example, or a
    symbol table constructed from a programming language's AST.

    We never transform the parse tree in place, because...

    * There are likely multiple references to the same ``Node`` object in a
      parse tree, and changes to one reference would surprise you elsewhere.
    * It makes it impossible to report errors: you'd end up with the "error"
      arrow pointing someplace in a half-transformed mishmash of nodes--and
      that's assuming you're even transforming the tree into another tree.
      Heaven forbid you're making it into a string or something else.

    Nr$   c           	      @   t        | d|j                  z   | j                        }	  |||D cg c]  }| j                  |       c}      S c c}w # t        t
        f$ r  t        $ r4}t        || j                        r t        |      }t	        |||      d}~ww xY w)a  Walk a parse tree, transforming it into another representation.

        Recursively descend a parse tree, dispatching to the method named after
        the rule in the :class:`~.grammar.Grammar` that produced
        each node. If, for example, a rule was... ::

            bold = '<b>'

        ...the ``visit_bold()`` method would be called. It is your
        responsibility to subclass :class:`NodeVisitor` and implement those
        methods.

        rP   N)
getattrr   generic_visitvisitr   r   	Exceptionr7   unwrapped_exceptionstype)r   nodemethodr3   exc	exc_classs         r   ru   zNodeVisitor.visit   s     x$..8$:L:LM	8$ =1A =>> =0 	 	8 #t889 S	I!#y$77	8s(   A A
A A B)/BBc                 N    t        d|j                  j                         z        )ae  Default visitor method

        :arg node: The node we're visiting
        :arg visited_children: The results of visiting the children of that
            node, in a list

        I'm not sure there's an implementation of this that makes sense across
        all (or even most) use cases, so we leave it to subclasses to implement
        for now.

        z5No visitor method was defined for this expression: %s)NotImplementedErrorr   as_rule)r   ry   visited_childrens      r   rt   zNodeVisitor.generic_visit   s)     ""Y"&))"3"3"5#6 7 	7r   c                 (    | j                  ||d      S )zParse some text with this Visitor's default grammar and return the
        result of visiting it.

        ``SomeVisitor().parse('some_string')`` is a shortcut for
        ``SomeVisitor().visit(some_grammar.parse('some_string'))``.

        parse_parse_or_matchr   r   poss      r   r   zNodeVisitor.parse        ##D#w77r   c                 (    | j                  ||d      S )a
  Parse and visit some text with this Visitor's default grammar, but
        don't insist on parsing all the way to the end.

        ``SomeVisitor().match('some_string')`` is a shortcut for
        ``SomeVisitor().visit(some_grammar.match('some_string'))``.

        rK   r   r   s      r   rK   zNodeVisitor.match   r   r   c                     |\  }|S )z7Lift the sole child of ``node`` up to replace the node.r$   )r   ry   r   first_childs       r   
lift_childzNodeVisitor.lift_child
  s    r   c                     | j                   s0t        dj                  | j                  j                  |            | j                   t        | j                   |      ||            S )zExecute a parse or match on the default grammar, followed by a
        visitation.

        Raise RuntimeError if there is no default grammar specified.

        zThe {cls}.{method}() shortcut won't work because {cls} was never associated with a specific grammar. Fill out its `grammar` attribute, and try again.)clsrz   )r   )rc   RuntimeErrorra   r.   r/   ru   rs   )r   r   r   method_names       r   r   zNodeVisitor._parse_or_match  sb     ||66<f//& 7= 7() ) zz<'$,,<TsKLLr   )r   )r/   rD   rE   rF   rc   rw   ru   rt   r   rK   r   r   r$   r   r   rq   rq      s6    4 G
 
8B7"88Mr   rq   )ri   c                       fd}|S )a  Decorate a NodeVisitor ``visit_*`` method to tie a grammar rule to it.

    The following will arrange for the ``visit_digit`` method to receive the
    results of the ``~"[0-9]"`` parse rule::

        @rule('~"[0-9]"')
        def visit_digit(self, node, visited_children):
            ...

    Notice that there is no "digit = " as part of the rule; that gets inferred
    from the method name.

    In cases where there is only one kind of visitor interested in a grammar,
    using ``@rule`` saves you having to look back and forth between the visitor
    and the grammar definition.

    On an implementation level, all ``@rule`` rules get stitched together into
    a :class:`~.Grammar` that becomes the NodeVisitor's
    :term:`default grammar`.

    Typically, the choice of a default rule for this grammar is simple: whatever
    ``@rule`` comes first in the class is the default. But the choice may become
    surprising if you divide the ``@rule`` calls among subclasses. At the
    moment, which method "comes first" is decided simply by comparing line
    numbers, so whatever method is on the smallest-numbered line will be the
    default. In a future release, this will change to pick the
    first ``@rule`` call on the basemost class that has one. That way, a
    subclass which does not override the default rule's ``visit_*`` method
    won't unintentionally change which rule is the default.

    c                     | _         | S r   )rT   )rz   rule_strings    r   	decoratorzrule.<locals>.decoratorB  s    "r   r$   )r   r   s   ` r   ruler   "  s    @ r   N)rF   inspectr   sysr   r   
exceptionsr   r   objectr
   rJ   rx   rM   rq   r   r$   r   r   <module>r      sW     & 7h6 hV K K2BM&$5 BMJ#r   