Skip to content

Commit

Permalink
Merge pull request #132 from kamadorueda/kamadorueda
Browse files Browse the repository at this point in the history
feat: lisp-like parens
  • Loading branch information
kamadorueda authored Feb 17, 2022
2 parents e5e42a3 + 9c27dfa commit ea6e3bf
Show file tree
Hide file tree
Showing 13 changed files with 1,565 additions and 1,882 deletions.
23 changes: 16 additions & 7 deletions src/rules/paren.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -19,7 +22,9 @@ pub fn rule(
steps.push_back(crate::builder::Step::Format(child.element));
match layout {
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 => {}
}
Expand All @@ -38,8 +43,10 @@ pub fn rule(
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
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 => {
Expand All @@ -61,9 +68,11 @@ pub fn rule(
let child = children.get_next().unwrap();
match layout {
crate::config::Layout::Tall => {
steps.push_back(crate::builder::Step::Dedent);
steps.push_back(crate::builder::Step::NewLine);
steps.push_back(crate::builder::Step::Pad);
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 => {}
}
Expand Down
12 changes: 5 additions & 7 deletions tests/cases/apply/out
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
(a b)
(a b)
(
a
/*
b
*/
c
)
(a
/*
b
*/
c)
(
/*
a
Expand Down
44 changes: 19 additions & 25 deletions tests/cases/assert/out
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
[
(assert b; c)
(
assert b;
/*
b
*/
c
)
(
assert
/*
a
*/
b; c
)
(
assert
/*
a
*/
b;
/*
b
*/
c
)
(assert b;
/*
b
*/
c)
(assert
/*
a
*/
b; c)
(assert
/*
a
*/
b;
/*
b
*/
c)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
(assert b; cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc)
]
104 changes: 45 additions & 59 deletions tests/cases/bin_op/out
Original file line number Diff line number Diff line change
@@ -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)
]
48 changes: 22 additions & 26 deletions tests/cases/comment/out
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,26 @@
#7
}

(
let
# 1
#2
a = 1; # 3
b = 1;
c = 1; # 4
#5

#6

d = 1;
#7
in
d
)

(
{
a,
# comment
b ? 2,
# comment
}:
_
)
(let
# 1
#2
a = 1; # 3
b = 1;
c = 1; # 4
#5

#6

d = 1;
#7
in
d)

({
a,
# comment
b ? 2,
# comment
}:
_)
]
Loading

0 comments on commit ea6e3bf

Please sign in to comment.