Skip to content

Commit

Permalink
Implemented lex_single_line_comment for // comment
Browse files Browse the repository at this point in the history
  • Loading branch information
hrszpuk committed Jan 5, 2025
1 parent 9d58782 commit 1442bfa
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,22 @@ Token Lexer::lex_symbol() {
return Token(TokenType::Unknown, value, line, column);
}
}

Token Lexer::lex_single_line_comment() {
std::string value = "";
size_t line = this->line;
size_t column = this->column;

while (true) {
auto opt_c = this->peek();
if (!opt_c.has_value() || opt_c.value() == '\n') {
break;
case '.':
printf("Next char: %c\n", lexer->source[lexer->position + 1]);
if (lexer->source[lexer->position + 1] == '.') {
type = TOKEN_RANGE;
value = strndup(lexer->source + lexer->position, 2);
lexer->position++;
} else {
type = TOKEN_INVALID;
value = strndup(lexer->source + lexer->position, 1);
}
}
value += this->advance().value();
}

return Token(TokenType::Comment, value, line, column);
}
break;
default:
type = TOKEN_INVALID;
Expand Down

0 comments on commit 1442bfa

Please sign in to comment.