Skip to content

Commit ab05bf6

Browse files
committed
Support let blocks in nickel
1 parent a495ecd commit ab05bf6

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

topiary-config/languages.ncl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
extensions = ["ncl"],
4444
grammar = {
4545
git = "https://github.com/nickel-lang/tree-sitter-nickel",
46-
rev = "43433d8477b24cd13acaac20a66deda49b7e2547",
46+
rev = "88d836a24b3b11c8720874a1a9286b8ae838d30a",
4747
},
4848
},
4949

topiary-queries/queries/nickel.scm

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@
295295
;
296296
; let [rec] IDENT = EXPR in EXPR
297297
;
298+
; or
299+
;
300+
; let [rec]
301+
; IDENT = EXPR,
302+
; IDENT = EXPR,
303+
; in
304+
; EXPR
305+
;
298306
; The formatting for the bound expression is handled by the above rules,
299307
; which also apply to record field values. The "in" should appear on a
300308
; new line, if the entire let expression is multi-line. The result
@@ -303,14 +311,43 @@
303311
; expression, to avoid long diagonals in a series of let expressions
304312
; (which is idiomatic).
305313

314+
; A let block containing multiple bindings. If this is multiline, the first
315+
; binding should appear on a new line, and the bindings should be indented.
316+
(let_expr
317+
(#scope_id! "let_result")
318+
(let_in_block
319+
"let"
320+
.
321+
; Prepend before the first binding instead of appending after the "let",
322+
; so that in the case of a "let rec" the line break goes after the "rec".
323+
(let_binding) @prepend_spaced_softline @prepend_indent_start
324+
(let_binding)
325+
"in" @prepend_indent_end @prepend_begin_scope @prepend_spaced_softline
326+
)
327+
(term) @append_end_scope
328+
)
329+
330+
; A let with a single binding. The binding should be on the same line as the "let".
306331
(let_expr
307332
(#scope_id! "let_result")
308333
(let_in_block
334+
"let"
335+
.
336+
(let_binding)
337+
.
309338
"in" @prepend_begin_scope @prepend_spaced_softline
310339
)
311340
(term) @append_end_scope
312341
)
313342

343+
; When binding multiple values in a let block, allow new lines between the bindings.
344+
(let_expr
345+
(#scope_id! "let_result")
346+
(let_in_block
347+
("," @append_spaced_softline)
348+
)
349+
)
350+
314351
(let_expr
315352
(#scope_id! "let_result")
316353
(term) @prepend_spaced_scoped_softline

0 commit comments

Comments
 (0)