本文整理汇总了Python中antlr3.tree.CommonTree.replaceChildren方法的典型用法代码示例。如果您正苦于以下问题:Python CommonTree.replaceChildren方法的具体用法?Python CommonTree.replaceChildren怎么用?Python CommonTree.replaceChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr3.tree.CommonTree
的用法示例。
在下文中一共展示了CommonTree.replaceChildren方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testReplaceInMiddle
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例2: testReplaceAtRight
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例3: testReplaceWithOneChildren
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例4: testReplaceWithNoChildren
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [as 别名]
def testReplaceWithNoChildren(self):
t = CommonTree(CommonToken(101))
newChild = CommonTree(CommonToken(5))
error = False
try:
t.replaceChildren(0, 0, newChild)
except IndexError:
error = True
self.failUnless(error)
示例5: testReplaceAtLeft
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例6: testReplaceTwoWithOneAtLeft
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例7: testReplaceTwoWithOneAtRight
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()
示例8: testReplaceAllWithTwo
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [as 别名]
def testReplaceAllWithTwo(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(0, 2, newChildren)
expecting = "(a x y)"
self.failUnlessEqual(expecting, t.toStringTree())
t.sanityCheckParentAndChildIndexes()
示例9: testReplaceOneWithTwoInMiddle
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import replaceChildren [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()