ó
Nä²Wc        	   @@  s   d  d l  m Z d  d l Z e j d e d e d e d e ƒ d d l m Z d d	 l m Z m	 Z	 m
 Z
 e ƒ  Z d
 e f d „  ƒ  YZ d S(   i    (   t   absolute_importNt   BOLt   EOLt   EOFt	   NOT_FOUNDi   (   t   Errors(   R   R   R   t   Scannerc           B@  sq   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d d
 „ Z d „  Z RS(   sÖ  
    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.

    t    c         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 |  _ |  _ n  d S(   sƒ  
        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.
        i    u    i   R   i   N(   t   tracet   buffert   buf_start_post   next_post   cur_post   cur_linet	   start_post
   start_linet	   start_colt   Nonet   textt
   state_namet   lexicont   streamt   namet   queuet   initial_statet   begint   cur_line_startR   t   cur_chart   input_state(   t   selfR   R   R   t   initial_pos(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyt   __init__H   s0    																					c         C@  s—   |  j  } xv | s |  j ƒ  \ |  _ } | d k rM |  j d ƒ |  j ƒ  q | j |  |  j ƒ } | d k	 r |  j | ƒ q q W| d } | d =| S(   s"  
        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.
        i    N(   R   t   scan_a_tokenR   R   t   producet   eoft   perform(   R   R   t   actiont   valuet   result(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyt   readp   s    		
c         C@  s  |  j  |  _ |  j |  _ |  j  |  j |  _ |  j ƒ  } | d k	 r• |  j rg d | |  j |  j  f GHn  |  j	 |  j |  j
 |  j  |  j
 !} | | f S|  j  |  j k rè |  j t k rÃ |  j ƒ  n  |  j d k sá |  j t k rè d Sn  t j |  |  j ƒ ‚ d S(   s–   
        Read the next input sequence recognised by the machine
        and return (text, action). Returns ('', None) on end of
        file.
        s"   Scanner: read: Performing %s %d:%du    N(   u    N(   R   R   R   R   R   R   t   run_machine_inlinedR   R   R	   R
   R   R   t	   next_charR   R   t   UnrecognizedInputR   (   R   R$   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR    …   s$    	
c         C@  sq  |  j  } |  j } |  j } |  j } |  j } |  j } |  j } |  j } |  j }	 t	 | ƒ }
 d \ } } } } } } } |  j } x’| r¬ d | d | | t | ƒ f GHn  | d } | d k	 rõ | | | | | | | f \ } } } } } } } n  | } | j | t ƒ } | t k r1| o+| j d ƒ } n  | r¾| rMd | d GHn  | } | d k rP| } | |	 } | |
 k  r’| | } | d 7} n… |  j |	 } |  j j d	 ƒ } |  j | | } | |  _ |	 | 7}	 |	 |  _ t	 | ƒ }
 | | 8} | r| | } | d 7} n d } | d
 k r2t } d } q»| sGt } d } q»| } q| d k rkd
 } d } q| d k rš| d 7} | } } t } d } q| d k rµt } d } qd } q„ | rÌd GHn  | d k	 r| | | | | | | f \ } } } } } } } n d } Pq„ W| |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | rm| d k	 rmd | GHqmn  | S(   s;   
        Inlined version of run_machine for speed.
        i    u    s   State %d, %d/%d:%s -->t   numberR$   t   elses   State %di   i   u   
i   i   i   i   t   blockeds   Doing %sN(   Ni    i    i    u    i    i    (   R   R   R   R   R   R   R   R	   R
   t   lenR   R   t   reprt   getR   R   R   R'   R   R   R   (   R   t   stateR   R   R   R   R   R   R	   R
   t   buf_lent   b_actiont	   b_cur_post
   b_cur_linet   b_cur_line_startt
   b_cur_chart   b_input_statet
   b_next_posR   R$   t   ct	   new_statet	   buf_indext   discardt   data(    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR(   Ÿ   s¢    										
3

	
	

				

			'						c         C@  sR  |  j  } |  j r* d d | |  j f GHn  | d k r– |  j |  _ |  j ƒ  } | d k ro t |  _ d |  _  q$| sŠ t |  _ d |  _  q$| |  _ nŽ | d k r· d |  _ d |  _  nm | d k rú |  j d 7_ |  j |  _ |  _ t	 |  _ d |  _  n* | d k rt
 |  _ d	 |  _  n	 d
 |  _ |  j rNd | |  j t |  j ƒ f GHn  d  S(   Ns   Scanner: next: %s [%d] %dt    i   i   u   
i   i   i   i   u    s   --> [%d] %d %ss                       (   R   R   R   R   t	   read_charR   R   R   R   R   R   R/   (   R   R   R:   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR)   	  s6    									c         C@  s   |  j  |  j |  j f S(   sm  
        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   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyt   position(  s    	c         C@  s
   |  j  ƒ  S(   sO   Python accessible wrapper around position(), only for error reporting.
        (   RA   (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyt   get_position3  s    c         C@  s"   |  j  j | ƒ |  _ | |  _ d S(   s8   Set the current state of the scanner to the named state.N(   R   t   get_initial_stateR   R   (   R   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR   8  s    c         C@  s2   | d k r |  j } n  |  j j | | f ƒ d S(   sÐ  
        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   R   t   append(   R   R%   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR!   >  s    c         C@  s   d S(   s_   
        Override this method if you want something to be done at
        end of file.
        N(    (   R   (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR"   M  s    N(   t   __name__t
   __module__t   __doc__R   R   R'   R    R(   R)   RA   RB   R   R!   R"   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyR      s   (			j				(   t
   __future__R    t   cythont   declaret   objectR   R   t   RegexpsR   R   R   R   R   (    (    (    s7   /bar/jli/Chip-seq/script/cython/Cython/Plex/Scanners.pyt   <module>
   s   "	