support zig 0.15.1
This commit is contained in:
parent
fd9be1afbf
commit
b7a9b568d0
3 changed files with 43 additions and 40 deletions
4
.mise.toml
Normal file
4
.mise.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[tools]
|
||||||
|
pre-commit = "latest"
|
||||||
|
"ubi:DonIsaac/zlint" = "latest"
|
||||||
|
zig = "0.15.1"
|
13
build.zig
13
build.zig
|
@ -15,13 +15,13 @@ pub fn build(b: *std.Build) void {
|
||||||
// set a preferred release mode, allowing the user to decide how to optimize.
|
// set a preferred release mode, allowing the user to decide how to optimize.
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
const lib = b.addStaticLibrary(.{
|
const lib = b.addLibrary(.{
|
||||||
.name = "smithy",
|
.name = "smithy",
|
||||||
// In this case the main source file is merely a path, however, in more
|
.root_module = b.addModule("smithy", .{
|
||||||
// complicated build scripts, this could be a generated file.
|
|
||||||
.root_source_file = b.path("src/smithy.zig"),
|
.root_source_file = b.path("src/smithy.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
// This declares intent for the library to be installed into the standard
|
// This declares intent for the library to be installed into the standard
|
||||||
|
@ -29,17 +29,16 @@ pub fn build(b: *std.Build) void {
|
||||||
// running `zig build`).
|
// running `zig build`).
|
||||||
b.installArtifact(lib);
|
b.installArtifact(lib);
|
||||||
|
|
||||||
const module = b.addModule("smithy", .{
|
lib.root_module.addImport("smithy", lib.root_module);
|
||||||
.root_source_file = b.path("src/smithy.zig"),
|
|
||||||
});
|
|
||||||
lib.root_module.addImport("smithy", module);
|
|
||||||
|
|
||||||
// Creates a step for unit testing. This only builds the test executable
|
// Creates a step for unit testing. This only builds the test executable
|
||||||
// but does not run it.
|
// but does not run it.
|
||||||
const main_tests = b.addTest(.{
|
const main_tests = b.addTest(.{
|
||||||
|
.root_module = b.addModule("smithy-test", .{
|
||||||
.root_source_file = b.path("src/smithy.zig"),
|
.root_source_file = b.path("src/smithy.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const run_main_tests = b.addRunArtifact(main_tests);
|
const run_main_tests = b.addRunArtifact(main_tests);
|
||||||
|
|
|
@ -285,11 +285,11 @@ pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
|
||||||
// list must be deinitialized by caller
|
// list must be deinitialized by caller
|
||||||
fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
var list = try std.ArrayList(ShapeInfo).initCapacity(allocator, map.count());
|
var list = try std.ArrayList(ShapeInfo).initCapacity(allocator, map.count());
|
||||||
defer list.deinit();
|
defer list.deinit(allocator);
|
||||||
var iterator = map.iterator();
|
var iterator = map.iterator();
|
||||||
while (iterator.next()) |kv| {
|
while (iterator.next()) |kv| {
|
||||||
const id_info = try parseId(kv.key_ptr.*);
|
const id_info = try parseId(kv.key_ptr.*);
|
||||||
try list.append(.{
|
list.appendAssumeCapacity(.{
|
||||||
.id = id_info.id,
|
.id = id_info.id,
|
||||||
.namespace = id_info.namespace,
|
.namespace = id_info.namespace,
|
||||||
.name = id_info.name,
|
.name = id_info.name,
|
||||||
|
@ -304,7 +304,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
// https://awslabs.github.io/smithy/1.0/spec/core/model.html#simple-types
|
// https://awslabs.github.io/smithy/1.0/spec/core/model.html#simple-types
|
||||||
// But I don't see it in the spec. We might need to preload other similar
|
// But I don't see it in the spec. We might need to preload other similar
|
||||||
// simple types?
|
// simple types?
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#String",
|
.id = "smithy.api#String",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "String",
|
.name = "String",
|
||||||
|
@ -315,7 +315,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Boolean",
|
.id = "smithy.api#Boolean",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Boolean",
|
.name = "Boolean",
|
||||||
|
@ -326,7 +326,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Integer",
|
.id = "smithy.api#Integer",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Integer",
|
.name = "Integer",
|
||||||
|
@ -337,7 +337,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Double",
|
.id = "smithy.api#Double",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Double",
|
.name = "Double",
|
||||||
|
@ -348,7 +348,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Timestamp",
|
.id = "smithy.api#Timestamp",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Timestamp",
|
.name = "Timestamp",
|
||||||
|
@ -359,7 +359,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Blob",
|
.id = "smithy.api#Blob",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Blob",
|
.name = "Blob",
|
||||||
|
@ -370,7 +370,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Unit",
|
.id = "smithy.api#Unit",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Unit",
|
.name = "Unit",
|
||||||
|
@ -381,7 +381,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Long",
|
.id = "smithy.api#Long",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Long",
|
.name = "Long",
|
||||||
|
@ -392,7 +392,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Float",
|
.id = "smithy.api#Float",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Float",
|
.name = "Float",
|
||||||
|
@ -403,7 +403,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#Document",
|
.id = "smithy.api#Document",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "Document",
|
.name = "Document",
|
||||||
|
@ -419,7 +419,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
// byte PrimitiveByte
|
// byte PrimitiveByte
|
||||||
// short PrimitiveShort
|
// short PrimitiveShort
|
||||||
|
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#PrimitiveBoolean",
|
.id = "smithy.api#PrimitiveBoolean",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "PrimitiveBoolean",
|
.name = "PrimitiveBoolean",
|
||||||
|
@ -430,7 +430,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#PrimitiveInteger",
|
.id = "smithy.api#PrimitiveInteger",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "PrimitiveInteger",
|
.name = "PrimitiveInteger",
|
||||||
|
@ -441,7 +441,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#PrimitiveDouble",
|
.id = "smithy.api#PrimitiveDouble",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "PrimitiveDouble",
|
.name = "PrimitiveDouble",
|
||||||
|
@ -452,7 +452,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#PrimitiveLong",
|
.id = "smithy.api#PrimitiveLong",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "PrimitiveLong",
|
.name = "PrimitiveLong",
|
||||||
|
@ -463,7 +463,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
try list.append(.{
|
try list.append(allocator, .{
|
||||||
.id = "smithy.api#PrimitiveFloat",
|
.id = "smithy.api#PrimitiveFloat",
|
||||||
.namespace = "smithy.api",
|
.namespace = "smithy.api",
|
||||||
.name = "PrimitiveFloat",
|
.name = "PrimitiveFloat",
|
||||||
|
@ -474,7 +474,7 @@ fn shapes(allocator: std.mem.Allocator, map: anytype) ![]ShapeInfo {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return list.toOwnedSlice();
|
return list.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseError!Shape {
|
fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseError!Shape {
|
||||||
|
@ -591,26 +591,26 @@ fn parseMembers(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyPars
|
||||||
|
|
||||||
const map = shape.?.object;
|
const map = shape.?.object;
|
||||||
var list = std.ArrayList(TypeMember).initCapacity(allocator, map.count()) catch return SmithyParseError.OutOfMemory;
|
var list = std.ArrayList(TypeMember).initCapacity(allocator, map.count()) catch return SmithyParseError.OutOfMemory;
|
||||||
defer list.deinit();
|
defer list.deinit(allocator);
|
||||||
var iterator = map.iterator();
|
var iterator = map.iterator();
|
||||||
while (iterator.next()) |kv| {
|
while (iterator.next()) |kv| {
|
||||||
try list.append(TypeMember{
|
list.appendAssumeCapacity(TypeMember{
|
||||||
.name = kv.key_ptr.*,
|
.name = kv.key_ptr.*,
|
||||||
.target = kv.value_ptr.*.object.get("target").?.string,
|
.target = kv.value_ptr.*.object.get("target").?.string,
|
||||||
.traits = try parseTraits(allocator, kv.value_ptr.*.object.get("traits")),
|
.traits = try parseTraits(allocator, kv.value_ptr.*.object.get("traits")),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return list.toOwnedSlice();
|
return list.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArrayList of std.Json.Value
|
// ArrayList of std.Json.Value
|
||||||
fn parseTargetList(allocator: std.mem.Allocator, list: anytype) SmithyParseError![][]const u8 {
|
fn parseTargetList(allocator: std.mem.Allocator, list: anytype) SmithyParseError![][]const u8 {
|
||||||
var array_list = std.ArrayList([]const u8).initCapacity(allocator, list.items.len) catch return SmithyParseError.OutOfMemory;
|
var array_list = std.ArrayList([]const u8).initCapacity(allocator, list.items.len) catch return SmithyParseError.OutOfMemory;
|
||||||
defer array_list.deinit();
|
defer array_list.deinit(allocator);
|
||||||
for (list.items) |i| {
|
for (list.items) |i| {
|
||||||
try array_list.append(i.object.get("target").?.string);
|
array_list.appendAssumeCapacity(i.object.get("target").?.string);
|
||||||
}
|
}
|
||||||
return array_list.toOwnedSlice();
|
return array_list.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
fn parseTraitsOnly(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseError!TraitsOnly {
|
fn parseTraitsOnly(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseError!TraitsOnly {
|
||||||
return TraitsOnly{
|
return TraitsOnly{
|
||||||
|
@ -625,13 +625,13 @@ fn parseTraits(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParse
|
||||||
|
|
||||||
const map = shape.?.object;
|
const map = shape.?.object;
|
||||||
var list = std.ArrayList(Trait).initCapacity(allocator, map.count()) catch return SmithyParseError.OutOfMemory;
|
var list = std.ArrayList(Trait).initCapacity(allocator, map.count()) catch return SmithyParseError.OutOfMemory;
|
||||||
defer list.deinit();
|
defer list.deinit(allocator);
|
||||||
var iterator = map.iterator();
|
var iterator = map.iterator();
|
||||||
while (iterator.next()) |kv| {
|
while (iterator.next()) |kv| {
|
||||||
if (try getTrait(kv.key_ptr.*, kv.value_ptr.*)) |t|
|
if (try getTrait(kv.key_ptr.*, kv.value_ptr.*)) |t|
|
||||||
try list.append(t);
|
list.appendAssumeCapacity(t);
|
||||||
}
|
}
|
||||||
return list.toOwnedSlice();
|
return list.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Trait {
|
fn getTrait(trait_type: []const u8, value: std.json.Value) SmithyParseError!?Trait {
|
||||||
|
|
Loading…
Add table
Reference in a new issue