Skip to content

Commit

Permalink
Fix formatting of let blocks in containers, and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Sep 25, 2024
1 parent 495a6f5 commit cf7697a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
10 changes: 10 additions & 0 deletions topiary-cli/tests/samples/expected/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@
in
foo
@ [],
let x = 1, y = 2 in x + y,
let
x = 1,
y = 2,
in x + y,
let rec
x = 1,
y = 2,
in
x + y,
],

# Nickel standard library as of 44aef1672a09a76a71946fbf822713747ab7b9df
Expand Down
12 changes: 12 additions & 0 deletions topiary-cli/tests/samples/input/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ else
in
foo
@ [],

let x = 1, y = 2 in x + y,

let x = 1,
y = 2,
in x + y,

let
rec x = 1,
y = 2,
in
x + y,
],

# Nickel standard library as of 44aef1672a09a76a71946fbf822713747ab7b9df
Expand Down
27 changes: 24 additions & 3 deletions topiary-queries/queries/nickel.scm
Original file line number Diff line number Diff line change
Expand Up @@ -640,12 +640,33 @@
.
)

; Allow newlines after the comma (or semicolon) following a container
; element.
(
(#scope_id! "container")
[
","
";"
] @append_spaced_scoped_softline
(record_field)
(record_last_field)
(field_pattern)
(last_field_pat)
(match_branch)
(term)
(pattern)
(last_elem_pat)
(enum)
]
.
["," ";"] @append_spaced_scoped_softline
.
(comment)? @do_nothing
)

; Enums and records can have a `;` at the very beginning; allow spaces after
; these ones also.
(_
(#scope_id! "container")
.
";" @append_spaced_scoped_softline
.
(comment)? @do_nothing
)

0 comments on commit cf7697a

Please sign in to comment.