diff --git a/biscuit-builder/src/check.zig b/biscuit-builder/src/check.zig index b4d395a..963fe1d 100644 --- a/biscuit-builder/src/check.zig +++ b/biscuit-builder/src/check.zig @@ -5,9 +5,14 @@ const Term = @import("term.zig").Term; const Rule = @import("rule.zig").Rule; pub const Check = struct { - kind: datalog.Check.Kind, + kind: Kind, queries: std.ArrayList(Rule), + pub const Kind = enum { + one, + all, + }; + pub fn deinit(_: Check) void { // for (check.queries.items) |query| { // query.deinit(); @@ -23,7 +28,12 @@ pub const Check = struct { try queries.append(try query.toDatalog(allocator, symbols)); } - return .{ .kind = check.kind, .queries = queries }; + const kind: datalog.Check.Kind = switch (check.kind) { + .one => .one, + .all => .all, + }; + + return .{ .kind = kind, .queries = queries }; } pub fn format(check: Check, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { diff --git a/biscuit-parser/build.zig b/biscuit-parser/build.zig index e5e89f2..686f2cb 100644 --- a/biscuit-parser/build.zig +++ b/biscuit-parser/build.zig @@ -16,18 +16,12 @@ pub fn build(b: *std.Build) void { const optimize = b.standardOptimizeOption(.{}); const ziglyph = b.dependency("ziglyph", .{ .optimize = optimize, .target = target }); - const schema = b.dependency("biscuit-schema", .{ .target = target, .optimize = optimize }); - const format = b.dependency("biscuit-format", .{ .target = target, .optimize = optimize }); const builder = b.dependency("biscuit-builder", .{ .target = target, .optimize = optimize }); - const datalog = b.dependency("biscuit-datalog", .{ .target = target, .optimize = optimize }); _ = b.addModule("biscuit-parser", .{ .root_source_file = .{ .path = "src/parser.zig" }, .imports = &.{ - .{ .name = "biscuit-schema", .module = schema.module("biscuit-schema") }, - .{ .name = "biscuit-format", .module = format.module("biscuit-format") }, .{ .name = "biscuit-builder", .module = builder.module("biscuit-builder") }, - .{ .name = "biscuit-datalog", .module = datalog.module("biscuit-datalog") }, .{ .name = "ziglyph", .module = ziglyph.module("ziglyph") }, }, }); @@ -39,10 +33,7 @@ pub fn build(b: *std.Build) void { .target = target, .optimize = optimize, }); - lib_unit_tests.root_module.addImport("biscuit-schema", schema.module("biscuit-schema")); - lib_unit_tests.root_module.addImport("biscuit-format", format.module("biscuit-format")); lib_unit_tests.root_module.addImport("biscuit-builder", builder.module("biscuit-builder")); - lib_unit_tests.root_module.addImport("biscuit-datalog", datalog.module("biscuit-datalog")); lib_unit_tests.root_module.addImport("ziglyph", ziglyph.module("ziglyph")); const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests); diff --git a/biscuit-parser/build.zig.zon b/biscuit-parser/build.zig.zon index 54f2748..eb581fc 100644 --- a/biscuit-parser/build.zig.zon +++ b/biscuit-parser/build.zig.zon @@ -41,7 +41,6 @@ .@"biscuit-schema" = .{ .path = "../biscuit-schema" }, .@"biscuit-format" = .{ .path = "../biscuit-format" }, .@"biscuit-builder" = .{ .path = "../biscuit-builder" }, - .@"biscuit-datalog" = .{ .path = "../biscuit-datalog" }, .ziglyph = .{ .url = "https://codeberg.org/dude_the_builder/ziglyph/archive/947ed39203bf90412e3d16cbcf936518b6f23af0.tar.gz", .hash = "12208b23d1eb6dcb929e85346524db8f8b8aa1401bdf8a97dee1e0cfb55da8d5fb42", diff --git a/biscuit-parser/src/parser.zig b/biscuit-parser/src/parser.zig index 9057c98..e0e23db 100644 --- a/biscuit-parser/src/parser.zig +++ b/biscuit-parser/src/parser.zig @@ -1,6 +1,5 @@ const std = @import("std"); const ziglyph = @import("ziglyph"); -const datalog = @import("biscuit-datalog"); const Term = @import("biscuit-builder").Term; const Fact = @import("biscuit-builder").Fact; const Check = @import("biscuit-builder").Check; @@ -32,12 +31,11 @@ pub const Parser = struct { parser.skipWhiteSpace(); - // Consume left paren try parser.consume("("); - // Parse terms var terms = std.ArrayList(Term).init(parser.allocator); + // Parse terms var it = parser.factTermsIterator(); while (try it.next()) |trm| { try terms.append(trm); @@ -230,7 +228,7 @@ pub const Parser = struct { } pub fn check(parser: *Parser) !Check { - const kind: datalog.Check.Kind = if (parser.startsWithConsuming("check if")) + const kind: Check.Kind = if (parser.startsWithConsuming("check if")) .one else if (parser.startsWithConsuming("check all")) .all