Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
zig-out/
zig-pkg/
.zig-cache/
.claude/settings.local.json
.DS_store
23 changes: 0 additions & 23 deletions .pre-commit-config.yaml

This file was deleted.

24 changes: 13 additions & 11 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ zig build run # Run the bbcodez executable
```

### Code Quality
The project uses pre-commit hooks with the following linters:
```bash
zlint --deny-warnings --fix # Run zlint for Zig code quality
zig fmt # Format Zig code
```
The project uses [hk](https://hk.jdx.dev/) for git hooks (configured in `hk.pkl`).

Pre-commit hooks (run on `git commit`):
- `trailing_whitespace`, `newlines`, `yamllint`, `check_added_large_files`
- `zig fmt` (fix mode) on `*.zig`
- `zlint --deny-warnings --fix` on `*.zig`

Pre-push hooks (run on `git push`):
- `zig build`
- `zig build test`

Pre-commit hooks automatically run:
- `zig fmt` for formatting
- `zig build` to ensure compilation
- `zig build test` to run tests
- `zlint --deny-warnings --fix` for linting
To install the git hooks after cloning: `hk install`
To run a hook manually: `hk run pre-commit` / `hk run pre-push`

## Architecture

Expand Down Expand Up @@ -92,4 +94,4 @@ Tests are embedded in each module using Zig's built-in testing framework. Run `z
## Dependencies

- Uses `cli` dependency for command-line argument parsing in the executable
- Requires Zig 0.15.1 (specified in `mise.toml`)
- Requires Zig 0.16.0 (specified in `mise.toml`)
10 changes: 3 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ pub fn build(b: *std.Build) void {
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.link_libcpp = true,
});

const lib = b.addLibrary(.{
.linkage = .static,
.name = "bbcodez",
.root_module = lib_mod,
});
lib.linkLibC();
lib.linkLibCpp();

var install = b.addInstallArtifact(lib, .{});

Expand All @@ -34,16 +34,12 @@ pub fn build(b: *std.Build) void {
docs_step.dependOn(&install_docs.step);
install.step.dependOn(docs_step);

const cli_dep = b.dependency("cli", .{});
const cli_mod = cli_dep.module("cli");

const exe_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe_mod.addImport("cli", cli_mod);
exe_mod.addImport("lib", lib_mod);
exe_mod.addImport("bbcodez", lib_mod);

const exe = b.addExecutable(.{
.name = "bbcodez",
Expand Down
9 changes: 2 additions & 7 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
.name = .bbcodez,
.version = "0.0.1-dev",
.fingerprint = 0x9e2aa21706ce5a62, // Changing this has security and trust implications.
.minimum_zig_version = "0.15.1",
.dependencies = .{
.cli = .{
.url = "git+https://github.com/sam701/zig-cli#f9a516ddc9771ddd2c8c46a280a9ab6cab8261f2",
.hash = "cli-0.10.0-2eKe_5kEAQBeHqKxUHNTGnETzu81rqKWwT1WPt1jXBt0",
},
},
.minimum_zig_version = "0.16.0",
.dependencies = .{},
.paths = .{
"build.zig",
"build.zig.zon",
Expand Down
45 changes: 45 additions & 0 deletions hk.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
amends "package://github.com/jdx/hk/releases/download/v1.42.0/hk@1.42.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v1.42.0/hk@1.42.0#/Builtins.pkl"

local linters: Mapping<String, Step> = new {
["trailing_whitespace"] = (Builtins.trailing_whitespace) {
exclude = List("snapshots/**")
}
["newlines"] = (Builtins.newlines) {
exclude = List("snapshots/**")
}
["check_added_large_files"] = Builtins.check_added_large_files
["yamllint"] = (Builtins.yamllint) {
check = "yamllint {{files}}"
}
["zig_fmt"] = new Step {
glob = List("*.zig")
check = "zig fmt --check {{files}}"
fix = "zig fmt {{files}}"
}
["zlint"] = new Step {
glob = List("*.zig")
check = "zlint --deny-warnings {{files}}"
fix = "zlint --deny-warnings --fix {{files}}"
}
}

hooks {
["pre-commit"] {
fix = true
stash = "git"
steps = linters
}
["pre-push"] {
steps {
["zig_build"] {
exclusive = true
check = "zig build"
}
["zig_build_test"] {
exclusive = true
check = "zig build test"
}
}
}
}
175 changes: 175 additions & 0 deletions mise.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# @generated - this file is auto-generated by `mise lock` https://mise.jdx.dev/dev-tools/mise-lock.html

[[tools."github:DonIsaac/zlint"]]
version = "0.7.9"
backend = "github:DonIsaac/zlint"

[tools."github:DonIsaac/zlint"."platforms.linux-arm64"]
checksum = "sha256:fb73191c680ac9303605ba8a05974f06827c980ea593316abc00934c6bd17faf"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-linux-aarch64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295160"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.linux-arm64-musl"]
checksum = "sha256:fb73191c680ac9303605ba8a05974f06827c980ea593316abc00934c6bd17faf"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-linux-aarch64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295160"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.linux-x64"]
checksum = "sha256:388c501bfb8ffe0e4ffb5ac633b71c1b74e4465a0d1cf8cb2f23f99b08299a29"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-linux-x86_64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295161"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.linux-x64-musl"]
checksum = "sha256:388c501bfb8ffe0e4ffb5ac633b71c1b74e4465a0d1cf8cb2f23f99b08299a29"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-linux-x86_64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295161"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.macos-arm64"]
checksum = "sha256:39e49f1fba0ffa636082a317c2970d1c5fa4d5db3dd059569fbc95c808788f1f"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-macos-aarch64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295157"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.macos-x64"]
checksum = "sha256:72b9abead168bd5d70a26de1da193a495f2ef243be80b02e41dfebdafb5345cf"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-macos-x86_64"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295159"
provenance = "github-attestations"

[tools."github:DonIsaac/zlint"."platforms.windows-x64"]
checksum = "sha256:565a1b5847205920a63f300587a4c8bac6191e7ebd268260d60d521c42df3a76"
url = "https://github.com/DonIsaac/zlint/releases/download/v0.7.9/zlint-windows-x86_64.exe"
url_api = "https://api.github.com/repos/DonIsaac/zlint/releases/assets/273295158"
provenance = "github-attestations"

[[tools.hk]]
version = "1.42.0"
backend = "aqua:jdx/hk"

[tools.hk."platforms.linux-arm64"]
checksum = "sha256:291ed6215703fc3aa6a9fcbb96a72b88751c50888a00a6a73140ae0fbc3eef70"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-aarch64-unknown-linux-gnu.tar.gz"

[tools.hk."platforms.linux-arm64-musl"]
checksum = "sha256:291ed6215703fc3aa6a9fcbb96a72b88751c50888a00a6a73140ae0fbc3eef70"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-aarch64-unknown-linux-gnu.tar.gz"

[tools.hk."platforms.linux-x64"]
checksum = "sha256:a4f8898a83c1521c3e184b8af613ddf8d121df21a4026c679b18b54e8b5953db"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-x86_64-unknown-linux-gnu.tar.gz"

[tools.hk."platforms.linux-x64-musl"]
checksum = "sha256:a4f8898a83c1521c3e184b8af613ddf8d121df21a4026c679b18b54e8b5953db"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-x86_64-unknown-linux-gnu.tar.gz"

[tools.hk."platforms.macos-arm64"]
checksum = "sha256:29c4d4aabda87ed8e0a3bcd97cffe288a6932f22ae0a49d77f8a1bb9430afdbe"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-aarch64-apple-darwin.tar.gz"

[tools.hk."platforms.windows-x64"]
checksum = "sha256:9706dab06f3ed468bb1247ce540dad677acea7bc9a023e8cdbdc5f79b2e4015a"
url = "https://github.com/jdx/hk/releases/download/v1.42.0/hk-x86_64-pc-windows-msvc.zip"

[[tools.pkl]]
version = "0.30.0"
backend = "aqua:apple/pkl"

[tools.pkl."platforms.linux-arm64"]
checksum = "sha256:a876085548bba146854d0e96df16df828a8b39d75b57674eb3ad73edd9e52d96"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-aarch64"

[tools.pkl."platforms.linux-arm64-musl"]
checksum = "sha256:a876085548bba146854d0e96df16df828a8b39d75b57674eb3ad73edd9e52d96"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-aarch64"

[tools.pkl."platforms.linux-x64"]
checksum = "sha256:182a50a2c84bb002010ea45c8982c1e63b54e7e6a40e939bb5eb70beaad38cd7"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-amd64"

[tools.pkl."platforms.linux-x64-musl"]
checksum = "sha256:182a50a2c84bb002010ea45c8982c1e63b54e7e6a40e939bb5eb70beaad38cd7"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-linux-amd64"

[tools.pkl."platforms.macos-arm64"]
checksum = "sha256:923a636f2c858029d9bf93f35aeae58ebd9783fbe0209f4787c4eed950142212"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-macos-aarch64"

[tools.pkl."platforms.macos-x64"]
checksum = "sha256:215c5c2b02bf4bfb5f7421d4bd81ce1f8781cc9aba93b09f86156c99553de143"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-macos-amd64"

[tools.pkl."platforms.windows-x64"]
checksum = "sha256:3af84f8f6753ae6cfab50f7127fbfb3b53d374c03079ca0cec27eddffc492b3c"
url = "https://github.com/apple/pkl/releases/download/0.30.0/pkl-windows-amd64.exe"

[[tools.yamllint]]
version = "1.38.0"
backend = "pipx:yamllint"

[[tools.zig]]
version = "0.16.0"
backend = "core:zig"

[tools.zig."platforms.linux-arm64"]
checksum = "sha256:ea4b09bfb22ec6f6c6ceac57ab63efb6b46e17ab08d21f69f3a48b38e1534f17"
url = "https://ziglang.org/download/0.16.0/zig-aarch64-linux-0.16.0.tar.xz"

[tools.zig."platforms.linux-arm64-musl"]
checksum = "sha256:ea4b09bfb22ec6f6c6ceac57ab63efb6b46e17ab08d21f69f3a48b38e1534f17"
url = "https://ziglang.org/download/0.16.0/zig-aarch64-linux-0.16.0.tar.xz"

[tools.zig."platforms.linux-x64"]
checksum = "sha256:70e49664a74374b48b51e6f3fdfbf437f6395d42509050588bd49abe52ba3d00"
url = "https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz"

[tools.zig."platforms.linux-x64-musl"]
checksum = "sha256:70e49664a74374b48b51e6f3fdfbf437f6395d42509050588bd49abe52ba3d00"
url = "https://ziglang.org/download/0.16.0/zig-x86_64-linux-0.16.0.tar.xz"

[tools.zig."platforms.macos-arm64"]
checksum = "sha256:b23d70deaa879b5c2d486ed3316f7eaa53e84acf6fc9cc747de152450d401489"
url = "https://ziglang.org/download/0.16.0/zig-aarch64-macos-0.16.0.tar.xz"

[tools.zig."platforms.macos-x64"]
checksum = "sha256:0387557ed1877bc6a2e1802c8391953baddba76081876301c522f52977b52ba7"
url = "https://ziglang.org/download/0.16.0/zig-x86_64-macos-0.16.0.tar.xz"

[tools.zig."platforms.windows-x64"]
checksum = "sha256:68659eb5f1e4eb1437a722f1dd889c5a322c9954607f5edcf337bc3684a75a7e"
url = "https://ziglang.org/download/0.16.0/zig-x86_64-windows-0.16.0.zip"

[[tools.zls]]
version = "0.16.0"
backend = "aqua:zigtools/zls"

[tools.zls."platforms.linux-arm64"]
url = "https://builds.zigtools.org/zls-aarch64-linux-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.linux-arm64-musl"]
url = "https://builds.zigtools.org/zls-aarch64-linux-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.linux-x64"]
url = "https://builds.zigtools.org/zls-x86_64-linux-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.linux-x64-musl"]
url = "https://builds.zigtools.org/zls-x86_64-linux-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.macos-arm64"]
url = "https://builds.zigtools.org/zls-aarch64-macos-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.macos-x64"]
url = "https://builds.zigtools.org/zls-x86_64-macos-0.16.0.tar.xz"
provenance = "minisign"

[tools.zls."platforms.windows-x64"]
url = "https://builds.zigtools.org/zls-x86_64-windows-0.16.0.zip"
provenance = "minisign"
10 changes: 6 additions & 4 deletions mise.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[tools]
zig = "0.15.1"
zls = "0.15.0"
pre-commit = "latest"
"ubi:DonIsaac/zlint" = "latest"
zig = "0.16.0"
zls = "0.16.0"
hk = "1.42.0"
pkl = "0.30.0"
yamllint = "1.38.0"
"github:DonIsaac/zlint" = "latest"
4 changes: 2 additions & 2 deletions src/Document.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub const Options = struct {
///
/// Args:
/// bbcode: BBCode string to parse
pub fn load(allocator: Allocator, reader: *std.io.Reader, options: Options) !Document {
pub fn load(allocator: Allocator, reader: *std.Io.Reader, options: Options) !Document {
var tokenizer_options: tokenizer.Options = options.tokenizer_options orelse .{};
var parser_options: parser.Options = options.parser_options orelse .{};

Expand Down Expand Up @@ -105,7 +105,7 @@ pub fn load(allocator: Allocator, reader: *std.io.Reader, options: Options) !Doc
/// Returns: A new Document containing the parsed tree structure
/// Errors: OutOfMemory or any parsing errors from `load()`
pub fn loadFromBuffer(allocator: Allocator, bbcode: []const u8, options: Options) !Document {
var fixed_reader = std.io.Reader.fixed(bbcode);
var fixed_reader = std.Io.Reader.fixed(bbcode);
return try load(allocator, &fixed_reader, options);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Node.zig
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn print(self: Node, writer: anytype, depth: usize) !void {
pub const NodePrinter = struct {
const indent_size = 4;

writer: *std.io.Writer,
writer: *std.Io.Writer,
depth: usize = 0,
indent: bool = true,

Expand Down
Loading
Loading