ZL i6dZddlZddlZddlZddlmZmZmZmZddl m Z eddZ e e eefZeee e e fZe eee e ffZeed fZGd dZd ZiZej1D]$Zesej5\ZZee eee<&y) aThis 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)AnyOptionalTypeVarUnion)token_PGrammar)boundzos.PathLike[str]czeZdZdZddZdeddfdZdeee fddfdZ deddfd Z d e ddfd Z d edefd ZddZy)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. returnNci|_i|_g|_i|_dg|_i|_i|_i|_i|_d|_ d|_ d|_ y)N)rEMPTY)rrF) symbol2number number2symbolstatesdfaslabelskeywords soft_keywordstokens symbol2labelversionstartasync_keywords)selfs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/blib2to3/pgen2/grammar.py__init__zGrammar.__init__Us]-/-/!# %' $0> (* -/&( ,.(.  #filenamecrt|dr |j}n|j}tjt j j|d5}tj||tjdddt jj|y#1swY*xYw)z)Dump the grammar tables to a pickle file.__dict__F)dirdeleteN) hasattrr# __getstate__tempfileNamedTemporaryFileospathdirnamepickledumpHIGHEST_PROTOCOLreplacename)rr!dfs rr.z Grammar.dumpds 4 $ A!!#A  ( ()%  7  KK1f55 6 7 1668$  7 7s &B--B6attrscN|jD]\}}t|||y)N)itemssetattr)rr4kvs r_updatezGrammar._updateus'KKM DAq D!Q  r ct|d5}tj|}ddd|jy#1swYxYw)z+Load the grammar tables from a pickle file.rbN)openr-loadr:)rr!r3r2s rr>z Grammar.loadys; (D ! Q AA  Q  s =ApklcL|jtj|y)z3Load the grammar tables from a pickle bytes object.N)r:r-loads)rr?s rrAz Grammar.loadss V\\#&'r rc 4|j}dD]'}t||t||j)|jdd|_|j dd|_|j |_|j|_|j|_|S)z# Copy the grammar. )rrrrrrrN) __class__r7getattrcopyrrrrr)rnew dict_attrs rrEz Grammar.copysnn EI CGD)$<$A$A$C D E[[^ [[^ JJ ll !00 r c^ddlm}td||jtd||jtd||jtd||j td||j td|jy ) z:Dump the grammar tables to standard output, for debugging.r)pprints2nn2srrrrN)rIprintrrrrrr)rrIs rreportzGrammar.reportsv! e t!!" e t!!" ht{{ f tyy ht{{ gtzz"r )r N)__name__ __module__ __qualname____doc__rPathr.dictstrrr:r>bytesrAr rErMr rr r sy3j $%T%d%" T#s(^  Td ((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 )rQr*r-r(typingrrrrrr tupleintrTLabellistDFArSDFASrRr opmap_rawopmap splitlineslinesplitopr1rDrVr rres  00 T# c8C= ! 4c3h ! S$sCx. ! S$ $%H#H#Z2  h   ")D ::<DE4(b )r