当前位置: 首页>>代码示例>>Python>>正文


Python CommonTree.addChild方法代码示例

本文整理汇总了Python中antlr3.tree.CommonTree.addChild方法的典型用法代码示例。如果您正苦于以下问题:Python CommonTree.addChild方法的具体用法?Python CommonTree.addChild怎么用?Python CommonTree.addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在antlr3.tree.CommonTree的用法示例。


在下文中一共展示了CommonTree.addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testAddListToExistChildren

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testAddListToExistChildren(self):
        # Add child ^(nil 101 102 103) to root ^(5 6)
        # should add 101 102 103 to end of 5's child list
        root = CommonTree(CommonToken(5))
        root.addChild(CommonTree(CommonToken(6)))

        # child tree
        r0 = CommonTree(None)
        c0 = CommonTree(CommonToken(101))
        r0.addChild(c0)
        c1 = CommonTree(CommonToken(102))
        r0.addChild(c1)
        c2 = CommonTree(CommonToken(103))
        r0.addChild(c2)

        root.addChild(r0)

        self.failUnless(root.parent is None)
        self.failUnlessEqual(-1, root.childIndex)
        # check children of root all point at root
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(1, c0.childIndex)
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(2, c1.childIndex)
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(3, c2.childIndex)
开发者ID:aopui,项目名称:antlr,代码行数:28,代码来源:testtree.py

示例2: testMarkRewindEntire

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testMarkRewindEntire(self):
        # ^(101 ^(102 103 ^(106 107) ) 104 105)
        # stream has 7 real + 6 nav nodes
        # Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
        r0 = CommonTree(CommonToken(101))
        r1 = CommonTree(CommonToken(102))
        r0.addChild(r1)
        r1.addChild(CommonTree(CommonToken(103)))
        r2 = CommonTree(CommonToken(106))
        r2.addChild(CommonTree(CommonToken(107)))
        r1.addChild(r2)
        r0.addChild(CommonTree(CommonToken(104)))
        r0.addChild(CommonTree(CommonToken(105)))

        stream = CommonTreeNodeStream(r0)
        m = stream.mark()  # MARK
        for _ in range(13):  # consume til end
            stream.LT(1)
            stream.consume()

        self.failUnlessEqual(EOF, stream.LT(1).getType())
        self.failUnlessEqual(UP, stream.LT(-1).getType())
        stream.rewind(m)  # REWIND

        # consume til end again :)
        for _ in range(13):  # consume til end
            stream.LT(1)
            stream.consume()

        self.failUnlessEqual(EOF, stream.LT(1).getType())
        self.failUnlessEqual(UP, stream.LT(-1).getType())
开发者ID:aopui,项目名称:antlr,代码行数:33,代码来源:testtree.py

示例3: test4Nodes

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def test4Nodes(self):
        # ^(101 ^(102 103) 104)
        r0 = CommonTree(CommonToken(101))
        r0.addChild(CommonTree(CommonToken(102)))
        r0.getChild(0).addChild(CommonTree(CommonToken(103)))
        r0.addChild(CommonTree(CommonToken(104)))

        self.assertIsNone(r0.parent)
        self.assertEqual(-1, r0.childIndex)
开发者ID:166MMX,项目名称:antlr3,代码行数:11,代码来源:testtree.py

示例4: test4Nodes

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def test4Nodes(self):
        # ^(101 ^(102 103) 104)
        r0 = CommonTree(CommonToken(101))
        r0.addChild(CommonTree(CommonToken(102)))
        r0.getChild(0).addChild(CommonTree(CommonToken(103)))
        r0.addChild(CommonTree(CommonToken(104)))

        self.failUnless(r0.parent is None)
        self.failUnlessEqual(-1, r0.childIndex)
开发者ID:aopui,项目名称:antlr,代码行数:11,代码来源:testtree.py

示例5: testBecomeRoot2

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testBecomeRoot2(self):
        # 5 becomes root of ^(101 102 103)
        newRoot = CommonTree(CommonToken(5))

        oldRoot = CommonTree(CommonToken(101))
        oldRoot.addChild(CommonTree(CommonToken(102)))
        oldRoot.addChild(CommonTree(CommonToken(103)))

        self.adaptor.becomeRoot(newRoot, oldRoot)
        newRoot.sanityCheckParentAndChildIndexes()
开发者ID:aopui,项目名称:antlr,代码行数:12,代码来源:testtree.py

示例6: testReplaceWithOneChildren

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceWithOneChildren(self):
        # assume token type 99 and use text
        t = CommonTree(CommonToken(99, text="a"))
        c0 = CommonTree(CommonToken(99, text="b"))
        t.addChild(c0)

        newChild = CommonTree(CommonToken(99, text="c"))
        t.replaceChildren(0, 0, newChild)
        expecting = "(a c)"
        self.failUnlessEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:aopui,项目名称:antlr,代码行数:13,代码来源:testtree.py

示例7: testReplaceInMiddle

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceInMiddle(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b")))
        t.addChild(CommonTree(CommonToken(99, text="c")))  # index 1
        t.addChild(CommonTree(CommonToken(99, text="d")))

        newChild = CommonTree(CommonToken(99, text="x"))
        t.replaceChildren(1, 1, newChild)
        expecting = "(a b x d)"
        self.failUnlessEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:aopui,项目名称:antlr,代码行数:13,代码来源:testtree.py

示例8: testReplaceAtRight

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceAtRight(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b")))
        t.addChild(CommonTree(CommonToken(99, text="c")))
        t.addChild(CommonTree(CommonToken(99, text="d")))  # index 2

        newChild = CommonTree(CommonToken(99, text="x"))
        t.replaceChildren(2, 2, newChild)
        expecting = "(a b c x)"
        self.failUnlessEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:aopui,项目名称:antlr,代码行数:13,代码来源:testtree.py

示例9: testReplaceAtLeft

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceAtLeft(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b"))) # index 0
        t.addChild(CommonTree(CommonToken(99, text="c")))
        t.addChild(CommonTree(CommonToken(99, text="d")))

        newChild = CommonTree(CommonToken(99, text="x"))
        t.replaceChildren(0, 0, newChild)
        expecting = "(a x c d)"
        self.assertEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:166MMX,项目名称:antlr3,代码行数:13,代码来源:testtree.py

示例10: testAoverB

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testAoverB(self):
        t = CommonTree(CommonToken(101))
        t.addChild(CommonTree(CommonToken(102)))

        stream = self.newStream(t)
        expecting = "101 102"
        found = self.toNodesOnlyString(stream)
        self.failUnlessEqual(expecting, found)

        expecting = "101 2 102 3"
        found = str(stream)
        self.failUnlessEqual(expecting, found)
开发者ID:aopui,项目名称:antlr,代码行数:14,代码来源:testtree.py

示例11: testReplaceTwoWithOneAtLeft

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceTwoWithOneAtLeft(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b")))
        t.addChild(CommonTree(CommonToken(99, text="c")))
        t.addChild(CommonTree(CommonToken(99, text="d")))

        newChild = CommonTree(CommonToken(99, text="x"))

        t.replaceChildren(0, 1, newChild)
        expecting = "(a x d)"
        self.failUnlessEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:aopui,项目名称:antlr,代码行数:14,代码来源:testtree.py

示例12: testReplaceTwoWithOneAtRight

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceTwoWithOneAtRight(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b")))
        t.addChild(CommonTree(CommonToken(99, text="c")))
        t.addChild(CommonTree(CommonToken(99, text="d")))

        newChild = CommonTree(CommonToken(99, text="x"))

        t.replaceChildren(1, 2, newChild)
        expecting = "(a b x)"
        self.assertEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:166MMX,项目名称:antlr3,代码行数:14,代码来源:testtree.py

示例13: testListWithOneNode

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testListWithOneNode(self):
        root = CommonTree(None)

        root.addChild(CommonTree(CommonToken(101)))

        stream = CommonTreeNodeStream(root)
        expecting = "101"
        found = self.toNodesOnlyString(stream)
        self.failUnlessEqual(expecting, found)

        expecting = "101"
        found = str(stream)
        self.failUnlessEqual(expecting, found)
开发者ID:aopui,项目名称:antlr,代码行数:15,代码来源:testtree.py

示例14: testList2

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testList2(self):
        # Add child ^(nil 101 102 103) to root 5
        # should pull 101 102 103 directly to become 5's child list
        root = CommonTree(CommonToken(5))

        # child tree
        r0 = CommonTree(None)
        c0 = CommonTree(CommonToken(101))
        r0.addChild(c0)
        c1 = CommonTree(CommonToken(102))
        r0.addChild(c1)
        c2 = CommonTree(CommonToken(103))
        r0.addChild(c2)

        root.addChild(r0)

        self.failUnless(root.parent is None)
        self.failUnlessEqual(-1, root.childIndex)
        # check children of root all point at root
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(0, c0.childIndex)
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(1, c1.childIndex)
        self.failUnlessEqual(root, c0.parent)
        self.failUnlessEqual(2, c2.childIndex)
开发者ID:aopui,项目名称:antlr,代码行数:27,代码来源:testtree.py

示例15: testReplaceOneWithTwoInMiddle

# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import addChild [as 别名]
    def testReplaceOneWithTwoInMiddle(self):
        t = CommonTree(CommonToken(99, text="a"))
        t.addChild(CommonTree(CommonToken(99, text="b")))
        t.addChild(CommonTree(CommonToken(99, text="c")))
        t.addChild(CommonTree(CommonToken(99, text="d")))

        newChildren = self.adaptor.nil()
        newChildren.addChild(CommonTree(CommonToken(99, text="x")))
        newChildren.addChild(CommonTree(CommonToken(99, text="y")))

        t.replaceChildren(1, 1, newChildren)
        expecting = "(a b x y d)"
        self.assertEqual(expecting, t.toStringTree())
        t.sanityCheckParentAndChildIndexes()
开发者ID:166MMX,项目名称:antlr3,代码行数:16,代码来源:testtree.py


注:本文中的antlr3.tree.CommonTree.addChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。