forked from VimPlug/jedi
convert: run away from tuples.
This commit is contained in:
@@ -95,7 +95,7 @@ class Parser(object):
|
|||||||
self.module.used_names = self.used_names
|
self.module.used_names = self.used_names
|
||||||
self.module.set_global_names(self.global_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.
|
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
|
grammar rule produces a new complete node, so that the tree is build
|
||||||
strictly bottom-up.
|
strictly bottom-up.
|
||||||
"""
|
"""
|
||||||
type, value, context, children = raw_node
|
#print(type, children, pytree.type_repr(type))
|
||||||
#print(raw_node, pytree.type_repr(type))
|
|
||||||
try:
|
try:
|
||||||
new_node = self._ast_mapping[type](children)
|
new_node = self._ast_mapping[type](children)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -129,10 +128,8 @@ class Parser(object):
|
|||||||
new_node.names_dict = scope_names
|
new_node.names_dict = scope_names
|
||||||
return new_node
|
return new_node
|
||||||
|
|
||||||
def convert_leaf(self, grammar, raw_node):
|
def convert_leaf(self, grammar, type, value, prefix, start_pos):
|
||||||
type, value, context, children = raw_node
|
#print('leaf', value, pytree.type_repr(type))
|
||||||
#print('leaf', raw_node, pytree.type_repr(type))
|
|
||||||
prefix, start_pos = context
|
|
||||||
if type == tokenize.NAME:
|
if type == tokenize.NAME:
|
||||||
if value in grammar.keywords:
|
if value in grammar.keywords:
|
||||||
if value in ('def', 'class'):
|
if value in ('def', 'class'):
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class Parser(object):
|
|||||||
"""Shift a token. (Internal)"""
|
"""Shift a token. (Internal)"""
|
||||||
dfa, state, node = self.stack[-1]
|
dfa, state, node = self.stack[-1]
|
||||||
newnode = (type, value, context, None)
|
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)
|
node[-1].append(newnode)
|
||||||
self.stack[-1] = (dfa, newstate, node)
|
self.stack[-1] = (dfa, newstate, node)
|
||||||
|
|
||||||
@@ -178,13 +178,14 @@ class Parser(object):
|
|||||||
def pop(self):
|
def pop(self):
|
||||||
"""Pop a nonterminal. (Internal)"""
|
"""Pop a nonterminal. (Internal)"""
|
||||||
popdfa, popstate, popnode = self.stack.pop()
|
popdfa, popstate, popnode = self.stack.pop()
|
||||||
|
type = popnode[0]
|
||||||
children = popnode[3]
|
children = popnode[3]
|
||||||
# If there's exactly one child, return that child instead of creating a
|
# 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
|
# new node. We still create expr_stmt and file_input though, because a
|
||||||
# lot of Jedi depends on its logic.
|
# 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']):
|
self.grammar.symbol2number['file_input']):
|
||||||
newnode = self.convert_node(self.grammar, popnode)
|
newnode = self.convert_node(self.grammar, type, children)
|
||||||
else:
|
else:
|
||||||
newnode = children[0]
|
newnode = children[0]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user