o
    \i                     @   sh   d Z ddlZddlmZ ddlmZ ddlmZ edZedZ	dd Z
d	d
 Zdd Zd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                 C   sJ   | sdS t | }t| }t|D ]\}}||| kr"|d|   S q|S )zJGiven an iterable of strings, returns the longest common leading substring N)minmax	enumerate)ms1s2ic r   O/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/pygments/regexopt.pycommonprefix   s   r   c                 C   s   dt dd d|  d S )N[c                 S   s   d|    S )N\)group)r	   r   r   r   <lambda>"   s    zmake_charset.<locals>.<lambda>r   ])	CS_ESCAPEsubjoin)lettersr   r   r   make_charset!   s   r   c           	   	      s  |rdpd}| s
dS | d  t | dkr|t  | S  s-|t| dd d d | S t  dkrlg }g }| D ]}t |dkrG|| q9|| q9t |dkrl|rd|t|d d t| | S |t| | S t| }|rt ||t| tfd	d
| D d | S dd
 | D }t|}|rt ||ttfdd| D d t|ddd  | S |ddd t|  fddD  | S )zEReturn a regex that matches any string in the sorted list of strings.)r   r      Nz(?:?|c                    s   g | ]}| d  qS Nr   .0s)plenr   r   
<listcomp>J   s    z#regex_opt_inner.<locals>.<listcomp>c                 S   s   g | ]	}|d d d qS )Nr   r    r   r   r   r$   M   s    c                 3   s    | ]
}|d    V  qd S r   r   r    )slenr   r   	<genexpr>S   s    z"regex_opt_inner.<locals>.<genexpr>r%   c                 s   s"    | ]}t t|d  dV  qdS )r   r   N)regex_opt_innerlist)r!   r   r   r   r   r'   X   s    c                    s   | d  d kS )Nr   r   )r"   )firstr   r   r   Y   s    z!regex_opt_inner.<locals>.<lambda>)	lenr   r(   appendr   r   sortedr   r   )	strings
open_parenclose_paren	oneletterrestr"   prefixstrings_revsuffixr   )r*   r#   r&   r   r(   %   sj   

r(   r   c                 C   s   t | } |t| d | 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.
    ()r-   r(   )r.   r3   r5   r   r   r   	regex_opt]   s   r7   )r   r   )__doc__rer   	itertoolsr   operatorr   compiler   FIRST_ELEMENTr   r   r(   r7   r   r   r   r   <module>   s    
8