
    ^h                     @   S r SSKrSSKrSSKrSSKJrJrJrJr  SSK	J
r
  \" SSS9r\\\\   4   r\\\\\4         r\\\\\4   4   r\\S	4   r " S
 S5      rSr0 r\R1                  5        H+  r\(       d  M  \R5                  5       u  rr\" \
\5      \\'   M-     g)a  This module defines the data structures used to represent a grammar.

These are a bit arcane because they are derived from the data
structures used by Python's 'pgen' parser generator.

There's also a table here mapping operators to their names in the
token module; the Python tokenize module reports all operators as the
fallback token code OP, but the parser needs the actual token code.

    N)AnyOptionalTypeVarUnion   )token_PGrammar)boundzos.PathLike[str]c                       \ rS rSrSrSS jrS\SS4S jrS\\	\
4   SS4S	 jrS\SS4S
 jrS\SS4S jrS\S\4S jrSS jrSrg)r
      a	  Pgen parsing tables conversion class.

Once initialized, this class supplies the grammar tables for the
parsing engine implemented by parse.py.  The parsing engine
accesses the instance variables directly.  The class here does not
provide initialization of the tables; several subclasses exist to
do this (see the conv and pgen modules).

The load() method reads the tables from a pickle file, which is
much faster than the other ways offered by subclasses.  The pickle
file is written by calling dump() (after loading the grammar
tables using a subclass).  The report() method prints a readable
representation of the tables to stdout, for debugging.

The instance variables are as follows:

symbol2number -- a dict mapping symbol names to numbers.  Symbol
                 numbers are always 256 or higher, to distinguish
                 them from token numbers, which are between 0 and
                 255 (inclusive).

number2symbol -- a dict mapping numbers to symbol names;
                 these two are each other's inverse.

states        -- a list of DFAs, where each DFA is a list of
                 states, each state is a list of arcs, and each
                 arc is a (i, j) pair where i is a label and j is
                 a state number.  The DFA number is the index into
                 this list.  (This name is slightly confusing.)
                 Final states are represented by a special arc of
                 the form (0, j) where j is its own state number.

dfas          -- a dict mapping symbol numbers to (DFA, first)
                 pairs, where DFA is an item from the states list
                 above, and first is a set of tokens that can
                 begin this grammar rule (represented by a dict
                 whose values are always 1).

labels        -- a list of (x, y) pairs where x is either a token
                 number or a symbol number, and y is either None
                 or a string; the strings are keywords.  The label
                 number is the index in this list; label numbers
                 are used to mark state transitions (arcs) in the
                 DFAs.

start         -- the number of the grammar's start symbol.

keywords      -- a dict mapping keyword strings to arc labels.

tokens        -- a dict mapping token numbers to arc labels.

returnNc                     0 U l         0 U l        / U l        0 U l        S/U l        0 U l        0 U l        0 U l        0 U l        SU l	        SU l
        SU l        g )N)r   EMPTY)r   r      F)symbol2numbernumber2symbolstatesdfaslabelskeywordssoft_keywordstokenssymbol2labelversionstartasync_keywords)selfs    P/home/james-whalen/.local/lib/python3.13/site-packages/blib2to3/pgen2/grammar.py__init__Grammar.__init__U   s]    -/-/!#%'	$0>(*-/&(,.(.
#    filenamec                    [        U S5      (       a  U R                  nOU R                  5       n[        R                  " [
        R                  R                  U5      SS9 n[        R                  " X#[        R                  5        SSS5        [
        R                  " WR                  U5        g! , (       d  f       N0= f)z)Dump the grammar tables to a pickle file.__dict__F)dirdeleteN)hasattrr%   __getstate__tempfileNamedTemporaryFileospathdirnamepickledumpHIGHEST_PROTOCOLreplacename)r   r#   dfs       r   r0   Grammar.dumpd   s     4$$A!!#A(()%
KKf556
 	

1668$	
 
s   !&B11
B?attrsc                 N    UR                  5        H  u  p#[        XU5        M     g )N)itemssetattr)r   r7   kvs       r   _updateGrammar._updateu   s    KKMDADQ "r"   c                     [        US5       n[        R                  " U5      nSSS5        U R                  W5        g! , (       d  f       N = f)z+Load the grammar tables from a pickle file.rbN)openr/   loadr=   )r   r#   r5   r4   s       r   rB   Grammar.loady   s4    (D!QAA "Q "!s	   >
Apklc                 N    U R                  [        R                  " U5      5        g)z3Load the grammar tables from a pickle bytes object.N)r=   r/   loads)r   rD   s     r   rF   Grammar.loads   s    V\\#&'r"   r   c           	      4   U R                  5       nS H&  n[        X[        X5      R                  5       5        M(     U R                  SS Ul        U R
                  SS Ul        U R                  Ul        U R                  Ul        U R                  Ul        U$ )z
Copy the grammar.
)r   r   r   r   r   r   r   N)		__class__r:   getattrcopyr   r   r   r   r   )r   new	dict_attrs      r   rK   Grammar.copy   s     nn
I CGD$<$A$A$CD
 [[^
[[^
JJ	ll!00
r"   c                 ^   SSK J n  [        S5        U" U R                  5        [        S5        U" U R                  5        [        S5        U" U R                  5        [        S5        U" U R
                  5        [        S5        U" U R                  5        [        SU R                  5        g	)
z:Dump the grammar tables to standard output, for debugging.r   )pprints2nn2sr   r   r   r   N)rP   printr   r   r   r   r   r   )r   rP   s     r   reportGrammar.report   sv    !et!!"et!!"ht{{ftyyht{{gtzz"r"   )r   r   r   r   r   r   r   r   r   r   r   r   )r   N)__name__
__module____qualname____firstlineno____doc__r    Pathr0   dictstrr   r=   rB   bytesrF   r	   rK   rT   __static_attributes__ r"   r   r
   r
      sy    3j$%T %d %" T#s(^    T d ( (4 (2 " ,#r"   a&  
( LPAR
) RPAR
[ LSQB
] RSQB
: COLON
, COMMA
; SEMI
+ PLUS
- MINUS
* STAR
/ SLASH
| VBAR
& AMPER
< LESS
> GREATER
= EQUAL
. DOT
% PERCENT
` BACKQUOTE
{ LBRACE
} RBRACE
@ AT
@= ATEQUAL
== EQEQUAL
!= NOTEQUAL
<> NOTEQUAL
<= LESSEQUAL
>= GREATEREQUAL
~ TILDE
^ CIRCUMFLEX
<< LEFTSHIFT
>> RIGHTSHIFT
** DOUBLESTAR
+= PLUSEQUAL
-= MINEQUAL
*= STAREQUAL
/= SLASHEQUAL
%= PERCENTEQUAL
&= AMPEREQUAL
|= VBAREQUAL
^= CIRCUMFLEXEQUAL
<<= LEFTSHIFTEQUAL
>>= RIGHTSHIFTEQUAL
**= DOUBLESTAREQUAL
// DOUBLESLASH
//= DOUBLESLASHEQUAL
-> RARROW
:= COLONEQUAL
! BANG
)rZ   r,   r/   r*   typingr   r   r   r    r   r	   tupleintr]   LabellistDFAr\   DFASr[   r
   	opmap_rawopmap
splitlineslinesplitopr3   rJ   r`   r"   r   <module>ro      s   	 
   0 0 T#c8C= !
4c3h !S$sCx. !S$$%H# H#Z2	h 	  "Dt::<DE4(b	 #r"   