Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unbalanced parenthesized expressions #722

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ This name should be decided amongst the team before the release.
### Added
- [#705](https://github.com/tweag/topiary/pull/705) Added support for Nickel 1.7 extended pattern formatting

### Fixed
- [#720](https://github.com/tweag/topiary/pull/720) [#722](https://github.com/tweag/topiary/pull/722) Various OCaml improvements

### Changed
- [#704](https://github.com/tweag/topiary/pull/704) Refactors our postprocessing code to be more versatile.
- [#711](https://github.com/tweag/topiary/pull/711) Feature gate all grammars, with supported and contributed languages built by default.
Expand Down
3 changes: 3 additions & 0 deletions topiary-cli/tests/samples/expected/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,9 @@ let _ =
match foo with
| Bar { baz } -> qux

(* #721: unbalanced spacing around parenthesized expressions *)
let _ = (begin end)

(* #659 handling of the `;;` separator *)

let bonjour () = "Bonjour"
Expand Down
3 changes: 3 additions & 0 deletions topiary-cli/tests/samples/input/ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,9 @@ let _ =
match foo with
| Bar { baz } -> qux

(* #721: unbalanced spacing around parenthesized expressions *)
let _ = (begin end)

(* #659 handling of the `;;` separator *)

let bonjour () = "Bonjour"
Expand Down
172 changes: 11 additions & 161 deletions topiary-queries/queries/ocaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
)

; Surround spaces
; A space is put after, and before (except just after an open parenthesis).
; A space is put after, except when followed by a PPX "%".
(
[
"and"
Expand Down Expand Up @@ -228,16 +228,22 @@
"%"? @do_nothing
)

; Those keywords are not expected to come right after an open parenthesis.
; Prepend a space. Note that these nodes are not expected to come after an open parenthesis,
; or if they do, we still want a space before.
[
"as"
(attribute)
"constraint"
"do"
"done"
"downto"
"else"
(floating_attribute)
"in"
; Infix operators can come after an open parenthesis, but we want a space before anyway
(item_attribute)
(module_parameter)
"nonrec"
"of"
(pow_operator)
(mult_operator)
(add_operator)
Expand All @@ -246,14 +252,14 @@
(and_operator)
(or_operator)
(assign_operator)
"nonrec"
"of"
(parameter)
"rec"
"then"
"to"
"virtual"
"when"
"with"
"="
"|"
"->"
"<-"
Expand All @@ -277,162 +283,6 @@
")"* @do_nothing
)

; For those queries, we should not have multiple queries,
; however, due to a known bug in tree-sitter queries
; https://github.com/tree-sitter/tree-sitter/issues/1811
; using an alternative after the starred parenthesis does not work as intented.
;
(
"("* @do_nothing
.
"assert" @prepend_space
)
(
"("* @do_nothing
.
(attribute) @prepend_space
)
(
"("* @do_nothing
.
"begin" @prepend_space
)
(
"("* @do_nothing
.
"class" @prepend_space
)
(
"("* @do_nothing
.
"exception" @prepend_space
)
(
"("* @do_nothing
.
"external" @prepend_space
)
(
"("* @do_nothing
.
(floating_attribute) @prepend_space
)
(
"("* @do_nothing
.
"for" @prepend_space
)
(
"("* @do_nothing
.
"include" @prepend_space
)
(
"("* @do_nothing
.
"inherit" @prepend_space
)
(
"("* @do_nothing
.
"initializer" @prepend_space
)
(
"("* @do_nothing
.
(item_attribute) @prepend_space
)
(
"("* @do_nothing
.
"let" @prepend_space
)
(
"("* @do_nothing
.
"method" @prepend_space
)
(
"("* @do_nothing
.
"module" @prepend_space
)
(
"("* @do_nothing
.
(module_parameter) @prepend_space
)
(
"("* @do_nothing
.
"mutable" @prepend_space
)
(
"("* @do_nothing
.
"new" @prepend_space
)
(
"("* @do_nothing
.
"object" @prepend_space
)
(
"("* @do_nothing
.
"open" @prepend_space
)
(
"("* @do_nothing
.
(parameter) @prepend_space
)
(
"("* @do_nothing
.
"private" @prepend_space
)
(
"("* @do_nothing
.
"sig" @prepend_space
)
(
"("* @do_nothing
.
"try" @prepend_space
)
(
"("* @do_nothing
.
"type" @prepend_space
)
(
"("* @do_nothing
.
"val" @prepend_space
)
(
"("* @do_nothing
.
"while" @prepend_space
)
(
"("* @do_nothing
.
"*" @prepend_space
)
(
"("* @do_nothing
.
"=" @prepend_space
)
(
"("* @do_nothing
.
"}" @prepend_space
)

; Put a space after commas, except the last one.
(
"," @append_space
Expand Down
Loading