AlkantarClanX12

Your IP : 3.145.39.176


Current Path : /opt/alt/python33/lib64/python3.3/lib2to3/pgen2/__pycache__/
Upload File :
Current File : //opt/alt/python33/lib64/python3.3/lib2to3/pgen2/__pycache__/conv.cpython-33.pyc

�
��f�%c@sEdZddlZddlmZmZGdd�dej�ZdS(u�Convert graminit.[ch] spit out by pgen to Python code.

Pgen is the Python parser generator.  It is useful to quickly create a
parser from a grammar file in Python's grammar notation.  But I don't
want my parsers to be written in C (yet), so I'm translating the
parsing tables to Python data structures and writing a Python parse
engine.

Note that the token numbers are constants determined by the standard
Python tokenizer.  The standard token module defines these numbers and
their names (the names are not used much).  The token numbers are
hardcoded into the Python tokenizer and into pgen.  A Python
implementation of the Python tokenizer is also available, in the
standard tokenize module.

On the other hand, symbol numbers (representing the grammar's
non-terminals) are assigned by pgen based on the actual grammar
input.

Note: this module is pretty much obsolete; the pgen module generates
equivalent grammar tables directly from the Grammar.txt input file
without having to invoke the Python pgen C program.

iN(ugrammarutokencBsJ|EeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S(u	Converteru2Grammar subclass that reads classic pgen output files.

    The run() method reads the tables as produced by the pgen parser
    generator, typically contained in two C files, graminit.h and
    graminit.c.  The other methods are for internal use only.

    See the base class for more documentation.

    cCs(|j|�|j|�|j�dS(u<Load the grammar tables from the text files written by pgen.N(uparse_graminit_huparse_graminit_cu
finish_off(uselfu
graminit_hu
graminit_c((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyurun/s

u
Converter.runc	Cs.yt|�}Wn=tk
rO}ztd||f�dSWYdd}~XnXi|_i|_d}x�|D]�}|d7}tjd|�}|r�|j�r�td|||j�f�qo|j	�\}}t
|�}||jks�t�||jkst�||j|<||j|<qoWdS(	u�Parse the .h file written by pgen.  (Internal)

        This file is a sequence of #define statements defining the
        nonterminals of the grammar as numbers.  We build two tables
        mapping the numbers to names and back.

        uCan't open %s: %sNiiu^#define\s+(\w+)\s+(\d+)$u%s(%s): can't parse %sFT(
uopenuIOErroruprintuFalseu
symbol2numberu
number2symbolureumatchustripugroupsuintuAssertionErroruTrue(	uselfufilenameufuerrulinenoulineumousymbolunumber((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyuparse_graminit_h5s*		


uConverter.parse_graminit_hc!Cs�	yt|�}Wn=tk
rO}ztd||f�dSWYdd}~XnXd}|dt|�}}|dks�t||f��|dt|�}}|dks�t||f��|dt|�}}i}g}x�|jd�r�xO|jd�rFtjd|�}|s1t||f��t	t
t|j���\}	}
}g}x�t
|�D]{}
|dt|�}}tjd	|�}|s�t||f��t	t
t|j���\}}|j||f�qhW|dt|�}}|d
kst||f��|||	|
f<|dt|�}}q�Wtjd|�}|sqt||f��t	t
t|j���\}}|t|�ks�t||f��g}x�t
|�D]�}
|dt|�}}tjd|�}|st||f��t	t
t|j���\}}	}
||	|
f}|t|�ksht||f��|j|�q�W|j|�|dt|�}}|d
ks�t||f��|dt|�}}q�W||_i}tjd
|�}|st||f��t|jd��}x�t
|�D]�}|dt|�}}tjd|�}|sxt||f��|jd�}t	t
t|jdddd���\}}}}|j||ks�t||f��|j||kst||f��|dks"t||f��||}|t|�ksPt||f��|dt|�}}tjd|�}|s�t||f��i}t|jd��}x`t|�D]R\}}t|�}x7t
d�D])}|d|>@r�d||d|<q�q�Wq�W||f||<q1W|dt|�}}|d
ksXt||f��||_g}|dt|�}}tjd|�}|s�t||f��t|jd��}x�t
|�D]�}|dt|�}}tjd|�}|st||f��|j�\}}t|�}|dkrDd}nt|�}|j||f�q�W|dt|�}}|d
ks�t||f��||_|dt|�}}|dks�t||f��|dt|�}}tjd|�}|st||f��t|jd��}|t|j�ksKt�|dt|�}}|dks�t||f��|dt|�}}tjd|�}|s�t||f��t|jd��}|t|j�ks�t||f��|dt|�}}tjd|�}|s>	t||f��t|jd��} | |jkst	t||f��| |_|dt|�}}|d
ks�	t||f��y|dt|�}}Wntk
r�	YnXds�	t||f��dS(u�Parse the .c file written by pgen.  (Internal)

        The file looks as follows.  The first two lines are always this:

        #include "pgenheaders.h"
        #include "grammar.h"

        After that come four blocks:

        1) one or more state definitions
        2) a table defining dfas
        3) a table defining labels
        4) a struct defining the grammar

        A state definition has the following form:
        - one or more arc arrays, each of the form:
          static arc arcs_<n>_<m>[<k>] = {
                  {<i>, <j>},
                  ...
          };
        - followed by a state array, of the form:
          static state states_<s>[<t>] = {
                  {<k>, arcs_<n>_<m>},
                  ...
          };

        uCan't open %s: %sNiiu#include "pgenheaders.h"
u#include "grammar.h"
ustatic arc u)static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$u\s+{(\d+), (\d+)},$u};
u'static state states_(\d+)\[(\d+)\] = {$u\s+{(\d+), arcs_(\d+)_(\d+)},$ustatic dfa dfas\[(\d+)\] = {$u0\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$iiiiu\s+("(?:\\\d\d\d)*")},$iu!static label labels\[(\d+)\] = {$u\s+{(\d+), (0|"\w+")},$u0ugrammar _PyParser_Grammar = {
u
\s+(\d+),$u	dfas,
u\s+{(\d+), labels},$u	\s+(\d+)$F(uopenuIOErroruprintuFalseunextuAssertionErroru
startswithureumatchulistumapuintugroupsurangeuappendulenustatesugroupu
symbol2numberu
number2symboluevalu	enumerateuordudfasuNoneulabelsustartu
StopIteration(!uselfufilenameufuerrulinenoulineuallarcsustatesumounumukuarcsu_uiujusutustateudfasundfasusymbolunumberuxuyuzufirstu	rawbitsetucubyteulabelsunlabelsustart((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyuparse_graminit_cTs�		$!!$$$
			3%%
$			'!	
uConverter.parse_graminit_ccCs�i|_i|_xjt|j�D]Y\}\}}|tjkr_|dk	r_||j|<q"|dkr"||j|<q"q"WdS(u1Create additional useful structures.  (Internal).N(ukeywordsutokensu	enumerateulabelsutokenuNAMEuNone(uselfuilabelutypeuvalue((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyu
finish_off�s		"uConverter.finish_offN(u__name__u
__module__u__qualname__u__doc__urunuparse_graminit_huparse_graminit_cu
finish_off(u
__locals__((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyu	Converter$s
	�u	Converter(u__doc__ureupgen2ugrammarutokenuGrammaru	Converter(((u7/opt/alt/python33/lib64/python3.3/lib2to3/pgen2/conv.pyu<module>s