本文整理汇总了Python中antlr3.treewizard.TreeWizard.parse方法的典型用法代码示例。如果您正苦于以下问题:Python TreeWizard.parse方法的具体用法?Python TreeWizard.parse怎么用?Python TreeWizard.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类antlr3.treewizard.TreeWizard
的用法示例。
在下文中一共展示了TreeWizard.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testParseWithText2
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [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())
示例2: testParseWithText
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [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)
示例3: testParseWithWildcardLabels
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [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"]))
示例4: testParseLabels
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [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"]))
示例5: testParseLabelsAndTestText
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [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"]))
示例6: testParseLabelsInNestedTree
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseLabelsInNestedTree(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A (B C) (D E))")
labels = {}
valid = wiz.parse(t, "(%a:A (%b:B %c:C) (%d:D %e:E) )", labels)
self.failUnless(valid)
self.failUnlessEqual("A", str(labels["a"]))
self.failUnlessEqual("B", str(labels["b"]))
self.failUnlessEqual("C", str(labels["c"]))
self.failUnlessEqual("D", str(labels["d"]))
self.failUnlessEqual("E", str(labels["e"]))
示例7: testNotParent
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testNotParent(self):
tree = "(PRINT (MULT ID[x] (VEC (MULT INT[9] INT[1]) INT[2] INT[3])))"
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokenNames)
t = wiz.create(tree)
labels = {}
valid = wiz.parse(t, "(PRINT (MULT ID (VEC (MULT INT %x:INT) INT INT)))", labels)
self.assertTrue(valid)
node = labels.get("x")
expecting = False
found = TreeParser._inContext(adaptor, self.tokenNames, node, "VEC")
self.assertEquals(expecting, found)
示例8: testLotsOfWildcards
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testLotsOfWildcards(self):
tree = "(nil (ASSIGN ID[x] INT[3]) (PRINT (MULT ID[x] (VEC INT[1] INT[2] INT[3]))))"
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokenNames)
t = wiz.create(tree)
labels = {}
valid = wiz.parse(t, "(nil (ASSIGN ID[x] INT[3]) (PRINT (MULT ID (VEC INT %x:INT INT))))", labels)
self.assertTrue(valid)
node = labels.get("x")
expecting = True
found = TreeParser._inContext(adaptor, self.tokenNames, node, "... PRINT ... VEC ...")
self.assertEquals(expecting, found)
示例9: testDotDot
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testDotDot(self):
tree = "(PRINT (MULT ID[x] (VEC (MULT INT[9] INT[1]) INT[2] INT[3])))"
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokenNames)
t = wiz.create(tree)
labels = {}
valid = wiz.parse(
t,
"(PRINT (MULT ID (VEC (MULT INT %x:INT) INT INT)))",
labels)
self.assertTrue(valid)
node = labels.get("x")
self.assertRaisesRegex(
ValueError, r'invalid syntax: \.\.',
TreeParser._inContext, adaptor, self.tokenNames, node, "PRINT .. VEC")
示例10: testDotDot
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testDotDot(self):
tree = "(PRINT (MULT ID[x] (VEC (MULT INT[9] INT[1]) INT[2] INT[3])))"
adaptor = CommonTreeAdaptor()
wiz = TreeWizard(adaptor, self.tokenNames)
t = wiz.create(tree)
labels = {}
valid = wiz.parse(t, "(PRINT (MULT ID (VEC (MULT INT %x:INT) INT INT)))", labels)
self.assertTrue(valid)
node = labels.get("x")
try:
TreeParser._inContext(adaptor, self.tokenNames, node, "PRINT .. VEC")
self.fail()
except ValueError, exc:
expecting = "invalid syntax: .."
found = str(exc)
self.assertEquals(expecting, found)
示例11: testParseFlatTreeFails2
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseFlatTreeFails2(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(nil A B C)")
valid = wiz.parse(t, "(nil A B A)")
self.assertFalse(valid)
示例12: testParseSingleNodeFails
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseSingleNodeFails(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("A")
valid = wiz.parse(t, "B")
self.assertFalse(valid)
示例13: testParseSingleNodeFails
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseSingleNodeFails(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("A")
valid = wiz.parse(t, "B")
self.failUnless(not valid)
示例14: testParseWithTextFails
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseWithTextFails(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(A B C)")
valid = wiz.parse(t, "(A[foo] B C)")
self.failUnless(not valid) # fails
示例15: testParseFlatTreeFails2
# 需要导入模块: from antlr3.treewizard import TreeWizard [as 别名]
# 或者: from antlr3.treewizard.TreeWizard import parse [as 别名]
def testParseFlatTreeFails2(self):
wiz = TreeWizard(self.adaptor, self.tokens)
t = wiz.create("(nil A B C)")
valid = wiz.parse(t, "(nil A B A)")
self.failUnless(not valid)