diff options
author | Benjamin Peterson <benjamin@python.org> | 2017-12-28 17:54:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-28 17:54:12 -0800 |
commit | e5f7dccefaa8d97ab53b3051acbb4a4d49379dc4 (patch) | |
tree | 87280f6c11c7bedaa5df1cd1090fcb70c0f4be9a /Lib/lib2to3/patcomp.py | |
parent | e5681b9822c633c77ddfeb94585d58895e0ecff5 (diff) | |
download | cpython-git-e5f7dccefaa8d97ab53b3051acbb4a4d49379dc4.tar.gz |
make PatternCompiler use the packaged grammar if possible (more bpo-24960) (#5034)
Diffstat (limited to 'Lib/lib2to3/patcomp.py')
-rw-r--r-- | Lib/lib2to3/patcomp.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/lib2to3/patcomp.py b/Lib/lib2to3/patcomp.py index 0fefa9a3a4..4e79ed2692 100644 --- a/Lib/lib2to3/patcomp.py +++ b/Lib/lib2to3/patcomp.py @@ -21,10 +21,6 @@ from .pgen2 import driver, literals, token, tokenize, parse, grammar from . import pytree from . import pygram -# The pattern grammar file -_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), - "PatternGrammar.txt") - class PatternSyntaxError(Exception): pass @@ -42,13 +38,17 @@ def tokenize_wrapper(input): class PatternCompiler(object): - def __init__(self, grammar_file=_PATTERN_GRAMMAR_FILE): + def __init__(self, grammar_file=None): """Initializer. Takes an optional alternative filename for the pattern grammar. """ - self.grammar = driver.load_grammar(grammar_file) - self.syms = pygram.Symbols(self.grammar) + if grammar_file is None: + self.grammar = pygram.pattern_grammar + self.syms = pygram.pattern_symbols + else: + self.grammar = driver.load_grammar(grammar_file) + self.syms = pygram.Symbols(self.grammar) self.pygrammar = pygram.python_grammar self.pysyms = pygram.python_symbols self.driver = driver.Driver(self.grammar, convert=pattern_convert) |