Compare commits

..

No commits in common. "79e77c40eb1451de96f65d68ddbd1737937b573b" and "d6b6331defdfd33f36258caf26b0b82ce794cd28" have entirely different histories.

3 changed files with 11 additions and 42 deletions

View File

@ -1,27 +0,0 @@
name: Generic zig build
on:
workflow_dispatch:
push:
branches:
- '*'
- '!zig-develop*'
jobs:
build:
steps:
- uses: actions/checkout@v4
- uses: elerch/setup-zig@v3
with:
version: 0.12.0
- uses: Hanaasagi/zig-action-cache@v1.1.5
- name: Build project
run: zig build
- name: Run tests
run: zig build test --summary all
- name: Notify
uses: elerch/action-notify-ntfy@v2
if: ${{ github.env.GITEA_ACTIONS == 'true' }}
with:
host: ${{ secrets.NTFY_HOST }}
topic: ${{ secrets.NTFY_TOPIC }}
user: ${{ secrets.NTFY_USER }}
password: ${{ secrets.NTFY_PASSWORD }}

View File

@ -30,9 +30,9 @@ pub fn build(b: *std.Build) void {
b.installArtifact(lib); b.installArtifact(lib);
const module = b.addModule("smithy", .{ const module = b.addModule("smithy", .{
.root_source_file = .{ .path = "src/smithy.zig" }, .source_file = .{ .path = "src/smithy.zig" },
}); });
lib.root_module.addImport("smithy", module); lib.addModule("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.

View File

@ -7,16 +7,14 @@ pub const Smithy = struct {
metadata: ModelMetadata, metadata: ModelMetadata,
shapes: []ShapeInfo, shapes: []ShapeInfo,
allocator: std.mem.Allocator, allocator: std.mem.Allocator,
json_source: std.json.Parsed(std.json.Value),
const Self = @This(); const Self = @This();
pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo, json_source: std.json.Parsed(std.json.Value)) Smithy { pub fn init(allocator: std.mem.Allocator, version: []const u8, metadata: ModelMetadata, shapeinfo: []ShapeInfo) Smithy {
return .{ return .{
.version = version, .version = version,
.metadata = metadata, .metadata = metadata,
.shapes = shapeinfo, .shapes = shapeinfo,
.allocator = allocator, .allocator = allocator,
.json_source = json_source,
}; };
} }
pub fn deinit(self: Self) void { pub fn deinit(self: Self) void {
@ -78,7 +76,6 @@ pub const Smithy = struct {
} }
} }
self.allocator.free(self.shapes); self.allocator.free(self.shapes);
self.json_source.deinit();
} }
}; };
pub const ShapeInfo = struct { pub const ShapeInfo = struct {
@ -133,6 +130,8 @@ pub const Trait = union(TraitType) {
}, },
aws_protocol: AwsProtocol, aws_protocol: AwsProtocol,
ec2_query_name: []const u8, ec2_query_name: []const u8,
json_name: []const u8,
xml_name: []const u8,
http: struct { http: struct {
method: []const u8, method: []const u8,
uri: []const u8, uri: []const u8,
@ -142,8 +141,6 @@ pub const Trait = union(TraitType) {
http_label: []const u8, http_label: []const u8,
http_query: []const u8, http_query: []const u8,
http_payload: struct {}, http_payload: struct {},
json_name: []const u8,
xml_name: []const u8,
required: struct {}, required: struct {},
client_optional: void, client_optional: void,
documentation: []const u8, documentation: []const u8,
@ -265,10 +262,10 @@ pub const AwsProtocol = enum {
}; };
pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy { pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
// construct a parser. We're not copying strings here // construct a parser. We're not copying strings here, but that may
// Instead, we keep the original json string around // be a poor decision
// This might be bad if we only need a small fraction of the original json source
var vt = try std.json.parseFromSlice(std.json.Value, allocator, json_model, .{}); var vt = try std.json.parseFromSlice(std.json.Value, allocator, json_model, .{});
defer vt.deinit();
return Smithy.init( return Smithy.init(
allocator, allocator,
vt.value.object.get("smithy").?.string, vt.value.object.get("smithy").?.string,
@ -277,7 +274,6 @@ pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
.suppressions = &.{}, .suppressions = &.{},
}, },
try shapes(allocator, vt.value.object.get("shapes").?.object), try shapes(allocator, vt.value.object.get("shapes").?.object),
vt,
); );
} }
@ -585,7 +581,7 @@ fn getShape(allocator: std.mem.Allocator, shape: std.json.Value) SmithyParseErro
} }
fn parseMembers(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]TypeMember { fn parseMembers(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]TypeMember {
const rc: []TypeMember = &.{}; var rc: []TypeMember = &.{};
if (shape == null) if (shape == null)
return rc; return rc;
@ -619,7 +615,7 @@ fn parseTraitsOnly(allocator: std.mem.Allocator, shape: std.json.Value) SmithyPa
} }
fn parseTraits(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]Trait { fn parseTraits(allocator: std.mem.Allocator, shape: ?std.json.Value) SmithyParseError![]Trait {
const rc: []Trait = &.{}; var rc: []Trait = &.{};
if (shape == null) if (shape == null)
return rc; return rc;
@ -891,7 +887,7 @@ fn read_file_to_string(allocator: std.mem.Allocator, file_name: []const u8, max_
return file.readToEndAlloc(allocator, max_bytes); return file.readToEndAlloc(allocator, max_bytes);
} }
const test_data: []const u8 = @embedFile("test.json"); const test_data: []const u8 = @embedFile("test.json");
const intrinsic_type_count: usize = 15; // 15 intrinsic types are added to every model (see shapes() function) const intrinsic_type_count: usize = 5; // 5 intrinsic types are added to every model
test "parse string" { test "parse string" {
const test_string = const test_string =