Example #1
0
 def p_block_value(self, p):
     """block_value : LBRACE statement_list_v_opt RBRACE"""
     ls=p[2]
     if len(ls)>0:
         #print((ls[0]))
         #print("VDEAL")
         ls[len(ls)-1]=ast.ReturnStatement(expression=ls[len(ls)-1])
     p[0] = ast.Block(statements=ls)
Example #2
0
 def test_parse_function_expression(self):
     self.assertEqual(self.parser.parse('function (x, y) { return x + y; }'),
                      ast.FunctionDefinition(parameters=[ast.Identifier(name='x'),
                                                         ast.Identifier(name='y')],
                                             body=ast.Block(
                 statements=[ast.ReturnStatement(expression=ast.BinaryOp(op='+',
                                                                         left_expression=ast.Identifier(name='x'),
                                                                         right_expression=ast.Identifier(name='y')))])))
Example #3
0
 def p_return_statement(self, p):
     """return_statement : RETURN expression_opt"""
     p[0] = ast.ReturnStatement(expression=p[2])