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

Merge pull request #52 from kamadorueda/kamadorueda

feat: apply without max-width
This commit is contained in:
Kevin Amado 2022-02-09 22:28:02 -05:00 committed by GitHub
commit 1cc586b32d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
38 changed files with 714 additions and 446 deletions

View file

@ -4,17 +4,23 @@
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
fenix.inputs.rust-analyzer-src.follows = "rustAnalyzer";
flakeCompat.url = github:edolstra/flake-compat;
flakeCompat.flake = false;
flakeUtils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
rustAnalyzer.url = "github:rust-analyzer/rust-analyzer";
rustAnalyzer.flake = false;
treefmt.url = "github:numtide/treefmt";
treefmt.inputs.flake-utils.follows = "flakeUtils";
treefmt.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs: inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
outputs = inputs:
inputs.flakeUtils.lib.eachSystem [ "x86_64-darwin" "x86_64-linux" ] (
system: let
nixpkgs = import inputs.nixpkgs { inherit system; };
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
@ -33,7 +39,8 @@
version =
let
commit = inputs.self.shortRev or "dirty";
date = inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
date =
inputs.self.lastModifiedDate or inputs.self.lastModified or "19700101";
in
"${builtins.substring 0 8 date}_${commit}";
src = inputs.self.sourceInfo;

View file

@ -296,6 +296,7 @@ pub fn fits_in_single_line(
build_ctx: &crate::builder::BuildCtx,
node: rnix::SyntaxElement,
) -> bool {
let line = build_ctx.pos_new.line;
let maybe_green_node = build(
&build_ctx.config.with_layout(crate::config::Layout::Wide),
node,
@ -304,10 +305,7 @@ pub fn fits_in_single_line(
);
match maybe_green_node {
Some(finished) => {
build_ctx.pos_new.column + finished.to_string().chars().count()
<= build_ctx.config.max_width()
}
Some(_) => build_ctx.pos_new.line == line,
None => false,
}
}

View file

@ -133,31 +133,6 @@ impl Children {
})
}
pub fn drain_newlines<F: FnMut(usize)>(&mut self, mut callback: F) {
let mut newlines = 0;
while let Some(child) = self.peek_next() {
match child.element.kind() {
rnix::SyntaxKind::TOKEN_WHITESPACE => {
newlines += child
.element
.into_token()
.unwrap()
.text()
.chars()
.filter(|c| *c == '\n')
.count();
self.move_next();
}
_ => {
break;
}
}
}
callback(newlines)
}
pub fn drain_comment<F: FnMut(String)>(&mut self, mut callback: F) {
if let Some(child) = self.peek_next() {
match child.element.kind() {

View file

@ -8,14 +8,6 @@ pub fn parse(args: Vec<String>) -> clap::ArgMatches {
.short('d')
.takes_value(false),
)
.arg(
clap::Arg::new("max-width")
.default_value("80")
.help("How many characters per line to allow.")
.long("max-width")
.takes_value(true)
.value_name("CHARS"),
)
.arg(
clap::Arg::new("paths")
.help("Files or directories, or none to format stdin.")

View file

@ -8,12 +8,11 @@ pub enum Layout {
pub struct Config {
debug: bool,
layout: Layout,
max_width: usize,
}
impl Config {
pub fn new() -> Config {
Config { debug: false, layout: Layout::Tall, max_width: 80 }
Config { debug: false, layout: Layout::Tall }
}
pub fn debug(&self) -> bool {
@ -24,19 +23,11 @@ impl Config {
&self.layout
}
pub fn max_width(&self) -> usize {
self.max_width
}
pub fn with_debug(&self, debug: bool) -> Config {
Config { debug, layout: self.layout.clone(), max_width: self.max_width }
Config { debug, layout: self.layout.clone() }
}
pub fn with_layout(&self, layout: Layout) -> Config {
Config { debug: self.debug, layout, max_width: self.max_width }
}
pub fn with_max_width(&self, max_width: usize) -> Config {
Config { debug: self.debug, layout: self.layout.clone(), max_width }
Config { debug: self.debug, layout }
}
}

View file

@ -5,12 +5,7 @@ fn main() -> std::io::Result<()> {
let matches = alejandra::cli::parse(std::env::args().collect());
let debug: bool = matches.is_present("debug");
let max_width: usize =
matches.value_of("max-width").unwrap().parse().unwrap();
let config = alejandra::config::Config::new()
.with_debug(debug)
.with_max_width(max_width);
let config = alejandra::config::Config::new().with_debug(debug);
match matches.values_of("paths") {
Some(paths) => {

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -24,10 +26,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
let child_prev = children.peek_prev().unwrap();
@ -36,7 +41,9 @@ pub fn rule(
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if let rnix::SyntaxKind::TOKEN_COMMENT = child_prev.element.kind() {
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE = child_prev.element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::NODE_ATTR_SET

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -17,13 +19,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -48,10 +54,13 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -36,10 +38,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// operator
@ -53,13 +58,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -25,10 +27,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr
@ -43,10 +48,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// }

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -24,10 +26,13 @@ pub fn rule(
loop {
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let Some(child) = children.get_next() {

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -25,7 +27,8 @@ pub fn rule(
}
}
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_next().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -33,28 +36,27 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// :
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| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// c
@ -62,18 +64,56 @@ pub fn rule(
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
if is_pattern_type {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
} else if let rnix::SyntaxKind::TOKEN_COMMENT =
child_prev.element.kind()
if is_pattern_type
|| matches!(
child_prev.element.kind(),
rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE
)
|| (matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_LAMBDA
) && matches!(
child
.element
.clone()
.into_node()
.unwrap()
.children()
.next()
.unwrap()
.kind(),
rnix::SyntaxKind::NODE_PATTERN
))
|| !matches!(
child.element.kind(),
rnix::SyntaxKind::NODE_ATTR_SET
| rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_LAMBDA
| rnix::SyntaxKind::NODE_LET_IN
| rnix::SyntaxKind::NODE_LIST
| rnix::SyntaxKind::NODE_LITERAL
| rnix::SyntaxKind::NODE_STRING
)
{
if build_ctx.pos_new.column > 1 {
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(
child.element,
));
if build_ctx.pos_new.column > 1 {
steps.push_back(crate::builder::Step::Dedent);
}
} else {
steps.push_back(crate::builder::Step::Whitespace);
steps.push_back(crate::builder::Step::FormatWider(
child.element,
));
}
steps.push_back(crate::builder::Step::FormatWider(child.element));
}
crate::config::Layout::Wide => {
steps.push_back(crate::builder::Step::Whitespace);

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -35,13 +37,17 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -55,13 +61,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -23,10 +25,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr
@ -43,10 +48,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// )

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -23,13 +25,17 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -26,13 +28,17 @@ pub fn rule(
if children.has_next() {
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -46,13 +52,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);

View file

@ -4,7 +4,9 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let has_comments = children.has_comments();
let has_comments_between_curly_b = node
@ -26,7 +28,7 @@ pub fn rule(
})
.count();
let layout = if has_comments {
let layout = if has_comments || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -55,10 +57,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// {
@ -79,6 +84,7 @@ pub fn rule(
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_ELLIPSIS
| rnix::SyntaxKind::TOKEN_WHITESPACE
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
{
steps.push_back(crate::builder::Step::Indent);
@ -94,6 +100,7 @@ pub fn rule(
| rnix::SyntaxKind::TOKEN_CURLY_B_OPEN
| rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_ELLIPSIS
| rnix::SyntaxKind::TOKEN_WHITESPACE
| rnix::SyntaxKind::NODE_PAT_ENTRY = prev_kind
{
steps.push_back(crate::builder::Step::Dedent);
@ -110,7 +117,9 @@ pub fn rule(
steps.push_back(crate::builder::Step::Whitespace);
}
if let rnix::SyntaxKind::TOKEN_COMMENT = prev_kind {
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE = prev_kind
{
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
steps.push_back(crate::builder::Step::Whitespace);
@ -143,6 +152,10 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
children.move_next();
}
// \n
rnix::SyntaxKind::TOKEN_WHITESPACE => {
children.move_next();
}
_ => {
break;
}
@ -160,10 +173,13 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// @ x

View file

@ -4,18 +4,24 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
};
while children.has_next() {
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let Some(child) = children.get_next() {

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -35,10 +37,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// .
@ -46,13 +51,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -25,10 +27,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr
@ -43,10 +48,13 @@ pub fn rule(
}
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// }

View file

@ -4,9 +4,11 @@ pub fn rule(
) -> std::collections::LinkedList<crate::builder::Step> {
let mut steps = std::collections::LinkedList::new();
let mut children = crate::children::Children::new(build_ctx, node);
let mut children = crate::children::Children::new_with_configuration(
build_ctx, node, true,
);
let layout = if children.has_comments() {
let layout = if children.has_comments() || children.has_newlines() {
&crate::config::Layout::Tall
} else {
build_ctx.config.layout()
@ -17,13 +19,17 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
if let rnix::SyntaxKind::TOKEN_COMMENT =
if let rnix::SyntaxKind::TOKEN_COMMENT
| rnix::SyntaxKind::TOKEN_WHITESPACE =
children.peek_prev().unwrap().element.kind()
{
steps.push_back(crate::builder::Step::NewLine);
@ -48,10 +54,13 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
// /**/
children.drain_comments(|text| {
children.drain_comments_and_newlines(|element| match element {
crate::children::DrainCommentOrNewline::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::children::DrainCommentOrNewline::Newline(_) => {}
});
// expr

View file

@ -1,10 +1,13 @@
(a b) (a b) (
(a b)
(a b)
(
a
/*
b
*/
c
) (
)
(
/*
a
*/

View file

@ -4,5 +4,6 @@
(assert /*a*/ b; c)
(assert /*a*/ b; /*b*/ c)
( assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( assert b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
]

View file

@ -19,7 +19,12 @@
rec /*a*/ { /*b*/ c=1; }
rec /*a*/ { /*b*/ c=1; /*d*/ }
{a=rec {a={a=rec {a={a=rec {a={a=rec {a={a=rec {a={};};};};};};};};};};}
{
a=rec {
a={
a=rec {
a={
a=rec {a={a=rec {a={a=rec {a={};};};};};};};};};};}
rec {

View file

@ -5,5 +5,6 @@
(1/**/+/**/1)
(1/**/+/**/(1/**/+/**/(1/**/+/**/1)))
( 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 )
( 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1)
( 1
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1)
]

View file

@ -1,6 +1,8 @@
[
{ inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; }
{ inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; }
{
inherit aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; }
{ inherit
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; }
{ inherit b d ; }
{ inherit b d /*e*/ ; }
{ inherit b /*c*/ d ; }

View file

@ -116,5 +116,6 @@ rec
;
p =
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { } a;
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { }
a;
}

View file

@ -9,6 +9,11 @@
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa )
({ pkgs ? import ./.. { }, locationsXml }: null)
(a: b: c:
{ }:
a: b: c:
a)
]

View file

@ -15,7 +15,8 @@
d
)
(
a: { }:
a:
{ }:
/*
c
*/
@ -34,7 +35,8 @@
/*
b
*/
: d
:
d
)
(
a
@ -47,7 +49,9 @@
*/
d
)
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
@ -57,4 +61,10 @@
}:
null
)
(
a: b: c:
{ }:
a: b: c:
a
)
]

View file

@ -1,9 +1,12 @@
[
(a ? a)
(a ?/**/a)
(a/**/? a)
(a/**/?/**/a)
(a/**/?/**/(a/**/?/**/(a/**/?/**/a)))
( a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a )
( a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a)
(a or a)
(a or/**/a)
(a/**/or a)
(a/**/or/**/a)
(a/**/or/**/(a/**/or/**/(a/**/or/**/a)))
(a/**/or/**/(a/**/or/**/(a/**/or/**/a)))
( a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a )
( a or a
or a
or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a)
]

View file

@ -1,63 +1,64 @@
[
(a ? a)
(a or a)
(
a
?
a or
/**/
a
)
(
a
/**/
? a
or a
)
(
a
/**/
?
or
/**/
a
)
(
a
/**/
?
or
/**/
(
a
/**/
?
or
/**/
(
a
/**/
?
or
/**/
a
)
)
)
(a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a ? a)
(
a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
? a
/**/
or
/**/
(
a
/**/
or
/**/
(
a
/**/
or
/**/
a
)
)
)
(a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a)
(
a or a
or a
or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a or a
)
]

View file

@ -1,17 +1,20 @@
(
((c)) (
((c))
(
(c)
/*
e
*/
) (
)
(
(
c
/*
d
*/
)
) (
)
(
(
c
/*
@ -21,14 +24,16 @@
/*
e
*/
) (
)
(
(
/*
b
*/
c
)
) (
)
(
(
/*
b
@ -38,7 +43,8 @@
/*
e
*/
) (
)
(
(
/*
b
@ -48,7 +54,8 @@
d
*/
)
) (
)
(
(
/*
b
@ -61,12 +68,14 @@
/*
e
*/
) (
)
(
/*
a
*/
(c)
) (
)
(
/*
a
*/
@ -74,7 +83,8 @@
/*
e
*/
) (
)
(
/*
a
*/
@ -84,7 +94,8 @@
d
*/
)
) (
)
(
/*
a
*/
@ -97,7 +108,8 @@
/*
e
*/
) (
)
(
/*
a
*/
@ -107,7 +119,8 @@
*/
c
)
) (
)
(
/*
a
*/
@ -120,7 +133,8 @@
/*
e
*/
) (
)
(
/*
a
*/
@ -133,7 +147,8 @@
d
*/
)
) (
)
(
/*
a
*/

View file

@ -74,4 +74,43 @@
({ a ? null }: _)
({ /*a*/ b /*a*/ ? /*a*/ null /*c*/ , /*d*/ e /*a*/ ? /*a*/ null /*f*/ , /*g*/ ... /*h*/ }: _)
({
/*a*/
#
b
/*a*/
#
?
/*a*/
#
null
/*c*/
#
,
/*d*/
#
e
/*a*/
#
?
/*a*/
#
null
/*f*/
#
,
/*g*/
#
...
/*h*/
#
}
/*i*/
#
:
/*j*/
#
_
)
]

View file

@ -1094,4 +1094,68 @@
}:
_
)
(
{
/*
a
*/
#
b
/*
a
*/
#
?
/*
a
*/
#
null
/*
c
*/
#
,
/*
d
*/
#
e
/*
a
*/
#
?
/*
a
*/
#
null
/*
f
*/
#
,
/*
g
*/
#
...
/*
h
*/
#
}
/*
i
*/
#
:
/*
j
*/
#
_
)
]

View file

@ -4,5 +4,6 @@
(a/**/. a)
(a/**/./**/a)
( a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a )
( a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a )
( a.a
.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a )
]

View file

@ -58,9 +58,7 @@
[${mkSectionName sectName}]
''
###
''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${
pkgs.writeText "couchdb-extra.ini" cfg.extraConfig
} ${cfg.configFile}''
''-couch_ini ${cfg.package}/etc/default.ini ${configFile} ${pkgs.writeText "couchdb-extra.ini" cfg.extraConfig} ${cfg.configFile}''
###
''exec i3-input -F "mark %s" -l 1 -P 'Mark: ' ''
###

View file

@ -4,5 +4,6 @@
(with /*a*/ b; c)
(with /*a*/ b; /*b*/ c)
( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
( with b;
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc )
]