mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
feat: expand all if/then/else
This commit is contained in:
parent
4a45bf1de4
commit
dee5de12d6
2 changed files with 232 additions and 62 deletions
|
@ -6,24 +6,11 @@ pub fn rule(
|
||||||
|
|
||||||
let mut children = crate::children::Children::new(build_ctx, node);
|
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"] {
|
for branch in ["if", "then", "else"] {
|
||||||
// if/then/else
|
// if/then/else
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
steps.push_back(crate::builder::Step::Format(child.element));
|
steps.push_back(crate::builder::Step::Format(child.element));
|
||||||
match layout {
|
steps.push_back(crate::builder::Step::Indent);
|
||||||
crate::config::Layout::Tall => {
|
|
||||||
steps.push_back(crate::builder::Step::Indent);
|
|
||||||
}
|
|
||||||
crate::config::Layout::Wide => {
|
|
||||||
steps.push_back(crate::builder::Step::Whitespace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments(|text| {
|
children.drain_comments(|text| {
|
||||||
|
@ -34,28 +21,15 @@ pub fn rule(
|
||||||
|
|
||||||
// expr
|
// expr
|
||||||
let child = children.get_next().unwrap();
|
let child = children.get_next().unwrap();
|
||||||
match layout {
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
crate::config::Layout::Tall => {
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
steps.push_back(crate::builder::Step::NewLine);
|
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||||
steps.push_back(crate::builder::Step::Pad);
|
steps.push_back(crate::builder::Step::Dedent);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if branch != "else" {
|
if branch != "else" {
|
||||||
|
steps.push_back(crate::builder::Step::NewLine);
|
||||||
|
steps.push_back(crate::builder::Step::Pad);
|
||||||
|
|
||||||
// /**/
|
// /**/
|
||||||
children.drain_comments(|text| {
|
children.drain_comments(|text| {
|
||||||
steps.push_back(crate::builder::Step::Comment(text));
|
steps.push_back(crate::builder::Step::Comment(text));
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
[
|
[
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
/**/
|
/**/
|
||||||
|
@ -19,29 +26,92 @@
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
|
@ -49,29 +119,92 @@
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
|
@ -79,29 +212,92 @@
|
||||||
if
|
if
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
if
|
if
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
then
|
then
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
else
|
else
|
||||||
(if a then b else c)
|
(
|
||||||
|
if
|
||||||
|
a
|
||||||
|
then
|
||||||
|
b
|
||||||
|
else
|
||||||
|
c
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue