feat: add comments

This commit is contained in:
samsonium
2026-10-15 15:52:47 +03:00
parent 36ed86b07c
commit 1035b9193c
3 changed files with 21 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
// I'm a comment
printline("Comment is skipped")
+2
View File
@@ -16,6 +16,8 @@ typedef enum
FZL_TOKTYPE_NAME, // abc
FZL_TOKTYPE_TYPE, // i16
FZL_TOKTYPE_DDASH, // // :D
FZL_TOKTYPE_LPAREN, // (
FZL_TOKTYPE_RPAREN, // )
FZL_TOKTYPE_LBRACE, // {
+16
View File
@@ -189,6 +189,17 @@ fzl_token_t *add_double(fzl_reader_t *reader, fzl_toktype_t type)
{
size_t p = move(reader, 2);
return fzl_mktoken(type, reader->line_n, p - reader->line_start, NULL, 0);
// Skip symbols until '\n' or EOF
void skip_comment(fzl_reader_t *reader)
{
move(reader, 2);
while (reader->position < reader->size)
{
if (reader->source[reader->position++] == '\n')
break;
}
}
int fzl_read(fzl_reader_t *reader)
@@ -210,6 +221,11 @@ int fzl_read(fzl_reader_t *reader)
if (curr == '\'' || curr == '"')
token = parse_string_literal(reader);
else if (curr == '/' && reader->source[p + 1] == '/')
{
skip_comment(reader);
continue;
}
else if (curr == '=' && reader->source[p + 1] == '=')
token = add_double(reader, FZL_TOKTYPE_EQEQ);
else if (curr == '>' && reader->source[p + 1] == '=')