Better parsing of if then else

This commit is contained in:
Rafał Grodziński
2025-06-13 11:13:13 +09:00
parent 37bcb5c2c7
commit 6b67154260
4 changed files with 32 additions and 33 deletions

View File

@@ -20,6 +20,10 @@ vector<shared_ptr<Token>> Lexer::getTokens() {
exit(1);
}
// Insert an additional new line just before end
if (token->getKind() == TokenKind::END && tokens.back()->getKind() != TokenKind::NEW_LINE)
tokens.push_back(make_shared<Token>(TokenKind::NEW_LINE, "\n", token->getLine(), token->getColumn()));
// filter out multiple new lines
if (tokens.empty() || token->getKind() != TokenKind::NEW_LINE || tokens.back()->getKind() != token->getKind())
tokens.push_back(token);