1
0
forked from VimPlug/jedi

convert: run away from tuples.

This commit is contained in:
Dave Halter
2014-11-04 19:26:33 +01:00
parent 73bd576bb2
commit 3b4a8dcd7e
2 changed files with 9 additions and 11 deletions

View File

@@ -95,7 +95,7 @@ class Parser(object):
self.module.used_names = self.used_names
self.module.set_global_names(self.global_names)
def convert_node(self, grammar, raw_node):
def convert_node(self, grammar, type, children):
"""
Convert raw node information to a Node instance.
@@ -103,8 +103,7 @@ class Parser(object):
grammar rule produces a new complete node, so that the tree is build
strictly bottom-up.
"""
type, value, context, children = raw_node
#print(raw_node, pytree.type_repr(type))
#print(type, children, pytree.type_repr(type))
try:
new_node = self._ast_mapping[type](children)
except KeyError:
@@ -129,10 +128,8 @@ class Parser(object):
new_node.names_dict = scope_names
return new_node
def convert_leaf(self, grammar, raw_node):
type, value, context, children = raw_node
#print('leaf', raw_node, pytree.type_repr(type))
prefix, start_pos = context
def convert_leaf(self, grammar, type, value, prefix, start_pos):
#print('leaf', value, pytree.type_repr(type))
if type == tokenize.NAME:
if value in grammar.keywords:
if value in ('def', 'class'):

View File

@@ -164,7 +164,7 @@ class Parser(object):
"""Shift a token. (Internal)"""
dfa, state, node = self.stack[-1]
newnode = (type, value, context, None)
newnode = self.convert_leaf(self.grammar, newnode)
newnode = self.convert_leaf(self.grammar, type, value, *context)
node[-1].append(newnode)
self.stack[-1] = (dfa, newstate, node)
@@ -178,13 +178,14 @@ class Parser(object):
def pop(self):
"""Pop a nonterminal. (Internal)"""
popdfa, popstate, popnode = self.stack.pop()
type = popnode[0]
children = popnode[3]
# If there's exactly one child, return that child instead of creating a
# new node. We still create expr_stmt and file_input though, because a
# lot of Jedi depends on its logic.
if len(children) != 1 or popnode[0] in (self.grammar.symbol2number['expr_stmt'],
if len(children) != 1 or type in (self.grammar.symbol2number['expr_stmt'],
self.grammar.symbol2number['file_input']):
newnode = self.convert_node(self.grammar, popnode)
newnode = self.convert_node(self.grammar, type, children)
else:
newnode = children[0]