3
h2                 @   sd   d Z ddlmZ ddlZejeeeed ddlmZ ddlm	Z	m
Z
mZ e ZG dd	 d	eZdS )
z3
Python Lexical Analyser

Scanning an input stream
    )absolute_importN)BOLEOLEOF	NOT_FOUND   )Errors)r   r   r   c               @   s   e Zd 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 Zdd Zdd ZdddZdd Zedd ZdS ) Scannera  
    A Scanner is used to read tokens from a stream of characters
    using the token set specified by a Plex.Lexicon.

    Constructor:

      Scanner(lexicon, stream, name = '')

        See the docstring of the __init__ method for details.

    Methods:

      See the docstrings of the individual methods for more
      information.

      read() --> (value, text)
        Reads the next lexical token from the stream.

      position() --> (name, line, col)
        Returns the position of the last token read using the
        read() method.

      begin(state_name)
        Causes scanner to change state.

      produce(value [, text])
        Causes return of a token value to the caller of the
        Scanner.

     Nc             C   s   d| _ d| _d| _d| _d| _d| _d| _d| _d| _d| _	d| _
|| _|| _|| _g | _d| _| jd d| _d| _d| _t| _d| _|dk	r|d |d   | _| _dS )a  
        Scanner(lexicon, stream, name = '')

          |lexicon| is a Plex.Lexicon instance specifying the lexical tokens
          to be recognised.

          |stream| can be a file object or anything which implements a
          compatible read() method.

          |name| is optional, and may be the name of the file being
          scanned or any other identifying string.
        r   r
   r   N   )r
   r   r   )r
   r   r   )tracebufferbuf_start_posnext_poscur_poscur_line	start_poscurrent_scanner_position_tuplelast_token_position_tupletext
state_namelexiconstreamnamequeueinitial_statebegincur_line_startr   cur_charinput_state)selfr   r   r   Zinitial_pos r!   f/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/Cython/Plex/Scanners.py__init__M   s0    
zScanner.__init__c             C   sr   | j }xR|sX| j \| _}|dkr6| jd | j  q|j| | j}|dk	r| j| qW |d \}| _|d= |S )a"  
        Read the next lexical token from the stream and return a
        tuple (value, text), where |value| is the value associated with
        the token as specified by the Lexicon, and |text| is the actual
        string read from the stream. Returns (None, '') on end of file.
        Nr   )r   scan_a_tokenr   produceeofZperformr   )r    r   actionvalueresultr!   r!   r"   readu   s    

zScanner.readc             C   s   | j jd||f|f d S )Nr   )r   insert)r    tokenr(   positionr!   r!   r"   unread   s    zScanner.unreadc             C   s   | j S )N)r   )r    r!   r!   r"   get_current_scan_pos   s    zScanner.get_current_scan_posc             C   s   | j | _| j| j| j | j f| _| j }|dk	rr| jrLtd|| j| j f  | j	| j| j
 | j | j
  }||fS | j | jkr| jtkr| j  | jdks| jtkrdS tj| | jdS )z
        Read the next input sequence recognised by the machine
        and return (text, action). Returns ('', None) on end of
        file.
        Nz"Scanner: read: Performing %s %d:%dr
   )r
   N)r   r   r   r   r   r   run_machine_inlinedr   printr   r   r   r   	next_charr   r   ZUnrecognizedInputr   )r    r'   r   r!   r!   r"   r$      s"    

zScanner.scan_a_tokenc             C   s  | j }| j}| j}| j}| j}| j}| j}| j}| j}	t	|}
d\}}}}}}}| j
}x|rztd|d ||t|f  |d }|dk	r|||||||f\}}}}}}}|}|j|t}|tkr|o|jd}|r|rtd|d   |}|d	kr|}||	 }||
k r || }|d	7 }nh| j|	 }| jjd
}| j|d | }|| _|	|7 }	|	| _t	|}
||8 }|r|| }|d	7 }nd}|dkrt}d}n|st}d}n|}nP|dkrd}d}n<|dkr|d	7 }| }}t}d	}n|dkrt}d}nd}qZ|rtd |dk	r>|||||||f\}}}}}}}nd}P qZW || _|| _|| _|| _|| _|| _|r|dk	rtd|  |S )z;
        Inlined version of run_machine for speed.
        Nr   r
   zState %d, %d/%d:%s -->numberr'   elsezState %dr   i   
r            ZblockedzDoing %s)Nr   r   r   r
   r   r   )r   r   r   r   r   r   r   r   r   lenr   r1   reprgetr   r   r   r*   r   r   r   )r    stater   r   r   r   r   r   r   r   Zbuf_lenZb_actionZ	b_cur_posZ
b_cur_lineZb_cur_line_startZ
b_cur_charZb_input_stateZ
b_next_posr   r'   cZ	new_stateZ	buf_indexdiscarddatar!   r!   r"   r0      s     










zScanner.run_machine_inlinedc             C   s   | j }| jr tdd|| jf  |dkrh| j| _| j }|dkrNt| _d| _ q|s`t| _d| _ q|| _nd|dkr~d| _d| _ nN|dkr|  jd7  _| j | _	| _t
| _d| _ n|dkrt| _d	| _ nd
| _| jrtd|| j| jf  d S )NzScanner: next: %s [%d] %d    r   r5   r   r6   r7   r8   r
   z--> [%d] %d %rz                    )r   r   r1   r   r   Z	read_charr   r   r   r   r   r   )r    r   r=   r!   r!   r"   r2     s6    zScanner.next_charc             C   s   | j S )am  
        Return a tuple (name, line, col) representing the location of
        the last token read using the read() method. |name| is the
        name that was provided to the Scanner constructor; |line|
        is the line number in the stream (1-based); |col| is the
        position within the line of the first character of the token
        (0-based).
        )r   )r    r!   r!   r"   r-   8  s    	zScanner.positionc             C   s   | j  S )zX
        Python accessible wrapper around position(), only for error reporting.
        )r-   )r    r!   r!   r"   get_positionC  s    zScanner.get_positionc             C   s   | j j|| _|| _dS )z8Set the current state of the scanner to the named state.N)r   Zget_initial_stater   r   )r    r   r!   r!   r"   r   I  s    zScanner.beginc             C   s(   |dkr| j }| jj||f| jf dS )a  
        Called from an action procedure, causes |value| to be returned
        as the token value from read(). If |text| is supplied, it is
        returned in place of the scanned text.

        produce() can be called more than once during a single call to an action
        procedure, in which case the tokens are queued up and returned one
        at a time by subsequent calls to read(), until the queue is empty,
        whereupon scanning resumes.
        N)r   r   appendr   )r    r(   r   r!   r!   r"   r%   O  s    zScanner.producec             C   s   dS )z_
        Override this method if you want something to be done at
        end of file.
        Nr!   )r    r!   r!   r"   r&   ^  s    zScanner.eofc             C   s
   | j d S )Nr   )r   )r    r!   r!   r"   
start_linee  s    zScanner.start_line)r
   N)N)__name__
__module____qualname____doc__r#   r*   r.   r/   r$   r0   r2   r-   rB   r   r%   r&   propertyrD   r!   r!   r!   r"   r	      s   
(m
r	   )rH   
__future__r   ZcythonZdeclareobjectr
   r   ZRegexpsr   r   r   r   r	   r!   r!   r!   r"   <module>   s   