source: python/trunk/Lib/lib2to3/pygram.py@ 20

Last change on this file since 20 was 2, checked in by Yuri Dario, 15 years ago

Initial import for vendor code.

  • Property svn:eol-style set to native
File size: 890 bytes
Line 
1# Copyright 2006 Google, Inc. All Rights Reserved.
2# Licensed to PSF under a Contributor Agreement.
3
4"""Export the Python grammar and symbols."""
5
6# Python imports
7import os
8
9# Local imports
10from .pgen2 import token
11from .pgen2 import driver
12from . import pytree
13
14# The grammar file
15_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
16
17
18class Symbols(object):
19
20 def __init__(self, grammar):
21 """Initializer.
22
23 Creates an attribute for each grammar symbol (nonterminal),
24 whose value is the symbol's type (an int >= 256).
25 """
26 for name, symbol in grammar.symbol2number.iteritems():
27 setattr(self, name, symbol)
28
29
30python_grammar = driver.load_grammar(_GRAMMAR_FILE)
31
32python_symbols = Symbols(python_grammar)
33
34python_grammar_no_print_statement = python_grammar.copy()
35del python_grammar_no_print_statement.keywords["print"]
Note: See TracBrowser for help on using the repository browser.