abccd47cf5
svn path=/nixpkgs/trunk/; revision=6532
82 lines
1.8 KiB
Plaintext
82 lines
1.8 KiB
Plaintext
/* 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
|
|
|
|
list-sep(s): [] -> []
|
|
list-sep(s): [x | xs] -> [[x | before] | <list-sep(s)> [split | after]]
|
|
where
|
|
<split-fetch-keep(s)> xs => (before, split, after)
|
|
list-sep(s): [x | xs] -> [[x | xs]]
|
|
where
|
|
<not(split-fetch-keep(s))> xs
|
|
|
|
|
|
|
|
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("{"), <no-wsp>, appl(p2, <concat> attrs'), ws2, lit("}")])
|
|
where
|
|
<debug> "found it";
|
|
<attach-wsp> [ws1 | attrs] => withWSP;
|
|
<list-sep(starts-section)> withWSP => groups;
|
|
<length; debug> groups;
|
|
<map( \[x | xs] -> [x | <qsort(compare-attrs)> xs]\ )> groups => attrs';
|
|
<debug> "did it"
|
|
|
|
|
|
attach-wsp: [a, b | cs] -> [(a, b) | <attach-wsp> cs]
|
|
attach-wsp: [] -> []
|
|
|
|
|
|
starts-section: x@(appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr) -> x
|
|
where <implode-string; is-substring(!"###")> cs
|
|
|
|
|
|
compare-attrs:
|
|
x@
|
|
( (_, appl(p1@prod(_, _, attrs([term(cons("Bind"))])), [id1 | xs1]))
|
|
, (_, appl(p2@prod(_, _, attrs([term(cons("Bind"))])), [id2 | xs2]))
|
|
)
|
|
-> x
|
|
where
|
|
<string-lt> (id1, id2)
|
|
|
|
|
|
strategies
|
|
|
|
main = io-wrap(
|
|
topdown(try(sort-attrs))
|
|
)
|