
    E#i3                         S r SSKJr  SSKJrJr  SSKJrJr   " S S\	5      r
 " S S	\
5      r " S
 S\5      r " S S\	\S9rS rg)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                   v    \ rS rSrSr/ SQrSS jr\S 5       rS r	\S 5       r
SS	 jrS
 rS rS rSS jrSrg)Node   a  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                 T    Xl         X l        X0l        X@l        U=(       d    / U l        g Nr   )selfr   r   r   r   r   s         e/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/parsimonious/nodes.py__init__Node.__init__(   s!    	"
 B    c                 .    U R                   R                  $ r   )r   namer   s    r   	expr_nameNode.expr_name/   s     yy~~r   c                 ,    [        U R                  5      $ )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__Node.__iter__4   s     DMM""r   c                 H    U R                   U R                  U R                   $ )z"Return the text this node matched.)r   r   r   r   s    r   text	Node.text=   s     ~~djj22r   c           	      0   S nSU R                   R                  < U R                  (       a  SU R                  -  OS< SU R                  < SXL a  SOS< 3/nU  H'  nUR	                  U" UR                  US95      5        M)     S	R                  U5      $ )
z{Return a unicode, pretty-printed representation of me.

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

c                 N    SR                  S U R                  5        5       5      $ )N
c              3   ,   #    U  H
  nS U-   v   M     g7f)z    N ).0lines     r   	<genexpr>0Node.prettily.<locals>.indent.<locals>.<genexpr>M   s     K9Jftm9Js   )join
splitlines)r#   s    r   indent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   r4   r0   retns        r   r8   Node.prettilyD   s    	L NN##15^dnn,RGII-2])B	D E
 AJJvajjuj567 yy~r   c                 "    U R                  5       $ )z6Return a compact, human-readable representation of me.)r8   r   s    r   __str__Node.__str__W   s    }}r   c                 j   [        U[        5      (       d  [        $ U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R
                  UR
                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ )z>Support by-value deep comparison with other nodes for testing.)
isinstancer
   NotImplementedr   r   r   r   r   r   others     r   __eq__Node.__eq__[   s    %&&!!		UZZ' 0%//10

ekk)0 EII%0 /		1r   c                     X:X  + $ r   r)   rB   s     r   __ne__Node.__ne__f   s      r   c                    U(       a  SU R                   -  /O/ nUR                  U R                  R                  < SU R                  < SU R
                  < SU R                  < U R                  (       a;  SSR                  U R                   Vs/ s H  o3R                  SS9PM     sn5      -  OS< S	3	5        S
R                  U5      $ s  snf )zFReturn a bit of code (though not an expression) that will recreate
me.zs = %r(z, s, z, z, children=[%s]F)	top_levelr3   )r'   )
r   r7   r5   r6   r   r   r   r   r.   __repr__)r   rK   r9   cs       r   rM   Node.__repr__i   s    
 .7x$..()B

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

U
3]KLM"$%& 	' yy~ Ls   C)r   r   r   r   r   r   )T)r6   
__module____qualname____firstlineno____doc__	__slots__r   propertyr   r    r#   r8   r=   rD   rG   rM   __static_attributes__r)   r   r   r
   r
      sY    "I'  # 3 3&	1!r   r
   c                       \ rS rSrSrS/rSrg)	RegexNodez   zNode returned from a ``Regex`` expression

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

matchr)   N)r6   rP   rQ   rR   rS   rT   rV   r)   r   r   rX   rX   z   s     	Ir   rX   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )RuleDecoratorMeta   c                 t  >^ S mUR                  5        VVs/ s H,  u  pE[        US5      (       d  M  [        U5      (       d  M*  UPM.     nnnU(       aJ  SSKJn  UR                  [        S   S:  a  S OS S	9  U" S
R                  U4S jU 5       5      5      US'   [        [        U ]+  XX#5      $ s  snnf )Nc                 <    U R                  S5      (       a  U SS $ U $ )z/Remove any leading "visit_" from a method name.visit_   N)
startswith)r   s    r   unvisit*RuleDecoratorMeta.__new__.<locals>.unvisit   s!    #x8848BdBr   _ruler   )Grammarr      c                 .    U R                   R                  $ r   )	func_codeco_firstlinenoxs    r   <lambda>+RuleDecoratorMeta.__new__.<locals>.<lambda>   s    (B(Br   c                 .    U R                   R                  $ r   )__code__rj   rk   s    r   rm   rn      s    

(A(Ar   )keyr'   c              3   x   >#    U  H/  nS R                  T" UR                  5      UR                  S9v   M1     g7f)z{name} = {expr})r   r   N)formatr6   re   )r*   mrc   s     r   r,   ,RuleDecoratorMeta.__new__.<locals>.<genexpr>   s;      ,#*a ,22

8K89 3 A#*s   7:grammar)itemshasattrr   rv   rf   sortr   r.   superr\   __new__)
	metaclassr   bases	namespacekvmethodsrf   rc   r5   s
           @r   r{   RuleDecoratorMeta.__new__   s    	C "+!2 :!21g& +5a= !2 :(LL ,Q! 3 CA  D $+		 ,#*, ,$-Ii  &((1 J	K:s   B4B4B4r)   )r6   rP   rQ   rR   r{   rV   __classcell__)r5   s   @r   r\   r\      s    K Kr   r\   c                   L    \ rS rSrSrSrSrS rS rSS jr	SS jr
S	 rS
 rSrg)NodeVisitor   a=  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           	      L   [        U SUR                  -   U R                  5      n U" X Vs/ s H  o0R                  U5      PM     sn5      $ s  snf ! [        [
        4 a    e [         a7  n[        X@R                  5      (       a  e [        U5      n[	        XEU5      eSnAff = f)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.

r`   N)
getattrr   generic_visitvisitr   r   	Exceptionr@   unwrapped_exceptionstype)r   nodemethodr:   exc	exc_classs         r   r   NodeVisitor.visit   s     x$..8$:L:LM	8$ =1A =>> =0 	 	8 #8899 S	I!#$77	8s(   A A
A A B#,2BB#c                 N    [        SUR                  R                  5       -  5      e)a-  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   r   visited_childrens      r   r   NodeVisitor.generic_visit   s)     ""Y"&))"3"3"5#6 7 	7r   c                 &    U R                  XS5      $ )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   NodeVisitor.parse        ##Dw77r   c                 &    U R                  XS5      $ )zParse 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'))``.

rZ   r   r   s      r   rZ   NodeVisitor.match   r   r   c                     Uu  nU$ )z7Lift the sole child of ``node`` up to replace the node.r)   )r   r   r   first_childs       r   
lift_childNodeVisitor.lift_child
  s    r   c                     U R                   (       d-  [        SR                  U R                  R                  US95      eU R                  [        U R                   U5      " XS95      $ )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.)clsr   )r   )rv   RuntimeErrorrs   r5   r6   r   r   )r   r#   r   method_names       r   r   NodeVisitor._parse_or_match  s]     ||66<f//& 7= 7() ) zz'$,,<TKLLr   )r   )r6   rP   rQ   rR   rS   rv   r   r   r   r   rZ   r   r   rV   r)   r   r   r   r      s6    4 G
 
8B7"88Mr   r   )r|   c                    ^  U 4S jnU$ )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                    > TU l         U $ r   )re   )r   rule_strings    r   	decoratorrule.<locals>.decoratorB  s    "r   r)   )r   r   s   ` r   ruler   "  s    @ r   N)rS   inspectr   sysr   r   
exceptionsr   r   objectr
   rX   r   r\   r   r   r)   r   r   <module>r      sW     & 7h6 hV K K2BM&$5 BMJ#r   