diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sys/include/os/np.h | 2 | ||||
-rw-r--r-- | src/sys/np/core/np_lex.c | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/sys/include/os/np.h b/src/sys/include/os/np.h index 3083ee1..5734e69 100644 --- a/src/sys/include/os/np.h +++ b/src/sys/include/os/np.h @@ -46,12 +46,14 @@ * @source_size: Source size in bytes * @line_no: Current line number * @lex_st: Lexer state + * @ccache: Character cache (temporary store for lexer) */ struct np_work { char *source; size_t source_size; size_t line_no; struct lexer_state lex_st; + char ccache; }; /* 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; |