ó
;ÏOc           @   sp   d  Z  d d l Z d e f d „  ƒ  YZ d d d „ Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d „  Z d S(   s   JsLex: a lexer for JavascriptiÿÿÿÿNt   Tokc           B   s    e  Z d  Z d Z d d „ Z RS(   s,   
    A specification for a token class.
    i    c         C   s:   t  j |  _ t  j d 7_ | |  _ | |  _ | |  _ d  S(   Ni   (   R    t   numt   idt   namet   regext   next(   t   selfR   R   R   (    (    s+   ../Django//lib/python/django/utils/jslex.pyt   __init__   s
    		N(   t   __name__t
   __module__t   __doc__R   t   NoneR   (    (    (    s+   ../Django//lib/python/django/utils/jslex.pyR       s   t    c            s&   d j  ‡  ‡ f d †  |  j ƒ  Dƒ ƒ S(   s¥   
    Create a regex from a space-separated list of literal `choices`.

    If provided, `prefix` and `suffix` will be attached to each choice
    individually.

    t   |c         3   s&   |  ] } ˆ  t  j | ƒ ˆ Vq d  S(   N(   t   ret   escape(   t   .0t   c(   t   prefixt   suffix(    s+   ../Django//lib/python/django/utils/jslex.pys	   <genexpr>   s    (   t   joint   split(   t   choicesR   R   (    (   R   R   s+   ../Django//lib/python/django/utils/jslex.pyt   literals   s    t   Lexerc           B   s    e  Z d  Z d „  Z d „  Z RS(   s2   
    A generic multi-state regex-based lexer.
    c         C   s³   i  |  _  i  |  _ x‘ | j ƒ  D]ƒ \ } } g  } xB | D]: } d | j } | |  j | <| j d | | j f ƒ q8 Wt j d j | ƒ t j	 t j
 Bƒ |  j  | <q W| |  _ d  S(   Ns   t%ds
   (?P<%s>%s)R   (   t   regexest   tokst   itemsR   t   appendR   R   t   compileR   t	   MULTILINEt   VERBOSEt   state(   R   t   statest   firstR    t   rulest   partst   tokt   groupid(    (    s+   ../Django//lib/python/django/utils/jslex.pyR   "   s    		0c         c   sÄ   t  | ƒ } |  j } |  j } |  j } d } x‡ | | k  r¶ xt | | j | | ƒ D]\ } | j } | | }	 | j | ƒ }
 | t  |
 ƒ 7} |	 j |
 f V|	 j rS |	 j } PqS qS Wq0 W| |  _ d S(   sX   
        Lexically analyze `text`.

        Yields pairs (`name`, `tokentext`).
        i    N(	   t   lenR    R   R   t   finditert	   lastgroupt   groupR   R   (   R   t   textt   endR    R   R   t   startt   matchR   R%   t   toktext(    (    s+   ../Django//lib/python/django/utils/jslex.pyt   lex0   s     				
		(   R   R	   R
   R   R0   (    (    (    s+   ../Django//lib/python/django/utils/jslex.pyR      s   	t   JsLexerc           B   s‹  e  Z d  Z e d d ƒ e d d ƒ e d d ƒ e d e d d	 d
 ƒd d ƒe d e d d	 d
 ƒd d ƒe d d d d ƒe d d d d ƒe d d ƒ e d d d d ƒe d e d ƒ d d ƒe d e d ƒ d d ƒe d e d ƒ d d ƒe d d d d ƒe d d d d ƒg Z e d d  ƒ g Z i e e d e d! ƒ d d ƒg e d 6e e d" d# d d ƒg e d 6Z d$ „  Z RS(%   sô   
    A Javascript lexer

    >>> lexer = JsLexer()
    >>> list(lexer.lex("a = 1"))
    [('id', 'a'), ('ws', ' '), ('punct', '='), ('ws', ' '), ('dnum', '1')]

    This doesn't properly handle non-Ascii characters in the Javascript source.
    t   comments   /\*(.|\n)*?\*/t   linecomments   //.*?$t   wss   \s+t   keywordsŠ  
                                break case catch class const continue debugger
                                default delete do else enum export extends
                                finally for function if import in instanceof
                                new return super switch this throw try typeof
                                var void while with
                                R   s   \bR   t   regt   reserveds   null true falset   divR   s·   
                            ([a-zA-Z_$   ]|\\u[0-9a-fA-Z]{4})   # first char
                            ([a-zA-Z_$0-9]|\\u[0-9a-fA-F]{4})*  # rest chars
                            t   hnums   0[xX][0-9a-fA-F]+t   onums   0[0-7]+t   dnumsä  
                            (   (0|[1-9][0-9]*)     # DecimalIntegerLiteral
                                \.                  # dot
                                [0-9]*              # DecimalDigits-opt
                                ([eE][-+]?[0-9]+)?  # ExponentPart-opt
                            |
                                \.                  # dot
                                [0-9]+              # DecimalDigits
                                ([eE][-+]?[0-9]+)?  # ExponentPart-opt
                            |
                                (0|[1-9][0-9]*)     # DecimalIntegerLiteral
                                ([eE][-+]?[0-9]+)?  # ExponentPart-opt
                            )
                            t   puncts§   
                                >>>= === !== >>> <<= >>= <= >= == != << >> &&
                                || += -= *= %= &= |= ^=
                                s	   ++ -- ) ]s)   { } ( [ . ; , < > + - * % & | ^ ! ~ ? : =t   strings   "([^"\\]|(\\(.|\n)))*?"s   '([^'\\]|(\\(.|\n)))*?'t   othert   .s   /= /R   së  
                    /                       # opening slash
                    # First character is..
                    (   [^*\\/[]            # anything but * \ / or [
                    |   \\.                 # or an escape sequence
                    |   \[                  # or a class, which has
                            (   [^\]\\]     #   anything but \ or ]
                            |   \\.         #   or an escape sequence
                            )*              #   many times
                        \]
                    )
                    # Following characters are same, except for excluding a star
                    (   [^\\/[]             # anything but \ / or [
                    |   \\.                 # or an escape sequence
                    |   \[                  # or a class, which has
                            (   [^\]\\]     #   anything but \ or ]
                            |   \\.         #   or an escape sequence
                            )*              #   many times
                        \]
                    )*                      # many times
                    /                       # closing slash
                    [a-zA-Z0-9]*            # trailing flags
                c         C   s    t  t |  ƒ j |  j d ƒ d  S(   NR6   (   t   superR1   R   R!   (   R   (    (    s+   ../Django//lib/python/django/utils/jslex.pyR   ´   s    (	   R   R	   R
   R    R   t   both_beforet
   both_afterR!   R   (    (    (    s+   ../Django//lib/python/django/utils/jslex.pyR1   K   s0   			'$c         C   sÓ   d „  } t  ƒ  } g  } x« | j |  ƒ D]š \ } } | d k rI d } nl | d k r” | j d ƒ rµ t j d | | d d !ƒ } d	 | d	 } qµ n! | d
 k rµ | j d d ƒ } n  | j | ƒ q( Wd j | ƒ S(   s³   
    Convert the Javascript source `js` into something resembling C for
    xgettext.

    What actually happens is that all the regex literals are replaced with
    "REGEX".
    c         S   s'   |  j  d ƒ } | d k r d S| Sd S(   s1   Used in a regex to properly escape double quotes.i    t   "s   \"N(   R*   (   t   mt   s(    (    s+   ../Django//lib/python/django/utils/jslex.pyt   escape_quotesÀ   s    R   s   "REGEX"R=   t   's   \\.|.i   iÿÿÿÿRC   R   s   \t   UR   (   R1   R0   t
   startswithR   t   subt   replaceR   R   (   t   jsRF   t   lexerR   R   R%   t   guts(    (    s+   ../Django//lib/python/django/utils/jslex.pyt   prepare_js_for_gettext¸   s    			(   R
   R   t   objectR    R   R   R1   RO   (    (    (    s+   ../Django//lib/python/django/utils/jslex.pyt   <module>   s   .m