
    ":hA                     v   d Z ddlmZmZmZmZ ddlZddlmZm	Z	 ddl
mZmZ ddlmZ  e       Zd Zd	 Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d  d!e      Zy)"zESubexpressions that make up a parsed grammar

These do the parsing.

    )getfullargspec
isfunctionismethodismethoddescriptorN   )
ParseErrorIncompleteParseError)Node	RegexNode)
StrAndReprc                 l    t         t        t        g}t        |D cg c]
  } ||        c}      S c c}w N)r   r   r   any)valuecriteria	criterions      k/var/www/html/turnos/venv/lib/python3.12/site-packages/ccxt/static_dependencies/parsimonious/expressions.pyis_callabler      s-    H&89H(;Y	% ;<<;s   1c                     t               rt         d      r j                   t        t	               j
                        }t               r|dz  }|dk(  rdn|dk(  rdnt        d|z         G  fdd	t              } ||
      S )a3  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                   &    e Zd Z fdZ fdZy)#expression.<locals>.AdHocExpressionc                     
r	 ||      n ||||	      }t        |t              r|d }}nt        |t              r|\  }}n|S t        | ||||      S Nchildren)
isinstanceinttupler
   )selftextposcacheerrorresultendr   callablegrammar	is_simples           r   _uncached_matchz3expression.<locals>.AdHocExpression._uncached_matchQ   sf    -6htS)tS%@  &#& &XFE* &X dCx@@    c                 "    dj                   z  S )Nz{custom function "%s"})__name__)r"   r)   s    r   _as_rhsz+expression.<locals>.AdHocExpression._as_rhs^   s    +h.?.???r-   N)r/   
__module____qualname__r,   r0   )r)   r*   r+   s   r   AdHocExpressionr   P   s    	A	@r-   r3   name)	r   hasattrr   lenr   argsr   RuntimeError
Expression)r)   	rule_namer*   num_argsr3   r+   s   ` `  @r   
expressionr=      s    R (#*(E$$>(+001HA1}		Q	 02:; < 	<@ @* @" 	**r-   c                   `    e Zd ZdZddgZddZd Zd Zd ZddZ	dd	Z
d
 Zd Zd Zd Zd Zy)r:   z3A thing that can be matched against a piece of textr5   identity_tuplec                 6    || _         | j                   f| _        y r   )r5   r?   )r"   r5   s     r   __init__zExpression.__init__m   s    	#yymr-   c                 ,    t        | j                        S r   )hashr?   r"   s    r   __hash__zExpression.__hash__q   s    D''((r-   c                 d    t        || j                        xr | j                  |j                  k(  S r   )r   	__class__r?   r"   others     r   __eq__zExpression.__eq__t   s)    %0`T5H5HEL`L`5``r-   c                     | |k(   S r    rH   s     r   __ne__zExpression.__ne__w   s    EM""r-   c                     | j                  ||      }|j                  t        |      k  rt        ||j                  |       |S )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(   r7   r	   )r"   r#   r$   nodes       r   parsezExpression.parsez   s>     zz$Cz(88c$i&tTXXt<<r-   c                 L    t        |      }| j                  ||i |      }|||S )a  Return 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&   rP   s        r   rO   zExpression.match   s1     4 tS"e4<Kr-   c                    t        |       }|j                  ||ft              }|t        u r| j                  ||||      x}|||f<   |@||j                  k\  r1| j
                  st        |j                  dd      | |_        ||_        |S )a  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.

        Nr5   )idgetMARKERr,   r$   r5   getattrexpr)r"   r#   r$   r%   r&   expr_idrP   s          r   rS   zExpression.match_core   s    @ T(yy'306>+/+?+?@C@E@E,G GD5'3( <C599,		WUZZ>F
 EJEIr-   c                 X    d| j                   j                  d| j                         dS )N< >)rG   r/   as_rulerD   s    r   __str__zExpression.__str__   s"    NN##LLN 	r-   c                     | j                         j                         }|j                  d      r|j                  d      r|dd }| j                  r| j                  d|S |S )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 = )r0   strip
startswithendswithr5   )r"   rhss     r   r_   zExpression.as_rule   sT     lln""$>>#3<<#4a)C26))dii-DDr-   c                 x    | j                   D cg c]   }|j                  xs |j                         " c}S c c}w )zReturn an iterable of my unicode-represented children, stopping
        descent when we hit a named node so the returned value resembles the
        input rule.)membersr5   r0   )r"   ms     r   _unicode_memberszExpression._unicode_members   s.     26>A&199;&>>>s   %7c                     t         )zfReturn the right-hand side of a rule that represents me.

        Implemented by subclasses.

        )NotImplementedErrorrD   s    r   r0   zExpression._as_rhs   s
     "!r-   N )r   )r/   r1   r2   __doc__	__slots__rA   rE   rJ   rM   rQ   rO   rS   r`   r_   rl   r0   rL   r-   r   r:   r:   d   sL    = )*I,)a#2h

E?"r-   r:   c                   6     e Zd ZdZdgZd fd	Zd Zd Z xZS )LiteralzFA string literal

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

    literalc                 L    t         t        |   |       || _        ||f| _        y r   )superrt   rA   ru   r?   )r"   ru   r5   rG   s      r   rA   zLiteral.__init__   s%    gt%d+#Wor-   c           	          |j                  | j                  |      r$t        | |||t        | j                        z         S y r   )rf   ru   r
   r7   )r"   r#   r$   r%   r&   s        r   r,   zLiteral._uncached_match   s8    ??4<<-dCs4<</@)@AA .r-   c                 ,    t        | j                        S r   )reprru   rD   s    r   r0   zLiteral._as_rhs   s    DLL!!r-   ro   	r/   r1   r2   rq   rr   rA   r,   r0   __classcell__rG   s   @r   rt   rt      s!    
 I.
B"r-   rt   c                       e Zd ZdZd Zy)TokenMatcherziAn expression matching a single token of a given type

    This is for use only with TokenGrammars.

    c                 ^    ||   j                   | j                  k(  rt        | |||dz         S y )Nr   )typeru   r
   )r"   
token_listr$   r%   r&   s        r   r,   zTokenMatcher._uncached_match  s2    c?4<</j#sQw77 0r-   N)r/   r1   r2   rq   r,   rL   r-   r   r   r      s    
8r-   r   c                   @     e Zd ZdZdgZ	 	 d fd	Zd Zd Zd Z xZ	S )RegexzAn 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
                    t         t        |   |       t        j                  ||xr t        j
                  |xr t        j                  z  |xr t        j                  z  |xr t        j                  z  |xr t        j                  z  |xr t        j                  z  |	xr t        j                  z        | _        | j                  | j                  f| _        y r   )rw   r   rA   r   compileILMSUXAr5   r?   )r"   patternr5   ignore_caselocale	multilinedot_allunicodeverboseasciirG   s             r   rA   zRegex.__init__  s    eT#D)**W{';rtt'-"$$'8'0'9RTT'; (/'7244'9 (/'7244	'9
 (/'7244'9 (-~'7 8  $yy$''2r-   c                     | j                   j                  ||      }|3|j                         }t        | ||||d   z   |d   z
        }||_        |S y)z-Return length of match, ``None`` if no match.Nr   r   )r   rO   spanr   )r"   r#   r$   r%   r&   rk   r   rP   s           r   r,   zRegex._uncached_match  sX    GGMM$$=668DT4cDGmd1g.EFDDJK	 r-   c           	      l    ddj                  fdt        dt              dz         D              S )zAReturn the textual equivalent of numerically encoded regex flags.ilmsuxarp   c              3   B   K   | ]  }d |z  z  r|d z
     nd  yw)r   rp   NrL   ).0ibitsflagss     r   	<genexpr>z/Regex._regex_flags_from_bits.<locals>.<genexpr>+  s(     a1Q$uQU|B>as   r   )joinranger7   )r"   r   r   s    `@r   _regex_flags_from_bitszRegex._regex_flags_from_bits(  s1    wwaaQTUZQ[^_Q_H`aaar-   c                     dj                  | j                  j                  | j                  | j                  j                              S )Nz~{!r}{})formatr   r   r   r   rD   s    r   r0   zRegex._as_rhs-  s7     $ ; ;DGGMM JL 	Lr-   )rp   FFFFFFF)
r/   r1   r2   rq   rr   rA   r,   r   r0   r|   r}   s   @r   r   r   
  s-     ICHUZ
3b
Lr-   r   c                   4     e Zd ZdZdgZ fdZd Zd Z xZS )Compoundz7An abstract expression which contains other expressionsrj   c                 Z    t         t        |   |j                  dd             || _        y)z)``members`` is a sequence of expressions.r5   rp   N)rw   r   rA   rV   rj   )r"   rj   kwargsrG   s      r   rA   zCompound.__init__7  s$    h&vzz&"'=>r-   c                 D    t        | j                  | j                  f      S r   )rC   rG   r5   rD   s    r   rE   zCompound.__hash__<  s     T^^TYY/00r-   c                     t        || j                        xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r   )r   rG   r5   rj   rH   s     r   rJ   zCompound.__eq__B  s?    udnn- *II#*LLEMM)	+r-   )	r/   r1   r2   rq   rr   rA   rE   rJ   r|   r}   s   @r   r   r   2  s    AI
1+r-   r   c                       e Zd ZdZd Zd Zy)SequencezA 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                     |}d}g }| j                   D ]N  }|j                  ||||      }	|	 y |j                  |	       |	j                  |	j                  z
  }
||
z  }||
z  }P t        | ||||z   |      S Nr   )rj   rS   appendr(   startr
   )r"   r#   r$   r%   r&   new_poslength_of_sequencer   rk   rP   lengths              r   r,   zSequence._uncached_matchQ  s     	)A<<gue<D|OOD!XX

*FvG&(	) D$S+=%=xHHr-   c                 ^    dj                  dj                  | j                                     S )N({0})r]   r   r   rl   rD   s    r   r0   zSequence._as_rhs`  s#    tyy)>)>)@ABBr-   Nr/   r1   r2   rq   r,   r0   rL   r-   r   r   r   I  s    ICr-   r   c                       e Zd ZdZd Zd Zy)OneOfzA series of expressions, one of which must match

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

    c                     | j                   D ]5  }|j                  ||||      }|t        | |||j                  |g      c S  y r   rj   rS   r
   r(   )r"   r#   r$   r%   r&   rk   rP   s          r   r,   zOneOf._uncached_matchk  sJ     	HA<<c5%8DD$TXXGG		Hr-   c                 ^    dj                  dj                  | j                                     S )Nr   z / r   rD   s    r   r0   zOneOf._as_rhsr  s#    v{{4+@+@+BCDDr-   Nr   rL   r-   r   r   r   d  s    HEr-   r   c                       e Zd ZdZd Zd Zy)	LookaheadzSAn expression which consumes nothing, even if its contained expression
    succeedsc                 f    | j                   d   j                  ||||      }|t        | |||      S y r   rj   rS   r
   r"   r#   r$   r%   r&   rP   s         r   r,   zLookahead._uncached_match~  s<    ||A))$UEBdC-- r-   c                 .    d| j                         d   z  S )Nz&%sr   rl   rD   s    r   r0   zLookahead._as_rhs      --/222r-   Nr   rL   r-   r   r   r   v  s    .
3r-   r   c                       e Zd ZdZd Zd Zy)NotzAn 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                 f    | j                   d   j                  ||||      }|t        | |||      S y r   r   r   s         r   r,   zNot._uncached_match  s=     ||A))$UEB<dC-- r-   c                 .    d| j                         d   z  S )Nz!%sr   r   rD   s    r   r0   zNot._as_rhs  s     --/222r-   Nr   rL   r-   r   r   r     s    
.3r-   r   c                       e Zd ZdZd Zd Zy)OptionalzAn 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                     | j                   d   j                  ||||      }|t        | |||      S t        | |||j                  |g      S )Nr   r   r   r   s         r   r,   zOptional._uncached_match  sT    ||A))$UEB.2lT4c* 	BT4dhh$@	Br-   c                 .    d| j                         d   z  S )Nz%s?r   r   rD   s    r   r0   zOptional._as_rhs  r   r-   Nr   rL   r-   r   r   r     s    B
3r-   r   c                       e Zd ZdZd Zd Zy)
ZeroOrMorez7An expression wrapper like the * quantifier in regexes.c                     |}g }	 | j                   d   j                  ||||      }||j                  |j                  z
  st	        | ||||      S |j                  |       ||j                  |j                  z
  z  }yr   )rj   rS   r(   r   r
   r   )r"   r#   r$   r%   r&   r   r   rP   s           r   r,   zZeroOrMore._uncached_match  s|    <<?--dGUEJD|DHHtzz$9D$Wh??OOD!txx$**,,G r-   c                 .    d| j                         d   z  S )Nz%s*r   r   rD   s    r   r0   zZeroOrMore._as_rhs  r   r-   Nr   rL   r-   r   r   r     s    A	-3r-   r   c                   6     e Zd ZdZdgZd fd	Zd Zd Z xZS )	OneOrMorezAn 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                 >    t         t        |   ||       || _        y )Nr4   )rw   r   rA   r   )r"   memberr5   r   rG   s       r   rA   zOneOrMore.__init__  s    i'T':r-   c                    |}g }	 | j                   d   j                  ||||      }|n6|j                  |       |j                  |j                  z
  }|dk(  rn||z  }Zt        |      | j                  k\  rt        | ||||      S y r   )rj   rS   r   r(   r   r7   r   r
   )	r"   r#   r$   r%   r&   r   r   rP   r   s	            r   r,   zOneOrMore._uncached_match  s    <<?--dGUEJD|OOD!XX

*F{vG  x=DHH$dC(;; %r-   c                 .    d| j                         d   z  S )Nz%s+r   r   rD   s    r   r0   zOneOrMore._as_rhs  r   r-   )rp   r   r{   r}   s   @r   r   r     s      I
<3r-   r   )rq   inspectr   r   r   r   r   
exceptionsr   r	   nodesr
   r   utilsr   objectrW   r   r=   r:   rt   r   r   r   r   r   r   r   r   r   r   rL   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-   