Add support for comments in config

This commit is contained in:
Nikita Ivanov 2022-06-09 12:34:21 +05:00
parent 0d5c32baf5
commit f0204c359e
No known key found for this signature in database
GPG Key ID: 6E656AC5B97B5133
2 changed files with 14 additions and 1 deletions

View File

@ -202,7 +202,7 @@ static int end(void)
static int commands(void) static int commands(void)
{ {
accept(TOK_NEW_LN); end();
while (1) { while (1) {
NOT_ACCEPT(TOK_EOF); NOT_ACCEPT(TOK_EOF);

View File

@ -195,6 +195,18 @@ static int cmp_nextn(Lexer *ctx, int n, char *s)
return ((unsigned char)c - *(unsigned 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) static void read_while(Lexer *ctx, Predicate p, int add)
{ {
char c; char c;
@ -366,6 +378,7 @@ Token lexer_get_token(Lexer *ctx)
return remove_token_queue(ctx); return remove_token_queue(ctx);
read_while(ctx, isblank, 0); read_while(ctx, isblank, 0);
ignore_comments(ctx);
ctx->tok_pos.line = ctx->line; ctx->tok_pos.line = ctx->line;
ctx->tok_pos.col = ctx->col; ctx->tok_pos.col = ctx->col;