diff --git a/exl/comment.fzs b/exl/comment.fzs new file mode 100644 index 0000000..883dc04 --- /dev/null +++ b/exl/comment.fzs @@ -0,0 +1,3 @@ +// I'm a comment +printline("Comment is skipped") + diff --git a/include/compiler/fzl_token.h b/include/compiler/fzl_token.h index bcc8de1..ce60c69 100644 --- a/include/compiler/fzl_token.h +++ b/include/compiler/fzl_token.h @@ -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, // { diff --git a/src/compiler/fzl_reader.c b/src/compiler/fzl_reader.c index 18d5426..adbf95e 100644 --- a/src/compiler/fzl_reader.c +++ b/src/compiler/fzl_reader.c @@ -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] == '=')