From: Brendan Hansen Date: Wed, 13 Dec 2023 04:03:52 +0000 (-0600) Subject: fixed: KDL parsing bug #62 X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=3647f1b62134b550d615ed10758e0f3f4ad0a1b8;p=onyx.git fixed: KDL parsing bug #62 --- 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 = .{} }; }