Skip to content

Commit f3b0bbb

Browse files
committed
Fix formatting of expr/eval_expr
wrt. newlines being added at the end
1 parent 1841873 commit f3b0bbb

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

shards/lang/src/formatter.rs

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,9 @@ impl<'a> FormatterVisitor<'a> {
238238
}
239239
}
240240
self.out.write_all(s.as_bytes()).unwrap();
241+
242+
// Enable for testing
243+
// self.out.flush().unwrap();
241244
}
242245

243246
fn write(&mut self, s: &str, top: FormatterTop) {
@@ -597,6 +600,7 @@ impl<'a> RuleVisitor for FormatterVisitor<'a> {
597600
self.newline();
598601
}
599602
self.write_joined(")");
603+
self.set_last_char(pair.as_span().end());
600604
}
601605
fn v_eval_expr<T: FnOnce(&mut Self)>(
602606
&mut self,
@@ -617,6 +621,7 @@ impl<'a> RuleVisitor for FormatterVisitor<'a> {
617621
self.newline();
618622
}
619623
self.write_joined(")");
624+
self.set_last_char(pair.as_span().end());
620625
}
621626
fn v_shards<T: FnOnce(&mut Self)>(&mut self, pair: Pair<Rule>, inner: T) {
622627
self.with_context(Context::Pipeline, |_self| {

shards/lang/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub mod rule_visitor;
1818

1919
use crate::ast::*;
2020

21-
use core::fmt;
21+
use core::fmt;
2222

2323
use std::borrow::Cow;
2424
use std::ops::Deref;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(Log
2+
a | Set("h")
3+
)
4+
; Blank
5+
6+
#(Log
7+
a | Set("h")
8+
) ; At end
9+
; JJ

shards/lang/src/tests/test16.shs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(Log
2+
a | Set("h")
3+
)
4+
; Blank
5+
6+
#(Log
7+
a | Set("h")
8+
) ; At end
9+
; JJ
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
a: {
3+
j: 2
4+
}
5+
}
6+
7+
{
8+
a: {
9+
j: 2
10+
j: 2
11+
j: 2
12+
j: [
13+
1 2 3
14+
]
15+
j: 2
16+
j: 2
17+
}
18+
}
19+
20+
@define(my-define 2)
21+
22+
{
23+
ShardParams(A: 1
24+
B: {
25+
Something({
26+
; Comment
27+
Log("Another callback")
28+
})
29+
}
30+
C: 3
31+
)
32+
}

shards/lang/src/tests/test17.shs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
a: {
3+
j: 2
4+
}
5+
}
6+
7+
{
8+
a: {
9+
j: 2
10+
j: 2
11+
j: 2
12+
j: [
13+
1 2 3
14+
]
15+
j: 2
16+
j: 2
17+
}
18+
}
19+
20+
@define(my-define 2)
21+
22+
{
23+
ShardParams(A: 1
24+
B: {
25+
Something({
26+
; Comment
27+
Log("Another callback")
28+
})
29+
}
30+
C: 3
31+
)
32+
}

0 commit comments

Comments
 (0)