
    eiA                        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dS )"zESubexpressions that make up a parsed grammar

These do the parsing.

    )getfullargspec
isfunctionismethodismethoddescriptorN   )
ParseErrorIncompleteParseError)Node	RegexNode)
StrAndReprc                 b     t           t          t          g}t           fd|D                       S )Nc                 &    g | ]} |          S  r   ).0	criterionvalues     o/var/www/html/volatility/venv/lib/python3.11/site-packages/ccxt/static_dependencies/parsimonious/expressions.py
<listcomp>zis_callable.<locals>.<listcomp>   s#    ;;;Y		%  ;;;    )r   r   r   any)r   criterias   ` r   is_callabler      s3    H&89H;;;;(;;;<<<r   c                 L    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dS )#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   s    -6 AhhtS)))htS%@@  &#&&  &XFE**  &XX dCx@@@@r   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)r2   
__module____qualname__r0   r3   )r-   r.   r/   s   r   AdHocExpressionr   P   s_        	A 	A 	A 	A 	A 	A 	A	@ 	@ 	@ 	@ 	@ 	@ 	@r   r6   name)	r   hasattrr   lenr   argsr   RuntimeError
Expression)r-   	rule_namer.   num_argsr6   r/   s   ` `  @r   
expressionr@      s    R (## %*(E(E %$>(++011H A1}}			Q		 02:; < < 	<@ @ @ @ @ @ @ @ @* @ @ @" ?	****r   c                   b    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dS )r=   z3A thing that can be matched against a piece of textr8   identity_tuple c                 .    || _         | j         f| _        d S N)r8   rB   )r&   r8   s     r   __init__zExpression.__init__m   s    	#ymr   c                 *    t          | j                  S rE   )hashrB   r&   s    r   __hash__zExpression.__hash__q   s    D'(((r   c                 L    t          || j                  o| j        |j        k    S rE   )r#   	__class__rB   r&   others     r   __eq__zExpression.__eq__t   s$    %00`T5HEL`5``r   c                     | |k     S rE   r   rM   s     r   __ne__zExpression.__ne__w   s    EM""r   r   c                     |                      ||          }|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,   r:   r	   )r&   r'   r(   nodes       r   parsezExpression.parsez   sE     zz$Cz((8c$ii&tTXt<<<r   c                 \    t          |          }|                     ||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*   rT   s        r   rS   zExpression.match   s7     4  tS"e44<Kr   c                    t          |           }|                    ||ft                    }|t          u r|                     ||||          x}|||f<   |6||j        k    r+| 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.

        Nr8   )idgetMARKERr0   r(   r8   getattrexpr)r&   r'   r(   r)   r*   expr_idrT   s          r   rW   zExpression.match_core   s    @ T((yy'3006>>+/+?+?@C@E@E,G ,G GD5'3( <C59,,	 -$UZ>>F
 EJEIr   c                 L    d| j         j        d|                                 dS )N< >)rL   r2   as_rulerI   s    r   __str__zExpression.__str__   s+     N###LLNNNN 	r   c                     |                                                                  }|                    d          r|                    d          r
|dd         }| j        r| j        d|n|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 = )r3   strip
startswithendswithr8   )r&   rhss     r   rc   zExpression.as_rule   sp     llnn""$$>># 	3<<#4#4 	ad)C26)Ddiii--Dr   c                 $    d | j         D             S )zReturn an iterable of my unicode-represented children, stopping
        descent when we hit a named node so the returned value resembles the
        input rule.c                 D    g | ]}|j         p|                                S r   )r8   r3   )r   ms     r   r   z/Expression._unicode_members.<locals>.<listcomp>   s'    >>>A&199;;>>>r   )membersrI   s    r   _unicode_memberszExpression._unicode_members   s     ?>>>>>r   c                     t           )zfReturn the right-hand side of a rule that represents me.

        Implemented by subclasses.

        )NotImplementedErrorrI   s    r   r3   zExpression._as_rhs   s
     "!r   NrC   )r   )r2   r4   r5   __doc__	__slots__rF   rJ   rO   rQ   rU   rS   rW   rd   rc   rq   r3   r   r   r   r=   r=   d   s        == )*I, , , ,) ) )a a a# # #      2 2 2h  

E 
E 
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.

    literalrC   c                 x    t          t          |                               |           || _        ||f| _        d S rE   )superrx   rF   ry   rB   )r&   ry   r8   rL   s      r   rF   zLiteral.__init__   s:    gt%%d+++#Wor   c           	          |                     | j        |          r't          | |||t          | j                  z             S d S rE   )rj   ry   r
   r:   )r&   r'   r(   r)   r*   s        r   r0   zLiteral._uncached_match   sJ    ??4<-- 	BdCs4</@/@)@AAA	B 	Br   c                 *    t          | j                  S rE   )reprry   rI   s    r   r3   zLiteral._as_rhs   s    DL!!!r   rt   	r2   r4   r5   ru   rv   rF   r0   r3   __classcell__rL   s   @r   rx   rx      sq         
 I. . . . . .
B B B" " " " " " "r   rx   c                       e Zd ZdZd ZdS )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 d S )Nr   )typery   r
   )r&   
token_listr(   r)   r*   s        r   r0   zTokenMatcher._uncached_match  s6    c?4<//j#sQw777 0/r   N)r2   r4   r5   ru   r0   r   r   r   r   r      s-         
8 8 8 8 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.

    rerC   Fc
                 ~   t          t          |                               |           t          j        ||ot          j        |ot          j        z  |ot          j        z  |ot          j        z  |ot          j	        z  |ot          j
        z  |	ot          j        z            | _        | j        | j        f| _        d S rE   )r{   r   rF   r   compileILMSUXAr8   rB   )r&   patternr8   ignore_caselocale	multilinedot_allunicodeverboseasciirL   s             r   rF   zRegex.__init__  s    eT##D)))*W{';rt'-"$'8'0'9RT'; (/'724'9 (/'724	'9
 (/'724'9 (-~'7 8 8  $y$'2r   c                     | j                             ||          }|A|                                }t          | ||||d         z   |d         z
            }||_        |S dS )z-Return length of match, ``None`` if no match.Nr   r   )r   rS   spanr   )r&   r'   r(   r)   r*   ro   r   rT   s           r   r0   zRegex._uncached_match  s`    GMM$$$=6688DT4cDGmd1g.EFFDDJK	 =r   c           	          dd                     fdt          dt                    dz             D                       S )zAReturn the textual equivalent of numerically encoded regex flags.ilmsuxarC   c              3   B   K   | ]}d |z  z  r|d z
           ndV  dS )r   rC   Nr   )r   ibitsflagss     r   	<genexpr>z/Regex._regex_flags_from_bits.<locals>.<genexpr>+  s<      aa1Q$>uQU||Baaaaaar   r   )joinranger:   )r&   r   r   s    `@r   _regex_flags_from_bitszRegex._regex_flags_from_bits(  sM    wwaaaaaaQTUZQ[Q[^_Q_H`H`aaaaaar   c                 |    d                     | j        j        |                     | j        j                            S )Nz~{!r}{})formatr   r   r   r   rI   s    r   r3   zRegex._as_rhs-  s8     $ ; ;DGM J JL L 	Lr   )rC   FFFFFFF)
r2   r4   r5   ru   rv   rF   r0   r   r3   r   r   s   @r   r   r   
  s          ICHUZ
3 
3 
3 
3 
3 
3  b b b
L L L L L L 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 expressionsrp   c                     t          t          |                               |                    dd                     || _        dS )z)``members`` is a sequence of expressions.r8   rC   N)r{   r   rF   rZ   rp   )r&   rp   kwargsrL   s      r   rF   zCompound.__init__7  s:    h&&vzz&"'='=>>>r   c                 8    t          | j        | j        f          S rE   )rH   rL   r8   rI   s    r   rJ   zCompound.__hash__<  s     T^TY/000r   c                 l    t          || j                  o| j        |j        k    o| j        |j        k    S rE   )r#   rL   r8   rp   rM   s     r   rO   zCompound.__eq__B  s8    udn-- *I#*LEM)	+r   )	r2   r4   r5   ru   rv   rF   rJ   rO   r   r   s   @r   r   r   2  sc        AAI    
1 1 1+ + + + + + +r   r   c                       e Zd ZdZd Zd ZdS )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 ]M}|                    ||||          }	|	 d S |                    |	           |	j        |	j        z
  }
||
z  }||
z  }Nt          | ||||z   |          S Nr   )rp   rW   appendr,   startr
   )r&   r'   r(   r)   r*   new_poslength_of_sequencer"   ro   rT   lengths              r   r0   zSequence._uncached_matchQ  s     	) 	)A<<gue<<D|ttOOD!!!X
*FvG&(D$S+=%=xHHHr   c                 v    d                     d                    |                                                     S )N({0})ra   r   r   rq   rI   s    r   r3   zSequence._as_rhs`  s,    tyy)>)>)@)@AABBBr   Nr2   r4   r5   ru   r0   r3   r   r   r   r   r   I  sD         I I IC C C C Cr   r   c                       e Zd ZdZd Zd ZdS )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 ]8}|                    ||||          }|t          | |||j        |g          c S 9d S r    rp   rW   r
   r,   )r&   r'   r(   r)   r*   ro   rT   s          r   r0   zOneOf._uncached_matchk  sf     	H 	HA<<c5%88DD$TXGGGGGG  	H 	Hr   c                 v    d                     d                    |                                                     S )Nr   z / r   rI   s    r   r3   zOneOf._as_rhsr  s,    v{{4+@+@+B+BCCDDDr   Nr   r   r   r   r   r   d  sD         H H HE E E E Er   r   c                       e Zd ZdZd Zd ZdS )	LookaheadzSAn expression which consumes nothing, even if its contained expression
    succeedsc                 t    | j         d                             ||||          }|t          | |||          S d S r   rp   rW   r
   r&   r'   r(   r)   r*   rT   s         r   r0   zLookahead._uncached_match~  sC    |A))$UEBBdC--- r   c                 <    d|                                  d         z  S )Nz&%sr   rq   rI   s    r   r3   zLookahead._as_rhs      --//222r   Nr   r   r   r   r   r   v  s<         . . .
3 3 3 3 3r   r   c                       e Zd ZdZd Zd ZdS )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                 t    | j         d                             ||||          }|t          | |||          S d S r   r   r   s         r   r0   zNot._uncached_match  sC     |A))$UEBB<dC--- <r   c                 <    d|                                  d         z  S )Nz!%sr   r   rI   s    r   r3   zNot._as_rhs  s      --//222r   Nr   r   r   r   r   r     s<         
. . .3 3 3 3 3r   r   c                       e Zd ZdZd Zd ZdS )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                             ||||          }|t          | |||          nt          | |||j        |g          S )Nr   r!   r   r   s         r   r0   zOptional._uncached_match  sY    |A))$UEBB.2lT4c***T4dh$@@@	Br   c                 <    d|                                  d         z  S )Nz%s?r   r   rI   s    r   r3   zOptional._as_rhs  r   r   Nr   r   r   r   r   r     s?         B B B
3 3 3 3 3r   r   c                       e Zd ZdZd Zd ZdS )
ZeroOrMorez7An expression wrapper like the * quantifier in regexes.c                     |}g }	 | j         d                             ||||          }||j        |j        z
  st	          | ||||          S |                    |           ||j        |j        z
  z  }oNTr   )rp   rW   r,   r   r
   r   )r&   r'   r(   r)   r*   r   r"   rT   s           r   r0   zZeroOrMore._uncached_match  s    	-<?--dGUEJJD|DHtz$9|D$Wh???OOD!!!tx$*,,G	-r   c                 <    d|                                  d         z  S )Nz%s*r   r   rI   s    r   r3   zZeroOrMore._as_rhs  r   r   Nr   r   r   r   r   r     s8        AA	- 	- 	-3 3 3 3 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.

    minrC   r   c                 j    t          t          |                               ||           || _        d S )Nr7   )r{   r   rF   r   )r&   memberr8   r   rL   s       r   rF   zOneOrMore.__init__  s1    i''T':::r   c                    |}g }	 | j         d                             ||||          }|n1|                    |           |j        |j        z
  }|dk    rn||z  }Wt          |          | j        k    rt          | ||||          S d S r   )rp   rW   r   r,   r   r:   r   r
   )	r&   r'   r(   r)   r*   r   r"   rT   r   s	            r   r0   zOneOrMore._uncached_match  s    	<?--dGUEJJD|OOD!!!X
*F{{vG	 x==DH$$dC(;;; %$r   c                 <    d|                                  d         z  S )Nz%s+r   r   rI   s    r   r3   zOneOrMore._as_rhs  r   r   )rC   r   r   r   s   @r   r   r     sn          I
     < < <3 3 3 3 3 3 3r   r   )ru   inspectr   r   r   r   r   
exceptionsr   r	   nodesr
   r   utilsr   objectr[   r   r@   r=   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s    M L L L L L L L L L L L 				 8 8 8 8 8 8 8 8 " " " " " " " "      	= = =
I+ I+ I+XC" C" C" C" C" C" C" C"L" " " " "j " " "*8 8 8 8 87 8 8 8%L %L %L %L %LJ %L %L %LP+ + + + +z + + +.C C C C Cx C C C6E E E E EH E E E$3 3 3 3 3 3 3 3"3 3 3 3 3( 3 3 3*3 3 3 3 3x 3 3 3"3 3 3 3 3 3 3 3$ 3  3  3  3  3  3  3  3  3  3r   