From 56a20074863641eb994e298afb4b38b27a277406 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 30 Sep 2025 22:28:59 -0400 Subject: np: lex: Cache last char during parse Sometimes when parsing while we are scanning for a string, we might loose the last character if we don't save it Signed-off-by: Ian Moffett --- src/sys/np/core/np_lex.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/sys/np') diff --git a/src/sys/np/core/np_lex.c b/src/sys/np/core/np_lex.c index 5ddb442..639e945 100644 --- a/src/sys/np/core/np_lex.c +++ b/src/sys/np/core/np_lex.c @@ -55,11 +55,22 @@ static char lex_pop(struct np_work *work) { struct lexer_state *lex_st; + char c; if (work == NULL) { return '\0'; } + /* + * First we check the cache, if there is a char, + * grab and clear it. + */ + if (work->ccache != '\0') { + c = work->ccache; + work->ccache = '\0'; + return c; + } + /* Don't overflow the source file */ lex_st = &work->lex_st; if (lex_st->source_idx >= work->source_size) { @@ -123,6 +134,7 @@ lex_matchstr(struct np_work *work, char c, struct lex_token *res) return -1; } if (!is_alpha(c) && !is_num(c)) { + work->ccache = c; break; } id[id_idx++] = c; -- cgit v1.2.3