mς
oήFc           @   s΄   d  k  l  Z  d   Z d   Z d e f d     YZ d e f d     YZ d e f d     YZ d	 e f d
     YZ e	 d j o, d k
 Z
 e   Z e i e
 i e
 i  n d S(   (   s   StringIOc         C   sj   t  |   } t    } t   i | |  | i   } t |  d j o | d d j o | d } n | S(   Ni    s   
i   (	   t   StringIOt   jst   inst   outst   JavascriptMinifyt   minifyt   getvaluet   strt   len(   R   R   R   R   (    (    t   ../tools/jsmin.pyt   jsmin#   s    	$c         C   s   |  d j o |  d j px |  d j o |  d j p^ |  d j o |  d j pD |  d j p7 |  d j p* |  d	 j p |  d j	 o t |   d
 j S(   sq   return true if the character is a letter, digit, underscore,
           dollar sign, or non-ASCII character.
    t   at   zt   0t   9t   At   Zt   _t   $s   \i~   N(   t   ct   Nonet   ord(   R   (    (    R	   t
   isAlphanum,   s     t   UnterminatedCommentc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    R	   R   3   s   t   UnterminatedStringLiteralc           B   s   t  Z RS(   N(   R   R   (    (    (    R	   R   6   s   t   UnterminatedRegularExpressionc           B   s   t  Z RS(   N(   R   R   (    (    (    R	   R   9   s   R   c           B   sP   t  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(	   Nc         C   s   |  i i |  i  d  S(   N(   t   selft	   outstreamt   writet   theA(   R   (    (    R	   t   _outA>   s    c         C   s   |  i i |  i  d  S(   N(   R   R   R   t   theB(   R   (    (    R	   t   _outB@   s    c         C   s   |  i } d |  _ | d j o |  i i d  } n | d j p | d j o | Sn | d j o d Sn | d j o d Sn d S(   s«   return the next character from stdin. Watch out for lookahead. If
           the character is a control character, translate it to a space or
           linefeed.
        i   t    s   
t    t    s   N(   R   t   theLookaheadR   R   t   instreamt   read(   R   R   (    (    R	   t   _getC   s     		c         C   s   |  i   |  _ |  i S(   N(   R   R)   R&   (   R   (    (    R	   t   _peekT   s    c         C   sπ   |  i   } | d j oΣ |  i   } | d j o5 |  i   } x | d j o |  i   } qA W| Sn | d j ot |  i   } xe |  i   } | d j o) |  i   d j o |  i   d SqΕ n | d j o t    q q Wqμ n | S(   s{   get the next character, excluding comments. peek() is used to see
           if a '/' is followed by a '/' or '*'.
        t   /s   
t   *i   R#   R%   N(   R   R)   R   R*   t   pR   (   R   R-   R   (    (    R	   t   _nextX   s,        
c         C   sJ  | d j o |  i   n | d j o· |  i |  _ |  i d j p |  i d j o x |  i   |  i   |  _ |  i |  i j o Pn |  i d j o t    n |  i d j o |  i   |  i   |  _ qW qW Wqί n | d j oZ|  i   |  _ |  i d j o7|  i d	 j p |  i d
 j pp |  i d j p` |  i d j pP |  i d j p@ |  i d j p0 |  i d j p  |  i d j p |  i d j o§ |  i   |  i   x} |  i   |  _ |  i d j o PnK |  i d j o |  i   |  i   |  _ n |  i d j o t	    n |  i   q²W|  i   |  _ qFn d S(   sl  do something! What you do is determined by the argument:
           1   Output A. Copy B to A. Get the next B.
           2   Copy B to A. Get the next B. (Delete A).
           3   Get the next B. (Delete B).
           action treats a string as a single character. Wow!
           action recognizes a regular expression if it is preceded by ( or , or =.
        i   i   t   't   "s   
s   \i   R+   t   (t   ,t   =t   :t   [t   ?t   !t   &t   |N(
   t   actionR   R    R!   R   R)   R   R.   R"   R   (   R   R:   (    (    R	   t   _actionq   sD        

  

  
c         C   sΞ  d |  _ |  i d  x±|  i d j o |  i d j o2 t |  i  o |  i d  qΕ|  i d  q |  i d j o |  i d d d	 d
 d g j o |  i d  qΕ|  i d j o |  i d  qΕt |  i  o |  i d  qΕ|  i d  q |  i d j o2 t |  i  o |  i d  qΕ|  i d  q |  i d j oh |  i d d d d
 d d d g j o |  i d  qΕt |  i  o |  i d  qΕ|  i d  q |  i d  q Wd S(   s   Copy the input to the output, deleting the characters which are
           insignificant to JavaScript. Comments will be removed. Tabs will be
           replaced with spaces. Carriage returns will be replaced with linefeeds.
           Most spaces and linefeeds will be removed.
        s   
i   R%   R#   i   i   t   {R5   R1   t   +t   -t   }t   ]t   )R0   s   'N(   R   R   R;   R   R!   (   R   (    (    R	   t   _jsmin‘   s8     	 %c         C   sH   | |  _  | |  _ d  |  _ d  |  _ d  |  _ |  i   |  i  i   d  S(   N(	   R'   R   R   R   R   t   thaBR&   RB   t   close(   R   R'   R   (    (    R	   R   Λ   s    					
(
   R   R   R    R"   R)   R*   R.   R;   RB   R   (    (    (    R	   R   <   s   						0	*t   __main__N(   R    R
   R   t	   ExceptionR   R   R   t   objectR   R   t   syst   jsmR   t   stdint   stdout(	   R   R    RI   R   R   R   RH   R
   R   (    (    R	   R6   !   s   					