summaryrefslogtreecommitdiff
path: root/src/sys/np
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-09-30 22:28:59 -0400
committerIan Moffett <ian@osmora.org>2025-09-30 22:28:59 -0400
commit56a20074863641eb994e298afb4b38b27a277406 (patch)
tree1affdfefe02c89f3f7f46c900ebea09baae41f60 /src/sys/np
parentff46d0abedb578dd8babc00ac3139c8e9c71d1fc (diff)
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 <ian@osmora.org>
Diffstat (limited to 'src/sys/np')
-rw-r--r--src/sys/np/core/np_lex.c12
1 files changed, 12 insertions, 0 deletions
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;