mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-18 19:45:57 +08:00
simplify the parser stack.
This commit is contained in:
@@ -92,9 +92,9 @@ class Parser(object):
|
|||||||
# Prepare for parsing.
|
# Prepare for parsing.
|
||||||
start = self.grammar.start
|
start = self.grammar.start
|
||||||
# Each stack entry is a tuple: (dfa, state, node).
|
# Each stack entry is a tuple: (dfa, state, node).
|
||||||
# A node is a tuple: (type, value, context, children),
|
# A node is a tuple: (type, children),
|
||||||
# where children is a list of nodes or None, and context may be None.
|
# where children is a list of nodes or None
|
||||||
newnode = (start, None, None, [])
|
newnode = (start, [])
|
||||||
stackentry = (self.grammar.dfas[start], 0, newnode)
|
stackentry = (self.grammar.dfas[start], 0, newnode)
|
||||||
self.stack = [stackentry]
|
self.stack = [stackentry]
|
||||||
self.rootnode = None
|
self.rootnode = None
|
||||||
@@ -170,15 +170,13 @@ class Parser(object):
|
|||||||
def push(self, type, newdfa, newstate):
|
def push(self, type, newdfa, newstate):
|
||||||
"""Push a nonterminal. (Internal)"""
|
"""Push a nonterminal. (Internal)"""
|
||||||
dfa, state, node = self.stack[-1]
|
dfa, state, node = self.stack[-1]
|
||||||
newnode = (type, None, None, [])
|
newnode = (type, [])
|
||||||
self.stack[-1] = (dfa, newstate, node)
|
self.stack[-1] = (dfa, newstate, node)
|
||||||
self.stack.append((newdfa, 0, newnode))
|
self.stack.append((newdfa, 0, newnode))
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
"""Pop a nonterminal. (Internal)"""
|
"""Pop a nonterminal. (Internal)"""
|
||||||
popdfa, popstate, popnode = self.stack.pop()
|
popdfa, popstate, (type, children) = self.stack.pop()
|
||||||
type = popnode[0]
|
|
||||||
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.
|
||||||
@@ -191,8 +189,8 @@ class Parser(object):
|
|||||||
try:
|
try:
|
||||||
# Equal to:
|
# Equal to:
|
||||||
# dfa, state, node = self.stack[-1]
|
# dfa, state, node = self.stack[-1]
|
||||||
# symbol, value, context, children = node
|
# symbol, children = node
|
||||||
self.stack[-1][2][3].append(newnode)
|
self.stack[-1][2][1].append(newnode)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# stack is empty, set the rootnode.
|
# stack is empty, set the rootnode.
|
||||||
self.rootnode = newnode
|
self.rootnode = newnode
|
||||||
|
|||||||
Reference in New Issue
Block a user