-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de6088b
commit 8ed23bf
Showing
9 changed files
with
161 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pub(crate) mod assert_or_with; | ||
pub(crate) mod if_else; | ||
pub(crate) mod pattern; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
pub(crate) 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::children2::new(build_ctx, node); | ||
|
||
let first = children.next().unwrap(); | ||
let second = children.next().unwrap(); | ||
let third = children.next().unwrap(); | ||
let fourth = children.next().unwrap(); | ||
|
||
let vertical = build_ctx.vertical | ||
|| first.has_inline_comment | ||
|| first.has_trivialities | ||
|| second.has_inline_comment | ||
|| second.has_trivialities | ||
|| third.has_inline_comment | ||
|| third.has_trivialities | ||
|| fourth.has_inline_comment | ||
|| fourth.has_trivialities; | ||
|
||
// first | ||
steps.push_back(crate::builder::Step::Format(first.element)); | ||
|
||
if let Some(text) = first.inline_comment { | ||
steps.push_back(crate::builder::Step::Whitespace); | ||
steps.push_back(crate::builder::Step::Comment(text)); | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
} else if first.has_comments { | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
} else { | ||
steps.push_back(crate::builder::Step::Whitespace); | ||
} | ||
|
||
for trivia in first.trivialities { | ||
match trivia { | ||
crate::children2::Trivia::Comment(text) => { | ||
steps.push_back(crate::builder::Step::Comment(text)); | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
} | ||
crate::children2::Trivia::Newlines(_) => {} | ||
} | ||
} | ||
|
||
// second | ||
if vertical { | ||
steps.push_back(crate::builder::Step::FormatWider(second.element)); | ||
} else { | ||
steps.push_back(crate::builder::Step::Format(second.element)); | ||
} | ||
|
||
// third | ||
steps.push_back(crate::builder::Step::Format(third.element)); | ||
|
||
if let Some(text) = third.inline_comment { | ||
steps.push_back(crate::builder::Step::Whitespace); | ||
steps.push_back(crate::builder::Step::Comment(text)); | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
} | ||
|
||
for trivia in third.trivialities { | ||
match trivia { | ||
crate::children2::Trivia::Comment(text) => { | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
steps.push_back(crate::builder::Step::Comment(text)); | ||
} | ||
crate::children2::Trivia::Newlines(_) => {} | ||
} | ||
} | ||
|
||
// fourth | ||
if vertical { | ||
if matches!( | ||
fourth.element.kind(), | ||
rnix::SyntaxKind::NODE_ASSERT | rnix::SyntaxKind::NODE_WITH | ||
) { | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
steps.push_back(crate::builder::Step::FormatWider(fourth.element)); | ||
} else if third.has_inline_comment | ||
|| third.has_comments | ||
|| !matches!( | ||
fourth.element.kind(), | ||
rnix::SyntaxKind::NODE_ATTR_SET | ||
| rnix::SyntaxKind::NODE_IDENT | ||
| rnix::SyntaxKind::NODE_PAREN | ||
| rnix::SyntaxKind::NODE_LET_IN | ||
| rnix::SyntaxKind::NODE_LIST | ||
| rnix::SyntaxKind::NODE_LITERAL | ||
| rnix::SyntaxKind::NODE_STRING | ||
) | ||
{ | ||
steps.push_back(crate::builder::Step::Indent); | ||
steps.push_back(crate::builder::Step::NewLine); | ||
steps.push_back(crate::builder::Step::Pad); | ||
steps.push_back(crate::builder::Step::FormatWider(fourth.element)); | ||
steps.push_back(crate::builder::Step::Dedent); | ||
} else { | ||
steps.push_back(crate::builder::Step::Whitespace); | ||
steps.push_back(crate::builder::Step::FormatWider(fourth.element)); | ||
} | ||
} else { | ||
steps.push_back(crate::builder::Step::Whitespace); | ||
steps.push_back(crate::builder::Step::Format(fourth.element)); | ||
} | ||
|
||
steps | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.