Skip to content

Commit

Permalink
More clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
malcolmstill committed Mar 30, 2024
1 parent 694cc4b commit d2cb81c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
14 changes: 12 additions & 2 deletions biscuit-builder/src/check.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 {
Expand Down
9 changes: 0 additions & 9 deletions biscuit-parser/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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") },
},
});
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion biscuit-parser/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions biscuit-parser/src/parser.zig
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d2cb81c

Please sign in to comment.