
    -Ph=:                        d Z ddlZddlmZ dZdZdZdZ ed	          Z	d
 Z
d Zd Zd Zd Z G d d          Zd Z G d de          Z G d de          Z 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 e            Zd e_         d!e_        d" Zd# Zd$ Zd% Z ed&          Zd'e_         d(e_        d4d)Z d* Z!d+ Z"d, Z#d- Z$ ee          Z%d.e%_         d/e%_         ee          Z&d0e&_         d1e&_         ee          Z'd2e'_         d3e'_        dS )5z.
Python Lexical Analyser

Regular Expressions
    N   )Errorsiboleoleof
c                    t          |           }|                                 d}t          |          }g }||k     rt          ||                   }|dz   }|dz  }||k     rB|t          ||                   k    r)|dz  }|dz  }||k     r|t          ||                   k    )|                    |           |                    |           ||k     |S )z
    Return a list of character codes consisting of pairs
    [code1a, code1b, code2a, code2b,...] which cover all
    the characters in |s|.
    r   r   )listsortlenordappend)s	char_listinresultcode1code2s          S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Plex/Regexps.pychars_to_rangesr      s     QINN	AIAF
a%%IaL!!		Q!eeYq\!2!222QJEFA !eeYq\!2!222 	ee a%% M    c                     t          | t          d                    }t          |t          d          dz             }||k     r)t          d          t          d          z
  }||z   ||z   fS dS )z
    If the range of characters from code1 to code2-1 includes any
    lower case letters, return the corresponding upper case range.
    azr   ANmaxr   minr   r   code3code4ds        r   uppercase_ranger$   3   i    
 s3xx  Es3xx!|$$Eu}}HHs3xx	519%%tr   c                     t          | t          d                    }t          |t          d          dz             }||k     r)t          d          t          d          z
  }||z   ||z   fS dS )z
    If the range of characters from code1 to code2-1 includes any
    upper case letters, return the corresponding lower case range.
    r   Zr   r   Nr   r    s        r   lowercase_ranger(   A   r%   r   c                 j      fdt          dt                     d          D             }t          | S )z
    Given a list of codes as returned by chars_to_ranges, return
    an RE which will match a character in any of the ranges.
    c                 N    g | ]!}t          |         |d z                      "S )r   )	CodeRange).0r   	code_lists     r   
<listcomp>zCodeRanges.<locals>.<listcomp>T   s0    ^^^Qy1yQ'788^^^r   r      )ranger   Alt)r-   re_lists   ` r   
CodeRangesr3   O   s<    
 _^^^%3y>>[\B]B]^^^G=r   c                     | t           cxk    r|k     rBn n?t          t          | t                     t          t          t           dz   |                    S t          | |          S )z
    CodeRange(code1, code2) is an RE which matches any character
    with a code |c| in the range |code1| <= |c| < |code2|.
    r   )nl_coder1   RawCodeRange
RawNewliner   r   s     r   r+   r+   X   sj    
 %<w//!U335 5 	5 E5)))r   c                   T    e Zd ZdZdZdZdZd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd ZdS )REa  RE is the base class for regular expression constructors.
    The following operators are defined on REs:

         re1 + re2         is an RE which matches |re1| followed by |re2|
         re1 | re2         is an RE which matches either |re1| or |re2|
    r   Nc                 :    t          d| j        j        z            )aM  
        This method should add states to |machine| to implement this
        RE, starting at |initial_state| and ending at |final_state|.
        If |match_bol| is true, the RE must be able to match at the
        beginning of a line. If nocase is true, upper and lower case
        letters should be treated as equivalent.
        z %s.build_machine not implemented)NotImplementedError	__class____name__)selfmachineinitial_statefinal_state	match_bolnocases         r   build_machinezRE.build_machineu   s&     ""D"&."9#: ; ; 	;r   c                     |                                 }|                    |           |                    ||           |S )z~
        Given a state |s| of machine |m|, return a new state
        reachable from |s| on character |c| or epsilon.
        )	new_statelink_toadd_transition)r?   mrA   cr   s        r   	build_optzRE.build_opt   s@    
 KKMMa   $$Q***r   c                 "    t          | |          S N)Seqr?   others     r   __add__z
RE.__add__       4r   c                 "    t          | |          S rN   )r1   rP   s     r   __or__z	RE.__or__   rS   r   c                 F    | j         r| j         S |                                 S rN   )strcalc_strr?   s    r   __str__z
RE.__str__   s!    8 	#8O==??"r   c                 b    t          |t                    s|                     ||d           d S d S )NzPlex.RE instance)
isinstancer:   
wrong_typer?   numvalues      r   check_rezRE.check_re   s;    %$$ 	<OOC(:;;;;;	< 	<r   c                 d    t          |          t          ur|                     ||d           d S d S )Nstring)typerW   r]   r^   s      r   check_stringzRE.check_string   s7    ;;c!!OOC11111 "!r   c                     |                      ||           t          |          dk    r1t          j        d|| j        j        t          |          fz            d S )Nr   zOInvalid value for argument %d of Plex.%s.Expected a string of length 1, got: %s)re   r   r   PlexValueErrorr=   r>   reprr^   s      r   
check_charzRE.check_char   sk    #u%%%u::??' )Q,/1H$u++TW)W X X X ?r   c                     t          |          t          j        k    r|j        j        d|j        j        d}nt          |          j        }t          j        d|| j        j        ||fz            )N.z	 instancez<Invalid type for argument %d of Plex.%s (expected %s, got %s)rd   typesInstanceTyper=   
__module__r>   r   PlexTypeError)r?   r_   r`   expectedgots        r   r]   zRE.wrong_type   s    ;;%,,,***EO,D,D,DFCC u++&C" $:'*DN,CXs=T$T U U 	Ur   )r>   rn   __qualname____doc__nullablematch_nlrW   rE   rL   rR   rU   rZ   ra   re   ri   r]    r   r   r:   r:   i   s          HH
C
; 
; 
;            # # #< < <2 2 2X X XU U U U Ur   r:   c                     t          |           dk    r.t          t          |           t          |           dz             }nt          |           }dt	          |           z  |_        |S )z;
    Char(c) is an RE which matches the character |c|.
    r   zChar(%s))r   r+   r   SpecialSymbolrh   rW   )rK   r   s     r   Charry      sX     1vv{{3q663q66A:..q!!d1gg%FJMr   c                   8    e Zd ZdZdZdZdZdZdZd Z	d Z
d ZdS )r6   z
    RawCodeRange(code1, code2) is a low-level RE which matches any character
    with a code |c| in the range |code1| <= |c| < |code2|, where the range
    does not include newline. For internal use only.
    r   Nc                 l    ||f| _         t          ||          | _        t          ||          | _        d S rN   )r0   r$   r(   )r?   r   r   s      r   __init__zRawCodeRange.__init__   s7    U^
.ue<<.ue<<r   c                    |r|                      ||t                    }|                    | j        |           |rF| j        r|                    | j        |           | j        r|                    | j        |           d S d S d S rN   )rL   BOLrI   r0   r$   r(   r?   rJ   rA   rB   rC   rD   s         r   rE   zRawCodeRange.build_machine   s     	B NN1mSAAM$$TZ=== 	P# P,,T-A;OOO# P,,T-A;OOOOO		P 	PP Pr   c                 $    d| j         | j        fz  S )NzCodeRange(%d,%d)r8   rY   s    r   rX   zRawCodeRange.calc_str   s    !TZ$<<<r   )r>   rn   rr   rs   rt   ru   r0   r$   r(   r|   rE   rX   rv   r   r   r6   r6      si         
 HHEOO= = =
P P P= = = = =r   r6   c                        e Zd ZdZdZdZd ZdS )_RawNewlinezd
    RawNewline is a low-level RE which matches a newline character.
    For internal use only.
    r   r   c                     |r|                      ||t                    }|                      ||t                    }|                    t          t          dz   f|           d S Nr   )rL   r~   EOLrI   r5   )r?   rJ   rA   rB   rC   rD   r   s          r   rE   z_RawNewline.build_machine   sZ     	B NN1mSAAMNN1mS11	'7Q;/=====r   N)r>   rn   rr   rs   rt   ru   rE   rv   r   r   r   r      s9          HH> > > > >r   r   c                   *    e Zd ZdZdZdZdZd Zd ZdS )rx   zx
    SpecialSymbol(sym) is an RE which matches the special input
    symbol |sym|, which is one of BOL, EOL or EOF.
    r   Nc                     || _         d S rN   )sym)r?   r   s     r   r|   zSpecialSymbol.__init__   s    r   c                     |r,| j         t          k    r|                     ||t                    }|                    | j         |           d S rN   )r   r   rL   r~   rI   r   s         r   rE   zSpecialSymbol.build_machine  sJ      	BS NN1mSAAM$$TX{;;;;;r   )	r>   rn   rr   rs   rt   ru   r   r|   rE   rv   r   r   rx   rx      sM          HH
C  < < < < <r   rx   c                   $    e Zd ZdZd Zd Zd ZdS )rO   z]Seq(re1, re2, re3...) is an RE which matches |re1| followed by
    |re2| followed by |re3|...c                    d}t          |          D ]$\  }}|                     ||           |o|j        }%|| _        || _        t	          |          }d}|r!|dz  }||         }|j        rd}n
|j        sn|!|| _        d S )Nr   r   )	enumeratera   rt   r2   r   ru   )r?   r2   rt   r   reru   s         r   r|   zSeq.__init__  s    w'' 	0 	0EArMM!R   /BKHH LL 	FAB{ ;   	 !r   c                 J   | j         }t          |          dk    r|                    |           d S |}t          |          }t          |          D ]P\  }	}
|	|dz
  k     r|                                }n|}|
                    |||||           |}|
j        p|o|
j        }Qd S Nr   r   )r2   r   rH   r   rG   rE   ru   rt   )r?   rJ   rA   rB   rC   rD   r2   s1r   r   r   s2s               r   rE   zSeq.build_machine   s    ,w<<1!!+.....BGA"7++ G G2q1u99BB$B  BIv>>>KFI,E"+		G Gr   c                 b    dd                     t          t          | j                            z  S )NzSeq(%s),joinmaprW   r2   rY   s    r   rX   zSeq.calc_str0  %    388CT\$:$:;;;;r   Nr>   rn   rr   rs   r|   rE   rX   rv   r   r   rO   rO   	  sN        " "! ! !&G G G < < < < <r   rO   c                   $    e Zd ZdZd Zd Zd ZdS )r1   zRAlt(re1, re2, re3...) is an RE which matches either |re1| or
    |re2| or |re3|...c                    || _         d}d}g }g }d}|D ]Z}|                     ||           |j        r|                    |           d}n|                    |           |j        rd}|dz  }[|| _        || _        || _        || _        d S r   )r2   ra   rt   r   ru   nullable_resnon_nullable_res)r?   r2   rt   ru   r   r   r   r   s           r   r|   zAlt.__init__8  s     		 		BMM!R   { ,##B''' ''+++{ FAA( 0  r   c                     | j         D ]}|                    |||||           | j        rA|r|                     ||t                    }| j        D ]}|                    |||d|           d S d S )Nr   )r   rE   r   rL   r~   )r?   rJ   rA   rB   rC   rD   r   s          r   rE   zAlt.build_machineN  s    # 	O 	OBQ{IvNNNN  	K F $q- E E+ K K  M;6JJJJ		K 	KK Kr   c                 b    dd                     t          t          | j                            z  S )NzAlt(%s)r   r   rY   s    r   rX   zAlt.calc_strW  r   r   Nr   rv   r   r   r1   r1   4  sN         ! ! !,K K K< < < < <r   r1   c                   $    e Zd ZdZd Zd Zd ZdS )Rep1z@Rep1(re) is an RE which matches one or more repetitions of |re|.c                 p    |                      d|           || _        |j        | _        |j        | _        d S r   )ra   r   rt   ru   )r?   r   s     r   r|   zRep1.__init__^  s3    ar   c                 (   |                                 }|                                 }|                    |           | j                            ||||p| j        j        |           |                    |           |                    |           d S rN   )rG   rH   r   rE   ru   )r?   rJ   rA   rB   rC   rD   r   r   s           r   rE   zRep1.build_machined  s    [[]][[]]b!!!aR)Fdg6FOOO


2


;r   c                     d| j         z  S )NzRep1(%s)r   rY   s    r   rX   zRep1.calc_strl  s    DG##r   Nr   rv   r   r   r   r   [  sG        JJ$ $ $     $ $ $ $ $r   r   c                   ,    e Zd ZdZdZdZd Zd Zd ZdS )
SwitchCasez
    SwitchCase(re, nocase) is an RE which matches the same strings as RE,
    but treating upper and lower case letters according to |nocase|. If
    |nocase| is true, case is ignored, otherwise it is not.
    Nc                 R    || _         || _        |j        | _        |j        | _        d S rN   )r   rD   rt   ru   )r?   r   rD   s      r   r|   zSwitchCase.__init__y  s&    r   c                 L    | j                             ||||| j                   d S rN   )r   rE   rD   r   s         r   rE   zSwitchCase.build_machine  s3    aY"k	+ 	+ 	+ 	+ 	+r   c                 4    | j         rd}nd}|d| j        dS )NNoCaseCase())rD   r   )r?   names     r   rX   zSwitchCase.calc_str  s-    ; 	DDD44))r   )	r>   rn   rr   rs   r   rD   r|   rE   rX   rv   r   r   r   r   p  sW         
 
BF$ $ $+ + +* * * * *r   r   z8
    Empty is an RE which matches the empty string.
    Emptyc                     t          t          t          t          |                      }dt	          |           z  |_        |S )z@
    Str1(s) is an RE which matches the literal string |s|.
    Str(%s))rO   tupler   ry   rh   rW   r   r   s     r   Str1r     s5     %D!%%&FT!WW$FJMr   c                     t          |           dk    rt          | d                   S t          t          t	          t          |                      }dd                    t	          t          |                     z  |_        |S )z
    Str(s) is an RE which matches the literal string |s|.
    Str(s1, s2, s3, ...) is an RE which matches any of |s1| or |s2| or |s3|...
    r   r   r   r   )r   r   r1   r   r   r   rh   rW   )strsr   s     r   Strr     sb    
 4yyA~~DG}}eCdOO,,-#dD//!:!::
r   c                 l    t          t          |                     }dt          |           z  |_        |S )zH
    Any(s) is an RE which matches any character in the string |s|.
    zAny(%s))r3   r   rh   rW   r   s     r   Anyr     s0     **++FT!WW$FJMr   c                     t          |           }|                    dt                      |                    t                     t	          |          }dt          |           z  |_        |S )zp
    AnyBut(s) is an RE which matches any character (including
    newline) which is not in the string |s|.
    r   z
AnyBut(%s))r   insertmaxintr   r3   rh   rW   )r   rangesr   s      r   AnyButr     s]    
 QF
MM!fW
MM&FQ'FJMr    zT
    AnyChar is an RE which matches any single character (including a newline).
    AnyCharc                    |r<t          t          |           t          |          dz             }d| d|d|_        ng }t          dt	          |           d          D ]Q}|                    t          t          | |                   t          | |dz                      dz                        Rt          | }dt          |           z  |_        |S )a  
    Range(c1, c2) is an RE which matches any single character in the range
    |c1| to |c2| inclusive.
    Range(s) where |s| is a string of even length is an RE which matches
    any single character in the ranges |s[0]| to |s[1]|, |s[2]| to |s[3]|,...
    r   zRange(r   r   r   r/   z	Range(%s))r+   r   rW   r0   r   r   r1   rh   )r   r   r   r   r   s        r   Ranger     s     
 ,3r77CGGaK00')rr222.

q#b''1%% 	E 	EAMM)C1JJBq1uI0BCCDDDDf 488+
Mr   c                 D    t          | t                    }d| z  |_        |S )zI
    Opt(re) is an RE which matches either |re| or the empty string.
    zOpt(%s))r1   r   rW   r   r   s     r   Optr     s!     U^^FRFJMr   c                 R    t          t          |                     }d| z  |_        |S )zJ
    Rep(re) is an RE which matches zero or more repetitions of |re|.
    zRep(%s))r   r   rW   r   s     r   Repr     s%     b]]FRFJMr   c                 $    t          | d          S )z
    NoCase(re) is an RE which matches the same strings as RE, but treating
    upper and lower case letters as equivalent.
    r   rD   r   r   s    r   r   r     s    
 b####r   c                 $    t          | d          S )z
    Case(re) is an RE which matches the same strings as RE, but treating
    upper and lower case letters as distinct, i.e. it cancels the effect
    of any enclosing NoCase().
    r   r   r   r   s    r   r   r     s     b####r   z=
    Bol is an RE which matches the beginning of a line.
    Bolz7
    Eol is an RE which matches the end of a line.
    Eolz9
    Eof is an RE which matches the end of the file.
    EofrN   )(rs   rl   r   r   r   r~   r   EOFr   r5   r   r$   r(   r3   r+   r:   ry   r6   r   r7   rx   rO   r1   r   r   r   rW   r   r   r   r   r   r   r   r   r   r   r   r   r   rv   r   r   <module>r      sV          	 
#d))  .      
* 
* 
*"EU EU EU EU EU EU EU EU^	 	 	= = = = =2 = = =>> > > > >" > > > []]
< < < < <B < < <((< (< (< (< (<" (< (< (<V$< $< $< $< $<" $< $< $<N$ $ $ $ $2 $ $ $** * * * * * * *D 	  	  
 
 
  
 
 
 &**     &    $ $ $$ $ $ d3ii  
d3ii  
d3ii  r   