diff --git a/tree-sitter/grammar.js b/tree-sitter/grammar.js index 47901b5..2b6091e 100644 --- a/tree-sitter/grammar.js +++ b/tree-sitter/grammar.js @@ -115,7 +115,7 @@ module.exports = grammar({ type_atom: $ => choice( $.just_type, - $.partial_type, + $.partial_type, seq('(', $.type, ')'), $.record_type, ), diff --git a/tree-sitter/queries/topiary.scm b/tree-sitter/queries/topiary.scm index c32febf..d666d32 100644 --- a/tree-sitter/queries/topiary.scm +++ b/tree-sitter/queries/topiary.scm @@ -20,6 +20,13 @@ value: (_) @prepend_indent_start @append_indent_end @prepend_begin_measuring_scope @append_end_measuring_scope body: (_) @prepend_hardline (#scope_id! "def")) +; ; remove `in` +; (let_binding +; "in" @delete) +; add `in` +(let_binding + value: (_) @append_delimiter @append_space + (#delimiter! " in")) (def ":" @prepend_space @append_spaced_softline @@ -105,16 +112,22 @@ (function_call "," @append_spaced_softline) + + +; ==== SIMILAR TO record_type ==== (record_expr_field ":" @append_spaced_softline) (record_expr "," @append_spaced_softline) (record_expr - "{" @append_empty_softline - "}" @prepend_empty_softline) + "{" @append_empty_softline @append_begin_measuring_scope @append_indent_start + "}" @prepend_empty_softline ; TODO: make this one configurable; also see lists and others + @append_end_measuring_scope @prepend_indent_end + (#scope_id! "record_expr")) ; remove trailing comma (record_expr "," @delete . "}") +; ====^^^^^^^^^^^^======== (atom "(" @append_begin_measuring_scope @append_empty_softline @append_indent_start @@ -133,12 +146,6 @@ "->" @prepend_space @append_spaced_softline body: (_) @prepend_indent_start @append_indent_end) - -(type_atom - "(" @append_begin_measuring_scope @append_empty_softline @append_indent_start - ")" @append_end_measuring_scope @prepend_empty_softline @append_indent_end - (#scope_id! "paren_type")) - (tag_expr tag: (_) @append_space) @@ -146,7 +153,54 @@ left: (_) @append_spaced_softline right: (_) @prepend_space) -; TODO: types + + + +(type_atom + "(" @append_begin_measuring_scope @append_empty_softline @append_indent_start + ")" @append_end_measuring_scope @prepend_empty_softline @append_indent_end + (#scope_id! "paren_type")) + +(fn_type + "->" @prepend_space @append_spaced_softline) + + +; ==== SIMILAR TO record_expr ==== +(record_type_field + ":" @append_spaced_softline) +(record_type + "," @append_spaced_softline) +(record_type + "{" @append_empty_softline @append_begin_measuring_scope @append_indent_start + "}" @prepend_empty_softline ; TODO: make this one configurable; also see lists and others + @append_end_measuring_scope @prepend_indent_end + (#scope_id! "record_type")) +; remove trailing comma +(record_type + "," @delete . "}") +; ====^^^^^^^^^^^^======== + +; 'Tag Unit -> 'Tag +(tagged_type + type: (type_atom (just_type (path + (identifier) @delete + (#eq? @delete "Unit"))))) +(tagged_type + type: (_) @prepend_space) + +(type_atom + "(" @delete + . (type (type_atom)) + . ")" @delete) + +; TODO: +; $.union_type, +; $.partial_union_type, +; $.parametrized_type, +; $.with_type, +; $.recursive_type, + + ; TODO: disable-format-regions ; TODO: folding query ; TODO: wrap confusing expressions (in terms of precedence) in parens