New line shouldn't be the first token

This commit is contained in:
Rafał Grodziński
2025-07-01 17:06:52 +09:00
parent 729ffd0ea2
commit e4a2b84154
3 changed files with 9 additions and 4 deletions

View File

@@ -22,7 +22,11 @@ vector<shared_ptr<Token>> Lexer::getTokens() {
if (!token->isValid()) {
cerr << "Unexpected character '" << token->getLexme() << "' at " << token->getLine() << ":" << token->getColumn() << endl;
exit(1);
}
}
// Don't add new line as the first token
if (tokens.empty() && token->isOfKind({TokenKind::NEW_LINE}))
continue;
// Insert an additional new line just before end
if (token->getKind() == TokenKind::END && tokens.back()->getKind() != TokenKind::NEW_LINE)