1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 21:17:45 +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,8 +22,10 @@ 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 => {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Indent); 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 => {
if has_comments_or_newlines {
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::FormatWider(child.element)); steps.push_back(crate::builder::Step::FormatWider(child.element));
} }
crate::config::Layout::Wide => { crate::config::Layout::Wide => {
@ -61,10 +68,12 @@ 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 => {
if has_comments_or_newlines {
steps.push_back(crate::builder::Step::Dedent); steps.push_back(crate::builder::Step::Dedent);
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);
} }
}
crate::config::Layout::Wide => {} crate::config::Layout::Wide => {}
} }
steps.push_back(crate::builder::Step::Format(child.element)); steps.push_back(crate::builder::Step::Format(child.element));

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,21 +1,16 @@
[ [
(assert b; c) (assert b; c)
( (assert b;
assert b;
/* /*
b b
*/ */
c c)
) (assert
(
assert
/* /*
a a
*/ */
b; c b; c)
) (assert
(
assert
/* /*
a a
*/ */
@ -23,8 +18,7 @@
/* /*
b b
*/ */
c c)
)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
] ]

View file

@ -1,45 +1,32 @@
[ [
(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
@ -58,6 +45,5 @@
+ 1 + 1
+ 1 + 1
+ 1 + 1
+ 1 + 1)
)
] ]

View file

@ -81,8 +81,7 @@
#7 #7
} }
( (let
let
# 1 # 1
#2 #2
a = 1; # 3 a = 1; # 3
@ -95,16 +94,13 @@
d = 1; d = 1;
#7 #7
in in
d d)
)
( ({
{
a, a,
# comment # comment
b ? 2, b ? 2,
# comment # comment
}: }:
_ _)
)
] ]

View file

@ -1,11 +1,8 @@
[ [
( (if ./a
if ./a
then b then b
else c else c)
) (if
(
if
/**/ /**/
a a
/**/ /**/
@ -15,10 +12,8 @@
/**/ /**/
else else
/**/ /**/
c c)
) (if
(
if
if a if a
then b then b
else c else c
@ -27,10 +22,8 @@
then b then b
else if a else if a
then b then b
else c else c)
) (if
(
if
if a if a
then b then b
else c else c
@ -43,206 +36,125 @@
*/ */
if a if a
then b then b
else c else c)
) (if
( (if
if (if
( (if a
if
(
if
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
then then
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
else else
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c)))
)
)
)
then then
( (if
if (if
( (if a
if
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
then then
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
else else
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c)))
)
)
)
else else
( (if
if (if
( (if a
if
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
then then
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))
)
)
else else
( (if
if (if a
(
if a
then b then b
else c else c)
)
then then
( (if a
if a
then b then b
else c else c)
)
else else
( (if a
if a
then b then b
else c else c))))
)
)
)
)
] ]

View file

@ -1,45 +1,34 @@
[ [
( (a: b:
a: b:
/* /*
c c
*/ */
d d)
) ({}:
(
{}:
b: b:
/* /*
c c
*/ */
d d)
) (a:
(
a:
{}: {}:
/* /*
c c
*/ */
d d)
)
(a: d) (a: d)
( (a:
a:
/* /*
c c
*/ */
d d)
) (a
(
a
/* /*
b b
*/ */
: :
d d)
) (a
(
a
/* /*
b b
*/ */
@ -47,25 +36,20 @@
/* /*
c c
*/ */
d 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: b: c:
a a)
)
] ]

View file

@ -1,67 +1,47 @@
[ [
(a or a) (a or a)
( (a
a
or or
/**/ /**/
a a)
) (a
(
a
/**/ /**/
or a or a)
) (a
(
a
/**/ /**/
or or
/**/ /**/
a a)
) (a
(
a
/**/ /**/
or or
/**/ /**/
( (a
a
/**/ /**/
or or
/**/ /**/
( (a
a
/**/ /**/
or or
/**/ /**/
a a)))
) (a
)
)
(
a
/**/ /**/
or or
/**/ /**/
( (a
a
/**/ /**/
or or
/**/ /**/
( (a
a
/**/ /**/
or 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) (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,8 +40,7 @@
e e
*/ */
) )
( ((
(
/* /*
b b
*/ */
@ -53,8 +48,7 @@
/* /*
d d
*/ */
) ))
)
( (
( (
/* /*

View file

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

View file

@ -1,54 +1,41 @@
[ [
( ({
{
self, self,
gomod2nix, gomod2nix,
mach-nix, mach-nix,
} }
@ inp: @ inp:
_ _)
)
({}: _) ({}: _)
({ a }: _) ({ a }: _)
( ({
{
/**/ /**/
}: }:
_ _)
)
({ ... }: _) ({ ... }: _)
( ({ ...
{ ...
/**/ /**/
}: }:
_ _)
) ({
(
{
/**/ /**/
... ...
}: }:
_ _)
) ({
(
{
/**/ /**/
... ...
/**/ /**/
}: }:
_ _)
)
( ({
{
b, b,
e, e,
... ...
}: }:
_ _)
) ({
(
{
b, b,
e, e,
... ...
@ -56,10 +43,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
e, e,
/* /*
@ -67,10 +52,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b, b,
e, e,
/* /*
@ -81,10 +64,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
e e
/* /*
@ -93,10 +74,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
b, b,
e e
/* /*
@ -108,10 +87,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
e e
/* /*
@ -123,10 +100,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b, b,
e e
/* /*
@ -141,10 +116,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -152,10 +125,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -166,10 +137,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -180,10 +149,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -197,10 +164,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -212,10 +177,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -230,10 +193,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -248,10 +209,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b, b,
/* /*
d d
@ -269,10 +228,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -281,10 +238,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -296,10 +251,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -311,10 +264,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -329,10 +280,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -345,10 +294,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -364,10 +311,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -383,10 +328,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -405,10 +348,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -420,10 +361,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -438,10 +377,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -456,10 +393,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -477,10 +412,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -496,10 +429,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -518,10 +449,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -540,10 +469,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
b b
/* /*
c c
@ -565,10 +492,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -576,10 +501,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -590,10 +513,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -604,10 +525,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -621,10 +540,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -636,10 +553,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -654,10 +569,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -672,10 +585,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -693,10 +604,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -707,10 +616,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -724,10 +631,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -741,10 +646,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -761,10 +664,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -779,10 +680,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -800,10 +699,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -821,10 +718,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -845,10 +740,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -860,10 +753,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -878,10 +769,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -896,10 +785,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -917,10 +804,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -936,10 +821,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -958,10 +841,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -980,10 +861,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1005,10 +884,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1023,10 +900,8 @@
e, e,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1044,10 +919,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1065,10 +938,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1089,10 +960,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1111,10 +980,8 @@
, ,
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1136,10 +1003,8 @@
h h
*/ */
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1161,10 +1026,8 @@
*/ */
... ...
}: }:
_ _)
) ({
(
{
/* /*
a a
*/ */
@ -1189,12 +1052,10 @@
h h
*/ */
}: }:
_ _)
)
({ a ? null }: _) ({ a ? null }: _)
( ({
{
/* /*
a a
*/ */
@ -1235,8 +1096,7 @@
h h
*/ */
}: }:
_ _)
)
( (
{ {

View file

@ -1,26 +1,19 @@
[ [
(a.a) (a.a)
( (a
a
. .
/**/ /**/
a a)
) (a
(
a
/**/ /**/
.a .a)
) (a
(
a
/**/ /**/
. .
/**/ /**/
a a)
)
(a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a) (a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a)
( (a
a
.a .a
.a .a
.a .a
@ -58,6 +51,5 @@
.a .a
.a .a
.a .a
.a .a)
)
] ]

View file

@ -1,21 +1,16 @@
[ [
(with b; c) (with b; c)
( (with b;
with b;
/* /*
b b
*/ */
c c)
) (with
(
with
/* /*
a a
*/ */
b; c b; c)
) (with
(
with
/* /*
a a
*/ */
@ -23,8 +18,7 @@
/* /*
b b
*/ */
c c)
)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc) (with b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
{ a = with b; 1; } { a = with b; 1; }
@ -47,16 +41,13 @@
# 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;
(
with a;
/* /*
comment comment
*/ */
@ -64,8 +55,7 @@
with c; { with c; {
a = 1; a = 1;
b = 2; b = 2;
} })
)
{ {
a = with b; with b; with b; 1; a = with b; with b; with b; 1;
} }