1
0
forked from VimPlug/jedi

Fix issues with flows in the fast parser.

This commit is contained in:
Dave Halter
2015-01-28 17:06:18 +01:00
parent b8c63f366c
commit e412694fa2
2 changed files with 22 additions and 11 deletions

View File

@@ -174,15 +174,13 @@ class ParserNode(object):
nodes should be added anymore.
"""
print('CLOSE NODE', id(self), self.parent, self._node_children)
if self.parser: print(self.parser.module.names_dict, [p.parser.module.names_dict for p in
print(self.parser.module.names_dict, [p.parser.module.names_dict for p in
self._node_children])
# We only need to replace the dict if multiple dictionaries are used:
if self._node_children:
dcts = [n.parser.module.names_dict for n in self._node_children]
if self.parser is not None:
# The first Parser node contains all the others and is
# typically empty.
dcts.insert(0, self._content_scope.names_dict)
# Need to insert the own node as well.
dcts.insert(0, self._content_scope.names_dict)
print('DCTS', self.parser, dcts, self._node_children)
self._content_scope.names_dict = MergedNamesDict(dcts)
@@ -512,6 +510,7 @@ class FastTokenizer(object):
self._indent_counter = 0
self._flow_indent_counter = 0
self._returned_endmarker = False
self._next_dedent_noclose = False
def __iter__(self):
return self
@@ -541,14 +540,19 @@ class FastTokenizer(object):
self._indent_counter += 1
elif typ == DEDENT:
self._indent_counter -= 1
print(self._flow_indent_counter)
if self._in_flow and self._indent_counter == self._flow_indent_counter:
self._in_flow = False
self._next_dedent_noclose = True
return current
if self.previous[0] == DEDENT and self._indent_counter == 0:
self._first_stmt = False
return self._close()
elif self.previous[0] in (NEWLINE, INDENT):
if self.previous[0] in (NEWLINE, INDENT, DEDENT):
if self.previous[0] == DEDENT:
if not self._next_dedent_noclose:
self._first_stmt = False
return self._close()
if not self._in_flow:
self._next_dedent_noclose = False
# Check for NEWLINE, which symbolizes the indent.
#print('X', repr(value), tokenize.tok_name[typ])
indent = start_pos[1]

View File

@@ -106,8 +106,6 @@ def test_positions():
def test_if():
# Empty the parser cache for the path None.
cache.parser_cache.pop(None, None)
src = dedent('''\
def func():
x = 3
@@ -124,6 +122,15 @@ def test_if():
assert [d.name for d in jedi.Script(src, 8, 6).goto_definitions()] == ['int']
def test_if_simple():
src = dedent('''\
if 1:
a = 3
''')
check_fp(src + 'a', 1)
check_fp(src + "else:\n a = ''\na", 1)
def test_incomplete_function():
source = '''return ImportErr'''