
    E#iA                     v   S r SSKJrJrJrJr  SSKrSSKJrJ	r	  SSK
JrJr  SSKJr  \" 5       rS rS	 r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S  S!\5      rg)"zESubexpressions that make up a parsed grammar

These do the parsing.

    )getfullargspec
isfunctionismethodismethoddescriptorN   )
ParseErrorIncompleteParseError)Node	RegexNode)
StrAndReprc                 p    [         [        [        /n[        U Vs/ s H
  o"" U 5      PM     sn5      $ s  snf N)r   r   r   any)valuecriteria	criterions      k/home/james-whalen/.local/lib/python3.13/site-packages/ccxt/static_dependencies/parsimonious/expressions.pyis_callabler      s1    H&89H(;(Y	% (;<<;s   3c                 <  ^ ^^ [        T 5      (       a  [        T S5      (       a  T R                  m [        [	        T 5      R
                  5      n[        T 5      (       a  US-  nUS:X  a  SmOUS:X  a  SmO[        SU-  5      e " U UU4S jS	[        5      nU" US
9$ )a  Turn a plain callable into an Expression.

The callable can be of this simple form::

    def foo(text, pos):
        '''If this custom expression matches starting at text[pos], return
        the index where it stops matching. Otherwise, return None.'''
        if the expression matched:
            return end_pos

If there child nodes to return, return a tuple::

    return end_pos, children

If the expression doesn't match at the given ``pos`` at all... ::

    return None

If your callable needs to make sub-calls to other rules in the grammar or
do error reporting, it can take this form, gaining additional arguments::

    def foo(text, pos, cache, error, grammar):
        # Call out to other rules:
        node = grammar['another_rule'].match_core(text, pos, cache, error)
        ...
        # Return values as above.

The return value of the callable, if an int or a tuple, will be
automatically transmuted into a :class:`~.Node`. If it returns
a Node-like class directly, it will be passed through unchanged.

:arg rule_name: The rule name to attach to the resulting
    :class:`~.Expression`
:arg grammar: The :class:`~.Grammar` this expression will be a
    part of, to make delegating to other rules possible

__func__r      T   Fz@Custom rule functions must take either 2 or 5 arguments, not %s.c                   2   > \ rS rSrU UU4S jrU 4S jrSrg)#expression.<locals>.AdHocExpressionP   c                    > T
(       a  T" X5      O	T" XX4T	5      n[        U[        5      (       a  US pvO[        U[        5      (       a  Uu  pgOU$ [        XX&US9$ Nchildren)
isinstanceinttupler
   )selftextposcacheerrorresultendr   callablegrammar	is_simples           r   _uncached_match3expression.<locals>.AdHocExpression._uncached_matchQ   s`    -6ht)t%@  &#&& &XFE** &X Cx@@    c                 "   > STR                   -  $ )Nz{custom function "%s"})__name__)r#   r*   s    r   _as_rhs+expression.<locals>.AdHocExpression._as_rhs^   s    +h.?.???r/    N)r1   
__module____qualname____firstlineno__r-   r2   __static_attributes__)r*   r+   r,   s   r   AdHocExpressionr   P   s    	A	@ 	@r/   r9   name)	r   hasattrr   lenr   argsr   RuntimeError
Expression)r*   	rule_namer+   num_argsr9   r,   s   ` `  @r   
expressionrC      s    R (##*(E(E$$>(+001HA1}		Q	 02:; < 	<@ @* @" 	**r/   c                   n    \ rS rSrSrSS/rSS jrS rS rS r	SS	 jr
SS
 jrS rS rS rS rS rSrg)r@   d   z3A thing that can be matched against a piece of textr;   identity_tuplec                 4    Xl         U R                   4U l        g r   )r;   rF   )r#   r;   s     r   __init__Expression.__init__m   s    	#yymr/   c                 ,    [        U R                  5      $ r   )hashrF   r#   s    r   __hash__Expression.__hash__q   s    D''((r/   c                 l    [        XR                  5      =(       a    U R                  UR                  :H  $ r   )r    	__class__rF   r#   others     r   __eq__Expression.__eq__t   s'    %0`T5H5HEL`L`5``r/   c                     X:X  + $ r   r4   rQ   s     r   __ne__Expression.__ne__w   s    ""r/   c                     U R                  XS9nUR                  [        U5      :  a  [        XR                  U 5      eU$ )zReturn a parse tree of ``text``.

Raise ``ParseError`` if the expression wasn't satisfied. Raise
``IncompleteParseError`` if the expression was satisfied but didn't
consume the full string.

)r%   )matchr)   r=   r	   )r#   r$   r%   nodes       r   parseExpression.parsez   s:     zz$z(88c$i&tXXt<<r/   c                 L    [        U5      nU R                  X0 U5      nUc  UeU$ )zReturn the parse tree matching this expression at the given
position, not necessarily extending all the way to the end of ``text``.

Raise ``ParseError`` if there is no match there.

:arg pos: The index at which to start matching

)r   
match_core)r#   r$   r%   r'   rZ   s        r   rY   Expression.match   s/     4 t"e4<Kr/   c                    [        U 5      nUR                  XR4[        5      nU[        L a  U R                  UUUU5      =ocXR4'   UcD  X$R                  :  a5  U R
                  (       d  [        UR                  SS5      c  Xl        X$l        U$ )aE  Internal guts of ``match()``

This is appropriate to call only from custom rules or Expression
subclasses.

:arg cache: The packrat cache::

    {(oid, pos): Node tree matched by object `oid` at index `pos` ...}

:arg error: A ParseError instance with ``text`` already filled in but
    otherwise blank. We update the error reporting info on this object
    as we go. (Sticking references on an existing instance is faster
    than allocating a new one for each expression that fails.) We
    return None rather than raising and catching ParseErrors because
    catching is slow.

Nr;   )idgetMARKERr-   r%   r;   getattrexpr)r#   r$   r%   r&   r'   expr_idrZ   s          r   r^   Expression.match_core   s    @ T(yy'06>+/+?+?@C@E@E,G GD'( <C99,		WUZZ>F
 JIr/   c                 \    SU R                   R                  < SU R                  5       < S3$ )N< >)rP   r1   as_rulerL   s    r   __str__Expression.__str__   s"    NN##LLN 	r/   c                     U R                  5       R                  5       nUR                  S5      (       a  UR                  S5      (       a  USS nU R                  (       a  U R                  < SU< 3$ U$ )zReturn the left- and right-hand sides of a rule that represents me.

Return unicode. If I have no ``name``, omit the left-hand side.

()r   z = )r2   strip
startswithendswithr;   )r#   rhss     r   rl   Expression.as_rule   sZ     lln""$>>#3<<#4#4a)C26))dii-DDr/   c                     U R                    Vs/ s H%  oR                  =(       d    UR                  5       PM'     sn$ s  snf )zReturn an iterable of my unicode-represented children, stopping
descent when we hit a named node so the returned value resembles the
input rule.)membersr;   r2   )r#   ms     r   _unicode_membersExpression._unicode_members   s0     26>A&199;&>>>s   ,>c                     [         e)zVReturn the right-hand side of a rule that represents me.

Implemented by subclasses.

)NotImplementedErrorrL   s    r   r2   Expression._as_rhs   s
     "!r/   )rF   r;   N )r   )r1   r5   r6   r7   __doc__	__slots__rH   rM   rS   rV   r[   rY   r^   rm   rl   r{   r2   r8   r4   r/   r   r@   r@   d   sL    = )*I,)a#2h

E?"r/   r@   c                   B   ^  \ rS rSrSrS/rSU 4S jjrS rS rSr	U =r
$ )	Literal   z>A string literal

Use these if you can; they're the fastest.

literalc                 H   > [         [        U ]  U5        Xl        X!4U l        g r   )superr   rH   r   rF   )r#   r   r;   rP   s      r   rH   Literal.__init__   s!    gt%d+#or/   c           	          UR                  U R                  U5      (       a"  [        XX"[        U R                  5      -   5      $ g r   )rt   r   r
   r=   )r#   r$   r%   r&   r'   s        r   r-   Literal._uncached_match   s7    ??4<<--Cs4<</@)@AA .r/   c                 ,    [        U R                  5      $ r   )reprr   rL   s    r   r2   Literal._as_rhs   s    DLL!!r/   )rF   r   r   r1   r5   r6   r7   r   r   rH   r-   r2   r8   __classcell__rP   s   @r   r   r      s&    
 I.
B" "r/   r   c                       \ rS rSrSrS rSrg)TokenMatcher   zaAn expression matching a single token of a given type

This is for use only with TokenGrammars.

c                 Z    X   R                   U R                  :X  a  [        XX"S-   5      $ g )Nr   )typer   r
   )r#   
token_listr%   r&   r'   s        r   r-   TokenMatcher._uncached_match  s,    ?4<</#Qw77 0r/   r4   N)r1   r5   r6   r7   r   r-   r8   r4   r/   r   r   r      s    
8r/   r   c                   L   ^  \ rS rSrSrS/r  S	U 4S jjrS rS rS r	Sr
U =r$ )
Regexi
  zAn expression that matches what a regex does.

Use these as much as you can and jam as much into each one as you can;
they're fast.

rec
                   > [         [        U ]  U5        [        R                  " X=(       a    [        R
                  U=(       a    [        R                  -  U=(       a    [        R                  -  U=(       a    [        R                  -  U=(       a    [        R                  -  U=(       a    [        R                  -  U	=(       a    [        R                  -  5      U l        U R                  U R                  4U l        g r   )r   r   rH   r   compileILMSUXAr;   rF   )r#   patternr;   ignore_caselocale	multilinedot_allunicodeverboseasciirP   s             r   rH   Regex.__init__  s    eT#D)**W';rtt'-"$$'8'0'9RTT'; (/'7244'9 (/'7244	'9
 (/'7244'9 (-~'7 8  $yy$''2r/   c                     U R                   R                  X5      nUb0  UR                  5       n[        XX"US   -   US   -
  5      nXWl        U$ g)z-Return length of match, ``None`` if no match.Nr   r   )r   rY   spanr   )r#   r$   r%   r&   r'   rz   r   rZ   s           r   r-   Regex._uncached_match  sP    GGMM$$=668DTDGmd1g.EFDJK	 r/   c           	      n   ^^ SmSR                  UU4S j[        S[        T5      S-   5       5       5      $ )zAReturn the textual equivalent of numerically encoded regex flags.ilmsuxar   c              3   R   >#    U  H  nS U-  T-  (       a  TUS -
     OSv   M     g7f)r   r   Nr4   ).0ibitsflagss     r   	<genexpr>/Regex._regex_flags_from_bits.<locals>.<genexpr>+  s*     aH`1Q$uQU|B>H`s   $'r   )joinranger=   )r#   r   r   s    `@r   _regex_flags_from_bitsRegex._regex_flags_from_bits(  s1    wwaaQTUZQ[^_Q_H`aaar/   c                     SR                  U R                  R                  U R                  U R                  R                  5      5      $ )Nz~{!r}{})formatr   r   r   r   rL   s    r   r2   Regex._as_rhs-  s7     $ ; ;DGGMM JL 	Lr/   )rF   r   )r   FFFFFFF)r1   r5   r6   r7   r   r   rH   r-   r   r2   r8   r   r   s   @r   r   r   
  s3     ICHUZ
3b
L Lr/   r   c                   >   ^  \ rS rSrSrS/rU 4S jrS rS rSr	U =r
$ )Compoundi2  z7An abstract expression which contains other expressionsry   c                 X   > [         [        U ]  UR                  SS5      5        Xl        g)z)``members`` is a sequence of expressions.r;   r   N)r   r   rH   rb   ry   )r#   ry   kwargsrP   s      r   rH   Compound.__init__7  s"    h&vzz&"'=>r/   c                 D    [        U R                  U R                  45      $ r   )rK   rP   r;   rL   s    r   rM   Compound.__hash__<  s     T^^TYY/00r/   c                     [        XR                  5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r   )r    rP   r;   ry   rQ   s     r   rS   Compound.__eq__B  s=    unn- *II#*LLEMM)	+r/   )ry   )r1   r5   r6   r7   r   r   rH   rM   rS   r8   r   r   s   @r   r   r   2  s!    AI
1+ +r/   r   c                   $    \ rS rSrSrS rS rSrg)SequenceiI  zA series of expressions that must match contiguous, ordered pieces of
the text

In other words, it's a concatenation operator: each piece has to match, one
after another.

c                     UnSn/ nU R                    HL  nUR                  XX45      n	U	c    g UR                  U	5        U	R                  U	R                  -
  n
XZ-  nXj-  nMN     [        XX"U-   U5      $ Nr   )ry   r^   appendr)   startr
   )r#   r$   r%   r&   r'   new_poslength_of_sequencer   rz   rZ   lengths              r   r-   Sequence._uncached_matchQ  s~    A<<u<D|OOD!XX

*FG(  D+=%=xHHr/   c                 ^    SR                  SR                  U R                  5       5      5      $ )N({0})rj   r   r   r{   rL   s    r   r2   Sequence._as_rhs`  s#    tyy)>)>)@ABBr/   r4   Nr1   r5   r6   r7   r   r-   r2   r8   r4   r/   r   r   r   I  s    ICr/   r   c                   $    \ rS rSrSrS rS rSrg)OneOfid  zA series of expressions, one of which must match

Expressions are tested in order from first to last. The first to succeed
wins.

c           	          U R                    H0  nUR                  XX45      nUc  M  [        XX&R                  U/S9s  $    g r   ry   r^   r
   r)   )r#   r$   r%   r&   r'   rz   rZ   s          r   r-   OneOf._uncached_matchk  s;    A<<58DDXXGG	 r/   c                 ^    SR                  SR                  U R                  5       5      5      $ )Nr   z / r   rL   s    r   r2   OneOf._as_rhsr  s#    v{{4+@+@+BCDDr/   r4   Nr   r4   r/   r   r   r   d  s    HEr/   r   c                   $    \ rS rSrSrS rS rSrg)	Lookaheadiv  zOAn expression which consumes nothing, even if its contained expression
succeedsc                 `    U R                   S   R                  XX45      nUb  [        XX"5      $ g r   ry   r^   r
   r#   r$   r%   r&   r'   rZ   s         r   r-   Lookahead._uncached_match~  s4    ||A))$UBC-- r/   c                 .    SU R                  5       S   -  $ )Nz&%sr   r{   rL   s    r   r2   Lookahead._as_rhs      --/222r/   r4   Nr   r4   r/   r   r   r   v  s    .
3r/   r   c                   $    \ rS rSrSrS rS rSrg)Noti  zAn expression that succeeds only if the expression within it doesn't

In any case, it never consumes any characters; it's a negative lookahead.

c                 `    U R                   S   R                  XX45      nUc  [        XX"5      $ g r   r   r   s         r   r-   Not._uncached_match  s5     ||A))$UB<C-- r/   c                 .    SU R                  5       S   -  $ )Nz!%sr   r   rL   s    r   r2   Not._as_rhs  s     --/222r/   r4   Nr   r4   r/   r   r   r     s    
.3r/   r   c                   $    \ rS rSrSrS rS rSrg)Optionali  zAn expression that succeeds whether or not the contained one does

If the contained expression succeeds, it goes ahead and consumes what it
consumes. Otherwise, it consumes nothing.

c                     U R                   S   R                  XX45      nUc  [        XX"5      $ [        XX%R                  U/S9$ )Nr   r   r   r   s         r   r-   Optional._uncached_match  sH    ||A))$UB.2lT* 	BThh$@	Br/   c                 .    SU R                  5       S   -  $ )Nz%s?r   r   rL   s    r   r2   Optional._as_rhs  r   r/   r4   Nr   r4   r/   r   r   r     s    B
3r/   r   c                   $    \ rS rSrSrS rS rSrg)
ZeroOrMorei  z7An expression wrapper like the * quantifier in regexes.c                    Un/ n U R                   S   R                  XX45      nUb  UR                  UR                  -
  (       d  [	        XX%U5      $ UR                  U5        XWR                  UR                  -
  -  nM{  r   )ry   r^   r)   r   r
   r   )r#   r$   r%   r&   r'   r   r   rZ   s           r   r-   ZeroOrMore._uncached_match  sr    <<?--dUJD|DHHtzz$9Dh??OOD!xx$**,,G r/   c                 .    SU R                  5       S   -  $ )Nz%s*r   r   rL   s    r   r2   ZeroOrMore._as_rhs  r   r/   r4   Nr   r4   r/   r   r   r     s    A	-3r/   r   c                   B   ^  \ rS rSrSrS/rSU 4S jjrS rS rSr	U =r
$ )		OneOrMorei  zAn expression wrapper like the + quantifier in regexes.

You can also pass in an alternate minimum to make this behave like "2 or
more", "3 or more", etc.

minc                 4   > [         [        U ]  XS9  X0l        g )Nr:   )r   r   rH   r   )r#   memberr;   r   rP   s       r   rH   OneOrMore.__init__  s    i'':r/   c                    Un/ n U R                   S   R                  XX45      nUc  O7UR                  U5        UR                  UR                  -
  nUS:X  a  OXX-  nMZ  [        U5      U R                  :  a  [        XX%U5      $ g r   )ry   r^   r   r)   r   r=   r   r
   )	r#   r$   r%   r&   r'   r   r   rZ   r   s	            r   r-   OneOrMore._uncached_match  s    <<?--dUJD|OOD!XX

*F{G  x=DHH$C(;; %r/   c                 .    SU R                  5       S   -  $ )Nz%s+r   r   rL   s    r   r2   OneOrMore._as_rhs  r   r/   )r   )r   r   r   r   s   @r   r   r     s%     I
<3 3r/   r   )r   inspectr   r   r   r   r   
exceptionsr   r	   nodesr
   r   utilsr   objectrc   r   rC   r@   r   r   r   r   r   r   r   r   r   r   r   r4   r/   r   <module>r     s    M L 	 8 " 	=
I+XC" C"L"j "*87 8%LJ %LP+z +.Cx C6EH E$3 3"3( 3*3x 3"3 3$ 3  3r/   