extracted the parsing of the "expressions" to it's
own function so we can just modify that once we get there
This commit is contained in:
@@ -50,14 +50,18 @@ namespace parser {
|
|||||||
next_error(t);
|
next_error(t);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
ast::expression* parser::parse_expression() {
|
||||||
|
// TODO: we are currently skipping expressions until we encounter a
|
||||||
|
// semicolon
|
||||||
|
for (; current.type != token::type::SEMICOLON; next_token()) {}
|
||||||
|
return nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
ast::return_stmt* parser::parse_return() {
|
ast::return_stmt* parser::parse_return() {
|
||||||
ast::return_stmt* stmt = new ast::return_stmt(current);
|
ast::return_stmt* stmt = new ast::return_stmt(current);
|
||||||
next_token();
|
next_token();
|
||||||
|
|
||||||
// TODO: we are currently skipping expressions until we encounter a
|
stmt->value = parse_expression();
|
||||||
// semicolon
|
|
||||||
for (; current.type != token::type::SEMICOLON; next_token()) {}
|
|
||||||
|
|
||||||
return stmt;
|
return stmt;
|
||||||
}
|
}
|
||||||
@@ -77,9 +81,10 @@ namespace parser {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we are currently skipping expressions until we encounter a
|
stmt->value = parse_expression();
|
||||||
// semicolon
|
return stmt;
|
||||||
for (; current.type != token::type::SEMICOLON; next_token()) {}
|
}
|
||||||
|
|
||||||
return stmt;
|
return stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,7 @@ namespace parser {
|
|||||||
|
|
||||||
void next_token();
|
void next_token();
|
||||||
ast::statement* parse_statement();
|
ast::statement* parse_statement();
|
||||||
|
ast::expression* parse_expression();
|
||||||
ast::let_stmt* parse_let();
|
ast::let_stmt* parse_let();
|
||||||
ast::return_stmt* parse_return();
|
ast::return_stmt* parse_return();
|
||||||
bool expect_next(token::type);
|
bool expect_next(token::type);
|
||||||
|
Reference in New Issue
Block a user