本文整理汇总了Python中antlr3.treewizard.TreeWizard.create方法的典型用法代码示例。如果您正苦于以下问题:Python TreeWizard.create方法的具体用法?Python TreeWizard.create怎么用?Python TreeWizard.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr3.treewizard.TreeWizard
的用法示例。
在下文中一共展示了TreeWizard.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testSingleNodeIndex
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例2: testRepeatsIndex
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例3: testParseWithText
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例4: testFindPattern
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例5: testParseWithText2
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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: testFindTokenType
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例7: testNoRepeatsIndex
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例8: testComplex
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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: testVerticalList
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例10: testNode
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例11: testABC
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例12: testFlatAB
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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)
示例13: testParseWithWildcardLabels
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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"]))
示例14: testParseLabelsAndTestText
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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"]))
示例15: testParseLabels
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import create [as 别名]
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"]))