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 6c0cc37 commit 9e056a4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
12 changes: 11 additions & 1 deletion topiary-cli/tests/samples/expected/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,17 @@
1
else
3
)
),
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
14 changes: 13 additions & 1 deletion topiary-cli/tests/samples/input/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,19 @@ bar == 'Goodbye
if x == 1 then
1
else
3)
3),

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 @@ -589,12 +589,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 9e056a4

Please sign in to comment.