mirror of
https://github.com/RGBCube/alejandra
synced 2025-08-01 04:57:44 +00:00
Merge pull request #35 from tomberek/with_simplify
with: attempt to simplify
This commit is contained in:
commit
c55a4f0a04
6 changed files with 101 additions and 19 deletions
|
@ -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
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,7 @@
|
||||||
description = "something";
|
description = "something";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
{ meta = with lib;
|
||||||
|
# comment
|
||||||
|
{ a=1; b=2; c=3; };}
|
||||||
]
|
]
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -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;})
|
||||||
]
|
]
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue