
    -Ph                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZdZ G d d	          Z	 G d
 d          Z
dS )z9
Python Lexical Analyser

Lexical Analyser Specification
   )Actions)DFA)Errors)Machines)Regexps   c                        e Zd ZdZdZdZd ZdS )Statez
    This class is used as part of a Plex.Lexicon specification to
    introduce a user-defined state.

    Constructor:

       State(name, token_specifications)
    Nc                 "    || _         || _        d S N)nametokens)selfr   r   s      T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/Cython/Plex/Lexicons.py__init__zState.__init__   s    	    )__name__
__module____qualname____doc__r   r   r    r   r   r
   r
      s9          DF    r   r
   c                   4    e Zd ZdZdZdZddZd Zd Zd Z	dS )	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 specification 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   c                    t          |t                    st          j        d          t	          j                    }|                    d          }d}|D ]}t          |t                    rB|                    |j                  }|j	        D ]}	| 
                    |||	|           |dz  } Yt          |t                    r| 
                    ||||           |dz  }t          j        |d          |r/|dz  r*|                    d           |                    |           t          j        ||dz  dk    o|          }
|r/|dz  r*|                    d	           |
                    |           |
| _        d S )
Nz Scanner definition is not a list r   z5Expected a token definition (tuple) or State instancez
============= NFA ===========
   )debugr   z
============= DFA ===========
)
isinstancelistr   InvalidScannerr   Machinenew_initial_stater
   r   r   add_token_to_machinetupleInvalidTokenwritedumpr   
nfa_to_dfamachine)r   specificationsr   debug_flagsnfadefault_initial_statetoken_numberspecuser_initial_statetokendfas              r   r   zLexicon.__init__o   s   .$// 	L'(JKKK   # 5 5b 9 9" 	M 	MD$&& M%(%:%:49%E%E"![ & &E--/F F F A%LL& D%(( M)).lD D D!) KM M M  	kAo 	KK;<<<HHUOOOnSqQ(>(H5III 	kAo 	KK;<<<HHUOOOr   c                    	 |                      |          \  }}t          |t          j                  r|}nA	 |j         t          j        |          }n$# t          $ r t          j        |          }Y nw xY w|                                }|	                    |||dd           |
                    ||            d S # t          j        $ r}	|	                    d||	fz            d }	~	ww xY w)Nr       )	match_bolnocase)priorityzToken number %d: %s)parse_token_definitionr   r   Action__call__CallAttributeErrorReturn	new_statebuild_machine
set_actionr   	PlexError	__class__)
r   r*   initial_state
token_specr/   reaction_specactionfinal_statees
             r   r$   zLexicon.add_token_to_machine   s+   	I $ ; ;J G GR+w~66 7$7(( %\+66FF & 9 9 9$^K88FFF9 "++--KWm['(  4 4 4""6\M"BBBBB 	I 	I 	I++3|Q6GGHHH	Is:   5C  A C  A52C  4A55A	C   C.C))C.c                    t          |t                    st          j        d          t	          |          dk    rt          j        d          |\  }}t          |t
          j                  st          j        d          ||fS )NzToken definition is not a tupler   z)Wrong number of items in token definitionzPattern is not an RE instance)r   r%   r   r&   lenr   RE)r   rE   patternrH   s       r   r9   zLexicon.parse_token_definition   s    *e,, 	I%&GHHHz??a%&QRRR$'7:.. 	G%&EFFF  r   c                 6    | j                             |          S r   )r*   get_initial_state)r   r   s     r   rP   zLexicon.get_initial_state   s    |--d333r   )Nr   )
r   r   r   r   r*   tablesr   r$   r9   rP   r   r   r   r   r   $   sr        E EN GF" " " "HI I I&	! 	! 	!4 4 4 4 4r   r   N)r   r   r   r   r   r   r   DUMP_NFADUMP_DFAr
   r   r   r   r   <module>rT      s                                          $N4 N4 N4 N4 N4 N4 N4 N4 N4 N4r   