B
    dH                 @   st  d dl mZ d dlZejeeeeeeed d dl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mZ dd
lmZmZmZ ddlmZ d Zd Zd ZdZdadd Zddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,gZed-d.d/d0d1d2d3d4d5g	 ZG d6d7 d7eZG d8d9 d9eZd:d; Z G d<d= d=eZ!G d>d? d?e!Z"G d@dA dAe!Z#G dBdC dCe
Z$dS )D    )absolute_importN)make_lexiconlexiconprint_functionerrorwarningosplatform   )Utils)Scanner)UnrecognizedInput   )r   r   )any_string_prefixr   IDENT)r   c               C   s   t s
t a t S )N)r   r    r   r   e/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/Cython/Compiler/Scanning.pyget_lexicon   s    r   globalnonlocaldefclassprintdelpassbreakcontinuereturnraiseimportexectryexceptfinallywhileifelifelseforinassertandornotislambdafromyieldwithincludeZctypedefZcdefZcpdefZcimportZDEFZIFZELIFELSEc               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
Methodc             K   s   || _ |pd | _|| _d S )N)namekwargs__name__)selfr6   r7   r   r   r   __init__8   s    
zMethod.__init__c             C   s,   t || j}| jd k	r$||f| jS ||S )N)getattrr6   r7   )r9   streamtextmethodr   r   r   __call__=   s    zMethod.__call__c             C   s   | S )Nr   )r9   r   r   r   __copy__B   s    zMethod.__copy__c             C   s   | S )Nr   )r9   memor   r   r   __deepcopy__E   s    zMethod.__deepcopy__N)r8   
__module____qualname__r:   r?   r@   rB   r   r   r   r   r5   6   s   r5   c               @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )CompileTimeScopeNc             C   s   i | _ || _d S )N)entriesouter)r9   rG   r   r   r   r:   M   s    zCompileTimeScope.__init__c             C   s   || j |< d S )N)rF   )r9   r6   valuer   r   r   declareQ   s    zCompileTimeScope.declarec             C   s   | j | d S )N)rF   update)r9   otherr   r   r   rJ   T   s    zCompileTimeScope.updatec             C   s
   | j | S )N)rF   )r9   r6   r   r   r   lookup_hereW   s    zCompileTimeScope.lookup_herec             C   s
   || j kS )N)rF   )r9   r6   r   r   r   __contains__Z   s    zCompileTimeScope.__contains__c             C   s:   y
|  |S  tk
r4   | j}|r.||S  Y nX d S )N)rL   KeyErrorrG   lookup)r9   r6   rG   r   r   r   rO   ]   s    

zCompileTimeScope.lookup)N)	r8   rC   rD   r:   rI   rJ   rL   rM   rO   r   r   r   r   rE   K   s   
rE   c           	   C   s  t  } d}x&t|t D ]\}}| || qW ydd l}W n tk
rZ   dd l}Y nX d}x8|D ]0}y| |t|| W qf t	k
r   Y qfX qfW ddl
m} | d| | dt|dt|d | dt|dt|d	 | d
t|d
t|d t | }|S )N)ZUNAME_SYSNAMEZUNAME_NODENAMEZUNAME_RELEASEZUNAME_VERSIONZUNAME_MACHINEr   )*FalseTrueabsallanyasciibinbool	bytearraybyteschrcmpcomplexdictdivmod	enumeratefilterfloatformat	frozensethashhexintlenlistmapmaxminoctordpowrangereprreversedroundsetslicesortedstrsumtuplezip)reducerz   unicoderv   longrf   xrangero   )rE   ry   r	   unamerI   __builtin__ImportErrorbuiltinsr;   AttributeError	functoolsrz   )Zbenvnamesr6   rH   r   rz   Zdenvr   r   r   initial_compile_time_envh   s*    

r   c               @   sp   e Zd ZdZdZdZdZdZdd Zdd Z	d	d
 Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )SourceDescriptorz<
    A SourceDescriptor should be considered immutable.
    Npyx c             C   s   dst d S )NF)AssertionError)r9   r   r   r   __str__   s    zSourceDescriptor.__str__c             C   s.   t j|\}}|dkr$|dd  p&d| _d S )N)z.pyxz.pxdz.pyr   r   )r   pathsplitext
_file_type)r9   filenamer6   extr   r   r   set_file_type_from_name   s    z(SourceDescriptor.set_file_type_from_namec             C   s
   | j dkS )N)r   Zpxd)r   )r9   r   r   r   is_cython_file   s    zSourceDescriptor.is_cython_filec             C   s
   | j dkS )Npy)r   )r9   r   r   r   is_python_file   s    zSourceDescriptor.is_python_filec             C   s4   | j d kr.|  ddd}|dd| _ | j S )NASCIIreplace\/)_escaped_descriptionget_descriptionencodedecoder   )r9   Zesc_descr   r   r   get_escaped_description   s    
z(SourceDescriptor.get_escaped_descriptionc             C   s&   y| j |j kS  tk
r    dS X d S )NF)	_cmp_namer   )r9   rK   r   r   r   __gt__   s    zSourceDescriptor.__gt__c             C   s&   y| j |j k S  tk
r    dS X d S )NF)r   r   )r9   rK   r   r   r   __lt__   s    zSourceDescriptor.__lt__c             C   s&   y| j |j kS  tk
r    dS X d S )NF)r   r   )r9   rK   r   r   r   __le__   s    zSourceDescriptor.__le__c             C   s   | S )Nr   )r9   r   r   r   r@      s    zSourceDescriptor.__copy__c             C   s   | S )Nr   )r9   rA   r   r   r   rB      s    zSourceDescriptor.__deepcopy__)r8   rC   rD   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r@   rB   r   r   r   r   r      s   	r   c               @   sT   e Zd ZdZdddZdddZdd Zd	d
 Zdd Zdd Z	dd Z
dd ZdS )FileSourceDescriptora7  
    Represents a code source. A code source is a more generic abstraction
    for a "filename" (as sometimes the code doesn't come from a file).
    Instances of code sources are passed to Scanner.__init__ as the
    optional name argument and will be passed back when asking for
    the position()-tuple.
    Nc             C   sf   t |}|p|| _|| _tjdtj }||rF|t	|d  n|| _
| | || _i | _d S )N.)r   decode_filenamepath_descriptionr   r   r   abspathsep
startswithrg   	file_pathr   r   _lines)r9   r   r   Zworkdirr   r   r   r:      s    

 
zFileSourceDescriptor.__init__c          	   C   s   ||f}y| j | }|d k	r |S W n tk
r6   Y nX tj| j||d}t|}W d Q R X || j krt|| j |< n
d | j |< |S )N)encodingerror_handling)r   rN   r   Zopen_source_filer   rh   )r9   r   r   keylinesfr   r   r   	get_lines   s    


zFileSourceDescriptor.get_linesc             C   s*   yt j| jS  tk
r$   | jS X d S )N)r   r   relpathr   
ValueError)r9   r   r   r   r      s    z$FileSourceDescriptor.get_descriptionc             C   s:   | j }tt tjj }||r6|t|d  S |S )N)	r   r   r   r   getcwdr   r   r   rg   )r9   r   cwdr   r   r   get_error_description   s
    
z*FileSourceDescriptor.get_error_descriptionc             C   s   | j S )N)r   )r9   r   r   r   get_filenametable_entry  s    z,FileSourceDescriptor.get_filenametable_entryc             C   s   t |to| j|jkS )N)
isinstancer   r   )r9   rK   r   r   r   __eq__  s    zFileSourceDescriptor.__eq__c             C   s
   t | jS )N)rd   r   )r9   r   r   r   __hash__  s    zFileSourceDescriptor.__hash__c             C   s
   d| j  S )Nz<FileSourceDescriptor:%s>)r   )r9   r   r   r   __repr__  s    zFileSourceDescriptor.__repr__)N)NN)r8   rC   rD   r   r:   r   r   r   r   r   r   r   r   r   r   r   r      s   

r   c               @   sN   e Zd ZdZdd ZdddZdd ZeZd	d
 Zdd Z	dd Z
dd ZdS )StringSourceDescriptorzu
    Instances of this class can be used instead of a filenames if the
    code originates from a string object.
    c             C   s&   || _ dd |dD | _|| _d S )Nc             S   s   g | ]}|d  qS )
r   ).0xr   r   r   
<listcomp>  s    z3StringSourceDescriptor.__init__.<locals>.<listcomp>r   )r6   split	codelinesr   )r9   r6   coder   r   r   r:     s    zStringSourceDescriptor.__init__Nc                s$    s
| j S  fdd| j D S d S )Nc                s   g | ]}|   qS r   )r   r   )r   line)r   r   r   r   r   !  s   z4StringSourceDescriptor.get_lines.<locals>.<listcomp>)r   )r9   r   r   r   )r   r   r   r     s    z StringSourceDescriptor.get_linesc             C   s   | j S )N)r6   )r9   r   r   r   r   $  s    z&StringSourceDescriptor.get_descriptionc             C   s   dS )NZstringsourcer   )r9   r   r   r   r   )  s    z.StringSourceDescriptor.get_filenametable_entryc             C   s   t | S )N)id)r9   r   r   r   r   ,  s    zStringSourceDescriptor.__hash__c             C   s   t |to| j|jkS )N)r   r   r6   )r9   rK   r   r   r   r   2  s    zStringSourceDescriptor.__eq__c             C   s
   d| j  S )Nz<StringSourceDescriptor:%s>)r6   )r9   r   r   r   r   5  s    zStringSourceDescriptor.__repr__)NN)r8   rC   rD   r   r:   r   r   r   r   r   r   r   r   r   r   r   r     s   
r   c               @   s   e Zd Zd<ddZdd Zdd Zd	d
 Zdd Zdd Zdd Z	dddddZ
dd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd=d(d)Zd>d*d+Zd?d,d-Zd@d.d/Zd0d1 Zd2d3 ZdAd6d7Zd8d9 Zd:d; ZdS )BPyrexScannerNTc	       	      C   s  t | t ||| | r.d| _tt| _nd| _tt| _d| _	|r|j
| _
|j| _|j| _|j| _|j| _|j	r|   n@|| _
|j| _t | _d| _d| _t|jdd r| j|jj || _|| _t| _dg| _d | _d| _| d d| _|   d S )NTFr   r   compile_time_envINDENTr   )r   r:   r   r   Zin_python_filers   py_reserved_wordskeywordspyx_reserved_wordsasync_enabledcontextZincluded_filesr   Zcompile_time_evalZcompile_time_exprenter_asyncr   r;   optionsrJ   parse_commentssource_encodingtrace_scannertraceindentation_stackindentation_charbracket_nesting_levelbeginsynext)	r9   filer   Zparent_scannerscoper   r   r   Zinitial_posr   r   r   r:   B  s>    


zPyrexScanner.__init__c             C   s   | j r| d| d S )Ncommentline)r   produce)r9   r=   r   r   r   r   k  s    zPyrexScanner.commentlinec             C   s   |  ||dd d S )N_r   )r   r   )r9   r=   symbolr   r   r   strip_underscoreso  s    zPyrexScanner.strip_underscoresc             C   s
   | j d S )N)r   )r9   r   r   r   current_levelr  s    zPyrexScanner.current_levelc             C   s   |  j d7  _ |S )Nr   )r   )r9   r=   r   r   r   open_bracket_actionu  s    z PyrexScanner.open_bracket_actionc             C   s   |  j d8  _ |S )Nr   )r   )r9   r=   r   r   r   close_bracket_actiony  s    z!PyrexScanner.close_bracket_actionc             C   s$   | j dkr | d | dd d S )Nr   r   NEWLINEr   )r   r   r   )r9   r=   r   r   r   newline_action}  s    

zPyrexScanner.newline_actionZ	SQ_STRINGZ	DQ_STRINGZ
TSQ_STRINGZ
TDQ_STRING)'"z'''z"""c             C   s@   x |d d t kr |dd  }qW | | j|  | d d S )Nr   ZBEGIN_STRING)r   r   string_statesr   )r9   r=   r   r   r   begin_string_action  s    z PyrexScanner.begin_string_actionc             C   s   |  d | d d S )Nr   Z
END_STRING)r   r   )r9   r=   r   r   r   end_string_action  s    
zPyrexScanner.end_string_actionc             C   s   |  | | d d S )NzUnclosed string literal)r   r   )r9   r=   r   r   r   unclosed_string_action  s    
z#PyrexScanner.unclosed_string_actionc             C   s   |  d |rV|d }| jd kr(|| _n| j|kr<| d ||ddkrV| d |  }t|}||krrd S ||kr| j| | dd n>x&||  k r| j	  | dd qW ||  kr| d d S )Nr   r   zMixed use of tabs and spacesr   DEDENTzInconsistent indentation)
r   r   r   r   r   rg   r   appendr   pop)r9   r=   cr   Z	new_levelr   r   r   indentation_action  s*    





zPyrexScanner.indentation_actionc             C   s:   x(t | jdkr(| dd | j  qW | dd d S )Nr   r   r   EOF)rg   r   r   r   )r9   r=   r   r   r   
eof_action  s    zPyrexScanner.eof_actionc             C   s   y|   \}}W n tk
r.   | d d S X |tkr|| jkr|dkrdt| jjkrd| jd n&|dkr| jj	dkr| jd n|}| j
|}|| _|| _d S )NzUnrecognized characterr   r       )readr   r   r   r   r   r   Zfuture_directivesdiscardZlanguage_levelintern_ustringr   systring)r9   r   r   r   r   r   r     s     

zPyrexScanner.nextc             C   s:   | j | jf}|   | j | jf}| j|  |\| _ | _|S )N)r   r   r   unread)r9   Zsavedr   r   r   r   peek  s    
zPyrexScanner.peekc             C   s    |  | j| j || _|| _d S )N)r   r   r   )r9   r   r   r   r   r   put_back  s    zPyrexScanner.put_backc             C   s   | j d||f d S )Nr   )queueinsert)r9   tokenrH   r   r   r   r     s    zPyrexScanner.unreadc             C   s:   |d kr|   }| jdkr$t|d t||}|r6|d S )Nr   z!Possible inconsistent indentation)positionr   r   )r9   messageposfatalerrr   r   r   r     s    


 zPyrexScanner.errorc             C   s$   | j |kr|   n| || d S )N)r   r   expected)r9   whatr   r   r   r   expect  s    

zPyrexScanner.expectc             C   s.   | j tkr| j|kr|   n| || d S )N)r   r   r   r   r  )r9   r  r   r   r   r   expect_keyword  s    
zPyrexScanner.expect_keywordc             C   s>   |r|  | n*| jtkr"| j}n| j}|  d||f  d S )NzExpected '%s', found '%s')r   r   r   r   )r9   r  r   foundr   r   r   r    s    
zPyrexScanner.expectedc             C   s   |  dd d S )Nr   z)Expected an increase in indentation level)r  )r9   r   r   r   expect_indent	  s    zPyrexScanner.expect_indentc             C   s   |  dd d S )Nr   z(Expected a decrease in indentation level)r  )r9   r   r   r   expect_dedent  s    zPyrexScanner.expect_dedentExpected a newlineFc             C   sN   d }|r"| j dkr"|  }|   | j dkr8| d| |d k	rJt|d d S )N;r   r   zuseless trailing semicolon)r   r   r   r  r   )r9   r   Zignore_semicolonZuseless_trailing_semicolonr   r   r   expect_newline  s    
zPyrexScanner.expect_newlinec             C   s4   |  j d7  _ | j dkr0| jd | jd d S )Nr   asyncawait)r   r   add)r9   r   r   r   r     s    
zPyrexScanner.enter_asyncc             C   s`   | j dkst|  j d8  _ | j s\| jd | jd | jdkr\t| j| j | _| _d S )Nr   r   r  r  )r  r  )	r   r   r   r   r   r   r   r   r   )r9   r   r   r   
exit_async   s    
zPyrexScanner.exit_async)NNNNTN)NT)N)N)N)r
  F)r8   rC   rD   r:   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r	  r  r   r  r   r   r   r   r   ;  s<    
($





r   )%
__future__r   cythonrI   objectr   r	   r   r   ZPlex.Scannersr   ZPlex.Errorsr   ZErrorsr   r   ZLexiconr   r   r   Futurer   Zdebug_scannerr   Zscanner_debug_flagsZscanner_dump_filer   r   r   r   r5   rE   r   r   r   r   r   r   r   r   r   <module>   sB   


*<D)