diff options
author | Anton Kling <anton@kling.gg> | 2024-09-09 16:06:28 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-09-12 00:53:48 +0200 |
commit | 1da6c154e32c171b4fbd9190344ba4c5c71c0d88 (patch) | |
tree | 61deed765e62759d5e9100444108f4dd10bf52ad /userland | |
parent | 0fcf691f149ea860034b9e016912d542d5b087ff (diff) |
sh: Add support for comments
Diffstat (limited to 'userland')
-rw-r--r-- | userland/minibox/utilities/sh/lexer.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/userland/minibox/utilities/sh/lexer.c b/userland/minibox/utilities/sh/lexer.c index 4ad2389..1d967e5 100644 --- a/userland/minibox/utilities/sh/lexer.c +++ b/userland/minibox/utilities/sh/lexer.c @@ -59,15 +59,23 @@ complete_return: return 1; } -void skip_whitespace(struct sv *s) { - *s = sv_skip_chars(*s, " \t\n\r"); +void skip_whitespace_and_comment(struct sv *s) { + struct sv start; + do { + start = *s; + *s = sv_skip_chars(*s, " \t\n\r"); + if (!sv_partial_eq(*s, C_TO_SV("#"))) { + return; + } + (void)sv_split_delim(*s, s, '\n'); + } while (start.length != s->length); } struct TOKEN *lex(struct sv code) { struct TOKEN *head = NULL; struct TOKEN *prev = NULL; for (; !sv_isempty(code);) { - skip_whitespace(&code); + skip_whitespace_and_comment(&code); if (sv_isempty(code)) { break; } @@ -80,7 +88,6 @@ struct TOKEN *lex(struct sv code) { } else if (parse_operand(&code, cur)) { } else { free(cur); - printf("at: %s\n", code); assert(0 && "Unknown token"); } if (!head) |