Skip to content

Commit

Permalink
Merge pull request #554 from tweag/erin/nickel-annotation-idempotency
Browse files Browse the repository at this point in the history
Nickel: Resolve annotation idempotency
  • Loading branch information
Erin van der Veen authored Jul 4, 2023
2 parents 008e983 + 980db0c commit a418103
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
18 changes: 17 additions & 1 deletion topiary/languages/nickel.scm
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,26 @@
(annot) @prepend_indent_start
) @append_indent_end

; Start a scope from the node previous to the annotations.
; This properly checks if the annotations were intended to be
; on newlines in such cases as:
; id
; | a -> a
; which, without the annotations scope, would consider the annotations to be a
; single line node and format it as such:
; id | a -> a
(
(#scope_id! "annotations")
(_) @begin_scope
.
(annot) @end_scope
)

; Put each annotation -- and the equals sign, if it follows annotations
; -- on a new line, in a multi-line context.
(annot
(annot_atom) @prepend_spaced_softline
(#scope_id! "annotations")
(annot_atom) @prepend_spaced_scoped_softline
)

(
Expand Down
5 changes: 4 additions & 1 deletion topiary/tests/samples/expected/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -2435,5 +2435,8 @@
```
"%
= fun s => %enum_from_str% s,
}
},

id
| a -> a,
}
5 changes: 4 additions & 1 deletion topiary/tests/samples/input/nickel.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -2425,5 +2425,8 @@
```
"%
= fun s => %enum_from_str% s,
}
},

id |
a -> a,
}

0 comments on commit a418103

Please sign in to comment.