Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/table.zig
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,22 @@ pub fn parseInlineTable(ctx: *parser.Context) !?*Table {
errdefer deinitTableRecursively(table);

while (true) {
spaces.skipSpaces(ctx);
spaces.skipSpacesAndLineBreaks(ctx);
var pair = try kv.parse(ctx);
errdefer pair.deinit(ctx.alloc);

try handleKeyPair(ctx, table, &pair);
spaces.skipSpaces(ctx);
spaces.skipSpacesAndLineBreaks(ctx);
parser.consumeString(ctx, ",") catch {
try parser.consumeString(ctx, "}");
break;
};

spaces.skipSpacesAndLineBreaks(ctx);
parser.consumeString(ctx, "}") catch {
continue;
};
break;
}

return table;
Expand Down Expand Up @@ -215,6 +221,21 @@ test "inline table" {
testing.allocator.destroy(m);
}

test "multi-line inline table" {
var ctx = parser.testInput(
\\{
\\ aa = 3,
\\ bb.cc = 4,
\\}
);
var m = (try parseInlineTable(&ctx)).?;
try testing.expect(m.count() == 2);
try testing.expect(m.get("aa").?.integer == 3);
try testing.expect(m.get("bb").?.table.get("cc").?.integer == 4);
deinitTableRecursively(m);
testing.allocator.destroy(m);
}

test "error in table" {
var ctx = parser.testInput(
\\aa = "test"
Expand Down
Loading