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

feat: lisp-like parens

This commit is contained in:
Kevin Amado 2022-02-17 13:16:03 -05:00
parent e5e42a325b
commit 9c27dfac78
No known key found for this signature in database
GPG key ID: FFF341057F503148
13 changed files with 1566 additions and 1883 deletions

View file

@ -8,7 +8,10 @@ pub fn rule(
build_ctx, node, true, build_ctx, node, true,
); );
let layout = if children.has_comments() || children.has_newlines() { let has_comments_or_newlines =
children.has_comments() || children.has_newlines();
let layout = if has_comments_or_newlines {
&crate::config::Layout::Tall &crate::config::Layout::Tall
} else { } else {
build_ctx.config.layout() build_ctx.config.layout()
@ -19,7 +22,9 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Indent); if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Indent);
}
} }
crate::config::Layout::Wide => {} crate::config::Layout::Wide => {}
} }
@ -38,8 +43,10 @@ pub fn rule(
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine); if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Pad); 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 => {
@ -61,9 +68,11 @@ pub fn rule(
let child = children.get_next().unwrap(); let child = children.get_next().unwrap();
match layout { match layout {
crate::config::Layout::Tall => { crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent); if has_comments_or_newlines {
steps.push_back(crate::builder::Step::NewLine); steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
}
} }
crate::config::Layout::Wide => {} crate::config::Layout::Wide => {}
} }

View file

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

View file

@ -1,30 +1,24 @@
[ [
(assert b; c) (assert b; c)
( (assert b;
assert b; /*
/* b
b */
*/ c)
c (assert
) /*
( a
assert */
/* b; c)
a (assert
*/ /*
b; c a
) */
( b;
assert /*
/* b
a */
*/ c)
b;
/*
b
*/
c
)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
] ]

View file

@ -1,63 +1,49 @@
[ [
(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
+ 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

@ -81,30 +81,26 @@
#7 #7
} }
( (let
let # 1
# 1 #2
#2 a = 1; # 3
a = 1; # 3 b = 1;
b = 1; c = 1; # 4
c = 1; # 4 #5
#5
#6 #6
d = 1; d = 1;
#7 #7
in in
d d)
)
( ({
{ a,
a, # comment
# comment b ? 2,
b ? 2, # comment
# comment }:
}: _)
_
)
] ]

View file

@ -1,248 +1,160 @@
[ [
( (if ./a
if ./a then b
else c)
(if
/**/
a
/**/
then
/**/
b
/**/
else
/**/
c)
(if
if a
then b then b
else c else c
) then b
( else if a
if then b
/**/ else if a
a then b
/**/ else c)
then (if
/**/ if a
b
/**/
else
/**/
c
)
(
if
if a
then b
else c
then b
else if a
then b
else if a
then b then b
else c else c
) then b
( else if a
if then b
if a else
then b /*
else c x
*/
if a
then b then b
else if a else c)
then b (if
else (if
/* (if
x (if a
*/ then b
if a else c)
then b then
else c (if a
) then b
( else c)
if else
( (if a
if then b
( else c))
if
(
if a
then b
else c
)
then
(
if a
then b
else c
)
else
(
if a
then b
else c
)
)
then
(
if
(
if a
then b
else c
)
then
(
if a
then b
else c
)
else
(
if a
then b
else c
)
)
else
(
if
(
if a
then b
else c
)
then
(
if a
then b
else c
)
else
(
if a
then b
else c
)
)
)
then then
( (if
if (if a
( then b
if else c)
( then
if a (if a
then b then b
else c else c)
) else
then (if a
( then b
if a else c))
then b
else c
)
else
(
if a
then b
else c
)
)
then
(
if
(
if a
then b
else c
)
then
(
if a
then b
else c
)
else
(
if a
then b
else c
)
)
else
(
if
(
if a
then b
else c
)
then
(
if a
then b
else c
)
else
(
if a
then b
else c
)
)
)
else else
( (if
if (if a
( then b
if else c)
( then
if a (if a
then b then b
else c else c)
) else
then (if a
( then b
if a else c)))
then b then
else c (if
) (if
else (if a
( then b
if a else c)
then b then
else c (if a
) then b
) else c)
then else
( (if a
if then b
( else c))
if a then
then b (if
else c (if a
) then b
then else c)
( then
if a (if a
then b then b
else c else c)
) else
else (if a
( then b
if a else c))
then b else
else c (if
) (if a
) then b
else else c)
( then
if (if a
( then b
if a else c)
then b else
else c (if a
) then b
then else c)))
( else
if a (if
then b (if
else c (if a
) then b
else else c)
( then
if a (if a
then b then b
else c else c)
) else
) (if a
) then b
) else c))
then
(if
(if a
then b
else c)
then
(if a
then b
else c)
else
(if a
then b
else c))
else
(if
(if a
then b
else c)
then
(if a
then b
else c)
else
(if a
then b
else c))))
] ]

View file

@ -1,71 +1,55 @@
[ [
( (a: b:
a: b: /*
c
*/
d)
({}:
b:
/* /*
c c
*/ */
d d)
) (a:
(
{}: {}:
b: /*
/* c
c */
*/ d)
d
)
(
a:
{}:
/*
c
*/
d
)
(a: d) (a: d)
( (a:
a: /*
/* c
c */
*/ d)
d (a
) /*
( b
a */
/* :
b d)
*/ (a
: /*
d b
) */
( :
a /*
/* c
b */
*/ d)
:
/*
c
*/
d
)
( (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) )
( (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) )
( ({
{ pkgs ? import ./.. {},
pkgs ? import ./.. {}, locationsXml,
locationsXml, }:
}: null)
null (a: b: c:
) {}:
( a: b: c:
a: b: c: a)
{}:
a: b: c:
a
)
] ]

View file

@ -1,67 +1,47 @@
[ [
(a or a) (a or a)
( (a
a or
or /**/
/**/ a)
a (a
) /**/
( or a)
a (a
/**/ /**/
or a or
) /**/
( a)
a (a
/**/ /**/
or or
/**/ /**/
a (a
) /**/
( or
a /**/
/**/ (a
or /**/
/**/ or
( /**/
a a)))
/**/ (a
or /**/
/**/ or
( /**/
a (a
/**/ /**/
or or
/**/ /**/
a (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)
( (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 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

@ -6,14 +6,12 @@
e e
*/ */
) )
( ((
( c
c /*
/* d
d */
*/ ))
)
)
( (
( (
c c
@ -25,14 +23,12 @@
e e
*/ */
) )
( ((
( /*
/* b
b */
*/ c
c ))
)
)
( (
( (
/* /*
@ -44,17 +40,15 @@
e e
*/ */
) )
( ((
( /*
/* b
b */
*/ c
c /*
/* d
d */
*/ ))
)
)
( (
( (
/* /*

View file

@ -1,45 +1,33 @@
[ [
({} @ a: _) ({} @ a: _)
( ({} @
{} @ /**/
/**/ a:
a: _)
_ ({}
) /**/
( @ a:
{} _)
/**/ ({}
@ a: /**/
_ @
) /**/
( a:
{} _)
/**/
@
/**/
a:
_
)
(a @ {}: _) (a @ {}: _)
( (a @
a @ /**/
/**/ {}:
{}: _)
_ (a
) /**/
( @ {}:
a _)
/**/ (a
@ {}: /**/
_ @
) /**/
( {}:
a _)
/**/
@
/**/
{}:
_
)
] ]

File diff suppressed because it is too large Load diff

View file

@ -1,63 +1,55 @@
[ [
(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 .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

@ -1,30 +1,24 @@
[ [
(with b; c) (with b; c)
( (with b;
with b; /*
/* b
b */
*/ c)
c (with
) /*
( a
with */
/* b; c)
a (with
*/ /*
b; c a
) */
( b;
with /*
/* b
a */
*/ c)
b;
/*
b
*/
c
)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{ a = with b; 1; } { a = with b; 1; }
@ -47,25 +41,21 @@
# comment # comment
} }
(with a; with b; with c; { a = 1; }) (with a; with b; with c; { a = 1; })
( (with a;
with a; with b;
with b; with c; {
with c; { a = 1;
a = 1; b = 2;
b = 2; })
} (with a;
) /*
( comment
with a; */
/* with b;
comment with c; {
*/ a = 1;
with b; b = 2;
with c; { })
a = 1;
b = 2;
}
)
{ {
a = with b; with b; with b; 1; a = with b; with b; with b; 1;
} }