1
0
forked from VimPlug/jedi

Start implementing GlobalStmt.

This commit is contained in:
Dave Halter
2014-10-17 15:13:45 +02:00
parent 6abafc40fa
commit f08811fba7
3 changed files with 14 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ class Parser(object):
if not source.endswith('\n'): if not source.endswith('\n'):
source += '\n' source += '\n'
self.global_names = []
#if self.options["print_function"]: #if self.options["print_function"]:
# python_grammar = pygram.python_grammar_no_print_statement # python_grammar = pygram.python_grammar_no_print_statement
#else: #else:
@@ -56,10 +57,16 @@ class Parser(object):
# files processed even if they were not changed during refactoring. If # files processed even if they were not changed during refactoring. If
# and only if the refactor method's write parameter was True. # and only if the refactor method's write parameter was True.
logger = logging.getLogger("RefactoringTool") logger = logging.getLogger("RefactoringTool")
d = Driver(pytree.python_grammar, convert=pytree.convert, logger=logger) d = Driver(pytree.python_grammar, convert=self.convert, logger=logger)
print(repr(source)) print(repr(source))
self.module = d.parse_string(source).get_parent_until() self.module = d.parse_string(source).get_parent_until()
def convert(self, grammar, raw_node):
new_node = pytree.convert(grammar, raw_node)
if isinstance(new_node, pr.GlobalStmt):
self.global_names += new_node.names()
return new_node
def __init__old__(self, source, module_path=None, no_docstr=False, def __init__old__(self, source, module_path=None, no_docstr=False,
tokenizer=None, top_module=None): tokenizer=None, top_module=None):
self.no_docstr = no_docstr self.no_docstr = no_docstr

View File

@@ -81,7 +81,7 @@ def convert(grammar, raw_node):
'yield_stmt': pr.KeywordStatement, 'yield_stmt': pr.KeywordStatement,
'del_stmt': pr.KeywordStatement, 'del_stmt': pr.KeywordStatement,
'pass_stmt': pr.KeywordStatement, 'pass_stmt': pr.KeywordStatement,
'global_stmt': pr.KeywordStatement, 'global_stmt': pr.GlobalStmt,
'nonlocal_stmt': pr.KeywordStatement, 'nonlocal_stmt': pr.KeywordStatement,
'assert_stmt': pr.KeywordStatement, 'assert_stmt': pr.KeywordStatement,
} }

View File

@@ -964,6 +964,11 @@ class KeywordStatement(Simple):
return self.children[0].value return self.children[0].value
class GlobalStmt(Simple):
def names(self):
return self.children[1::2]
class Statement(Simple, DocstringMixin): class Statement(Simple, DocstringMixin):
""" """
This is the class for all the possible statements. Which means, this class This is the class for all the possible statements. Which means, this class