
    'i                         d dl mZ d Zy)   )
Expressionc                     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 )aW  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:`~parsimonious.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:`~parsimonious.Expression`
    :arg grammar: The :class:`~parsimonious.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tupleNode)selftextposcacheerrorresultendr   callablegrammar	is_simples           N/var/www/br/venv/lib/python3.12/site-packages/parsimonious/adhoc_expression.py_uncached_matchz3expression.<locals>.AdHocExpression._uncached_match;   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_rhsH   s    +h.?.???r   N)r   
__module____qualname__r   r   )r   r   r   s   r   AdHocExpressionr	   :   s    	A	@r   r"   )name)	ismethoddescriptorhasattrr   lengetfullargspecargsismethodRuntimeErrorr   )r   	rule_namer   num_argsr"   r   s   ` `  @r   
expressionr-      s    R (#*(E$$>(+001HA1}		Q	 02:; < 	<@ @* @" 	**r   N)expressionsr   r-    r   r   <module>r0      s    #I+r   