
^Yc        
   @   s7  d  d l  m Z d  d l Z e j j d k  r= e e f Z n e Z e Z	 d d d d d d	 d
 d d d f
 Z
 d Z d   Z d Z d Z d Z d   Z e Z d Z d   Z d   Z d   Z d   Z d   Z d  d l Z d  d l Z d  d l Z d  d l Z e j d  Z i	 d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6Z d-   Z  d. e! f d/     YZ" d0 e! f d1     YZ# e$ d2 k r3d  d l% j& Z& e& j&   Z' d  d l Z e( e j) d3  Z* e* j+   Z, e# e'  Z- e- j. e, e j) d3  x/ e/ r/e- j0   Z1 e1 rPn  e- j2 e1 f GHqWn  d S(4   i(   t
   generatorsNi   t   CPP_IDt   CPP_INTEGERt	   CPP_FLOATt
   CPP_STRINGt   CPP_CHARt   CPP_WSt   CPP_COMMENT1t   CPP_COMMENT2t	   CPP_POUNDt
   CPP_DPOUNDs   +-*/%|&~^<>=!?()[]{}.,;:\'"c         C   s"   |  j  j |  j j d  7_ |  S(   s   \s+s   
(   t   lexert   linenot   valuet   count(   t   t(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   t_CPP_WS!   s    s   \#s   \#\#s   [A-Za-z_][\w_]*c         C   s   |  S(   sA   (((((0x)|(0X))[0-9a-fA-F]+)|(\d+))([uU][lL]|[lL][uU]|[uU]|[lL])?)(    (   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR   -   s    s?   ((\d+)(\.\d+)(e(\+|-)?(\d+))? | (\d+)e(\+|-)?(\d+))([lL]|[fF])?c         C   s"   |  j  j |  j j d  7_ |  S(   s   \"([^\\\n]|(\\(.|\n)))*?\"s   
(   R   R   R   R   (   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   t_CPP_STRING7   s    c         C   s"   |  j  j |  j j d  7_ |  S(   s   (L)?\'([^\\\n]|(\\(.|\n)))*?\'s   
(   R   R   R   R   (   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt
   t_CPP_CHAR=   s    c         C   sJ   |  j  j d  } |  j j | 7_ d |  _ | r= d | n d |  _  |  S(   s   (/\*(.|\n)*?\*/)s   
R   t    (   R   R   R   R   t   type(   R   t   ncr(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   t_CPP_COMMENT1C   s
    	 c         C   s   d |  _  d |  _ |  S(   s   (//.*?(\n|$))R   s   
(   R   R   (   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   t_CPP_COMMENT2L   s    	 	c         C   s4   |  j  d |  _ |  j  d |  _  |  j j d  |  S(   Ni    i   (   R   R   R   t   skip(   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   t_errorR   s    s   \?\?[=/\'\(\)\!<>\-]t   #t   =s   \t   /t   ^t   't   [t   (t   ]t   )t   |t   !t   {t   <t   }t   >t   ~t   -c         C   s   t  j d   |   S(   Nc         S   s   t  |  j   d S(   Ni(   t   _trigraph_rept   group(   t   g(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   <lambda>|   s    (   t   _trigraph_patt   sub(   t   input(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   trigraph{   s    t   Macroc           B   s   e  Z d e d   Z RS(   c         C   sG   | |  _  | |  _ | |  _ | |  _ | r: | d |  _ n  d  |  _ d  S(   Ni(   t   nameR   t   arglistt   variadict   varargt   Nonet   source(   t   selfR4   R   R5   R6   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   __init__   s    				N(   t   __name__t
   __module__R8   t   FalseR;   (    (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR3      s   t   Preprocessorc           B   s   e  Z d d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d d
  Z d   Z d d  Z d   Z d   Z d   Z d i  d  Z d   Z RS(   c         C   s   | d  k r t j } n  | |  _ i  |  _ g  |  _ g  |  _ |  j   t j   } |  j	 d t j
 d |   |  j	 d t j
 d |   d  |  _ d  S(   Ns   __DATE__ "%s"s   %b %d %Ys   __TIME__ "%s"s   %H:%M:%S(   R8   t   lexR   t   macrost   patht	   temp_patht   lexprobet   timet	   localtimet   definet   strftimet   parser(   R:   R   t   tm(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR;      s    				
c         C   sM   g  } |  j  j |  x0 t rH |  j  j   } | s8 Pn  | j |  q W| S(   N(   R   R1   t   Truet   tokent   append(   R:   t   textt   tokenst   tok(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   tokenize   s    	 c         C   s   d | | | f GHd  S(   Ns   %s:%d %s(    (   R:   t   filet   linet   msg(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   error   s    c      	   C   s  |  j  j d  |  j  j   } | s5 | j d k r= d GHn | j |  _ |  j  j d  |  j  j   } | s t | j  d k r d GHn | j |  _ t | j  |  _ |  j  j d  |  j  j   } | s | j d k r d GHn | j |  _	 |  j  j d  |  j  j   } | s(| j d k r4d  |  _ n | j |  _ |  j  j d	  |  j  j   } | su| j d	 k rd  |  _ d
 GHn | j |  _ |  j |  j f |  _ d d d d d d d d d g	 } xO | D]G } |  j  j |  |  j  j   } | s
| j | k rd | GHqqWd  S(   Nt
   identifiers"   Couldn't determine identifier typet   12345i90  s   Couldn't determine integer types
   "filename"s   Couldn't determine string types     s   
s%   Couldn't determine token for newlinesR&   R(   R   s   ##s   \R    R"   t   ,t   .s,   Unable to lex '%s' required for preprocessor(   R   R1   RL   R   R   t   t_IDt   intt	   t_INTEGERt   t_INTEGER_TYPEt   t_STRINGR8   t   t_SPACEt	   t_NEWLINEt   t_WS(   R:   RP   t   charst   c(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyRD      sD    	!c         C   s   |  j  j |  d  S(   N(   RB   RM   (   R:   RB   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   add_path  s    c   	      c   sQ  |  j  j   } g  | j   D] } | j   ^ q } x~ t t |   D]j } | d } xW | | j d  r | t |  k  r | | d  | | | | <d | | <| d 7} qZ WqG Wd j |  } | j |  d | _	 g  } x\ t
 r>| j   } | s Pn  | j |  | j |  j k r d | j k r | Vg  } q q W| rM| Vn  d  S(   Ni   s   \it    s   
(   R   t   clonet
   splitlinest   rstript   xranget   lent   endswitht   joinR1   R   RK   RL   RM   R   Ra   R   (	   R:   R1   R@   t   xt   linest   it   jt   current_lineRP   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   group_lines  s,    %
(
		!c         C   s   d } x6 | t  |  k  r> | | j |  j k r> | d 7} q	 W| | 4t  |  d } x0 | d k r | | j |  j k r | d 8} qY W| | d 3| S(   Ni    i   (   Rj   R   Ra   (   R:   RO   Ro   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt
   tokenstrip:  s    +%c   	      C   s  g  } g  } g  } d } t  |  } d } x0 | | k  r\ | | j |  j k r\ | d 7} q- W| | k  r | | j d k r | j | d  n* |  j |  j | d j d  d g  g  f S| d 7} x| | k  r| | } | j d k r| j |  | d 7} n | j d k rx| d 8} | d k rh| rW| j |  j |   | j |  n  | d | | f S| j |  nX | j d k r| d k r| j |  j |   | j | d  g  } n | j |  | d 7} q W|  j |  j | d j d  d g  g  f S(	   Ni   i    R    s   Missing '(' in macro argumentsR"   RX   is   Missing ')' in macro arguments(	   Rj   R   Ra   R   RM   RU   R9   R   Rs   (	   R:   t	   tokenlistt   argst	   positionst   current_argt   nestingt   tokenlenRo   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   collect_argsV  sD    %


	c         C   s  g  | _  g  | _ g  | _ d } xv| t | j  k  r| j | j |  j k r| j | j | j k r| j j | j | j  } | d k r| j | d j d k rt	 j	 | j |  | j | <|  j
 | j | _ | j | d =| j j | | d f  q$ q| d k rb| j | d j d k rb| j  j d | | d f  | j | d =q$ q| d t | j  k  r| j | d j d k r| j  j d | | f  | d 7} q$ q| j  j d | | f  n | j | j d k r| j r| d k r| j | d j d k r| d t | j  k  r| j | d j |  j k r| j | d j | j k r| j j | d  qn  | d 7} q$ W| j  j d d	   d
 t  d  S(   Ni    i   R   s   ##Rc   t   eRX   t   keyc         S   s   |  d S(   Ni   (    (   Rm   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR.     s    t   reverse(   t   patcht	   str_patcht   var_comma_patchRj   R   R   RZ   R5   t   indext   copyR^   RM   R6   R7   t   sortRK   (   R:   t   macroRo   t   argnum(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   macro_prescan  s:    			2&&3
/6c         C   s  g  | j  D] } t j |  ^ q
 } i  } x | j D] \ } } | | k r d d j g  | | D] } | j  ^ qa  j d d  | | <n  t j | |  | | <| | | | _  q5 Wt }	 | j r | d r x$ | j D] } d  | | <t	 }	 q Wn  i  }
 x | j
 D]} \ } } } | d k r=| | | | | d +q
| d k r
| |
 k ro|  j | |  |
 | <n  |
 | | | | d +q
q
W|	 rg  | D] } | r| ^ q} n  | S(	   Ns   "%s"Re   s   \s   \\iRc   i   R{   (   R   R   R   Rl   t   replaceR>   R6   R   R8   RK   R~   t   expand_macros(   R:   R   Ru   t   _xt   rept   str_expansionR   Ro   Rm   t   comma_patcht   expandedt   ptypet   _i(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   macro_expand_args  s.    %@
"c         C   s  | d  k r i  } n  d } x| t |  k  r| | } | j |  j k r| j |  j k r| j | k rt | | j <|  j | j } | j s|  j g  | j D] } t	 j	 |  ^ q |  } x | D] } | j
 | _
 q W| | | | d +| t |  7} nq| d }	 x6 |	 t |  k  rG| |	 j |  j k rG|	 d 7}	 qW| |	 j d k rv|  j | |	  \ }
 } } | j rt |  t | j  k r|  j |  j | j
 d | j t | j  f  |	 |
 } qv| j rt |  t | j  d k  rt | j  d k rK|  j |  j | j
 d | j t | j  d f  n3 |  j |  j | j
 d | j t | j  d f  |	 |
 } qv| j rt |  t | j  d k r| j g   q| |	 | t | j  d |	 |
 d !| t | j  d <| t | j  3n  |  j | |  } |  j | |  } x | D] } | j
 | _
 q<W| | | |	 |
 +| t |  7} n  | | j =q q| j d k r|  j | _ |  j | j
  | _ qn  | d 7} q W| S(	   Ni    i   R    s   Macro %s requires %d argumentsi   s(   Macro %s must have at least %d argumentss'   Macro %s must have at least %d argumentt   __LINE__(   R8   Rj   R   RZ   R   RA   RK   R5   R   R   R   Ra   Rz   R6   RU   R9   RM   R   R\   R]   (   R:   RO   R   Ro   R   t   mR   t   exR{   Rp   t   tokcountRu   Rv   R   t   r(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR     s\    	
!	1
+%/(63	;
c   	      C   s"  d } x{| t  |  k  r| | j |  j k rv| | j d k rv| d } t } d } x | t  |  k  r:| | j |  j k r | d 7} q] n | | j |  j k r | | j |  j k r d } n d } | s-Pq-nP | | j d k r t } n4 | | j d k rPn |  j |  j	 | | j
 d  | d 7} q] W|  j | | _ |  j |  | | _ | | d | d 5n  | d 7} q	 W|  j |  } x t |  D] \ } } | j |  j k rt j |  | | <|  j | | _ |  j d  | | _ q| j |  j k rt j |  | | <t | | j  | | _ x6 | | j d	 d
 k rn| | j d	  | | _ q<WqqWd j g  | D] } t | j  ^ q } | j d d  } | j d d  } | j d d  } y t |  } Wn4 t k
 r|  j |  j	 | d j
 d  d } n X| S(   Ni    t   definedi   t   0Lt   1LR    R"   s   Malformed defined()it   0123456789abcdefABCDEFRe   s   &&s    and s   ||s    or R$   s    not s   Couldn't evaluate expression(   Rj   R   RZ   R   R>   Ra   RA   RK   RU   R9   R   R\   R]   R   t	   enumerateR   t   strRl   R   t   evalt	   Exception(	   R:   RO   Ro   Rp   t	   needparent   resultR   Rm   t   expr(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   evalexpr*  s^    )

	 	#+
c         c   s  t  |  } |  j |  } | s* d } n  |  j d |  | |  _ g  } t } t } g  } x>| D]6}	 x0 t |	  D]" \ }
 } | j |  j k rv Pqv qv W| j	 d k rx? |	 D]7 } | j |  j k r d | j	 k r | j
 |  q q W|  j |	 |
 d  } | r-| d j	 } |  j | d  } n d } g  } | d k r| rx |  j |  D] } | Vq[Wg  } |  j |  qq| d k r| rx |  j |  D] } | VqWg  } |  j d	 } x |  j |  D] } | VqW| |  j d	 <| |  _ qq| d
 k rL| rx |  j |  D] } | Vq$Wg  } |  j |  qq| d k r| j
 | | f  | r| d j	 |  j k rt } t } qt } qq| d k r| j
 | | f  | r| d j	 |  j k rt } t } qt } qq| d k rM| j
 | | f  | r|  j |  } | sAt } t } qJt } qq| d k r| r| d d r| r|t } q| s|  j |  } | rt } t } qqqq|  j |  j | d j d  q| d k r9| r| d d r6| rt } q| st } t } qq6q|  j |  j | d j d  q| d k r| r`| j   \ } } q|  j |  j | d j d  qqc | rc | j |	  qc qc Wx |  j |  D] } | VqWg  } d  S(   NRe   s   __FILE__ "%s"R   s   
i   i    RG   t   includet   __FILE__t   undeft   ifdeft   ifndeft   ift   elifis   Misplaced #elift   elses   Misplaced #elset   endifs   Misplaced #endif(   R2   Rr   RG   R9   RK   R>   R   R   Ra   R   RM   Rs   R   RA   R   R   R   RU   R   t   popt   extend(   R:   R1   R9   R   Rn   t   chunkt   enablet	   iftriggert   ifstackRm   Ro   RP   t	   dirtokensR4   Ru   t   oldfileR   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   parsegene  s    		 !								 	  	c         c   s  | s
 d  S| r=| d j  d k rK | d j |  j k rK |  j |  } n  | d j  d k r d } x@ | t |  k  r | | j  d k r Pn  | d 7} qg Wd GHd  Sd j g  | d | !D] } | j  ^ q  } |  j d g |  j } q=| d j |  j k r1| d j  d d !} |  j d g |  j } q=d GHd  Sn  x | D] } t j j | |  } y} t	 | d	  j
   } t j j |  }	 |	 r|  j j d |	  n  x |  j | |  D] }
 |
 VqW|	 r|  j d =n  PWqDt k
 rqDXqDWd
 | GHd  S(   Ni    R&   i   R(   s   Malformed #include <...>Re   is   Malformed #include statementR   s   Couldn't find '%s'(   R   R   R^   R   Rj   Rl   RB   RC   t   ost   opent   readt   dirnamet   insertR   t   IOError(   R:   RO   Ro   Rm   t   filenameRB   t   pt   inamet   datat   dnameRP   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR     sF    ),	c         C   se  t  | t  r! |  j |  } n  | } y!| d } t |  d k rS | d } n d  } | s t | j g   } | |  j | j <n| j |  j	 k r t | j |  j
 | d   } | |  j | j <n| j d k rB|  j | d  \ } } } t }	 xK| D]}
 |	 rd GHPn  d j g  |
 D] } t | j  ^ q" } | d k rt }	 |  j |
 d _ d |
 d _ t }	 |
 d 3q nk | d	 d k r|
 d j |  j k rt }	 |
 d 3|
 d j d	 d k r |
 d j d	  |
 d _ q q n  t |
  d k s|
 d j |  j k r d
 GHPq q W|  j
 | d |  } d } x | t |  k  r| d t |  k  r| | j |  j	 k r| | d j d k r| | =qBq| | j d k r| | d j |  j	 k r| | d =qn  | d 7} qBWt | j | g  | D] } | d j ^ q|	  } |  j |  | |  j | j <n d GHWn t k
 r`d GHn Xd  S(   Ni    i   i   R    s0   No more arguments may follow a variadic argumentRe   s   ...t   __VA_ARGS__is   Invalid macro arguments   ##s   Bad macro definition(   t
   isinstancet   STRING_TYPESRQ   Rj   R8   R3   R   RA   R   Ra   Rs   Rz   R>   Rl   R   RK   RZ   R   t   LookupError(   R:   RO   t   linetokR4   t   mtypeR   R   Ru   Rv   R6   t   aR   t   astrt   mvalueRo   Rm   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyRG     sl    
+&(--2	c         C   s3   | d j  } y |  j | =Wn t k
 r. n Xd  S(   Ni    (   R   RA   R   (   R:   RO   t   id(    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR   _  s
    c         C   s"   | |  _  |  j | |  |  _ d  S(   N(   t   ignoreR   RI   (   R:   R1   R9   R   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   parsek  s    	c         C   sX   y6 x/ t  r4 t |  j  } | j |  j k r | Sq WWn t k
 rS d  |  _ d  SXd  S(   N(   RK   t   nextRI   R   R   t   StopIterationR8   (   R:   RP   (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyRL   t  s    	 	N(   R<   R=   R8   R;   RQ   RU   RD   Rd   Rr   Rs   Rz   R   R   R   R   R   R   RG   R   R   RL   (    (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyR?      s$   			<		!		5	+	2B	;	1	F		t   __main__i   (3   t
   __future__R    t   syst   version_infot   majorR   t   unicodeR   t   rangeRi   RO   t   literalsR   t   t_CPP_POUNDt   t_CPP_DPOUNDt   t_CPP_IDR   t   t_CPP_INTEGERt   t_CPP_FLOATR   R   R   R   R   t   reR   RE   t   os.pathR   t   compileR/   R+   R2   t   objectR3   R?   R<   t   ply.lexR@   R   R   t   argvt   fR   R1   R   R   RK   RL   RP   R9   (    (    (    s$   /tmp/pip-build-kpPAdC/ply/ply/cpp.pyt   <module>
   sh   $								
	  	 