mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-18 02:16:03 +08:00
Refactor the parse function to be more readable.
This commit is contained in:
@@ -68,21 +68,12 @@ def parse(code=None, **kwargs):
|
|||||||
|
|
||||||
:return: A syntax tree node. Typically the module.
|
:return: A syntax tree node. Typically the module.
|
||||||
"""
|
"""
|
||||||
# Wanted python3.5 * operator and keyword only arguments.
|
# Wanted python3.5 * operator and keyword only arguments. Therefore just
|
||||||
path = kwargs.pop('path', None)
|
# wrap it all.
|
||||||
grammar = kwargs.pop('grammar', None)
|
def _parse(code=None, path=None, grammar=None, error_recovery=True,
|
||||||
error_recovery = kwargs.pop('error_recovery', True)
|
start_symbol='file_input', cache=False, diff_cache=False,
|
||||||
start_symbol = kwargs.pop('start_symbol', 'file_input')
|
cache_path=None):
|
||||||
cache = kwargs.pop('cache', False)
|
|
||||||
diff_cache = kwargs.pop('diff_cache', False)
|
|
||||||
cache_path = kwargs.pop('cache_path', None)
|
|
||||||
|
|
||||||
if kwargs:
|
|
||||||
raise TypeError(
|
|
||||||
"parse() got an unexpected keyword argument '%s'"
|
|
||||||
% next(iter(kwargs)))
|
|
||||||
|
|
||||||
# Start with actual code.
|
|
||||||
if code is None and path is None:
|
if code is None and path is None:
|
||||||
raise TypeError("Please provide either code or a path.")
|
raise TypeError("Please provide either code or a path.")
|
||||||
|
|
||||||
@@ -142,3 +133,4 @@ def parse(code=None, **kwargs):
|
|||||||
save_module(grammar, path, root_node, lines, pickling=cache,
|
save_module(grammar, path, root_node, lines, pickling=cache,
|
||||||
cache_path=cache_path)
|
cache_path=cache_path)
|
||||||
return root_node
|
return root_node
|
||||||
|
return _parse(code=code, **kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user