]> git.madduck.net Git - etc/vim.git/blob - blib2to3/pygram.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

change some numeric behavior (#469)
[etc/vim.git] / blib2to3 / pygram.py
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
7 import os
8
9 # Local imports
10 from .pgen2 import token
11 from .pgen2 import driver
12 from . import pytree
13
14 # The grammar file
15 _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt")
16 _PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__),
17                                      "PatternGrammar.txt")
18
19
20 class Symbols(object):
21
22     def __init__(self, grammar):
23         """Initializer.
24
25         Creates an attribute for each grammar symbol (nonterminal),
26         whose value is the symbol's type (an int >= 256).
27         """
28         for name, symbol in grammar.symbol2number.items():
29             setattr(self, name, symbol)
30
31
32 def initialize(cache_dir=None):
33     global python_grammar
34     global python_grammar_no_print_statement
35     global python_grammar_no_print_statement_no_exec_statement
36     global python_symbols
37     global pattern_grammar
38     global pattern_symbols
39
40     # Python 2
41     python_grammar = driver.load_packaged_grammar("blib2to3", _GRAMMAR_FILE,
42                                                   cache_dir)
43
44     python_symbols = Symbols(python_grammar)
45
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"]
49
50     # Python 3
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"]
54
55     pattern_grammar = driver.load_packaged_grammar("blib2to3", _PATTERN_GRAMMAR_FILE,
56                                                    cache_dir)
57     pattern_symbols = Symbols(pattern_grammar)