Enhance ZON parser to support tuples and update documentation

- Modify parser to handle ZON tuples (`.{ 1, 2, 3 }`) as arrays
- Update README with more detailed explanation of ZON tuple syntax
- Add multiple example ZON files demonstrating tuple usage
- Implement tuple parsing in `parser.py`
- Add test case for tuple parsing
This commit is contained in:
2025-03-07 17:01:12 +08:00
parent 807fcb2849
commit fd29f7e3af
9 changed files with 129 additions and 24 deletions

View File

@ -7,5 +7,5 @@
.hash = "abcdef123456",
},
},
.tags = .["tag1", "tag2"],
}
.tags = .{ "tag1", "tag2" },
}

14
examples/nested_test.zon Normal file
View File

@ -0,0 +1,14 @@
.{
.simple_object = .{
.x = 1,
.y = 2,
},
.simple_tuple = .{ 1, 2, 3 },
.nested_object = .{
.nested = .{
.a = 1,
.b = 2,
},
},
.nested_tuple = .{ .{ 1, 2 }, .{ 3, 4 } },
}

6
examples/simple.zon Normal file
View File

@ -0,0 +1,6 @@
.{
.name = "example",
.version = "1.0.0",
.numbers = .{ 1, 2, 3 },
.strings = .{ "one", "two", "three" },
}

View File

@ -0,0 +1,4 @@
.{
.simple_tuple = .{ 1, 2, 3 },
.nested_tuple = .{ .{ 1, 2 }, .{ 3, 4 } },
}

6
examples/tuple_test.zon Normal file
View File

@ -0,0 +1,6 @@
.{
.simple_tuple = .{ 1, 2, 3 },
.string_tuple = .{ "one", "two", "three" },
.empty_tuple = .{""},
.mixed_tuple = .{ 1, "two", true },
}

22
examples/zig_tuples.zon Normal file
View File

@ -0,0 +1,22 @@
.{
// Object with field values
.metadata = .{
.name = "example",
.version = "1.0.0",
},
// Tuples of different types
.numbers = .{ 1, 2, 3 },
.strings = .{ "one", "two", "three" },
.mixed = .{ 1, "two", true, null },
.empty_string = .{""},
// Nested structures
.nested = .{
.tuple_in_object = .{ 4, 5, 6 },
.object_in_tuple = .{ .{ .x = 1, .y = 2 }, .{ .x = 3, .y = 4 } },
},
// Empty tuple
.empty = .{},
}