diff --git a/maintainers/scripts/sort-attrs.str b/maintainers/scripts/sort-attrs.str index 4511cec2b5e..3ce118f51f7 100644 --- a/maintainers/scripts/sort-attrs.str +++ b/maintainers/scripts/sort-attrs.str @@ -35,6 +35,12 @@ rules where xs + list-sep-end(s): xs -> [ (before, [split]) | after] + where + xs => (before, split, after) + list-sep-end(s): xs -> [xs] + where + xs sort-attrs: @@ -52,7 +58,13 @@ rules [ws1 | attrs] => withWSP; withWSP => groups; groups; - [x | xs]\ )> groups => attrs'; + [x''' | xs'] + where + x => (x', starts); + [x' | xs] => [x'' | xs']; + <[] <+ \x -> ["\n\n\n" | x]\ > starts => starts'; + (starts', x'') => x''' + \ })> groups => attrs'; "did it" @@ -60,8 +72,47 @@ rules attach-wsp: [] -> [] - starts-section: x@(appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr) -> x - where cs +strategies + + starts-section = + ?x@(appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr); + cs; + !x + + +rules + + remove-section-start: + (appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr) -> + ((appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs'), attr), starts) + where + !cs; + list-sep-end(?10); // separate into lines, keeping the \n + map(implode-string); + partition(where(is-substring(!"###"))) => (starts, rest); + rest => cs' + + + regularise-empty-lines: + (appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr) -> + (appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs''), attr) + where + // separate into lines, keeping the \n + // last whitespace is significant, keep + cs => (init, last); + init => cs'; // remove whitespace-only lines + [ "\n\n", cs', last] => cs''; // add one empty line + "A"; + cs; + cs'' + + + prepend-layout: + (text, (appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs), attr)) -> + (appl(prod([cf(layout())], cf(opt(layout())), no-attrs()), cs''), attr) + where + cs => cs'; + ( text, cs') => cs'' compare-attrs: @@ -77,5 +128,5 @@ rules strategies main = io-wrap( - topdown(try(sort-attrs)) + oncetd(sort-attrs) )