/Lib/lib2to3/pygram.py

http://unladen-swallow.googlecode.com/ · Python · 31 lines · 8 code · 7 blank · 16 comment · 0 complexity · 3a20d757a7db6a30ec477352f7c9cf6a MD5 · raw file

  1. # Copyright 2006 Google, Inc. All Rights Reserved.
  2. # Licensed to PSF under a Contributor Agreement.
  3. """Export the Python grammar and symbols."""
  4. # Python imports
  5. import os
  6. # Local imports
  7. from .pgen2 import token
  8. from .pgen2 import driver
  9. from . import pytree
  10. # The grammar file
  11. _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
  12. class Symbols(object):
  13. def __init__(self, grammar):
  14. """Initializer.
  15. Creates an attribute for each grammar symbol (nonterminal),
  16. whose value is the symbol's type (an int >= 256).
  17. """
  18. for name, symbol in grammar.symbol2number.iteritems():
  19. setattr(self, name, symbol)
  20. python_grammar = driver.load_grammar(_GRAMMAR_FILE)
  21. python_symbols = Symbols(python_grammar)