1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +00:00

with: inline follow on expressions

This commit is contained in:
Tom Bereknyei 2022-02-10 20:16:08 -05:00
parent 0c095ed50d
commit 77db3703b1
6 changed files with 101 additions and 19 deletions

View file

@ -56,6 +56,7 @@ pub fn rule(
next_kind, next_kind,
rnix::SyntaxKind::NODE_ATTR_SET rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN | rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_WITH
| rnix::SyntaxKind::NODE_LET_IN | rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST | rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_STRING | rnix::SyntaxKind::NODE_STRING
@ -87,6 +88,7 @@ pub fn rule(
rnix::SyntaxKind::NODE_ATTR_SET rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN | rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LIST | rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_WITH
| rnix::SyntaxKind::NODE_STRING | rnix::SyntaxKind::NODE_STRING
)) ))
{ {

View file

@ -40,6 +40,19 @@ pub fn rule(
// expr // expr
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
if let rnix::SyntaxKind::TOKEN_COMMENT =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
if let rnix::SyntaxKind::NODE_WITH = child.element.kind() {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
}
}
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::FormatWider(child.element)); steps.push_back(crate::builder::Step::FormatWider(child.element));
@ -54,25 +67,30 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
// /**/ // /**/
let mut comment : bool = false;
children.drain_comments_and_newlines(|element| match element { children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::Comment(text) => { crate::children::DrainCommentOrNewline::Comment(text) => {
steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Comment(text)); steps.push_back(crate::builder::Step::Comment(text));
comment = true;
} }
crate::children::DrainCommentOrNewline::Newline(_) => {} crate::children::DrainCommentOrNewline::Newline(_) => {}
}); });
// expr // expr
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
if comment || matches!(child.element.kind(),rnix::SyntaxKind::NODE_WITH) {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else {
steps.push_back(crate::builder::Step::Whitespace);
}
match layout { match layout {
crate::config::Layout::Tall => { 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::FormatWider(child.element));
} }
crate::config::Layout::Wide => { crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
} }
} }

View file

@ -12,4 +12,7 @@
description = "something"; description = "something";
}; };
} }
{ meta = with lib;
# comment
{ a=1; b=2; c=3; };}
] ]

View file

@ -1,12 +1,10 @@
[ [
{ {
meta = meta = with lib; {
with lib; a = 1;
{ b = 2;
a = 1; c = 3;
b = 2; };
c = 3;
};
} }
{ stdenv { stdenv
, lib , lib
@ -19,11 +17,18 @@
src = fetchFrom { src = fetchFrom {
url = "example/${version}"; url = "example/${version}";
}; };
meta = meta = with lib; {
with lib; maintainers = with maintainers; [ someone ];
{ description = "something";
maintainers = with maintainers; [ someone ]; };
description = "something"; }
}; {
meta = with lib;
# comment
{
a = 1;
b = 2;
c = 3;
};
} }
] ]

View file

@ -6,4 +6,19 @@
( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) ( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( with b; ( with b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ) cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
{ a = with b; 1;}
{ a = with b; 1 + 1;}
{ a = with b; {c=1;};}
{ a = with b; {c=1; d=2; e=3;};}
{ a = with b;
# comment
1;
}
{ a = with b;
1;
# comment
}
(with a; with b; with c; {a=1;})
(with a; with b; with c; {a=1;b=2;})
(with a; /* comment */ with b; with c; {a=1;b=2;})
] ]

View file

@ -12,8 +12,7 @@
/* /*
a a
*/ */
b; b; c
c
) )
( (
with with
@ -27,8 +26,48 @@
c c
) )
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{ a = with b; 1; }
{ a = with b; 1 + 1; }
{ a = with b; { c = 1; }; }
{
a = with b; {
c = 1;
d = 2;
e = 3;
};
}
{
a = with b;
# comment
1;
}
{
a = with b; 1;
# comment
}
( (
with a;
with b; with b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc with c; { a = 1; }
)
(
with a;
with b;
with c; {
a = 1;
b = 2;
}
)
(
with a;
/*
comment
*/
with b;
with c; {
a = 1;
b = 2;
}
) )
] ]