From 5a5b0d01d8ae198120969802b96a14ac483cbdf0 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 18 Nov 2024 15:19:26 +0000 Subject: [PATCH] lang: lex: only read linefeeds up to the end of the current line buffer --- lang/lex.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lang/lex.c b/lang/lex.c index f7ae876..5c5f712 100644 --- a/lang/lex.c +++ b/lang/lex.c @@ -482,6 +482,11 @@ static int advance(struct ivy_lexer *lex) return c; } +static bool input_available(struct ivy_lexer* lex) +{ + return lex->lex_linebuf_ptr < lex->lex_linebuf_len; +} + static bool char_can_begin_symbol(char c) { for (size_t i = 0; i < nr_symbols; i++) { @@ -999,6 +1004,11 @@ static enum ivy_status pump_tokens(struct ivy_lexer *lex) if (c == '\n') { while (c == '\n') { advance(lex); + + if (!input_available(lex)) { + break; + } + c = peek(lex); }