当前位置: 首页>>代码示例>>Python>>正文


Python TreeWizard.parse方法代码示例

本文整理汇总了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())
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:9,代码来源:testtreewizard.py

示例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)
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:9,代码来源:testtreewizard.py

示例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"]))
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:10,代码来源:testtreewizard.py

示例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"]))
开发者ID:166MMX,项目名称:antlr3,代码行数:11,代码来源:testtreewizard.py

示例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"]))
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:11,代码来源:testtreewizard.py

示例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"]))
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:13,代码来源:testtreewizard.py

示例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)
开发者ID:aopui,项目名称:antlr,代码行数:16,代码来源:testtree.py

示例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)
开发者ID:aopui,项目名称:antlr,代码行数:16,代码来源:testtree.py

示例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")
开发者ID:166MMX,项目名称:antlr3,代码行数:19,代码来源:testtree.py

示例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)
开发者ID:aopui,项目名称:antlr,代码行数:20,代码来源:testtree.py

示例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)
开发者ID:166MMX,项目名称:antlr3,代码行数:7,代码来源:testtreewizard.py

示例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)
开发者ID:166MMX,项目名称:antlr3,代码行数:7,代码来源:testtreewizard.py

示例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)
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:7,代码来源:testtreewizard.py

示例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
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:7,代码来源:testtreewizard.py

示例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)
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:7,代码来源:testtreewizard.py


注:本文中的antlr3.treewizard.TreeWizard.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。