[Python-checkins] make PatternCompiler use the packaged grammar if possible (more bpo-24960) (GH-5034) (#5036)

Benjamin Peterson webhook-mailer at python.org
Thu Dec 28 21:12:43 EST 2017


https://github.com/python/cpython/commit/85f71aa9d6f834c7d64e979009c8fda0f19b585d
commit: 85f71aa9d6f834c7d64e979009c8fda0f19b585d
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Benjamin Peterson <benjamin at python.org>
date: 2017-12-28T18:12:41-08:00
summary:

make PatternCompiler use the packaged grammar if possible (more bpo-24960) (GH-5034) (#5036)

(cherry picked from commit e5f7dccefaa8d97ab53b3051acbb4a4d49379dc4)

files:
M Lib/lib2to3/patcomp.py

diff --git a/Lib/lib2to3/patcomp.py b/Lib/lib2to3/patcomp.py
index 06a4b9dd230..5bda0f9299d 100644
--- a/Lib/lib2to3/patcomp.py
+++ b/Lib/lib2to3/patcomp.py
@@ -21,10 +21,6 @@
 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)



More information about the Python-checkins mailing list