
    h                     t    S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SrSr " S S	5      r	 " S
 S5      r
g)z9
Python Lexical Analyser

Lexical Analyser Specification
   )Actions)DFA)Errors)Machines)Regexps   c                   &    \ rS rSrSrSrSrS rSrg)State   z
This class is used as part of a Plex.Lexicon specification to
introduce a user-defined state.

Constructor:

   State(name, token_specifications)
Nc                     Xl         X l        g Nnametokens)selfr   r   s      N/var/www/fran/franai/venv/lib/python3.13/site-packages/Cython/Plex/Lexicons.py__init__State.__init__   s    	    r   )	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__ r   r   r
   r
      s     DFr   r
   c                   <    \ rS rSrSrSrSrS	S jrS rS r	S r
Srg)
Lexicon$   a  
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.
Nc                    [        U[        5      (       d  [        R                  " S5      e[        R
                  " 5       nUR                  S5      nSnU H  n[        U[        5      (       aG  UR                  UR                  5      nUR                   H  n	U R                  XHX5        US-  nM     M_  [        U[        5      (       a  U R                  XEXv5        US-  nM  [        R                  " US5      e   U(       a,  US-  (       a"  UR                  S5        UR                  U5        [        R                   " XCS-  S:H  =(       a    US9n
U(       a,  US-  (       a"  UR                  S	5        U
R                  U5        Xl        g )
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   Lexicon.__init__o   sJ   .$//''(JKK  # 5 5b 9"D$&&%(%:%:499%E"![[E--F A%L ) D%(())D!)) KM M #  kAoKK;<HHUOnnSqQ(>(H5IkAoKK;<HHUOr   c                     U R                  U5      u  pV[        U[        R                  5      (       a  UnO# UR                    [        R
                  " U5      nUR                  5       nUR                  XUSSS9  UR                  Xt* S9  g ! [         a    [        R                  " U5      n NUf = f! [        R                   a  n	U	R                  SXI4-  5      eS n	A	ff = f)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_specr4   reaction_specactionfinal_statees
             r   r)   Lexicon.add_token_to_machine   s    	I $ ; ;J GR+w~~66$7(( %\\+6F!++-KW['(  4""6M"B & 9$^^K8F9  	I++3|6GGHH	Is;   5B3 B AB3  B0-B3 /B00B3 3C!CC!c                    [        U[        5      (       d  [        R                  " S5      e[	        U5      S:w  a  [        R                  " S5      eUu  p#[        U[
        R                  5      (       d  [        R                  " S5      eX#4$ )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   rK   patternrN   s       r   r?   Lexicon.parse_token_definition   sr    *e,,%%&GHHz?a%%&QRR$'7::..%%&EFF  r   c                 8    U R                   R                  U5      $ r   )r/   get_initial_state)r   r   s     r   rX   Lexicon.get_initial_state   s    ||--d33r   )r/   )N   )r   r   r   r   r   r/   tablesr   r)   r?   rX   r   r   r   r   r   r   $   s+    EN GF"HI&	!4r   r   N)r   r!   r   r   r   r   r   DUMP_NFADUMP_DFAr
   r   r   r   r   <module>r^      s=          $N4 N4r   