Skip to content

Commit c07bd4d

Browse files
committed
Bump topiary
Topiary now does not seem to coalesce multiple empty lines into one so we need to reorganize a couple of formatting rules. While we are at it we clean up a few oddities around block formatting.
1 parent 233e53e commit c07bd4d

7 files changed

+54
-84
lines changed

Cargo.lock

+25-60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ repository = "https://github.com/bbannier/spicy-format"
99

1010
[dependencies]
1111
tree-sitter-spicy = { git = "https://github.com/bbannier/tree-sitter-spicy" }
12-
topiary-core = { git = "https://github.com/tweag/topiary.git", version = "0.3.0" }
13-
topiary-tree-sitter-facade = { git = "https://github.com/tweag/topiary.git", version = "0.3.0" }
14-
tree-sitter-facade = { git = "https://github.com/tweag/tree-sitter-facade" }
12+
topiary-core = { git = "https://github.com/tweag/topiary.git", version = "0.4.0" }
13+
topiary-tree-sitter-facade = { git = "https://github.com/tweag/topiary.git", version = "0.4.0" }
1514
clap = { version = "4.5.4", features = ["std", "derive", "help"], default-features = false }
1615
tree-sitter = "0.22.6"
1716
thiserror = "1.0.61"

corpus/constructs.spicy

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ for (i in [1,2,3]) {
1212
for (i in [1,2,3])
1313
print i;
1414

15-
while (1);
15+
while (1){}
1616
while (1) { print 1;break;}
1717

1818
if (1 in [1,2,3])

corpus/constructs.spicy.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ for (i in [1, 2, 3]) {
1212
for (i in [1, 2, 3])
1313
print i;
1414

15-
while (1) ;
15+
while (1) {}
1616
while (1) {
1717
print 1;
1818
break;

corpus/statements.spicy.expected

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ function f() {
88
}
99

1010
function f() {
11-
if (True)
12-
{
11+
if (True) {
1312
1;
14-
}
15-
else if (False) {
13+
} else if (False) {
1614
2;
17-
}
18-
else {
15+
} else {
1916
3;
2017
}
2118
}

corpus/unit.spicy.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type X = unit {};
5353
type X = unit(inout n: uint8) {};
5454

5555
type X = unit {
56-
: uint8 if (True);
56+
: uint8 if(True);
5757
};
5858

5959
public type X = unit {

src/query.scm

+21-12
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
(comment)*
131131
; We only match statements with a single expression here since statements
132132
; with blocks do their own indention.
133-
(statement (expression)) @append_indent_end
133+
(statement (expression)) @prepend_input_softline @append_indent_end
134134
)
135135

136136
; Switch with local binding.
@@ -170,7 +170,6 @@
170170
"on"
171171
"="
172172
(is_debug)
173-
"if"
174173
(hook_priority)
175174
] @append_space @prepend_space
176175

@@ -299,10 +298,10 @@
299298

300299
(sink_decl "sink" @append_space)
301300

302-
(statement) @prepend_input_softline
303-
304301
(
305-
(statement)
302+
(statement
303+
(block)? @do_nothing
304+
)
306305
.
307306
(comment)? @do_nothing
308307
) @append_hardline
@@ -339,6 +338,9 @@
339338
; Unit `switch` statement.
340339
(unit_switch (expression) ")" @append_space)
341340

341+
(if
342+
"if" @append_space
343+
)
342344
(if
343345
"if"
344346
(expression) @append_indent_start
@@ -349,6 +351,9 @@
349351
"else" @append_indent_start
350352
(statement [(block) (if)]*@do_nothing) @prepend_hardline @append_indent_end
351353
)
354+
(if
355+
"else" @prepend_space @append_space
356+
)
352357

353358

354359
(for
@@ -361,11 +366,11 @@
361366
)
362367
(for
363368
")" @append_indent_start
364-
(statement (block)*@do_nothing) @append_indent_end
369+
(statement (block)*@do_nothing) @prepend_input_softline @append_indent_end
365370
)
366371

367372
(while
368-
"while" @prepend_space
373+
"while" @append_space
369374
"(" @prepend_space
370375
")" @append_space
371376
)
@@ -392,17 +397,21 @@
392397
(#multi_line_only!)
393398
)
394399

395-
; Suppress space before field `;` decl with `if.
396-
(field_decl
397-
(is_skip)? @append_space
398-
(if (statement ";") @prepend_antispace)?
399-
)
400400
; Enforce spaces around `->` in field sink syntax.
401401
(field_decl
402402
"->" @prepend_space @append_space
403403
(sink)
404404
)
405405

406+
(field_decl
407+
(is_skip)? @append_space
408+
)
409+
410+
(field_decl
411+
"if" @prepend_space
412+
.
413+
"("
414+
)
406415
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
407416
; Bitfields.
408417

0 commit comments

Comments
 (0)