mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
make PatternCompiler use the packaged grammar if possible (more bpo-24960) (#5034)
This commit is contained in:
parent
e5681b9822
commit
e5f7dccefa
1 changed files with 7 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue