mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
feat: get inherit
done right
This commit is contained in:
parent
6a5f456d72
commit
56ed74357c
8 changed files with 1180 additions and 118 deletions
|
@ -178,7 +178,7 @@ fn format(
|
|||
rnix::SyntaxKind::NODE_IF_ELSE => crate::rules::if_else::rule,
|
||||
rnix::SyntaxKind::NODE_INHERIT => crate::rules::inherit::rule,
|
||||
rnix::SyntaxKind::NODE_INHERIT_FROM => {
|
||||
crate::rules::inherit_from::rule
|
||||
crate::rules::inherit::rule
|
||||
}
|
||||
rnix::SyntaxKind::NODE_KEY => crate::rules::default,
|
||||
rnix::SyntaxKind::NODE_KEY_VALUE => {
|
||||
|
|
|
@ -10,7 +10,12 @@ pub fn rule(
|
|||
&crate::config::Layout::Tall
|
||||
} else if node
|
||||
.children()
|
||||
.filter(|node| node.kind() == rnix::SyntaxKind::NODE_KEY_VALUE)
|
||||
.filter(|node| match node.kind() {
|
||||
rnix::SyntaxKind::NODE_KEY_VALUE
|
||||
| rnix::SyntaxKind::NODE_INHERIT
|
||||
| rnix::SyntaxKind::NODE_INHERIT_FROM => true,
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
> 1
|
||||
{
|
||||
|
|
|
@ -30,17 +30,8 @@ pub fn rule(
|
|||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
});
|
||||
|
||||
if let Some(child) = children.peek_next() {
|
||||
let kind = child.element.kind();
|
||||
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT
|
||||
| rnix::SyntaxKind::TOKEN_SEMICOLON = kind
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if let Some(child) = children.get_next() {
|
||||
// expr
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
|
@ -50,7 +41,12 @@ pub fn rule(
|
|||
));
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
if let rnix::SyntaxKind::TOKEN_SEMICOLON =
|
||||
child.element.kind()
|
||||
{
|
||||
} else {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
steps
|
||||
.push_back(crate::builder::Step::Format(child.element));
|
||||
}
|
||||
|
@ -60,30 +56,12 @@ pub fn rule(
|
|||
}
|
||||
}
|
||||
|
||||
// /**/
|
||||
children.drain_comments(|text| {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
});
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
// ;
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
}
|
||||
crate::config::Layout::Wide => {}
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
|
||||
steps
|
||||
}
|
||||
|
|
|
@ -1,64 +0,0 @@
|
|||
pub fn rule(
|
||||
build_ctx: &crate::builder::BuildCtx,
|
||||
node: &rnix::SyntaxNode,
|
||||
) -> std::collections::LinkedList<crate::builder::Step> {
|
||||
let mut steps = std::collections::LinkedList::new();
|
||||
|
||||
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()
|
||||
};
|
||||
|
||||
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);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
}
|
||||
|
||||
children.drain_comments(|text| {
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
});
|
||||
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::FormatWider(child.element));
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
}
|
||||
}
|
||||
|
||||
children.drain_comments(|text| {
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
steps.push_back(crate::builder::Step::Comment(text));
|
||||
});
|
||||
|
||||
let child = children.get_next().unwrap();
|
||||
match layout {
|
||||
crate::config::Layout::Tall => {
|
||||
steps.push_back(crate::builder::Step::Dedent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
crate::config::Layout::Wide => {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
}
|
||||
}
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
|
||||
steps
|
||||
}
|
|
@ -5,7 +5,6 @@ pub mod bin_op;
|
|||
pub mod dynamic;
|
||||
pub mod if_else;
|
||||
pub mod inherit;
|
||||
pub mod inherit_from;
|
||||
pub mod key_value;
|
||||
pub mod lambda;
|
||||
pub mod let_in;
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
}
|
||||
{
|
||||
inherit
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
|
||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
;
|
||||
}
|
||||
{ inherit b d; }
|
||||
{
|
||||
|
@ -22,7 +23,8 @@
|
|||
/*
|
||||
c
|
||||
*/
|
||||
d;
|
||||
d
|
||||
;
|
||||
}
|
||||
{
|
||||
inherit
|
||||
|
@ -42,7 +44,8 @@
|
|||
a
|
||||
*/
|
||||
b
|
||||
d;
|
||||
d
|
||||
;
|
||||
}
|
||||
{
|
||||
inherit
|
||||
|
@ -65,7 +68,8 @@
|
|||
/*
|
||||
c
|
||||
*/
|
||||
d;
|
||||
d
|
||||
;
|
||||
}
|
||||
{
|
||||
inherit
|
||||
|
|
|
@ -1,6 +1,66 @@
|
|||
[
|
||||
{ inherit ( b ) d; }
|
||||
{ inherit ( b /*c*/) d; }
|
||||
{ inherit (/*a*/ b ) d; }
|
||||
{ inherit (/*a*/ b /*c*/) d; }
|
||||
{ inherit ( c ) f h ; }
|
||||
{ inherit ( c ) f h /*i*/; }
|
||||
{ inherit ( c ) f /*g*/ h ; }
|
||||
{ inherit ( c ) f /*g*/ h /*i*/; }
|
||||
{ inherit ( c ) /*e*/ f h ; }
|
||||
{ inherit ( c ) /*e*/ f h /*i*/; }
|
||||
{ inherit ( c ) /*e*/ f /*g*/ h ; }
|
||||
{ inherit ( c ) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit ( c /*d*/) f h ; }
|
||||
{ inherit ( c /*d*/) f h /*i*/; }
|
||||
{ inherit ( c /*d*/) f /*g*/ h ; }
|
||||
{ inherit ( c /*d*/) f /*g*/ h /*i*/; }
|
||||
{ inherit ( c /*d*/) /*e*/ f h ; }
|
||||
{ inherit ( c /*d*/) /*e*/ f h /*i*/; }
|
||||
{ inherit ( c /*d*/) /*e*/ f /*g*/ h ; }
|
||||
{ inherit ( c /*d*/) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit (/*b*/ c ) f h ; }
|
||||
{ inherit (/*b*/ c ) f h /*i*/; }
|
||||
{ inherit (/*b*/ c ) f /*g*/ h ; }
|
||||
{ inherit (/*b*/ c ) f /*g*/ h /*i*/; }
|
||||
{ inherit (/*b*/ c ) /*e*/ f h ; }
|
||||
{ inherit (/*b*/ c ) /*e*/ f h /*i*/; }
|
||||
{ inherit (/*b*/ c ) /*e*/ f /*g*/ h ; }
|
||||
{ inherit (/*b*/ c ) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit (/*b*/ c /*d*/) f h ; }
|
||||
{ inherit (/*b*/ c /*d*/) f h /*i*/; }
|
||||
{ inherit (/*b*/ c /*d*/) f /*g*/ h ; }
|
||||
{ inherit (/*b*/ c /*d*/) f /*g*/ h /*i*/; }
|
||||
{ inherit (/*b*/ c /*d*/) /*e*/ f h ; }
|
||||
{ inherit (/*b*/ c /*d*/) /*e*/ f h /*i*/; }
|
||||
{ inherit (/*b*/ c /*d*/) /*e*/ f /*g*/ h ; }
|
||||
{ inherit (/*b*/ c /*d*/) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ ( c ) f h ; }
|
||||
{ inherit /*a*/ ( c ) f h /*i*/; }
|
||||
{ inherit /*a*/ ( c ) f /*g*/ h ; }
|
||||
{ inherit /*a*/ ( c ) f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ ( c ) /*e*/ f h ; }
|
||||
{ inherit /*a*/ ( c ) /*e*/ f h /*i*/; }
|
||||
{ inherit /*a*/ ( c ) /*e*/ f /*g*/ h ; }
|
||||
{ inherit /*a*/ ( c ) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ ( c /*d*/) f h ; }
|
||||
{ inherit /*a*/ ( c /*d*/) f h /*i*/; }
|
||||
{ inherit /*a*/ ( c /*d*/) f /*g*/ h ; }
|
||||
{ inherit /*a*/ ( c /*d*/) f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ ( c /*d*/) /*e*/ f h ; }
|
||||
{ inherit /*a*/ ( c /*d*/) /*e*/ f h /*i*/; }
|
||||
{ inherit /*a*/ ( c /*d*/) /*e*/ f /*g*/ h ; }
|
||||
{ inherit /*a*/ ( c /*d*/) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c ) f h ; }
|
||||
{ inherit /*a*/ (/*b*/ c ) f h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c ) f /*g*/ h ; }
|
||||
{ inherit /*a*/ (/*b*/ c ) f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c ) /*e*/ f h ; }
|
||||
{ inherit /*a*/ (/*b*/ c ) /*e*/ f h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c ) /*e*/ f /*g*/ h ; }
|
||||
{ inherit /*a*/ (/*b*/ c ) /*e*/ f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) f h ; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) f h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) f /*g*/ h ; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) f /*g*/ h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) /*e*/ f h ; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) /*e*/ f h /*i*/; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) /*e*/ f /*g*/ h ; }
|
||||
{ inherit /*a*/ (/*b*/ c /*d*/) /*e*/ f /*g*/ h /*i*/; }
|
||||
]
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue