From 1fb3ed0496eff4a29c12b7b016e84360f3413279 Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Fri, 25 Apr 2025 18:35:54 +0200 Subject: [PATCH] add: README, LICENSE and initial project structure --- .gitignore | 2 ++ LICENSE | 9 +++++++++ README.md | 27 +++++++++++++++++++++++++++ build.zig | 23 +++++++++++++++++++++++ build.zig.zon | 13 +++++++++++++ src/ast.zig | 0 src/lexer.zig | 0 src/parser.zig | 1 + src/root.zig | 6 ++++++ 9 files changed, 81 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 build.zig create mode 100644 build.zig.zon create mode 100644 src/ast.zig create mode 100644 src/lexer.zig create mode 100644 src/parser.zig create mode 100644 src/root.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dca1103 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +zig-out/ +.zig-cache/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..76b9653 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2024 Yves Biener + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..40c3d3b --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# nf file format - parser + +This is a zig library implementing a parser for `nf` files. + +> [!CAUTION] +> Only builds using the zig master version are tested to work. + +## Usage + +To add or update this library as a dependency in your project run the following command: + +```sh +zig fetch --save git+https://gitea.yves-biener.de/yves-biener/nf/parser +``` + +Add the dependency to your module as follows in your *build.zig*: + +```zig +const parser: *Dependency = b.dependency("parser", .{ + .target = target, + .optimize = optimize, +}); +// ... +exe.root_module.addImport("parser", zterm.module("parser")); +``` + +Or link against the statically linked library of the parser implementation. To allow updates to the parser without requiring a re-build of the using application and/or library. diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..b707ab1 --- /dev/null +++ b/build.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const lib_mod = b.createModule(.{ + .root_source_file = b.path("src/root.zig"), + .target = target, + .optimize = optimize, + }); + + const lib = b.addLibrary(.{ + .linkage = .static, + .name = "parser", + .root_module = lib_mod, + }); + b.installArtifact(lib); + + const run_lib_unit_tests = b.addRunArtifact(b.addTest(.{ .root_module = lib_mod })); + const test_step = b.step("test", "Run unit tests"); + test_step.dependOn(&run_lib_unit_tests.step); +} diff --git a/build.zig.zon b/build.zig.zon new file mode 100644 index 0000000..67638bd --- /dev/null +++ b/build.zig.zon @@ -0,0 +1,13 @@ +.{ + .name = .parser, + .version = "0.0.0", + .fingerprint = 0x2fb2c373289a7f2b, // Changing this has security and trust implications. + .minimum_zig_version = "0.15.0-dev.56+d0911786c", + .dependencies = .{}, + .paths = .{ + "build.zig", + "build.zig.zon", + "src", + "LICENSE", + }, +} diff --git a/src/ast.zig b/src/ast.zig new file mode 100644 index 0000000..e69de29 diff --git a/src/lexer.zig b/src/lexer.zig new file mode 100644 index 0000000..e69de29 diff --git a/src/parser.zig b/src/parser.zig new file mode 100644 index 0000000..a65a6dc --- /dev/null +++ b/src/parser.zig @@ -0,0 +1 @@ +pub const lexer = @import("lexer.zig"); diff --git a/src/root.zig b/src/root.zig new file mode 100644 index 0000000..325b051 --- /dev/null +++ b/src/root.zig @@ -0,0 +1,6 @@ +///! Parser for nf file contents. This library provides a lexer and parser and +///! emits an AST of valid nf file contents. In case of invalid files, +///! corresponding errors are returned. For detailed error messages refer to +///! `errorMessage()` +pub const ast = @import("ast.zig"); +pub const parser = @import("parser.zig");