1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-07-31 12:37:45 +00:00

feat: expand all if/then/else

This commit is contained in:
Kevin Amado 2022-01-30 22:38:14 -05:00
parent 4a45bf1de4
commit dee5de12d6
No known key found for this signature in database
GPG key ID: FFF341057F503148
2 changed files with 232 additions and 62 deletions

View file

@ -6,24 +6,11 @@ pub fn rule(
let mut children = crate::children::Children::new(build_ctx, node);
let layout = if children.has_comments() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
for branch in ["if", "then", "else"] {
// if/then/else
let child = children.get_next().unwrap();
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent);
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
}
}
steps.push_back(crate::builder::Step::Indent);
// /**/
children.drain_comments(|text| {
@ -34,28 +21,15 @@ pub fn rule(
// expr
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
steps.push_back(crate::builder::Step::Dedent);
if branch != "else" {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Format(child.element));
if branch != "else" {
steps.push_back(crate::builder::Step::Whitespace);
}
}
}
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::FormatWider(child.element));
steps.push_back(crate::builder::Step::Dedent);
if branch != "else" {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
// /**/
children.drain_comments(|text| {
steps.push_back(crate::builder::Step::Comment(text));

View file

@ -1,5 +1,12 @@
[
(if a then b else c)
(
if
a
then
b
else
c
)
(
if
/**/
@ -19,29 +26,92 @@
if
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
then
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
else
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
)
then
@ -49,29 +119,92 @@
if
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
then
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
else
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
)
else
@ -79,29 +212,92 @@
if
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
then
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
else
(
if
(if a then b else c)
(
if
a
then
b
else
c
)
then
(if a then b else c)
(
if
a
then
b
else
c
)
else
(if a then b else c)
(
if
a
then
b
else
c
)
)
)
)