
    Ki                         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y)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yt        |       }t        |       }t        |      D ]  \  }}|||   k7  s|d| c S  |S )zJGiven an iterable of strings, returns the longest common leading substring N)minmax	enumerate)ms1s2ics        ]/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/pygments/regexopt.pycommonprefixr      sN    	QB	QB" 11:bq6M I    c                 Z    dt         j                  d dj                  |             z   dz   S )N[c                 (    d| j                         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   !   s'    92777;KLLsRRr   c           	      r  
 |xr dxs d}| sy| d   
t        |       dk(  r|t        
      z   |z   S 
s|t        | dd d      z   dz   |z   S t        
      dk(  r~g }g }| D ]3  }t        |      dk(  r|j                  |       #|j                  |       5 t        |      dkD  r4|r!|t        |d      z   dz   t	        |      z   |z   S |t	        |      z   |z   S t        |       }|r:t        |      }|t        |      z   t        | D cg c]  }||d 	 c}d      z   |z   S | D cg c]
  }|ddd	    }}t        |      }	|	rAt        |	      |t        t        fd
| D              d      z   t        |	ddd	         z   |z   S |dj                  d t        | 
fd      D              z   |z   S c c}w c c}w )zEReturn a regex that matches any string in the sorted list of strings.)r   r      Nz(?:?|c              3   *   K   | ]
  }|d     y w)N ).0sslens     r   	<genexpr>z"regex_opt_inner.<locals>.<genexpr>S   s     $@1QvY$@s   c              3   L   K   | ]  }t        t        |d          d        yw)r!   r   N)regex_opt_innerlist)r'   r   s     r   r*   z"regex_opt_inner.<locals>.<genexpr>X   s)      L !eAh4 Ls   "$c                     | d   d   k(  S )Nr   r&   )r(   firsts    r   r   z!regex_opt_inner.<locals>.<lambda>Y   s    1q9I r   )	lenr   r,   appendr   r   sortedr   r   )strings
open_parenclose_paren	oneletterrestr(   prefixplenstrings_revsuffixr/   r)   s             @@r   r,   r,   %   s   $*KAJE
7|qF5M)K77OGABK??  	 
5zQ	 	A1v{  #A		
 y>A!OD"$==C"9-.0;< < Y 77+EE'"F6{ F6N*9Aqx95AB 	 %,,q1TrT7,K,+&F6{f$@$@@%HIVDbD\"#%01 	1
  L%g/IJL 	LL   : -s   F/
%F4c                 <    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.
    ()r2   r,   )r3   r8   r;   s      r   	regex_optr>   ]   s$     WoGOGS11F::r   )r   r   )__doc__rer   	itertoolsr   operatorr   compiler   FIRST_ELEMENTr   r   r,   r>   r&   r   r   <module>rE      sG   	 
   BJJ'	1	S5p	;r   