Compare commits
No commits in common. "79e77c40eb1451de96f65d68ddbd1737937b573b" and "d6b6331defdfd33f36258caf26b0b82ce794cd28" have entirely different histories.
79e77c40eb
...
d6b6331def
27
.github/workflows/zig-build.yaml
vendored
27
.github/workflows/zig-build.yaml
vendored
|
@ -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 }}
|
|
@ -30,9 +30,9 @@ pub fn build(b: *std.Build) void {
|
|||
b.installArtifact(lib);
|
||||
|
||||
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
|
||||
// but does not run it.
|
||||
|
|
|
@ -7,16 +7,14 @@ pub const Smithy = struct {
|
|||
metadata: ModelMetadata,
|
||||
shapes: []ShapeInfo,
|
||||
allocator: std.mem.Allocator,
|
||||
json_source: std.json.Parsed(std.json.Value),
|
||||
|
||||
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 .{
|
||||
.version = version,
|
||||
.metadata = metadata,
|
||||
.shapes = shapeinfo,
|
||||
.allocator = allocator,
|
||||
.json_source = json_source,
|
||||
};
|
||||
}
|
||||
pub fn deinit(self: Self) void {
|
||||
|
@ -78,7 +76,6 @@ pub const Smithy = struct {
|
|||
}
|
||||
}
|
||||
self.allocator.free(self.shapes);
|
||||
self.json_source.deinit();
|
||||
}
|
||||
};
|
||||
pub const ShapeInfo = struct {
|
||||
|
@ -133,6 +130,8 @@ pub const Trait = union(TraitType) {
|
|||
},
|
||||
aws_protocol: AwsProtocol,
|
||||
ec2_query_name: []const u8,
|
||||
json_name: []const u8,
|
||||
xml_name: []const u8,
|
||||
http: struct {
|
||||
method: []const u8,
|
||||
uri: []const u8,
|
||||
|
@ -142,8 +141,6 @@ pub const Trait = union(TraitType) {
|
|||
http_label: []const u8,
|
||||
http_query: []const u8,
|
||||
http_payload: struct {},
|
||||
json_name: []const u8,
|
||||
xml_name: []const u8,
|
||||
required: struct {},
|
||||
client_optional: void,
|
||||
documentation: []const u8,
|
||||
|
@ -265,10 +262,10 @@ pub const AwsProtocol = enum {
|
|||
};
|
||||
|
||||
pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
|
||||
// construct a parser. We're not copying strings here
|
||||
// Instead, we keep the original json string around
|
||||
// This might be bad if we only need a small fraction of the original json source
|
||||
// construct a parser. We're not copying strings here, but that may
|
||||
// be a poor decision
|
||||
var vt = try std.json.parseFromSlice(std.json.Value, allocator, json_model, .{});
|
||||
defer vt.deinit();
|
||||
return Smithy.init(
|
||||
allocator,
|
||||
vt.value.object.get("smithy").?.string,
|
||||
|
@ -277,7 +274,6 @@ pub fn parse(allocator: std.mem.Allocator, json_model: []const u8) !Smithy {
|
|||
.suppressions = &.{},
|
||||
},
|
||||
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 {
|
||||
const rc: []TypeMember = &.{};
|
||||
var rc: []TypeMember = &.{};
|
||||
if (shape == null)
|
||||
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 {
|
||||
const rc: []Trait = &.{};
|
||||
var rc: []Trait = &.{};
|
||||
if (shape == null)
|
||||
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);
|
||||
}
|
||||
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" {
|
||||
const test_string =
|
||||
|
|
Loading…
Reference in New Issue
Block a user