
    -Ph3                         d Z ddlZ ej        eeee           ddlmZ ddlmZmZm	Z	  e            Z
 G d d          ZdS )	z3
Python Lexical Analyser

Scanning an input stream
    N)BOLEOLEOF	NOT_FOUND   )Errors)r   r   r   c                   z    e Zd ZdZddZd Zd Zd Zd Zd	 Z	d
 Z
defdZd Zd ZddZd Ze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                    d| _         d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _	        d| _
        || _        || _        || _        g | _        d| _        |                     d           d| _        d| _        d| _        t$          | _        d| _        ||d         |d          c| _        | _        dS 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   )r   r   r   N   )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   initial_poss        T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Plex/Scanners.py__init__zScanner.__init__J   s     
.8+)3&		
!

2"1<Q+a..DM4... #"    c                 6   | j         }|s||                                 \  | _        }|*|                     d           |                                  n2|                    | | j                  }||                     |           |||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eofperformr   )r"   r   actionvalueresults        r$   readzScanner.readr   s     
 	( $ 1 1 3 3DIv~T"""



tTY77$LL'''  	( 27q..!Hr&   c                 D    | j                             d||f|f           d S )Nr   )r   insert)r"   tokenr-   positions       r$   unreadzScanner.unread   s)    
!uenh788888r&   c                     | j         S N)r   r"   s    r$   get_current_scan_poszScanner.get_current_scan_pos   s    22r&   c                    | j         | _        | j        | j        | j         | j        z
  f| _        |                                 }|S| j        rt          d|| j        | j         fz             | j	        | j        | j
        z
  | j         | j
        z
           }||fS | j         | j        k    r9| j        t          u r|                                  | j        | j        t          u rdS t          j        | | j                  )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:%dr   N)r   r   r   r   r   r   run_machine_inlinedr   printr   r   r    r   	next_charr   r   UnrecognizedInputr   )r"   r,   r   s      r$   r(   zScanner.scan_a_token   s
    It}dlT5H&H/
+ ))++z ;:DNDL>: : ; ; ;;!33t1123D &>!|t~--=C''NN$$$=(DMS,@,@%:*4AAAr&   c           	         | j         }| j        }| j        }| j        }| j        }| j        }| j        }| j        }| j        }	t          |          }
d\  }}}}}}}| j
        }	 |r)t          d|d         ||t          |          fz             |d         }||||||||f\  }}}}}}}|}|                    |t                    }|t          u r|o|                    d          }|r|rt          d|d         z             |}|dk    r|}||	z
  }||
k     r||         }|dz  }no| j        |	z
  }| j                            d	          }| j        |d         |z   }|| _        |	|z  }	|	| _        t          |          }
||z  }|r||         }|dz  }nd
}|dk    r
t$          }d}nn|s
t$          }d}nb|}n_|dk    rd}d}nT|dk    r|dz  }|x}}t&          }d}n;|dk    r
t(          }d}n+d
}n(|rt          d           ||||||||f\  }}}}}}}nd}n|| _        || _        || _        || _        || _        || _        |r|t          d|z             |S )z;
        Inlined version of run_machine for speed.
        )Nr   r   r   r   r   r   r   zState %d, %d/%d:%s -->numberr,   NelsezState %di   r   
r            blockedzDoing %s)r   r   r   r   r    r!   r   r   r   lenr   r<   reprgetr   r   r   r/   r   r   r   )r"   stater   r   r   r    r!   r   r   r   buf_lenb_action	b_cur_pos
b_cur_lineb_cur_line_start
b_cur_charb_input_state
b_next_posr   r,   c	new_state	buf_indexdiscarddatas                            r$   r;   zScanner.run_machine_inlined   s`    (%)\&*m,0,?=#'#3&*mk+/+=%([[
 $ 	a)Z)9:}V` "ZM	 L.(O['4>>2K K L L L 8_F!GX~xV^^ i)Z1A:}^h A		!Y//II%%3%))F"3"3	 < <*y'::;;;!!##&G (= 8I 7**"9- A"&.="@#{//77!%WXX!6!=&,%0-:*"%f++!W,	 # &y 1A$MHH "ADyy#&&' %#&&'#$ A%%#H"#KK A%%MH/77NW"H"#KK A%%"H"#KK!HH  %)$$$' "9j:J#]J@6VWh{HH "F[M	`  , &  	+!j6)***r&   c                 H   | j         }| j        rt          dd|| j        fz             |dk    rX| j        | _        |                                 }|dk    rt          | _        d| _         n|st          | _        d| _         n{|| _        ns|dk    rd| _        d| _         n^|dk    r7| xj        dz  c_        | j        x| _	        | _        t          | _        d| _         n!|dk    rt          | _        d| _         nd	| _        | j        r!t          d
|| j        | j        fz             d S d S )NzScanner: next: %s [%d] %dz                    r   rB   r   rC   rD   rE   r   z--> [%d] %d %r)r!   r   r<   r   r   	read_charr   r    r   r   r   r   )r"   r!   rS   s      r$   r=   zScanner.next_char  sN   "&"2: 	W-;0UUVVV!=DL  ADyy ##$   " ##$   !A DM DAMMQMM15>D$,DM DADM DDM: 	Q"k4<%OOPPPPP	Q 	Qr&   returnc                     | 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   r7   s    r$   r3   zScanner.position9  s     --r&   c                 *    |                                  S )zX
        Python accessible wrapper around position(), only for error reporting.
        )r3   r7   s    r$   get_positionzScanner.get_positionD  s     }}r&   c                 R    | j                             |          | _        || _        dS )z8Set the current state of the scanner to the named state.N)r   get_initial_stater   r   )r"   r   s     r$   r   zScanner.beginJ  s*     L**:66 	$r&   c                 ^    || 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   s      r$   r)   zScanner.produceP  s8     <9D
E4=$*MNOOOOOr&   c                     dS )z_
        Override this method if you want something to be done at
        end of file.
        N r7   s    r$   r*   zScanner.eof_  s	    
 	r&   c                     | j         d         S )Nr   r\   r7   s    r$   
start_linezScanner.start_linef  s    -a00r&   r:   r6   )__name__
__module____qualname____doc__r%   r/   r4   r8   r(   r;   r=   tupler3   r^   r   r)   r*   propertyrf   rd   r&   r$   r
   r
      s        p&Q &Q &Q &QP  *9 9 93 3 3B B B6o o obQ Q Q>	.% 	. 	. 	. 	.  % % %P P P P   1 1 X1 1 1r&   r
   )rj   cythondeclareobjectr   r   Regexpsr   r   r   r   r
   rd   r&   r$   <module>rq      s      6v6V D D D D       " " " " " " " " " "FHH	W1 W1 W1 W1 W1 W1 W1 W1 W1 W1r&   