
    .Cc4&                     6   d dl mZ g dZd dlmZ d dlmZ d dlmZm	Z	m
Z
m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 eej        dd          Z G d de          Zd Zd Zd ZddZd ZdS )    )print_function)Token	ParseNodeOperatorparse)
PatsyError)Origin)repr_pretty_delegaterepr_pretty_implno_picklingassert_no_picklingc                       e Zd Zd Zd ZeZdS )_UniqueValuec                     || _         d S N)	_print_as)selfprint_ass     2lib/python3.11/site-packages/patsy/infix_parser.py__init__z_UniqueValue.__init__)   s    !    c                 0    | j         j        d| j        dS )N())	__class____name__r   r   s    r   __repr__z_UniqueValue.__repr__,   s    >222DNNNCCr   Nr   
__module____qualname__r   r   r   __getstate__ r   r   r   r   (   s6        " " "D D D LLLr   r   c                   T    e Zd ZdZ ed          Z ed          ZddZeZ	d Z
eZdS )r   zA token with possible payload.

    .. attribute:: type

       An arbitrary object indicating the type of this token. Should be
      :term:`hashable`, but otherwise it can be whatever you like.
    LPARENRPARENNc                 0    || _         || _        || _        d S r   )typeoriginextra)r   r(   r)   r*   s       r   r   zToken.__init__<   s    	


r   c                 l    |rJ g }| j         
d| j         fg}t          || | j        | j        g|          S )Nr*   )r*   r   r(   r)   )r   pcyclekwargss       r   _repr_pretty_zToken._repr_pretty_B   sI    : 	-
+,F4$)T[)A6JJJr   r   )r   r    r!   __doc__r   r%   r&   r   r
   r   r/   r   r"   r#   r   r   r   r   1   sl          \(##F\(##F   
 $HK K K LLLr   r   c                   "    e Zd Zd ZeZd ZeZdS )r   c                 >    || _         || _        || _        || _        d S r   )r(   tokenargsr)   )r   r(   r3   r4   r)   s        r   r   zParseNode.__init__L   s"    	
	r   c                 H    t          || | j        | j        | j        g          S r   )r   r(   r3   r4   )r   r,   r-   s      r   r/   zParseNode._repr_pretty_S   s!    4$)TZ)KLLLr   N)	r   r    r!   r   r
   r   r/   r   r"   r#   r   r   r   r   K   s=           $HM M M LLLr   r   c                       e Zd Zd Zd ZeZdS )r   c                 0    || _         || _        || _        d S r   )
token_typearity
precedence)r   r8   r9   r:   s       r   r   zOperator.__init__Y   s    $
$r   c                 P    | j         j        d| j        d| j        d| j        dS )Nr   z, r   )r   r   r8   r9   r:   r   s    r   r   zOperator.__repr__^   s5    #'>#:#:#:#'???DJJJQ 	Qr   Nr   r#   r   r   r   r   X   s6        % % %
Q Q Q LLLr   r   c                       e Zd Zd ZeZdS )_StackOperatorc                 "    || _         || _        d S r   )opr3   )r   r?   r3   s      r   r   z_StackOperator.__init__e   s    


r   Nr   r    r!   r   r   r"   r#   r   r   r=   r=   d   s$           LLLr   r=   iigc                       e Zd Zd ZeZdS )_ParseContextc                 Z    g | _         g | _        || _        || _        || _        || _        d S r   )op_stack
noun_stack	unary_ops
binary_opsatomic_typestrace)r   rG   rH   rI   rJ   s        r   r   z_ParseContext.__init__n   s1    "$(


r   Nr@   r#   r   r   rC   rC   m   s$           LLLr   rC   c                    | j         t          j        k    rE|j        rt	          d           |j                            t          t          |                      dS | j         |j	        v rX|j        rt	          d| j                    |j                            t          |j	        | j                  |                      dS | j         |j
        v r]|j        r t	          d| j         d| j        d           |j                            t          | j         | g | j                             dS t          d| j                                        d	|           )
NzPushing open-parenTzPushing unary op zPushing noun  (r   Fzexpected a noun, not '')r(   r   r%   rJ   printrE   appendr=   _open_parenrG   rI   r*   rF   r   r)   r   relevant_code)r3   cs     r   _read_noun_contextrS   x   sY   zU\! #7 	(&'''	
.e<<===t	q{	" #7 	9E5::7888	
.UZ)@%HHIIIt	q~	% 	#7 	FEEJJJDEEE	Iej%&+l4 4 	5 	5 	5uj$|99;;;;>!# # 	#r   c           	          | j         sJ | j                                         }g }t          |j        j                  D ].}|                    | j                                                   /|                                 | j        r t          d|j        j
        d|d           t          |j        j
        |j        |t          j        |j        g|z                       }| j                            |           d S )Nz	Reducing rL   r   )rE   popranger?   r9   rO   rF   reverserJ   rN   r8   r   r3   r	   combine)rR   stackopr4   inodes        r   _run_opr\      s    :jnnGD7:#$$ ( (AL$$&&''''LLNNNw BGJ$9$9$9444@AAAWZ*GM4^W]Od$:;;= =DLr   c                    | j         t          j        k    r|j        rt	          d           |j        r`|j        d         j        j        t          j        k    r;t          |           |j        r%|j        d         j        j        t          j        k    ;|j        st          d|           |j        d         j        j        t          j        k    sJ t          j        |j        d         j        |j        d         j        | g          }||j        d         _        |j                                         dS | j         |j        v r|j        rt	          d| j         z             t%          |j        | j                  |           }|j        r`|j        j        |j        d         j        j        k    r;t          |           |j        r%|j        j        |j        d         j        j        k    ;|j        rt	          d| j         z             |j                            |           dS t          d| j                                        d	|           )
NzFound close-parenrA   zmissing '(' or extra ')'FzFound binary operator %rzPushing binary operator %rTzexpected an operator, not 'rM   )r(   r   r&   rJ   rN   rE   r?   r8   r%   r\   r   r	   rX   r3   rF   r)   rU   rH   r=   r:   rO   rQ   )r3   rR   combinedrY   s       r   _read_op_contextr_      s-   zU\! #7 	'%&&&j 	QZ^.9U\I 	AJJJ j 	QZ^.9U\I 	z 	@7???z"~ +u|;;;; >1:b>#7#$<#3#9#(#* + + #+R	
u	q|	# #7 	=,
;<<< ej!95AAz 	:(AJrN,=,HH	AJJJ z 	:(AJrN,=,HH	 7 	?.%*=>>>	
'"""tj$|99;;;;>!# # 	#r   Fc                 $   t          |           }i }i }|D ]S}|j        t          j        k    sJ |j        dk    r|||j        <   /|j        dk    r|||j        <   Et          d          t          ||||          }d}	|D ]?}
|j        rt          d|	d           |	rt          |
|          }	/t          |
|          }	@|j        rt          d           |	r%t          d|j        d	         j        j                  |j        r[|j        d	         j        j        t           j        k    r t          d
|j        d	         j                  t%          |           |j        [t'          |j                  dk    sJ |j                                        S )N      z!operators must be unary or binaryTzReading next token (want_noun=r   zEnd of token streamz1expected a noun, but instead the expression endedrA   zUnmatched '(')iterr:   rP   r9   r8   
ValueErrorrC   rJ   rN   rS   r_   r   rE   r3   r)   r?   r   r%   r\   lenrF   rU   )tokens	operatorsrI   rJ   token_sourcerG   rH   r?   rR   	want_nounr3   s              r   infix_parserj      s   <<LIJ B B}{555558q= 	B')Ibm$$X] 	B(*Jr}%%@AAAi\5AAA I 3 37 	FEDEEE 	3*5!44II(22IIw %#$$$ 9LJrN079 9 	9 * :b>'5<7 	D_ajn.BCCC


 * 
 q|!!!!<r   c                  h   t          ddd          t          ddd          t          ddd          g} d	d
g}t          ddd          }t          d	|d          t          d|d          t          d|d          t          d
|d          t          d|d          t          t          j        |d          t          d	|d          t          d|d          t          d
|d          t          t          j        |d          g
}t          || |          }d } ||dd            ||j        d         d	d           |j        d         j        g k    sJ  ||j        d         dd            ||j        d         j        d         dd           t          |j        d         j        d         j                  dk    sJ  ||j        d         j        d         j        d         d
d            ||j        d         j        d         dd            ||j        d         j        d         j        d         d	d            ||j        d         j        d         j        d         d
d           dd l}|	                    t          t
          g t          ddd          gdg           t          || |d           d S )N+rb   
   *   -ra      ATOM1ATOM2asdf   abr   rR   dr   c                 D    | j         |k    sJ | j        j        |k    sJ d S r   )r(   r3   r*   )treer(   r*   s      r   teztest_infix_parse.<locals>.te   s1    yD    z5((((((r   r   ATOMICT)rJ   )r   r	   r   r%   r&   rj   r4   re   pytestraisesrd   )opsatomicmock_originrf   rz   r{   r}   s          r   test_infix_parser      s   CBCBCB!C wFA&&KG[#..Cc**Cc**G[#..Cc**EL+s33G[#..Cc**G[#..EL+s33	5F vsF++D) ) ) BtS#Bty|Wc"""9Q<""""Bty|S#Bty|S#&&&ty| #())Q....Bty| #Wc222Bty|S#&&&Bty| #Wc222Bty| #Wc222MMM
MM*rHS!R$8$8#9H:G G G V4000000r   N)F)
__future__r   __all__patsyr   patsy.originr	   
patsy.utilr
   r   r   r   objectr   r   r   r   r=   r%   rP   rC   rS   r\   r_   rj   r   r#   r   r   <module>r      s  > & % % % % %
5
5
5            9 9 9 9 9 9 9 9 9 9 9 9    6       F   4       
 
 
 
 
v 
 
 
    V    hu|R22	 	 	 	 	F 	 	 	# # #,   #  #  #D) ) ) )X&1 &1 &1 &1 &1r   