
    i                         d Z ddlZddlmZ ddlmZ ddlmZ  ej        d          Z ed          Z	d Z
d Zd	 ZddZdS )a  
    pygments.regexopt
    ~~~~~~~~~~~~~~~~~

    An algorithm that generates optimized regexes for matching long lists of
    literal strings.

    :copyright: Copyright 2006-present by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)escape)groupby)
itemgetterz[\[\^\\\-\]]c                     | sdS t          |           }t          |           }t          |          D ]\  }}|||         k    r|d|         c S |S )zJGiven an iterable of strings, returns the longest common leading substring N)minmax	enumerate)ms1s2ics        N/root/projects/qq-shell/venv/lib/python3.11/site-packages/pygments/regexopt.pycommonprefixr      sf     r	QB	QB"  11::bqb6MMM I    c                 l    dt                               d d                    |                     z   dz   S )N[c                 0    d|                                  z   S )N\)group)r   s    r   <lambda>zmake_charset.<locals>.<lambda>"   s    		)9 r   r   ])	CS_ESCAPEsubjoin)letterss    r   make_charsetr   !   s0    992777;K;KLLLsRRr   c           	        	
 |rdpd}| sdS | d         	t          |           dk    r|t          	          z   |z   S 	s!|t          | dd         d          z   dz   |z   S t          	          dk    rg }g }| D ]@}t          |          dk    r|                    |           +|                    |           At          |          dk    r@|r)|t          |d          z   dz   t	          |          z   |z   S |t	          |          z   |z   S t          |           }|rAt          |          
|t          |          z   t          
fd	| D             d          z   |z   S d
 | D             }t          |          }|rWt          |          |t          t          fd| D                       d          z   t          |ddd                   z   |z   S |d                    d t          | 	fd          D                       z   |z   S )zEReturn a regex that matches any string in the sorted list of strings.)r   r      Nz(?:?|c                 $    g | ]}|d          S N ).0splens     r   
<listcomp>z#regex_opt_inner.<locals>.<listcomp>J   s!    999Aqx999r   c                 $    g | ]}|d d d         S )Nr&   )r'   r(   s     r   r*   z#regex_opt_inner.<locals>.<listcomp>M   s"    ,,,q1TTrT7,,,r   c              3   .   K   | ]}|d           V  d S r%   r&   )r'   r(   slens     r   	<genexpr>z"regex_opt_inner.<locals>.<genexpr>S   s-      $@$@1QvvY$@$@$@$@$@$@r   r,   c              3   \   K   | ]'}t          t          |d                    d          V  (dS )r!   r   N)regex_opt_innerlist)r'   r   s     r   r/   z"regex_opt_inner.<locals>.<genexpr>X   sR       L L !eAh44 L L L L L Lr   c                 (    | d         d         k    S )Nr   r&   )r(   firsts    r   r   z!regex_opt_inner.<locals>.<lambda>Y   s    1q9I r   )	lenr   r1   appendr   r   sortedr   r   )strings
open_parenclose_paren	oneletterrestr(   prefixstrings_revsuffixr4   r)   r.   s            @@@r   r1   r1   %   s   $*K rAJE
7||qF5MM)K77  OGABBK???  	 
5zzQ	 	 	A1vv{{  ####Ay>>A <!OD"$=$==C"9--.0;< < Y 7 77+EE'""F 6{{ F6NN*99999995AAB 	 -,G,,,K+&&F 16{{f$@$@$@$@$@$@$@@@%HHIVDDbD\""#%01 	1
  L L%g/I/I/I/IJJL L L 	L 	LL  r   r   c                 L    t          |           } |t          | d          z   |z   S )zReturn a compiled regex that matches any string in the given list.

    The strings to match must be literal strings, not regexes.  They will be
    regex-escaped.

    *prefix* and *suffix* are pre- and appended to the final regex.
    ()r7   r1   )r8   r=   r?   s      r   	regex_optrB   ]   s)     WooGOGS111F::r   )r   r   )__doc__rer   	itertoolsr   operatorr   compiler   FIRST_ELEMENTr   r   r1   rB   r&   r   r   <module>rI      s   	 	 
			                  BJ''	
1	 	 	S S S5 5 5p	; 	; 	; 	; 	; 	;r   