Features
-
✔️ Fast
It parses all the files in Nixpkgs in under 25 seconds, single-threaded. [^benchmark-specs]
It's written in Rust and a little bit of C++, Flex and GNU Bison.
-
✔️ Correct
This library is a copy-paste of the original lexer and parser of Nix, with some types adapted for better ergonomy.
No parser can get closer to the original implementation than this.
-
✔️ Reliable
High coverage, battle-tested, and memory-safe[^memory-safe].
-
✔️ Useful
It gives you comments, whitespace, starting and end positions, automatic string un-escaping, multiline string indentation handling, a typed API, and everything you need to parse the Nix language!
Usage
You can check out the documentation at docs.rs/nixel.
This is a full usage example:
let input: String = String from;
let parsed: Parsed = parse;
match &*parsed.expression
Or from the CLI using Rust's Debug trait:
|
)
Or from the CLI using JSON format:
|
{
}
You can check out more examples in the tests folder.
Alternatives
License
Please read LICENSE.md.
Footnotes
[^benchmark-specs]: Running on a machine with:
- CPU: 4 physical, 4 logical, 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
- MHz: from 400 to 4700 MHz
- BogoMips: 5606.40
- Cache L3: 12 MiB
The following command takes around 1 minute:
```bash
$ nix build --system x86_64-linux
$ time find /data/nixpkgs -type f -name '*.nix' \
-exec ./result/bin/nixel --format=none {} \;
real 0m24.293s
user 0m15.066s
sys 0m8.955s
```
[^memory-safe]: Tested under real-life workloads using Valgrind, and by running an infinite loop of parsing cycles over Nixpkgs :).
```bash
$ nix build --system x86_64-linux
$ valgrind ./result/bin/nixel $file
LEAK SUMMARY:
definitely lost: 0 bytes in 0 blocks
indirectly lost: 0 bytes in 0 blocks
possibly lost: 0 bytes in 0 blocks
suppressed: 0 bytes in 0 blocks
```