Avoid nasty side effects in creation of Node

This issue led to bugs in Jedi, because Jedi used the nodes in a wrong way.
This commit is contained in:
Dave Halter
2019-01-01 23:35:20 +01:00
parent 29325d3052
commit c7c464e5e9
5 changed files with 16 additions and 9 deletions

View File

@@ -90,7 +90,7 @@ class Parser(BaseParser):
strictly bottom-up.
"""
try:
return self.node_map[nonterminal](children)
node = self.node_map[nonterminal](children)
except KeyError:
if nonterminal == 'suite':
# We don't want the INDENT/DEDENT in our parser tree. Those
@@ -104,7 +104,10 @@ class Parser(BaseParser):
elif nonterminal == 'listmaker':
# Same as list_if above.
nonterminal = 'testlist_comp'
return self.default_node(nonterminal, children)
node = self.default_node(nonterminal, children)
for c in children:
c.parent = node
return node
def convert_leaf(self, type, value, prefix, start_pos):
# print('leaf', repr(value), token.tok_name[type])
@@ -189,7 +192,10 @@ class Parser(BaseParser):
all_nodes = [node for stack_node in self.stack[start_index:] for node in stack_node.nodes]
if all_nodes:
self.stack[start_index - 1].nodes.append(tree.PythonErrorNode(all_nodes))
node = tree.PythonErrorNode(all_nodes)
for n in all_nodes:
n.parent = node
self.stack[start_index - 1].nodes.append(node)
self.stack[start_index:] = []
return bool(all_nodes)