fixed: KDL parsing bug #62
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 13 Dec 2023 04:03:52 +0000 (22:03 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 13 Dec 2023 04:03:52 +0000 (22:03 -0600)
core/encoding/kdl/parser.onyx

index 303f00508b55bdf383e4e1e5e5ba2cd5449bd74e..ba3f7fe534e84ff61e347617c436257c86360bec 100644 (file)
@@ -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 = .{} };
     }