fixed tests
This commit is contained in:
@@ -16,6 +16,12 @@ namespace parser {
|
||||
next = lexer.next_token();
|
||||
}
|
||||
|
||||
void parser::skip_until_semicolon() {
|
||||
for (; current.type != token::type::SEMICOLON
|
||||
&& current.type != token::type::END_OF_FILE;
|
||||
next_token()) {};
|
||||
}
|
||||
|
||||
ast::program* parser::parse_program() {
|
||||
ast::program* p = new ast::program();
|
||||
|
||||
@@ -51,6 +57,8 @@ namespace parser {
|
||||
next_token();
|
||||
|
||||
stmt->value = parse_expression();
|
||||
if (next.type == token::type::SEMICOLON)
|
||||
next_token();
|
||||
|
||||
return stmt;
|
||||
}
|
||||
@@ -60,6 +68,7 @@ namespace parser {
|
||||
|
||||
if (!expect_next(token::type::IDENTIFIER)) {
|
||||
delete stmt;
|
||||
skip_until_semicolon();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -67,10 +76,14 @@ namespace parser {
|
||||
|
||||
if (!expect_next(token::type::ASSIGN)) {
|
||||
delete stmt;
|
||||
skip_until_semicolon();
|
||||
return nullptr;
|
||||
}
|
||||
next_token();
|
||||
|
||||
stmt->value = parse_expression();
|
||||
if (next.type == token::type::SEMICOLON)
|
||||
next_token();
|
||||
return stmt;
|
||||
}
|
||||
|
||||
@@ -79,6 +92,9 @@ namespace parser {
|
||||
|
||||
stmt->expression = parse_expression();
|
||||
|
||||
if (next.type == token::type::SEMICOLON)
|
||||
next_token();
|
||||
|
||||
return stmt;
|
||||
};
|
||||
|
||||
|
@@ -32,6 +32,7 @@ namespace parser {
|
||||
std::unordered_map<token::type, infix_parse_fn> infix_parse_fns;
|
||||
|
||||
void next_token();
|
||||
void skip_until_semicolon();
|
||||
ast::statement* parse_statement();
|
||||
ast::expression* parse_expression();
|
||||
ast::let_stmt* parse_let();
|
||||
|
Reference in New Issue
Block a user