All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
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
14 _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
15 _PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
19 class Symbols(object):
21 def __init__(self, grammar):
24 Creates an attribute for each grammar symbol (nonterminal),
25 whose value is the symbol's type (an int >= 256).
27 for name, symbol in grammar.symbol2number.items():
28 setattr(self, name, symbol)
31 def initialize(cache_dir=None):
33 global python_grammar_no_print_statement
34 global python_grammar_no_print_statement_no_exec_statement
35 global python_grammar_no_print_statement_no_exec_statement_async_keywords
37 global pattern_grammar
38 global pattern_symbols
41 python_grammar = driver.load_packaged_grammar("blib2to3", _GRAMMAR_FILE,
44 python_symbols = Symbols(python_grammar)
46 # Python 2 + from __future__ import print_function
47 python_grammar_no_print_statement = python_grammar.copy()
48 del python_grammar_no_print_statement.keywords["print"]
51 python_grammar_no_print_statement_no_exec_statement = python_grammar.copy()
52 del python_grammar_no_print_statement_no_exec_statement.keywords["print"]
53 del python_grammar_no_print_statement_no_exec_statement.keywords["exec"]
56 python_grammar_no_print_statement_no_exec_statement_async_keywords = (
57 python_grammar_no_print_statement_no_exec_statement.copy()
59 python_grammar_no_print_statement_no_exec_statement_async_keywords.async_keywords = True
61 pattern_grammar = driver.load_packaged_grammar("blib2to3", _PATTERN_GRAMMAR_FILE,
63 pattern_symbols = Symbols(pattern_grammar)