commit 516941ab2da836ffab7e0e9c0135487bbdb9551f
parent cca85f7e89bab2663604f403819ef7583b38d749
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date: Thu, 5 Sep 2024 14:31:46 +0800
lexer_peek_token: show the next token without advancing
Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Diffstat:
1 file changed, 7 insertions(+), 0 deletions(-)
diff --git a/lex.odin b/lex.odin
@@ -232,6 +232,13 @@ lexer_peek :: proc(l: ^Lexer, step: u32 = 1) -> (p: string) {
return l.source[start:end]
}
+// lexer_peek_token returns the next token without advancing the lexer.
+lexer_peek_token :: proc(l: ^Lexer) -> (t: Token, ok: bool) {
+ start := l.cursor
+ defer l.cursor = start
+ return lexer_next(l)
+}
+
lexer_skip_space :: proc(l: ^Lexer) {
lexer_advance_until_proc(l, proc(l: ^Lexer) -> bool {
peek := lexer_peek(l)