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

Merge pull request #132 from kamadorueda/kamadorueda

feat: lisp-like parens
This commit is contained in:
Kevin Amado 2022-02-17 14:18:27 -05:00 committed by GitHub
commit ea6e3bfc92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 1566 additions and 1883 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,45 +1,34 @@
[
(
a: b:
(a: b:
/*
c
*/
d
)
(
{}:
d)
({}:
b:
/*
c
*/
d
)
(
a:
d)
(a:
{}:
/*
c
*/
d
)
d)
(a: d)
(
a:
(a:
/*
c
*/
d
)
(
a
d)
(a
/*
b
*/
:
d
)
(
a
d)
(a
/*
b
*/
@ -47,25 +36,20 @@
/*
c
*/
d
)
d)
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
)
(
{
({
pkgs ? import ./.. {},
locationsXml,
}:
null
)
(
a: b: c:
null)
(a: b: c:
{}:
a: b: c:
a
)
a)
]

View file

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

View file

@ -6,14 +6,12 @@
e
*/
)
(
(
((
c
/*
d
*/
)
)
))
(
(
c
@ -25,14 +23,12 @@
e
*/
)
(
(
((
/*
b
*/
c
)
)
))
(
(
/*
@ -44,8 +40,7 @@
e
*/
)
(
(
((
/*
b
*/
@ -53,8 +48,7 @@
/*
d
*/
)
)
))
(
(
/*

View file

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

View file

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

View file

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