From f0204c359e1ea823c0c5b90b04a5e55ba79e7245 Mon Sep 17 00:00:00 2001 From: Nikita Ivanov Date: Thu, 9 Jun 2022 12:34:21 +0500 Subject: [PATCH] Add support for comments in config --- src/config.c | 2 +- src/lexer.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index f1c8073..c214fb4 100644 --- a/src/config.c +++ b/src/config.c @@ -202,7 +202,7 @@ static int end(void) static int commands(void) { - accept(TOK_NEW_LN); + end(); while (1) { NOT_ACCEPT(TOK_EOF); diff --git a/src/lexer.c b/src/lexer.c index d509085..6ab40c4 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -195,6 +195,18 @@ static int cmp_nextn(Lexer *ctx, int n, char *s) return ((unsigned char)c - *(unsigned char *)s); } +static void ignore_comments(Lexer *ctx) +{ + char c; + + if (peek_char(ctx) != '#') + return; + + do { + c = next_char(ctx); + } while (c != '\n'); +} + static void read_while(Lexer *ctx, Predicate p, int add) { char c; @@ -366,6 +378,7 @@ Token lexer_get_token(Lexer *ctx) return remove_token_queue(ctx); read_while(ctx, isblank, 0); + ignore_comments(ctx); ctx->tok_pos.line = ctx->line; ctx->tok_pos.col = ctx->col;