Skip to content

Commit

Permalink
:update: remove useless adopt_children since the bug was fixed in grako
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdd committed Oct 5, 2016
1 parent 6471239 commit f2f4172
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 34 deletions.
2 changes: 1 addition & 1 deletion link/utils/__init__.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

__version__ = '1.6'
__version__ = '2.0'

CONF_BASE_PATH = 'link/utils'
30 changes: 0 additions & 30 deletions link/utils/grammar.py
Expand Up @@ -47,36 +47,6 @@ def codegenerator(modname, prefix, grammar):
return module


def adopt_children(ast, parent=None):
"""
Make sure that grako Nodes have the parent property set correctly.
:param ast: Grako AST
:type ast: grako.model.Node, grako.util.Mapping or list
:param parent: Parent Node
:type parent: grako.model.Node or None
"""

childset = set()

if isinstance(ast, Node) and ast not in childset:
if isinstance(parent, Node):
ast._parent = parent
childset.add(ast)

elif isinstance(ast, Mapping):
for c in ast.values():
adopt_children(c, parent=parent)

elif isinstance(ast, list):
for c in ast:
adopt_children(c, parent=parent)

for child in childset:
adopt_children(child._ast, parent=child)


def find_ancestor(node, classname):
"""
Find first node's ancestor which match class' name.
Expand Down
4 changes: 1 addition & 3 deletions link/utils/test/grammar.py
Expand Up @@ -3,7 +3,7 @@
from b3j0f.utils.ut import UTCase
from unittest import main

from link.utils.grammar import codegenerator, adopt_children, find_ancestor
from link.utils.grammar import codegenerator, find_ancestor
from grako.model import ModelBuilderSemantics, Node
from grako.exceptions import FailedToken
import sys
Expand Down Expand Up @@ -34,7 +34,6 @@ def test_adopt_children(self):
model = parser.parse('DSL', rule_name='dsl')
self.assertIsInstance(model, Node)

adopt_children(model._ast, parent=model)
self.assertIs(model.sub[0].parent, model)

def test_find_ancestor(self):
Expand All @@ -46,7 +45,6 @@ def test_find_ancestor(self):

parser = mod.MyDSLParser(semantics=ModelBuilderSemantics())
model = parser.parse('DSL', rule_name='dsl')
adopt_children(model._ast, parent=model)
pnode = find_ancestor(model.sub.sub, 'RootNode')

self.assertIs(pnode, model)
Expand Down

0 comments on commit f2f4172

Please sign in to comment.