const std = @import("std"); const Allocator = std.mem.Allocator; const hashString = std.hash_map.hashString; const eqlString = std.hash_map.eqlString; const HashMap = std.HashMap; const AutoHashMap = std.AutoHashMap; const ArrayList = std.ArrayList; const PropertyHashMap = AutoHashMap([] const u8, PropertyValue); const NodeList = ArrayList(Node); const Definitions = AutoHashMap([] const u8, Node); pub const Node = struct { id: ?[] const u8, type_name: [] const u8, properties: PropertyHashMap, children: NodeList, }; const PropertyValueTags = enum { string, integer, float, reference, }; pub const PropertyValue = union(PropertyValueTags) { // nil: null, string: [] const u8, // String. integer: u64, // Num (integer). float: f64, // Num (float). reference: [] const u8, // Reference to another property (property binding). }; pub const Root = struct { definitions: Definitions, children: NodeList, }; test "simple test about structures" { const allocator = std.heap.page_allocator; var value = PropertyValue { .integer = 10 }; var properties = PropertyHashMap.init(allocator); defer properties.deinit(); try properties.put("hello", value); std.debug.print("\n", .{}); var it = properties.iterator(); while(it.next()) |kv| { std.debug.print("key: {} => value: {}\n", .{kv.key, properties.get(kv.key)}); } }