本文整理汇总了Python中antlr3.tree.CommonTree.getChild方法的典型用法代码示例。如果您正苦于以下问题:Python CommonTree.getChild方法的具体用法?Python CommonTree.getChild怎么用?Python CommonTree.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr3.tree.CommonTree
的用法示例。
在下文中一共展示了CommonTree.getChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test4Nodes
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import getChild [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)
示例2: test4Nodes
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import getChild [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)
示例3: testLT
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import getChild [as 别名]
def testLT(self):
# ^(101 ^(102 103) 104)
t = CommonTree(CommonToken(101))
t.addChild(CommonTree(CommonToken(102)))
t.getChild(0).addChild(CommonTree(CommonToken(103)))
t.addChild(CommonTree(CommonToken(104)))
stream = self.newStream(t)
self.failUnlessEqual(101, stream.LT(1).getType())
self.failUnlessEqual(DOWN, stream.LT(2).getType())
self.failUnlessEqual(102, stream.LT(3).getType())
self.failUnlessEqual(DOWN, stream.LT(4).getType())
self.failUnlessEqual(103, stream.LT(5).getType())
self.failUnlessEqual(UP, stream.LT(6).getType())
self.failUnlessEqual(104, stream.LT(7).getType())
self.failUnlessEqual(UP, stream.LT(8).getType())
self.failUnlessEqual(EOF, stream.LT(9).getType())
# check way ahead
self.failUnlessEqual(EOF, stream.LT(100).getType())
示例4: testList
# 需要导入模块: from antlr3.tree import CommonTree [as 别名]
# 或者: from antlr3.tree.CommonTree import getChild [as 别名]
def testList(self):
root = CommonTree(None)
t = CommonTree(CommonToken(101))
t.addChild(CommonTree(CommonToken(102)))
t.getChild(0).addChild(CommonTree(CommonToken(103)))
t.addChild(CommonTree(CommonToken(104)))
u = CommonTree(CommonToken(105))
root.addChild(t)
root.addChild(u)
stream = CommonTreeNodeStream(root)
expecting = "101 102 103 104 105"
found = self.toNodesOnlyString(stream)
self.failUnlessEqual(expecting, found)
expecting = "101 2 102 2 103 3 104 3 105"
found = str(stream)
self.failUnlessEqual(expecting, found)