
    k"gq                     \    d Z ddlZ G d d      ZddZ G d d      Z G d d	e      Zd
 Zy)zJsLex: a lexer for JavaScript    Nc                       e Zd ZdZdZddZy)Tokz,
    A specification for a token class.
    r   Nc                     t         j                  | _        t         xj                  dz  c_        || _        || _        || _        y )N   )r   numidnameregexnext)selfr	   r
   r   s       K/var/www/html/djangosite/lib/python3.12/site-packages/django/utils/jslex.py__init__zTok.__init__   s/    ''1	
	    N)__name__
__module____qualname____doc__r   r    r   r   r   r      s     Cr   r   c                 X    dj                  fd| j                         D              S )z
    Create a regex from a space-separated list of literal `choices`.

    If provided, `prefix` and `suffix` will be attached to each choice
    individually.
    |c              3   T   K   | ]  }t        j                  |      z   z    ! y wr   )reescape).0cprefixsuffixs     r   	<genexpr>zliterals.<locals>.<genexpr>   s#     LqFRYYq\)F2Ls   %()joinsplit)choicesr   r   s    ``r   literalsr#      s      88LGMMOLLLr   c                       e Zd ZdZd Zd Zy)Lexerz2
    A generic multi-state regex-based lexer.
    c           	         i | _         i | _        |j                         D ]  \  }}g }|D ]B  }d|j                  z  }|| j                  |<   |j	                  d|d|j
                  d       D t        j                  dj                  |      t        j                  t        j                  z        | j                   |<    || _        y )Nzt%dz(?P<>)r   )regexestoksitemsr   appendr
   r   compiler    	MULTILINEVERBOSEstate)r   statesfirstr0   rulespartstokgroupids           r   r   zLexer.__init__%   s    	"LLN 	YLE5E B#&&.%(		'"Wcii@AB #%**SXXe_bllRZZ>W"XDLL	Y 
r   c              #   b  K   t        |      }| j                  }| j                  }| j                  }d}||k  rn||   j	                  ||      D ]P  }|j
                  }||   }	||   }
|t        |
      z  }|	j                  |
f |	j                  sD|	j                  } n ||k  rn|| _        yw)zW
        Lexically analyze `text`.

        Yield pairs (`name`, `tokentext`).
        r   N)lenr0   r)   r*   finditer	lastgroupr	   r   )r   textendr0   r)   r*   startmatchr	   r5   toktexts              r   lexz	Lexer.lex3   s      $i

,,yyck 00u= 	4j+W%xx))88HHE	 ck 
s   BB/B/'B/N)r   r   r   r   r   r@   r   r   r   r%   r%       s    r   r%   c                       e Zd ZdZ edd       edd       edd       ed ed	d
      d       ed edd
      d       eddd       eddd       edd       eddd       ed ed      d       ed ed      d       ed ed      d       eddd       eddd      gZ ed d!      gZe ed ed"      d      gz   ez   e ed#d$d      gz   ez   d%Z fd&Z	 xZ
S )'JsLexerz
    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.
    commentz/\*(.|\n)*?\*/linecommentz//.*?$wsz\s+keywordal  
                           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
                           z\b)r   reg)r   reservedznull true falsedivr   z
                  ([a-zA-Z_$   ]|\\u[0-9a-fA-Z]{4})   # first char
                  ([a-zA-Z_$0-9]|\\u[0-9a-fA-F]{4})*  # rest chars
                  hnumz0[xX][0-9a-fA-F]+onumz0[0-7]+dnuma|  
                    (   (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
                    )
                    punctz
                         >>>= === !== >>> <<= >>= <= >= == != << >> &&
                         || += -= *= %= &= |= ^=
                         z	++ -- ) ]z){ } ( [ . ; , < > + - * % & | ^ ! ~ ? : =stringz"([^"\\]|(\\(.|\n)))*?"z'([^'\\]|(\\(.|\n)))*?'other.z/= /r
   a  
                    /                       # 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
                )rI   rG   c                 :    t         |   | j                  d       y )NrG   )superr   r1   )r   	__class__s    r   r   zJsLexer.__init__   s    e,r   )r   r   r   r   r   r#   both_before
both_afterr1   r   __classcell__)rS   s   @r   rB   rB   N   s   0 	I()M9%D& 	 	
 	J!25AN 	
 	F(u5FJ !	
$ 	 		
 	GXk*7GXIJQVWH0u=H0u=y=K@ 	GTJ &)6

 	 . 3

< ='FR- -r   rB   c                 F   d }t               }g }|j                  |       D ]n  \  }}|dk(  rd}nP|dk(  r4|j                  d      r:t        j                  d||dd       }d	|z   d	z   }n|d
k(  r|j                  dd      }|j                  |       p dj                  |      S )z
    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                     | d   }|dk(  ry|S )z1Used in a regex to properly escape double quotes.r   "z\"r   )mss     r   escape_quotesz-prepare_js_for_gettext.<locals>.escape_quotes   s    aD8Hr   r
   z"REGEX"rN   'z\\.|.r   rY   r   \U )rB   r@   
startswithr   subreplacer,   r    )jsr\   lexerr   r	   r5   gutss          r   prepare_js_for_gettextrh      s     IE
AYYr] 	c7? CX ~~c"vvhs1RyADj3&T\ ++dC(C	!" 771:r   )ra   ra   )r   r   r   r#   r%   rB   rh   r   r   r   <module>ri      s<    # 
 M+ +\E-e E-P$r   