mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 21:04:29 +08:00
Some minor restructurings.
This commit is contained in:
@@ -76,8 +76,10 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
if grammar is None:
|
if grammar is None:
|
||||||
grammar = load_grammar()
|
grammar = load_grammar()
|
||||||
|
|
||||||
if cache and not code and path is not None:
|
if cache and code is None and path is not None:
|
||||||
# In this case we do actual caching. We just try to load it.
|
# With the current architecture we cannot load from cache if the
|
||||||
|
# code is given, because we just load from cache if it's not older than
|
||||||
|
# the latest change (file last modified).
|
||||||
module_node = load_module(grammar, path, cache_path=cache_path)
|
module_node = load_module(grammar, path, cache_path=cache_path)
|
||||||
if module_node is not None:
|
if module_node is not None:
|
||||||
return module_node
|
return module_node
|
||||||
@@ -108,8 +110,8 @@ def parse(code=None, path=None, grammar=None, error_recovery=True,
|
|||||||
cache_path=cache_path)
|
cache_path=cache_path)
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
added_newline = not code.endswith('\n')
|
|
||||||
lines = tokenize_lines = splitlines(code, keepends=True)
|
lines = tokenize_lines = splitlines(code, keepends=True)
|
||||||
|
added_newline = not code.endswith('\n')
|
||||||
if added_newline:
|
if added_newline:
|
||||||
code += '\n'
|
code += '\n'
|
||||||
tokenize_lines = list(tokenize_lines)
|
tokenize_lines = list(tokenize_lines)
|
||||||
|
|||||||
Reference in New Issue
Block a user