Author: Carl Friedrich Bolz-Tereick <cfb...@gmx.de> Branch: pyparser-improvements Changeset: r93978:8cafe63e849a Date: 2018-03-12 17:09 +0100 http://bitbucket.org/pypy/pypy/changeset/8cafe63e849a/
Log: Nonterminal again always has children diff --git a/pypy/interpreter/pyparser/parser.py b/pypy/interpreter/pyparser/parser.py --- a/pypy/interpreter/pyparser/parser.py +++ b/pypy/interpreter/pyparser/parser.py @@ -133,9 +133,11 @@ class Nonterminal(AbstractNonterminal): __slots__ = ("_children", ) - def __init__(self, type): + def __init__(self, type, children=None): Node.__init__(self, type) - self._children = None + if children is None: + children = [] + self._children = children def __repr__(self): return "Nonterminal(type=%s, children=%r)" % (self.type, self._children) @@ -145,15 +147,10 @@ return self._children[i] def num_children(self): - if self._children is None: - return 0 return len(self._children) def append_child(self, child): - if self._children is None: - self._children = [child] - else: - self._children.append(child) + self._children.append(child) class Nonterminal1(AbstractNonterminal): @@ -211,8 +208,8 @@ if node is None: self.node = Nonterminal1(self.dfa.symbol_id, child) elif isinstance(node, Nonterminal1): - self.node = Nonterminal(self.dfa.symbol_id) - self.node._children = [node._child, child] + newnode = self.node = Nonterminal( + self.dfa.symbol_id, [node._child, child]) else: self.node.append_child(child) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit