Plan 9 from Bell Labs’s /usr/web/sources/contrib/jas/root/sys/lib/python2.7/lib2to3/pgen2/grammar.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


��Qc@s�dZddlZddlmZmZdefd��YZdZiZxBej	�D]4Z
e
rWe
j�\ZZ
eee
�ee<qWqWWdS(s�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.

i�Ni(ttokenttokenizetGrammarcBs;eZdZd�Zd�Zd�Zd�Zd�ZRS(s�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.

    cCsXi|_i|_g|_i|_dg|_i|_i|_i|_d|_dS(NitEMPTYi(iR(	t
symbol2numbert
number2symboltstatestdfastlabelstkeywordsttokenstsymbol2labeltstart(tself((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyt__init__Ls							cCs3t|d�}tj|j|d�|j�dS(s)Dump the grammar tables to a pickle file.twbiN(topentpickletdumpt__dict__tclose(R
tfilenametf((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyRWscCs<t|d�}tj|�}|j�|jj|�dS(s+Load the grammar tables from a pickle file.trbN(RRtloadRRtupdate(R
RRtd((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyR]s
cCsf|j�}x-dD]%}t||t||�j��qW|j|_|j|_|j|_|S(s#
        Copy the grammar.
        RRRR	R
R(s
symbol2numbers
number2symbolsdfasskeywordsstokensssymbol2label(t	__class__tsetattrtgetattrtcopyRRR(R
tnewt	dict_attr((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyRds
#

cCszddlm}dGH||j�dGH||j�dGH||j�dGH||j�dGH||j�dG|jGHd	S(
s:Dump the grammar tables to standard output, for debugging.i�(tpprintts2ntn2sRRRRN(R!RRRRRR(R
R!((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pytreportqs




(t__name__t
__module__t__doc__RRRRR$(((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyRs4				
s
( LPAR
) RPAR
[ LSQB
] RSQB
: COLON
, COMMA
; SEMI
+ PLUS
- MINUS
* STAR
/ SLASH
| VBAR
& AMPER
< LESS
> GREATER
= EQUAL
. DOT
% PERCENT
` BACKQUOTE
{ LBRACE
} RBRACE
@ AT
== EQEQUAL
!= NOTEQUAL
<> NOTEQUAL
<= LESSEQUAL
>= GREATEREQUAL
~ TILDE
^ CIRCUMFLEX
<< LEFTSHIFT
>> RIGHTSHIFT
** DOUBLESTAR
+= PLUSEQUAL
-= MINEQUAL
*= STAREQUAL
/= SLASHEQUAL
%= PERCENTEQUAL
&= AMPEREQUAL
|= VBAREQUAL
^= CIRCUMFLEXEQUAL
<<= LEFTSHIFTEQUAL
>>= RIGHTSHIFTEQUAL
**= DOUBLESTAREQUAL
// DOUBLESLASH
//= DOUBLESLASHEQUAL
-> RARROW
(R'RtRRtobjectRt	opmap_rawtopmapt
splitlinestlinetsplittoptnameR(((s+/sys/lib/python2.7/lib2to3/pgen2/grammar.pyt<module>
s�

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.