Skip to content

Commit

Permalink
Format our query files with Topiary
Browse files Browse the repository at this point in the history
  • Loading branch information
nbacquey committed Feb 22, 2023
1 parent 8fbd19f commit e928fca
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 57 deletions.
35 changes: 23 additions & 12 deletions languages/bash.scm
Original file line number Diff line number Diff line change
Expand Up @@ -276,35 +276,43 @@
)

(if_statement
. _ "then"
.
_
"then"
[(command) (list) (pipeline) (compound_statement) (subshell) (redirected_statement) (variable_assignment)] @append_hardline
.
"\n"
)

(elif_clause
. _ "then"
.
_
"then"
[(command) (list) (pipeline) (compound_statement) (subshell) (redirected_statement) (variable_assignment)] @append_hardline
.
"\n"
)

(else_clause
. "else"
.
"else"
[(command) (list) (pipeline) (compound_statement) (subshell) (redirected_statement) (variable_assignment)] @append_hardline
.
"\n"
)

(case_item
. _ ")"
.
_
")"
[(command) (list) (pipeline) (compound_statement) (subshell) (redirected_statement) (variable_assignment)] @append_hardline
.
"\n"
)

(do_group
. "do"
.
"do"
[(command) (list) (pipeline) (compound_statement) (subshell) (redirected_statement) (variable_assignment)] @append_hardline
.
"\n"
Expand All @@ -324,7 +332,7 @@
)

(pipeline
[(_) "|" "|&" ] @append_space
[(_) "|" "|&"] @append_space
.
_
)
Expand Down Expand Up @@ -418,7 +426,8 @@
[
(if_statement)
(elif_clause)
] "then" @append_hardline @append_indent_start
]
"then" @append_hardline @append_indent_start

; New line after "else" and start indent block
(else_clause
Expand All @@ -442,7 +451,6 @@
";"* @do_nothing
.
"then" @prepend_delimiter @prepend_space

(#delimiter! ";")
)

Expand All @@ -459,16 +467,20 @@
; in the context of a (test_command); it does work in other contexts
; See https://github.com/tweag/topiary/pull/155#issuecomment-1364143677
(binary_expression
left: _ @append_space
right: _ @prepend_space
left: _ @append_space
right: _ @prepend_space
)

;; Case Statements

; Indentation block between the "in" and the "esac"
(case_statement
.
"case" . _ . "in" @append_hardline @append_indent_start
"case"
.
_
.
"in" @append_hardline @append_indent_start
_
"esac" @prepend_hardline @prepend_indent_end
.
Expand Down Expand Up @@ -523,7 +535,6 @@
";"* @do_nothing
.
(do_group) @prepend_delimiter @prepend_space

(#delimiter! ";")
)

Expand Down
2 changes: 1 addition & 1 deletion languages/nickel.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(
(comment) @append_input_softline
.
[ "," ";" ]* @do_nothing
["," ";"]* @do_nothing
)

; Surround spaces
Expand Down
85 changes: 45 additions & 40 deletions languages/ocaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@
(exception_definition)
(external)
(floating_attribute)
; equivalence class
(include_module)
(include_module_type)
; start equivalence class
(include_module)
(include_module_type)
; end equivalence class
(inheritance_definition)
(inheritance_specification)
(instance_variable_definition)
Expand Down Expand Up @@ -98,9 +99,10 @@
; Append line break after module include, except if it's alone in a single-lined struct
(
[
; equivalence class
; start equivalence class
(include_module)
(include_module_type)
; end equivalence class
] @append_hardline
.
"end"? @do_nothing
Expand All @@ -109,9 +111,10 @@
"struct"
.
[
; equivalence class
; start equivalence class
(include_module)
(include_module_type)
; end equivalence class
] @append_spaced_softline
.
"end"
Expand Down Expand Up @@ -203,28 +206,28 @@

; Those keywords are not expected to come right after an open parenthesis.
[
"as"
"constraint"
"do"
"done"
"downto"
"else"
"in"
"nonrec"
"of"
"rec"
"then"
"to"
"virtual"
"when"
"with"
"|"
"->"
"<-"
"+="
":="
":>"
"::"
"as"
"constraint"
"do"
"done"
"downto"
"else"
"in"
"nonrec"
"of"
"rec"
"then"
"to"
"virtual"
"when"
"with"
"|"
"->"
"<-"
"+="
":="
":>"
"::"
] @prepend_space

; let-like and and-like operators are only followed by a closing parenthesis
Expand Down Expand Up @@ -431,10 +434,11 @@
(field_get_expression)
(hash_type)
(labeled_argument)
; equivalence class
(extended_module_path)
(module_path)
(module_type_path)
; start equivalence class
(extended_module_path)
(module_path)
(module_type_path)
; end equivalence class
(number)
(parenthesized_expression)
(parenthesized_pattern)
Expand Down Expand Up @@ -477,10 +481,11 @@
(field_get_expression)
(local_open_pattern)
(labeled_argument)
; equivalence class
(extended_module_path)
(module_path)
(module_type_path)
; start equivalence class
(extended_module_path)
(module_path)
(module_type_path)
; end equivalence class
(number)
(parenthesized_expression)
(parenthesized_pattern)
Expand Down Expand Up @@ -522,7 +527,6 @@
] @append_space
)


; Some kinds of colons should have a space in front.
(
[
Expand Down Expand Up @@ -820,9 +824,10 @@
[
(value_specification)
(type_definition)
; equivalence class
(include_module)
(include_module_type)
; start equivalence class
(include_module)
(include_module_type)
; end equivalence class
] @append_spaced_softline
)

Expand Down Expand Up @@ -1497,5 +1502,5 @@
(
(comment) @append_input_softline
.
[ "," ";" ]* @do_nothing
["," ";"]* @do_nothing
)
4 changes: 2 additions & 2 deletions languages/rust.scm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
(
(block_comment) @append_input_softline
.
[ "," ";" ]* @do_nothing
["," ";"]* @do_nothing
)

; Append line breaks. If there is a comment following, we don't add anything,
Expand Down Expand Up @@ -101,7 +101,7 @@
";"
] @append_spaced_softline
.
[ (block_comment) (line_comment) ]* @do_nothing
[(block_comment) (line_comment)]* @do_nothing
)

; Prepend softlines before dots
Expand Down
4 changes: 2 additions & 2 deletions languages/toml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
)

(table
[ (bare_key) (dotted_key) ]
[(bare_key) (dotted_key)]
.
"]" @append_hardline
)

(table_array_element
[ (bare_key) (dotted_key) ]
[(bare_key) (dotted_key)]
.
"]]" @append_hardline
)
Expand Down

0 comments on commit e928fca

Please # to comment.