fixed grammar, grammar injections, wip topiary formatter
This commit is contained in:
112
tree-sitter/queries/topiary.scm
Normal file
112
tree-sitter/queries/topiary.scm
Normal file
@@ -0,0 +1,112 @@
|
||||
; do not format inside these
|
||||
[(string_literal)
|
||||
(char_literal)
|
||||
(comment)
|
||||
(doc_comment)
|
||||
] @leaf
|
||||
|
||||
; TODO: word wrapping in comments
|
||||
|
||||
(definition) @allow_blank_line_before
|
||||
|
||||
(doc_comment_value) @append_hardline
|
||||
(doc_comment) @prepend_hardline @append_hardline
|
||||
|
||||
(comment) @append_hardline
|
||||
|
||||
(let_binding
|
||||
"let" @prepend_spaced_softline @append_space
|
||||
"=" @prepend_space @append_space ; @append_spaced_softline
|
||||
value: (_) @prepend_indent_start @append_indent_end
|
||||
body: (_) @prepend_hardline)
|
||||
|
||||
; TODO: report assertion error
|
||||
;(await_binding
|
||||
; body: (_) @prepend_hardline)
|
||||
|
||||
(def
|
||||
":" @prepend_space @append_spaced_softline
|
||||
signature: (_) @prepend_spaced_softline @prepend_indent_start @append_indent_end)
|
||||
|
||||
(def
|
||||
"=" @prepend_space @append_spaced_softline @append_indent_start
|
||||
value: (_) @append_indent_end)
|
||||
|
||||
(def "def" @append_space)
|
||||
|
||||
(if_expr
|
||||
"if" @prepend_space @append_space
|
||||
"then" @prepend_space @append_spaced_softline
|
||||
then: (_) @prepend_indent_start @append_indent_end @append_hardline
|
||||
"else" @prepend_space @append_spaced_softline
|
||||
else: (_) @prepend_indent_start @append_indent_end)
|
||||
|
||||
((match_arm) @append_hardline . (match_arm))
|
||||
(match_arm
|
||||
"->" @append_spaced_softline @prepend_indent_start @append_indent_end)
|
||||
(match_expr
|
||||
"|" @append_space)
|
||||
(match_expr
|
||||
"match" @append_space
|
||||
"with" @prepend_space @append_hardline
|
||||
. (match_arm) @prepend_indent_start @append_indent_end)
|
||||
|
||||
; add newline between two consecutive definitions
|
||||
((definition) @append_hardline . (definition))
|
||||
|
||||
(list_expression
|
||||
"," @append_spaced_softline)
|
||||
(list_expression
|
||||
"[" @append_empty_softline
|
||||
"]" @prepend_empty_softline)
|
||||
(list_expression) @prepend_space @append_space
|
||||
|
||||
(atom
|
||||
"(" @append_empty_softline
|
||||
")" @prepend_empty_softline)
|
||||
|
||||
(extensible_union
|
||||
"extensible" @append_space
|
||||
"union" @append_space)
|
||||
|
||||
(extend_decl
|
||||
"extend" @append_space
|
||||
"with" @prepend_spaced_softline @append_space
|
||||
tag: (_) @append_space)
|
||||
|
||||
(atom
|
||||
"(" @delete
|
||||
. (expression (atom))
|
||||
. ")" @delete)
|
||||
|
||||
(full_partial_type_definition
|
||||
"type" @append_space
|
||||
"=" @prepend_space @append_spaced_softline)
|
||||
|
||||
(type_definition
|
||||
"[" @prepend_space
|
||||
"]" @append_space)
|
||||
(type_definition
|
||||
"," @append_space)
|
||||
(type_definition
|
||||
arg: (_) @append_space)
|
||||
(type_definition
|
||||
"type" @append_space
|
||||
"=" @prepend_space @append_spaced_softline)
|
||||
|
||||
(function_call
|
||||
"," @append_spaced_softline)
|
||||
|
||||
(record_expr_field
|
||||
":" @append_spaced_softline)
|
||||
(record_expr
|
||||
"," @append_spaced_softline)
|
||||
(record_expr
|
||||
"{" @append_empty_softline
|
||||
"}" @prepend_empty_softline)
|
||||
|
||||
; TODO: unify binary exprs
|
||||
; TODO: scopes
|
||||
; TODO: non-atom exprs
|
||||
; TODO: types
|
||||
; TODO: disable format regions
|
Reference in New Issue
Block a user