Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/Plex/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/Plex/__pycache__/Lexicons.cpython-37.pyc

B

Z��Z��@s|ddlmZddlZddlmZddlmZddlmZddlmZddlmZdZ	d	Z
Gd
d�de�ZGdd
�d
e�Z
dS)�)�absolute_importN�)�Actions)�DFA)�Errors)�Machines)�Regexps�c@s eZdZdZdZdZdd�ZdS)�Statez�
    This class is used as part of a Plex.Lexicon specification to
    introduce a user-defined state.

    Constructor:

       State(name, token_specifications)
    NcCs||_||_dS)N)�name�tokens)�selfrr�r�G/opt/alt/python37/lib64/python3.7/site-packages/Cython/Plex/Lexicons.py�__init__%szState.__init__)�__name__�
__module__�__qualname__�__doc__rrrrrrrr
sr
c@s:eZdZdZdZdZddd�Zdd�Zdd	�Zd
d�Z	dS)
�Lexicona}	
    Lexicon(specification) builds a lexical analyser from the given
    |specification|. The specification consists of a list of
    specification items. Each specification item may be either:

       1) A token definition, which is a tuple:

             (pattern, action)

          The |pattern| is a regular axpression built using the
          constructors defined in the Plex module.

          The |action| is the action to be performed when this pattern
          is recognised (see below).

       2) A state definition:

             State(name, tokens)

          where |name| is a character string naming the state,
          and |tokens| is a list of token definitions as
          above. The meaning and usage of states is described
          below.

    Actions
    -------

    The |action| in a token specication may be one of three things:

       1) A function, which is called as follows:

             function(scanner, text)

          where |scanner| is the relevant Scanner instance, and |text|
          is the matched text. If the function returns anything
          other than None, that value is returned as the value of the
          token. If it returns None, scanning continues as if the IGNORE
          action were specified (see below).

        2) One of the following special actions:

           IGNORE means that the recognised characters will be treated as
                  white space and ignored. Scanning will continue until
                  the next non-ignored token is recognised before returning.

           TEXT   causes the scanned text itself to be returned as the
                  value of the token.

        3) Any other value, which is returned as the value of the token.

    States
    ------

    At any given time, the scanner is in one of a number of states.
    Associated with each state is a set of possible tokens. When scanning,
    only tokens associated with the current state are recognised.

    There is a default state, whose name is the empty string. Token
    definitions which are not inside any State definition belong to
    the default state.

    The initial state of the scanner is the default state. The state can
    be changed in one of two ways:

       1) Using Begin(state_name) as the action of a token.

       2) Calling the begin(state_name) method of the Scanner.

    To change back to the default state, use '' as the state name.
    N�cCs�t|t�st�d��|r.ddlm}d}|�}t��}|�d�}	d}
x||D]t}t|t	�r�|�|j
�}xX|jD]}
|�|||
|
�|
d7}
qlWqJt|t
�r�|�||	||
�|
d7}
qJt�|
d��qJW|r�|�}|||}|�}|r�|d@r�|�d�|�|�tj||d@dk�o|d	�}|�r2|�}|||}|�rV|d
@�rV|�d�|�|�|�r�|�d||�|�d
||�|�d|�||_dS)Nz Scanner definition is not a listr)�timeg�z5Expected a token definition (tuple) or State instancez
============= NFA ===========
�)�debugr	z
============= DFA ===========
zConstructing NFA : %5.2f
zConverting to DFA: %5.2f
zTOTAL            : %5.2f
)�
isinstance�listrZInvalidScannerZTimingrrZMachineZnew_initial_stater
rr�add_token_to_machine�tuple�InvalidToken�write�dumprZ
nfa_to_dfa�machine)r
ZspecificationsrZdebug_flagsZtimingsrZ
total_timeZtime1ZnfaZdefault_initial_state�token_number�specZuser_initial_state�tokenZtime2Ztime3ZdfaZtime4rrrrusT











zLexicon.__init__c

Cs�y�|�|�\}}t|tj�r"|}n4y
|jWntk
rJt�|�}YnXt�|�}|��}|j	|||ddd�|j
||d�Wn6tjk
r�}	z|	�
d||	f��Wdd}	~	XYnXdS)Nrr)Z	match_bolZnocase)�priorityzToken number %d: %s)�parse_token_definitionrrZAction�__call__�AttributeError�Return�CallZ	new_stateZ
build_machineZ
set_actionrZ	PlexError�	__class__)
r
r"Z
initial_state�
token_specr#�reZaction_spec�actionZfinal_state�errrr�s



zLexicon.add_token_to_machinecCsPt|t�st�d��t|�dkr*t�d��|\}}t|tj�sHt�d��||fS)NzToken definition is not a tupler	z)Wrong number of items in token definitionzPattern is not an RE instance)rrrr�lenrZRE)r
r-�patternr/rrrr'�s



zLexicon.parse_token_definitioncCs|j�|�S)N)r"�get_initial_state)r
rrrrr3�szLexicon.get_initial_state)NrN)
rrrrr"Ztablesrrr'r3rrrrr*sF
.
r)�
__future__r�typesrrrrrrZDUMP_NFAZDUMP_DFA�objectr
rrrrr�<module>	s