B
    (d                  @   sl   d Z ddlZddlm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dZdS )a  
    pygments.regexopt
    ~~~~~~~~~~~~~~~~~

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

    :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)escape)commonprefix)groupby)
itemgetterz[\[\^\\\-\]]c             C   s   dt dd d|  d S )N[c             S   s   d|    S )N\)group)m r
   ^/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/pygments/regexopt.py<lambda>       zmake_charset.<locals>.<lambda> ])	CS_ESCAPEsubjoin)lettersr
   r
   r   make_charset   s    r   c       	   	      s  |rdp
d}| sdS | d  t | dkr8|t  | S  sZ|t| dd d d | S t  dkrg }g }x.| D ]&}t |dkr|| qt|| qtW t |dkr|r|t|d d t| | S |t| | S t| }|rt ||t| tfd	d
| D d | S dd
 | D }t|}|rtt ||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>?   s    z#regex_opt_inner.<locals>.<listcomp>c             S   s   g | ]}|d d d qS )Nr
   )r   r   r
   r
   r   r   B   s    c             3   s   | ]}|d    V  qd S )Nr
   )r   r   )slenr
   r   	<genexpr>H   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   M   s   c                s   | d  d kS )Nr   r
   )r   )firstr
   r   r   N   r   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       s:    
(6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&   r+   r-   r
   r
   r   	regex_optR   s    r/   )r   r   )__doc__rer   os.pathr   	itertoolsr   operatorr   compiler   FIRST_ELEMENTr   r    r/   r
   r
   r
   r   <module>
   s   
8