
    [Fi                        d Z ddlZddlZddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ ddlmZ d	d
gZ G d dej                        Z ej                   d       G d d             Z G d d
e      Z G d d      ZdZdedej,                  fdZdedej0                  fdZdedej0                  fdZdedej0                  fdZ G d de	eef         Z G d d	      Zy)a  Evaluate match expressions, as used by `-k` and `-m`.

The grammar is:

expression: expr? EOF
expr:       and_expr ('or' and_expr)*
and_expr:   not_expr ('and' not_expr)*
not_expr:   'not' not_expr | '(' expr ')' | ident
ident:      (\w|:|\+|-|\.|\[|\]|\\|/)+

The semantics are:

- Empty expression evaluates to False.
- ident evaluates to True of False according to a provided matcher function.
- or/and/not evaluate according to the usual boolean semantics.
    N)Callable)Iterator)Mapping)NoReturn)Optional)Sequence
Expression
ParseErrorc                   (    e Zd ZdZdZdZdZdZdZdZ	y)		TokenTypezleft parenthesiszright parenthesisorandnot
identifierzend of inputN)
__name__
__module____qualname__LPARENRPARENORANDNOTIDENTEOF     i/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/mark/expression.pyr   r   %   s%    F F	B
C
CE
Cr   r   T)frozenc                   0    e Zd ZU dZeed<   eed<   eed<   y)Token)typevalueposr!   r"   r#   N)r   r   r   	__slots__r   __annotations__strintr   r   r   r    r    /   s    (I
OJ	Hr   r    c                   0    e Zd ZdZdededdfdZdefdZy)r
   zThe expression contains invalid syntax.

    :param column: The column in the line where the error occurred (1-based).
    :param message: A description of the error.
    columnmessagereturnNc                      || _         || _        y Nr)   r*   )selfr)   r*   s      r   __init__zParseError.__init__>   s    r   c                 :    d| j                    d| j                   S )Nz
at column z: r.   r/   s    r   __str__zParseError.__str__B   s    DKK=4<<.99r   )r   r   r   __doc__r'   r&   r0   r3   r   r   r   r
   r
   7   s-    s S T : :r   c                   l    e Zd ZdZdeddfdZdedee   fdZddd	e	d
e
dee   fdZdee	   defdZy)Scanner)tokenscurrentinputr+   Nc                 d    | j                  |      | _        t        | j                        | _        y r-   )lexr7   nextr8   )r/   r9   s     r   r0   zScanner.__init__I   s!    hhuoDKK(r   c              #      K   d}|t        |      k  rL||   dv r|dz  }n.||   dk(  r$t        t        j                  d|       |dz  }n||   dk(  r#t        t        j                  d|       |dz  }nt        j                  d||d        }|r|j                  d      }|dk(  rt        t        j                  ||       nc|dk(  rt        t        j                  ||       n@|d	k(  rt        t        j                  ||       nt        t        j                  ||       |t        |      z  }nt        |dz   d
||    d      |t        |      k  rLt        t        j                  d|       y w)Nr   ) 	   ()z(:?\w|:|\+|-|\.|\[|\]|\\|/)+r   r   r   zunexpected character "" )lenr    r   r   r   rematchgroupr   r   r   r   r
   r   )r/   r9   r#   rG   r"   s        r   r;   zScanner.lexM   s]    CJSz[(qss"I,,c377qss"I,,c377q!@%+N!KKNE}#ILL%==%#IMM5#>>%#IMM5#>>#IOOUC@@3u:%C$a0sA> / CJ6 IMM2s++s   EE> E>Frejectr!   rJ   c                    | j                   j                  |u rD| j                   }|j                  t        j                  urt	        | j
                        | _         |S |r| j                  |f       y r-   )r8   r!   r   r   r<   r7   rJ   )r/   r!   rJ   tokens       r   acceptzScanner.acceptl   sV    <<$LLEzz.#DKK0LKK r   expectedc           	          t        | j                  j                  dz   dj                  dj	                  d |D              | j                  j
                  j                              )Nr@   zexpected {}; got {}z OR c              3   4   K   | ]  }|j                     y wr-   )r"   ).0r!   s     r   	<genexpr>z!Scanner.reject.<locals>.<genexpr>z   s     <4DJJ<s   )r
   r8   r#   formatjoinr!   r"   )r/   rN   s     r   rJ   zScanner.rejectv   sT    LLq !((<8<<!!''
 	
r   )r   r   r   r$   r&   r0   r   r    r;   r   boolr   rM   r   r   rJ   r   r   r   r6   r6   F   sl    %I)c )d ), ,% ,> 9> 9  (5/ 
x	2 
x 
r   r6   $sr+   c                    | j                  t        j                        rt        j                  d      }n,t        |       }| j                  t        j                  d       t        j                  t        j                  |            S )NFTrI   )rM   r   r   astConstantexprfix_missing_locationsr	   )rW   rets     r   
expressionr^      sW    xx	U+1g	t,$$S^^C%899r   c                    t        |       }| j                  t        j                        rUt        |       }t	        j
                  t	        j                         ||g      }| j                  t        j                        rU|S r-   )and_exprrM   r   r   rY   BoolOpOrrW   r]   rhss      r   r[   r[      sW    
1+C
((9<<
 qkjjC:. ((9<<
  Jr   c                    t        |       }| j                  t        j                        rUt        |       }t	        j
                  t	        j                         ||g      }| j                  t        j                        rU|S r-   )not_exprrM   r   r   rY   ra   Andrc   s      r   r`   r`      sW    
1+C
((9==
!qkjjS#J/ ((9==
! Jr   c                 n   | j                  t        j                        r1t        j                  t        j
                         t        |             S | j                  t        j                        r.t        |       }| j                  t        j                  d       |S | j                  t        j                        }|r9t        j                  t        |j                  z   t        j                               S | j                  t        j                  t        j                  t        j                  f       y )NTrI   )rM   r   r   rY   UnaryOpNotrf   r   r[   r   r   NameIDENT_PREFIXr"   LoadrJ   )rW   r]   idents      r   rf   rf      s    xx	{{3779hqk22xx	  !1g	!!$/
HHY__%Exxu{{2CHHJ??HHimmY--y?@r   c                   Z    e Zd ZdZdeegef   ddfdZdedefdZde	e   fdZ
defd	Zy)
MatcherAdapterzDAdapts a matcher function to a locals mapping as required by eval().matcherr+   Nc                     || _         y r-   )rq   )r/   rq   s     r   r0   zMatcherAdapter.__init__   s	    r   keyc                 D    | j                  |t        t              d        S r-   )rq   rE   rl   )r/   rs   s     r   __getitem__zMatcherAdapter.__getitem__   s    ||CL 1 3455r   c                     t               r-   NotImplementedErrorr2   s    r   __iter__zMatcherAdapter.__iter__       !##r   c                     t               r-   rw   r2   s    r   __len__zMatcherAdapter.__len__   rz   r   )r   r   r   r4   r   r&   rU   r0   ru   r   ry   r'   r|   r   r   r   rp   rp      sR    N# 5 $ 6s 6t 6$(3- $$ $r   rp   c                   n    e Zd ZdZdZdej                  ddfdZede	dd fd       Z
d	ee	gef   defd
Zy)r	   zwA compiled match expression as used by -k and -m.

    The expression can be evaluated against different matchers.
    coder   r+   Nc                     || _         y r-   r~   )r/   r   s     r   r0   zExpression.__init__   s	    	r   r9   c                 \    t        t        |            }t        |dd      }t        |      S )z\Compile a match expression.

        :param input: The input expression - one line.
        z<pytest match expression>eval)filenamemode)r^   r6   compiler	   )r/   r9   astexprr   s       r   r   zExpression.compile   s2     WU^,&0 

 $r   rq   c                 J    t        | j                  di it        |            }|S )a	  Evaluate the match expression.

        :param matcher:
            Given an identifier, should return whether it matches or not.
            Should be prepared to handle arbitrary strings as input.

        :returns: Whether the expression matches or not.
        __builtins__)r   r   rp   )r/   rq   r]   s      r   evaluatezExpression.evaluate   s%     ^R$8.:QR
r   )r   r   r   r4   r$   typesCodeTyper0   classmethodr&   r   r   rU   r   r   r   r   r	   r	      se    
 IU^^    S  \    
# 5 
$ 
r   )r4   rY   dataclassesenumrF   r   typingr   r   r   r   r   r   __all__Enumr   	dataclassr    	Exceptionr
   r6   rl   r	   r^   r[   r`   rf   r&   rU   rp   r   r   r   <module>r      s  "    	        		  d#  $: :7
 7
z :' :cnn :G   CHH 
A 
ACHH 
A$WS$Y' $ # #r   