NixEl is a Rust library that turns Nix code into a correct, typed data-structured.
It's based on the original lexer and parser of Nix, using the same algorithms and methods, which means guaranteed correctness. Additionally, it's been tested against every file in Nixpkgs, and also continuously on our infrastructure.
It also provides a command line application
called $ nixel
which calls the library
and pretty-prints the results.
For example, given some code:
let
greeting = "Hello World!";
in
greeting
NixEL can generate an Abstract Syntax Tree for you:
LetIn
Or perform Lexical Analysis:
LET "let"
ID "greeting"
= "="
" "\""
STR "Hello World!"
" "\""
; ";"
IN "in"
ID "greeting"
And produce a Parse Tree:
Γ := rules "expr"
expr := rules "expr_function"
expr_function := rules "LET" "binds" "IN" "expr_function"
LET := lexemes "LET"
LET "let"
binds := rules "binds" "attrpath" "=" "expr" ";"
binds := rules
attrpath := rules "attr"
attr := rules "ID"
ID := lexemes "ID"
ID "greeting"
= := lexemes "="
= "="
expr := rules "expr_function"
expr_function := rules "expr_if"
expr_if := rules "expr_op"
expr_op := rules "expr_app"
expr_app := rules "expr_select"
expr_select := rules "expr_simple"
expr_simple := rules "\"" "string_parts" "\""
" := lexemes "\""
" "\""
string_parts := rules "STR"
STR := lexemes "STR"
STR "Hello World!"
" := lexemes "\""
" "\""
; := lexemes ";"
; ";"
IN := lexemes "IN"
IN "in"
expr_function := rules "expr_if"
expr_if := rules "expr_op"
expr_op := rules "expr_app"
expr_app := rules "expr_select"
expr_select := rules "expr_simple"
expr_simple := rules "ID"
ID := lexemes "ID"
ID "greeting"
This library is based on Santiago and can be used to implement tools like Code Formatters, documentation generators, and even alternative evaluators of the Nix expression language.
You can checkout more examples in the tests folder.
We hope you find NixEL useful!
And don’t forget to give us a star ⭐