From 811910342a1a58ee36a89a8facf534efb9cdb1f1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 Sep 2006 14:33:32 +0000 Subject: * Program to sort all-packages.nix, first attempt. svn path=/nixpkgs/trunk/; revision=6492 --- maintainers/scripts/sort-attrs.str | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 maintainers/scripts/sort-attrs.str (limited to 'maintainers') diff --git a/maintainers/scripts/sort-attrs.str b/maintainers/scripts/sort-attrs.str new file mode 100644 index 000000000000..611521b0b4a4 --- /dev/null +++ b/maintainers/scripts/sort-attrs.str @@ -0,0 +1,68 @@ +/* Tool to sort attribute sets. Primarily useful for keeping + all-packages.nix tidy. + + To compile: + + $ strc -i ../../maintainers/scripts/sort-attrs.str -la stratego-lib + + Typical invocation: + + $ sglr -m -p ~/Dev/nix/src/libexpr/nix.tbl -i all-packages.nix \ + | implode-asfix --lex \ + | ../../maintainers/scripts/sort-attrs \ + | asfix-yield +*/ + +module sort-attrs + +imports + libstratego-lib + libstratego-sglr + + +strategies + + no-wsp = !appl(prod([], cf(opt(layout())), no-attrs()), []) + + +rules + + sort-attrs: + appl(p@prod(_, _, attrs([term(cons("Attrs"))])), + [ lit("{") + , ws1 + , appl(p2@list(cf(iter-star(sort("Bind")))), attrs) + , ws2 + , lit("}") + ] + ) -> + appl(p, [lit("{"), , appl(p2, attrs'), ws2, lit("}")]) + where + "found it"; + [ws1 | attrs] => groups; + groups => attrs'; + "did it" + + + group: [a, b | cs] -> [(a, b) | cs] + group: [] -> [] + + + compare-attrs: + x@ + ( (_, appl(p1@prod(_, _, attrs([term(cons("Bind"))])), [id1 | xs1])) + , (_, appl(p2@prod(_, _, attrs([term(cons("Bind"))])), [id2 | xs2])) + ) + -> x + where + "foo"; + id1; + id2; + (id1, id2) + + +strategies + + main = io-wrap( + topdown(try(sort-attrs)) + ) -- cgit 1.4.1