本文整理汇总了Python中antlr3.treewizard.TreeWizard类的典型用法代码示例。如果您正苦于以下问题:Python TreeWizard类的具体用法?Python TreeWizard怎么用?Python TreeWizard使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TreeWizard类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRepeatsIndex
def testRepeatsIndex(self):
wiz = TreeWizard(self.adaptor, self.tokens)
tree = wiz.create("(A B (A C B) B D D)")
indexMap = wiz.index(tree)
found = self.__simplifyIndexMap(indexMap)
expecting = { 8: ['D', 'D'], 6: ['B', 'B', 'B'], 7: ['C'], 5: ['A', 'A'] }
self.failUnlessEqual(expecting, found)
示例2: testParseWithText
def testParseWithText(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B[foo] C[bar])")
# C pattern has no text arg so despite [bar] in t, no need
# to match text--check structure only.
valid = wiz.parse(t, "(A B[foo] C)")
self.failUnless(valid)
示例3: testFindPattern
def testFindPattern(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))")
subtrees = wiz.find(t, "(A B)")
found = [str(node) for node in subtrees]
expecting = ['foo', 'big']
self.assertEqual(expecting, found)
示例4: testSingleNodeIndex
def testSingleNodeIndex(self):
wiz = TreeWizard(self.adaptor, self.tokens)
tree = wiz.create("ID")
indexMap = wiz.index(tree)
found = self.__simplifyIndexMap(indexMap)
expecting = { 10: ["ID"] }
self.failUnlessEqual(expecting, found)
示例5: testParseWithText2
def testParseWithText2(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B[T__32] (C (D E[a])))")
# C pattern has no text arg so despite [bar] in t, no need
# to match text--check structure only.
valid = wiz.parse(t, "(A B[foo] C)")
self.assertEquals("(A T__32 (C (D a)))", t.toStringTree())
示例6: testNoRepeatsIndex
def testNoRepeatsIndex(self):
wiz = TreeWizard(self.adaptor, self.tokens)
tree = wiz.create("(A B C D)")
indexMap = wiz.index(tree)
found = self.__simplifyIndexMap(indexMap)
expecting = { 8:['D'], 6:['B'], 7:['C'], 5:['A'] }
self.assertEqual(expecting, found)
示例7: testFindTokenType
def testFindTokenType(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))")
subtrees = wiz.find(t, wiz.getTokenType('A'))
found = [str(node) for node in subtrees]
expecting = ['A', 'foo', 'big']
self.failUnlessEqual(expecting, found)
示例8: testComplex
def testComplex(self):
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokens)
t = wiz.create("(A (B (C D E) F) G)")
it = TreeIterator(t)
expecting = "A DOWN B DOWN C DOWN D E UP F UP G UP EOF"
found = self.toString(it)
self.assertEquals(expecting, found)
示例9: testNode
def testNode(self):
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokens)
t = wiz.create("A")
it = TreeIterator(t)
expecting = "A EOF"
found = self.toString(it)
self.assertEquals(expecting, found)
示例10: testABC
def testABC(self):
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokens)
t = wiz.create("(A B C)")
it = TreeIterator(t)
expecting = "A DOWN B C UP EOF"
found = self.toString(it)
self.assertEqual(expecting, found)
示例11: testFlatAB
def testFlatAB(self):
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokens)
t = wiz.create("(nil A B)")
it = TreeIterator(t)
expecting = "nil DOWN A B UP EOF"
found = self.toString(it)
self.assertEquals(expecting, found)
示例12: testParseWithWildcardLabels
def testParseWithWildcardLabels(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B C)")
labels = {}
valid = wiz.parse(t, "(A %b:. %c:.)", labels)
self.failUnless(valid)
self.failUnlessEqual("B", str(labels["b"]))
self.failUnlessEqual("C", str(labels["c"]))
示例13: testVerticalList
def testVerticalList(self):
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokens)
t = wiz.create("(A (B C))")
it = TreeIterator(t)
expecting = "A DOWN B DOWN C UP UP EOF"
found = self.toString(it)
self.assertEquals(expecting, found)
示例14: testParseLabels
def testParseLabels(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B C)")
labels = {}
valid = wiz.parse(t, "(%a:A %b:B %c:C)", labels)
self.assertTrue(valid)
self.assertEqual("A", str(labels["a"]))
self.assertEqual("B", str(labels["b"]))
self.assertEqual("C", str(labels["c"]))
示例15: testParseLabelsAndTestText
def testParseLabelsAndTestText(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B[foo] C)")
labels = {}
valid = wiz.parse(t, "(%a:A %b:B[foo] %c:C)", labels)
self.failUnless(valid)
self.failUnlessEqual("A", str(labels["a"]))
self.failUnlessEqual("foo", str(labels["b"]))
self.failUnlessEqual("C", str(labels["c"]))