From: mar77i Date: Thu, 21 Nov 2024 08:48:39 +0000 (+0100) Subject: skip shell-style '#' comments X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=HEAD;p=shitscript skip shell-style '#' comments --- diff --git a/parser.c b/parser.c index 8ef121b..a11ec69 100644 --- a/parser.c +++ b/parser.c @@ -51,6 +51,17 @@ static inline int read_ident_or_keyword( return 0; } +static inline int is_newline(int c) { + return c == '\n'; +} + +static inline void skip_comment(FILE *fh) { + int c; + while ((c = getc(fh)) != EOF) + if (is_newline(c)) + return; +} + int parse_input(FILE *fh, struct program *p) { int c; struct ast_item ai; @@ -90,6 +101,9 @@ int parse_input(FILE *fh, struct program *p) { case '/': ai.type = AST_ITEM_DIVIDE; goto add_item; + case '#': + skip_comment(fh); + continue; } if (isdigit(c)) { ai.type = AST_ITEM_INT;