ó
l2RTc           @   s’   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 j	 d ƒ Z
 e d ƒ Z d	 „  Z d
 „  Z d d d „ Z d S(   s  
    pygments.regexopt
    ~~~~~~~~~~~~~~~~~

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

    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
iÿÿÿÿN(   t   escape(   t   commonprefix(   t   groupby(   t
   itemgetters
   [\^\\\-\]]i    c         C   s$   d t  j d „  d j |  ƒ ƒ d S(   Nt   [c         S   s   d |  j  ƒ  S(   Ns   \(   t   group(   t   m(    (    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyt   <lambda>   s    t    t   ](   t	   CS_ESCAPEt   subt   join(   t   letters(    (    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyt   make_charset   s    c   
         s  | r d p d } |  s d S|  d ‰  t  |  ƒ d k rJ | t ˆ  ƒ | Sˆ  sm | t |  d d ƒ d | St  ˆ  ƒ d k rg  } g  } x= |  D]5 } t  | ƒ d k rº | j | ƒ q’ | j | ƒ q’ Wt  | ƒ d k r| r| t | d ƒ d t | ƒ | St | ƒ Sn  t |  ƒ } | rgt  | ƒ } | t | ƒ t g  |  D] } | | ^ qHd ƒ | Sg  |  D] } | d d d	 … ^ qn} t | ƒ }	 |	 rít  |	 ƒ ‰ | t t ‡ f d
 †  |  Dƒ ƒ d ƒ t |	 d d d	 … ƒ | S| d j d „  t |  ‡  f d †  ƒ Dƒ ƒ | S(   sE   Return a regex that matches any string in the sorted list of strings.t   )R   i    i   s   (?:t   ?t   |Niÿÿÿÿc         3   s   |  ] } | ˆ   Vq d  S(   N(    (   t   .0t   s(   t   slen(    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pys	   <genexpr>I   s    c         s   s(   |  ] } t  t | d  ƒ d ƒ Vq d S(   i   R   N(   t   regex_opt_innert   list(   R   R   (    (    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pys	   <genexpr>N   s   c            s   |  d ˆ  d k S(   Ni    (    (   R   (   t   first(    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyR   O   s    (	   t   lenR    R   t   appendR   R   t   sortedR   R   (
   t   stringst
   open_parent   close_parent	   onelettert   restR   t   prefixt   plent   strings_revt   suffix(    (   R   R   s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyR      s:    
#6&BR   c         C   s!   t  |  ƒ }  | t |  d ƒ | S(   sí   Return 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.
    t   ((   R   R   (   R   R    R#   (    (    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyt	   regex_optS   s    (   t   __doc__t   reR    t   os.pathR   t	   itertoolsR   t   operatorR   t   compileR
   t   FIRST_ELEMENTR   R   R%   (    (    (    s5   /usr/lib/python2.7/dist-packages/pygments/regexopt.pyt   <module>   s   		8