def test_simple_return_2(self): ''' Parse return stmt without any value. ''' input_string = 'func start { return }' real_ast = _parse(input_string) expected_ast = _std_module() expected_ast.decl_list[0].body.append(ast.Return(expr=None), ) misc.assert_equal(self, expected_ast, real_ast)
def test_simple_return_1(self): ''' Parse return stmt with integer. ''' input_string = 'func start { return 1 }' real_ast = _parse(input_string) expected_ast = _std_module() expected_ast.decl_list[0].body.append(ast.Return(expr=ast.Number(1)), ) misc.assert_equal(self, expected_ast, real_ast)
def test_string(self): ''' Parse anythong with string. ''' input_string = 'func start { return "hi" }' real_ast = _parse(input_string) expected_ast = _std_module() expected_ast.decl_list[0].body.append( ast.Return(expr=ast.String('hi')), ) misc.assert_equal(self, expected_ast, real_ast)
def test_simple_return_3(self): ''' Parse return stmt with func call. ''' input_string = 'func start { return x() }' real_ast = _parse(input_string) expected_ast = _std_module() expected_ast.decl_list[0].body.append( ast.Return(expr=ast.FuncCall(expr=ast.Ident('x'), ), ), ) misc.assert_equal(self, expected_ast, real_ast)
def p_block_3(p): 'block : LCURLY stmt_list RETURN expr RCURLY' p[2].append(ast.Return(expr=p[4])) p[0] = p[2]
def p_block_2(p): 'block : LCURLY stmt_list RETURN RCURLY' p[2].append(ast.Return(expr=None)) p[0] = p[2]