Git Product home page Git Product logo

rnix-parser's Introduction

rnix-parser Crates.io Chat on Matrix

rnix is a parser for the Nix language written in Rust.

This can be used to manipulate the Nix AST and can for example be used for:

  • Interactively render Nix on a GUI
  • Formatting Nix code
  • Rename identifiers

and a lot more!

rnix nowadays uses @matklad's rowan crate to ensure:

  • all span information is preserved, meaning you can use the AST to for example apply highlighting
  • printing out the AST prints out 100% the original code. This is not an over-exaggeration, even completely invalid nix code such as this README can be intact after a parsing session (though the AST will mark errnous nodes)
  • easy ways to walk the tree without resorting to recursion

Demo

Examples can be found in the examples/ directory.

You may also want to see nix-explorer: An example that highlights AST nodes in Nix code. This demonstrates how whitespaces and commands are preserved.

Hacking

Tests can be run with cargo test.

In order to update all .expect-files to the currently expected results, you may run UPDATE_TESTS=1 cargo test.

You can parse Nix expressions from standard input using the from-stdin example. To try that, run the following in your shell:

echo "[hello nix]" | cargo run --quiet --example from-stdin

Release Checklist

  • Ensure that all PRs that were scheduled for the release are merged (or optionally move them to another milestone).

  • Close the milestone for the release (if any).

  • Run cargo test on master (or the branch to release from) with all changes being pulled in.

  • Apply the following patch to nixpkgs-fmt:

    diff --git a/Cargo.toml b/Cargo.toml
    index 0891350..edad471 100644
    --- a/Cargo.toml
    +++ b/Cargo.toml
    @@ -13,6 +13,9 @@ repository = "https://github.com/nix-community/nixpkgs-fmt"
     [workspace]
     members = [ "./wasm" ]
     
    +[patch.crates-io]
    +rnix = { path = "/home/ma27/Projects/rnix-parser" }
    +
     [dependencies]
     rnix = "0.9.0"
     smol_str = "0.1.17"

    and run cargo test.

    While it's planned to add fuzzing to rnix-parser as well, nixpkgs-fmt has a decent test-suite that would've helped to catch regressions in the past.

    Note: API changes are OK (and fixes should be contributed to nixpkgs-fmt), behavioral changes are not unless explicitly discussed before.

  • Update the CHANGELOG.md.

  • Bump the version number in Cargo.toml & re-run cargo build to refresh the lockfile.

  • Commit & run nix build.

  • Tag the release and push everything.

  • As soon as the CI has completed, run cargo publish.

RIP jd91mzm2

Sadly, the original author of this project, @jD91mZM2 has passed away. His online presence was anonymous and what we have left is his code. This is but one of his many repos that he contributed to.

rnix-parser's People

Contributors

jd91mzm2 avatar ma27 avatar matklad avatar oberblastmeister avatar darichey avatar fogti avatar zimbatm avatar oppiliappan avatar dependabot[bot] avatar selaux avatar kamadorueda avatar andir avatar lukateras avatar oxalica avatar aaronjanse avatar flokli avatar jonas-schievink avatar ncfavier avatar nmattia avatar samhug avatar slabity avatar wchresta avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.