Skip to content

Commit

Permalink
Support let blocks in nickel
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Sep 11, 2024
1 parent a495ecd commit 08deba5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion topiary-config/languages.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
extensions = ["ncl"],
grammar = {
git = "https://github.com/nickel-lang/tree-sitter-nickel",
rev = "43433d8477b24cd13acaac20a66deda49b7e2547",
rev = "88d836a24b3b11c8720874a1a9286b8ae838d30a",
},
},

Expand Down
37 changes: 37 additions & 0 deletions topiary-queries/queries/nickel.scm
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
;
; let [rec] IDENT = EXPR in EXPR
;
; or
;
; let [rec]
; IDENT = EXPR,
; IDENT = EXPR,
; in
; EXPR
;
; The formatting for the bound expression is handled by the above rules,
; which also apply to record field values. The "in" should appear on a
; new line, if the entire let expression is multi-line. The result
Expand All @@ -303,14 +311,43 @@
; expression, to avoid long diagonals in a series of let expressions
; (which is idiomatic).

; A let block containing multiple bindings. If this is multiline, the first
; binding should appear on a new line, and the bindings should be indented.
(let_expr
(#scope_id! "let_result")
(let_in_block
"let"
.
; Prepend before the first binding instead of appending after the "let",
; so that in the case of a "let rec" the line break goes after the "rec".
(let_binding) @prepend_spaced_softline @prepend_indent_start
(let_binding)
"in" @prepend_indent_end @prepend_begin_scope @prepend_spaced_softline
)
(term) @append_end_scope
)

; A let with a single binding. The binding should be on the same line as the "let".
(let_expr
(#scope_id! "let_result")
(let_in_block
"let"
.
(let_binding)
.
"in" @prepend_begin_scope @prepend_spaced_softline
)
(term) @append_end_scope
)

; When binding multiple values in a let block, allow new lines between the bindings.
(let_expr
(#scope_id! "let_result")
(let_in_block
("," @append_spaced_softline)
)
)

(let_expr
(#scope_id! "let_result")
(term) @prepend_spaced_scoped_softline
Expand Down

0 comments on commit 08deba5

Please sign in to comment.