From 3647f1b62134b550d615ed10758e0f3f4ad0a1b8 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Tue, 12 Dec 2023 22:03:52 -0600 Subject: [PATCH] fixed: KDL parsing bug #62 --- core/encoding/kdl/parser.onyx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/encoding/kdl/parser.onyx b/core/encoding/kdl/parser.onyx index 303f0050..ba3f7fe5 100644 --- a/core/encoding/kdl/parser.onyx +++ b/core/encoding/kdl/parser.onyx @@ -59,16 +59,20 @@ Token :: union { } peek_char :: (self: &#Self) -> ? u32 { + if self.cursor >= self.doc.length do return .None; + codepoint_length := utf8.rune_length_from_first_byte(self.doc[self.cursor]); - if self.cursor + codepoint_length >= self.doc.length do return .None; + if self.cursor + codepoint_length > self.doc.length do return .None; value := utf8.decode_rune(string.advance(self.doc, self.cursor)); return value; } eat_char :: (self: &#Self) -> ? u32 { + if self.cursor >= self.doc.length do return .None; + codepoint_length := utf8.rune_length_from_first_byte(self.doc[self.cursor]); - if self.cursor + codepoint_length >= self.doc.length do return .None; + if self.cursor + codepoint_length > self.doc.length do return .None; value := utf8.decode_rune(string.advance(self.doc, self.cursor)); self.cursor += codepoint_length; @@ -129,7 +133,6 @@ Token :: union { } return .{ Newline = .{} }; - // return self->next_token(); } if c == ';' { self->eat_char(); return .{ Semicolon = .{} }; } @@ -146,7 +149,6 @@ Token :: union { return self->handle_word(); } - // assert(false, tprintf("Unhandled character, {}", c)); return .{ Error = .{} }; } -- 2.25.1