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


Python pypeg2.compose函数代码示例

本文整理汇总了Python中pypeg2.compose函数的典型用法代码示例。如果您正苦于以下问题:Python compose函数的具体用法?Python compose怎么用?Python compose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compose

    def compose(self, p, **x):
        """Produce the equivalent simple language as matched.

        Might have different whitespace and be otherwise formatted
        in a normalized fashion.

        """
        return "{0} = {1}".format(compose(self[0]), compose(self[1]))
开发者ID:jserv,项目名称:lang-simple,代码行数:8,代码来源:parsing_simple.py

示例2: test_expression

 def test_expression(string):
     expression = expressions.parse(string)
     switched = expression.accept(Switcher())
     assert_equal(compose(expression)
                    .replace('and', '%OLDAND%')
                    .replace('or', 'and')
                    .replace('%OLDAND%', 'or'),
                  compose(switched))
开发者ID:varda,项目名称:varda,代码行数:8,代码来源:test_expressions.py

示例3: test_if_tx1yx2y

    def test_if_tx1yx2y(self):
        """Test parsing if statement if (x > y) {...} else {...}."""
        expected = "if (x > y)\n"
        expected += "{\n"
        expected += "  x = 1;\n"
        expected += "  y = x * 3;\n"
        expected += "}\n"
        expected += "else\n"
        expected += "{\n"
        expected += "  x = 2;\n"
        expected += "  y = 3 * x;\n"
        expected += "}"
        ast = parse(expected, p.If)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual(expected, c)
        self.assertEqual(
            If(
                GreaterThan(Variable('x'), Variable('y')),
                Sequence(
                    Assign('x', Number(1)),
                    Assign('y', Multiply(Variable('x'), Number(3)))),
                Sequence(
                    Assign('x', Number(2)),
                    Assign('y', Multiply(Number(3), Variable('x'))))),
            e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:27,代码来源:test_parsing_simple.py

示例4: test_not_x

    def test_not_x(self):
        """Test parsing logical negation expression !x."""
        ast = parse("!x", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("!x", c)
        self.assertEqual(Not(Variable('x')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例5: test_multiplication_15x

    def test_multiplication_15x(self):
        """Test parsing multiplication expression 1.5 * x."""
        ast = parse("1.5 * x", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("1.5 * x", c)
        self.assertEqual(Multiply(Number(1.5), Variable('x')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例6: test_division_xy

    def test_division_xy(self):
        """Test parsing division expression x / y."""
        ast = parse("x / y", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("x / y", c)
        self.assertEqual(Divide(Variable('x'), Variable('y')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例7: test_or_nxy

    def test_or_nxy(self):
        """Test parsing logical or expression !x || y."""
        ast = parse("!x || y", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("!x || y", c)
        self.assertEqual(Or(Not(Variable('x')), Variable('y')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例8: test_assign_nxt

    def test_assign_nxt(self):
        """Test parsing assignment statement."""
        ast = parse("x = !true;", p.Assign)
        c = compose(ast, indent="  ", autoblank=False)
        s = ast.to_simple()

        self.assertEqual("x = !true;", c)
        self.assertEqual(Assign('x', Not(Boolean(True))), s)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例9: test_lessthan_2m1m

    def test_lessthan_2m1m(self):
        """Test parsing less than expression -2 - -1."""
        ast = parse("-2 < -1", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("-2 < -1", c)
        self.assertEqual(LessThan(Number(-2), Number(-1)), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例10: test_or_xf

    def test_or_xf(self):
        """Test parsing logical or expression x || false."""
        ast = parse("x || false", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("x || false", c)
        self.assertEqual(Or(Variable('x'), Boolean(False)), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例11: test_subtraction_xy

    def test_subtraction_xy(self):
        """Test parsing subtraction expression x - y."""
        ast = parse("x - y", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("x - y", c)
        self.assertEqual(Subtract(Variable('x'), Variable('y')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例12: test_greaterthan_x25

    def test_greaterthan_x25(self):
        """Test parsing greater than expression x > 2.5."""
        ast = parse("x > 2.5", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("x > 2.5", c)
        self.assertEqual(GreaterThan(Variable('x'), Number(2.5)), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例13: test_subtraction_15x

    def test_subtraction_15x(self):
        """Test parsing subtraction expression 1.5 - x."""
        ast = parse("1.5 - x", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("1.5 - x", c)
        self.assertEqual(Subtract(Number(1.5), Variable('x')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例14: test_subtraction_2m1m

    def test_subtraction_2m1m(self):
        """Test parsing subtraction expression -2 - -1."""
        ast = parse("-2 - -1", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("-2 - -1", c)
        self.assertEqual(Subtract(Number(-2), Number(-1)), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py

示例15: test_multiplication_xy

    def test_multiplication_xy(self):
        """Test parsing multiplication expression x * y."""
        ast = parse("x * y", p.Expression)
        c = compose(ast, indent="  ", autoblank=False)
        e = ast.to_simple()

        self.assertEqual("x * y", c)
        self.assertEqual(Multiply(Variable('x'), Variable('y')), e)
开发者ID:JeNeSuisPasDave,项目名称:lang-simple,代码行数:8,代码来源:test_parsing_simple.py


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