1 # Copyright 2006 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement.
4 """Export the Python grammar and symbols."""
10 from .pgen2 import token
11 from .pgen2 import driver
15 _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
18 class Symbols(object):
20 def __init__(self, grammar):
23 Creates an attribute for each grammar symbol (nonterminal),
24 whose value is the symbol's type (an int >= 256).
26 for name, symbol in grammar.symbol2number.iteritems():
27 setattr(self, name, symbol)
30 python_grammar = driver.load_grammar(_GRAMMAR_FILE)
31 python_symbols = Symbols(python_grammar)