renamed function->block to function->body
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
namespace ast {
|
||||
function_literal::function_literal(token::token token)
|
||||
: token(std::move(token)),
|
||||
block(nullptr) {};
|
||||
body(nullptr) {};
|
||||
|
||||
std::string function_literal::token_literal() const {
|
||||
return token.literal;
|
||||
@@ -22,14 +22,14 @@ namespace ast {
|
||||
first = false;
|
||||
}
|
||||
ss << ")";
|
||||
ss << block->str();
|
||||
ss << body->str();
|
||||
return ss.str();
|
||||
};
|
||||
|
||||
function_literal::~function_literal() {
|
||||
for (auto& param : parameters)
|
||||
delete param;
|
||||
if (block != nullptr)
|
||||
delete block;
|
||||
if (body != nullptr)
|
||||
delete body;
|
||||
}
|
||||
} // namespace ast
|
||||
|
@@ -12,7 +12,7 @@ namespace ast {
|
||||
function_literal(token::token);
|
||||
token::token token;
|
||||
std::vector<identifier*> parameters;
|
||||
ast::block_stmt* block;
|
||||
ast::block_stmt* body;
|
||||
|
||||
std::string token_literal() const override;
|
||||
std::string str() const override;
|
||||
|
@@ -282,7 +282,7 @@ namespace parser {
|
||||
delete ret;
|
||||
return nullptr;
|
||||
}
|
||||
ret->block = parse_block();
|
||||
ret->body = parse_block();
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
@@ -98,9 +98,9 @@ fn () {\
|
||||
CHECK(fun->parameters.size() == 0);
|
||||
|
||||
// block
|
||||
REQUIRE(fun->block->statements.size() == 1);
|
||||
REQUIRE(fun->body->statements.size() == 1);
|
||||
ast::return_stmt* ret =
|
||||
cast<ast::return_stmt>(fun->block->statements[0]);
|
||||
cast<ast::return_stmt>(fun->body->statements[0]);
|
||||
test_boolean_literal(ret->value, true);
|
||||
|
||||
// full string
|
||||
@@ -127,9 +127,9 @@ fn (x) {\
|
||||
test_identifier(fun->parameters[0], "x");
|
||||
|
||||
// block
|
||||
REQUIRE(fun->block->statements.size() == 1);
|
||||
REQUIRE(fun->body->statements.size() == 1);
|
||||
ast::return_stmt* ret =
|
||||
cast<ast::return_stmt>(fun->block->statements[0]);
|
||||
cast<ast::return_stmt>(fun->body->statements[0]);
|
||||
test_infix_expression(ret->value, "x", "+", 1);
|
||||
|
||||
// full string
|
||||
@@ -157,9 +157,9 @@ fn (x, y) {\
|
||||
test_identifier(fun->parameters[1], "y");
|
||||
|
||||
// block
|
||||
REQUIRE(fun->block->statements.size() == 1);
|
||||
REQUIRE(fun->body->statements.size() == 1);
|
||||
ast::return_stmt* ret =
|
||||
cast<ast::return_stmt>(fun->block->statements[0]);
|
||||
cast<ast::return_stmt>(fun->body->statements[0]);
|
||||
test_infix_expression(ret->value, "x", "+", "y");
|
||||
|
||||
// full string
|
||||
@@ -192,9 +192,9 @@ let fun = fn (x, y) {\
|
||||
test_identifier(fun->parameters[1], "y");
|
||||
|
||||
// block
|
||||
REQUIRE(fun->block->statements.size() == 1);
|
||||
REQUIRE(fun->body->statements.size() == 1);
|
||||
ast::return_stmt* ret =
|
||||
cast<ast::return_stmt>(fun->block->statements[0]);
|
||||
cast<ast::return_stmt>(fun->body->statements[0]);
|
||||
test_infix_expression(ret->value, "x", "+", "y");
|
||||
|
||||
// full string
|
||||
|
Reference in New Issue
Block a user