Skip to content

Commit

Permalink
fix(toml): cursor pos for duplicate key errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Jan 11, 2025
1 parent b04ce67 commit 9f6b1e4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/toml/toml_parser.zig
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ pub const TOML = struct {
pub fn parseAssignment(p: *TOML, obj: *E.Object, allocator: std.mem.Allocator) anyerror!void {
p.lexer.allow_double_bracket = false;
const rope = try p.parseKey(allocator);
const rope_end = p.lexer.start;

const is_array = p.lexer.token == .t_empty_array;
if (is_array) {
Expand All @@ -262,7 +263,11 @@ pub const TOML = struct {
obj.setRope(rope, p.allocator, try p.parseValue()) catch |err| {
switch (err) {
error.Clobber => {
try p.lexer.addDefaultError("Cannot redefine key");
const loc = rope.head.loc;
assert(loc.start > 0);
const start: u32 = @intCast(loc.start);
const key_name = std.mem.trimRight(u8, p.source().contents[start..rope_end], &std.ascii.whitespace);
p.lexer.addError(start, "Cannot redefine key '{s}'", .{key_name});
return error.SyntaxError;
},
else => return err,
Expand Down

0 comments on commit 9f6b1e4

Please sign in to comment.