zigsyn
zigsyn is a pure Rust scanner and parser for Zig source code. It parses Zig
syntax into a structured AST while preserving token-level information for
lossless inspection.
The parser is driven by the bundled spec/grammar.peg
snapshot from ziglang/zig-spec.
API documentation is available on docs.rs.
Features
- Pure Rust scanner and parser for Zig syntax.
- Public helpers for parsing source strings, individual files, and directories.
- Structured AST types exposed through
zigsyn::ast. - Structured syntax errors instead of unparsed token buckets.
- Optional
serdesupport for AST and token data. - Grammar snapshot and deviation notes kept under
spec/.
Installation
Add zigsyn to your Cargo.toml:
[]
= "0.1"
To enable serialization support:
[]
= { = "0.1", = ["serde"] }
If you are using this repository directly:
[]
= { = "../zigsyn" }
Usage
Parse a source string:
Parse a file:
For lower-level control, construct a parser directly:
let mut parser = from;
let expression = parser.expression.expect;
API Overview
zigsyn::parse_source(source)parses a string intoast::File.zigsyn::parse_file(path)parses a.zigfile intoast::File.zigsyn::parse_dir(path)parses direct.zigchildren of a directory.zigsyn::Parserexposes lower-level parsing entry points.zigsyn::scanner::Scannerexposes tokenization.
Project Layout
src/ast.rs: AST definitions.src/scanner.rs: Zig tokenizer.src/parser.rs: parser implementation.src/token.rs: token and operator definitions.spec/: grammar snapshot and deviation notes.tests/: integration and fixture-based tests.benches/: Criterion benchmarks.fuzz/: cargo-fuzz target.CHANGELOG.md: release notes.
Development
Run the standard checks:
Run benchmarks:
Run the fuzz target with cargo-fuzz:
Specification
The active grammar snapshot is documented in spec/README.md.
Accepted grammar deviations and implementation decisions are tracked in
spec/DEVIATIONS.md.
License
Licensed under the MIT License.