mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-07 21:34:32 +08:00
Use the diff parser as well.
This commit is contained in:
@@ -82,6 +82,9 @@ class Grammar(object):
|
|||||||
|
|
||||||
lines = tokenize_lines = splitlines(code, keepends=True)
|
lines = tokenize_lines = splitlines(code, keepends=True)
|
||||||
if diff_cache:
|
if diff_cache:
|
||||||
|
if self._diff_parser is None:
|
||||||
|
raise TypeError("You have to define a diff parser to be able "
|
||||||
|
"to use this option.")
|
||||||
try:
|
try:
|
||||||
module_cache_item = parser_cache[path]
|
module_cache_item = parser_cache[path]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -95,7 +98,7 @@ class Grammar(object):
|
|||||||
cache_path=cache_path)
|
cache_path=cache_path)
|
||||||
return module_node
|
return module_node
|
||||||
|
|
||||||
new_node = DiffParser(self._pgen_grammar, module_node).update(
|
new_node = self._diff_parser(self._pgen_grammar, module_node).update(
|
||||||
old_lines=old_lines,
|
old_lines=old_lines,
|
||||||
new_lines=lines
|
new_lines=lines
|
||||||
)
|
)
|
||||||
@@ -153,7 +156,7 @@ def load_grammar(version=None):
|
|||||||
try:
|
try:
|
||||||
with open(path) as f:
|
with open(path) as f:
|
||||||
bnf_text = f.read()
|
bnf_text = f.read()
|
||||||
grammar = Grammar(bnf_text, parser=PythonParser)
|
grammar = Grammar(bnf_text, parser=PythonParser, diff_parser=DiffParser)
|
||||||
return _loaded_grammars.setdefault(path, grammar)
|
return _loaded_grammars.setdefault(path, grammar)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
# Just load the default if the file does not exist.
|
# Just load the default if the file does not exist.
|
||||||
|
|||||||
Reference in New Issue
Block a user