@hackage / nix-lang

Parser and printers for the Nix language

Latest0.1.0.0

About

Metadata

  • Last updated , by berberman
  • License BSD-3-Clause
  • Maintained by: berberman <berberman@yandex.com>

  • Lottery factor: 1

Links

Installation

Tested Compilers

  1. 9.10.3

Readme

nix-lang

nix-lang is a parser, exact printer, and formatter for the Nix language built around a Trees that Grow style AST. Inspired by ghc-exactprint, it supports lossless round-tripping for parsed source while preserving comments, formatting, and multiline structure after modifying the syntax tree. It also provides a fresh syntax tree for generated Nix code together with an RFC 166-oriented formatter for canonical output.

nix-lang-qq provides quasiquoter for building fresh Nix expressions in Haskell file and supports embedding Haskell expressions.

formatExpr [nixQQ| { value = 1; } |]
  -- => {
  --      value = 1; 
  --    }
formatExpr [nixQQ| %%(foldl (\acc _ -> mkApp (mkVar "f") acc) (mkVar "x") [1..10 :: Int])]
  -- => f (f (f (f (f (f (f (f (f (f x)))))))))

Known unsupported syntax

Although it now parses the entire nixpkgs, some valid syntax is not supported.

  • Legacy let
let { x = 233; body = x; }
  • Floating number starting with a decimal point
.233
  • Chained has-attribute expressions
a ? b ? c ? d
  • Operator without white spaces
1+-1