diff --git a/Cargo.lock b/Cargo.lock index 36f6908..cb8b988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1104,7 +1104,7 @@ dependencies = [ [[package]] name = "tree-sitter-spicy" version = "0.0.1" -source = "git+https://github.com/bbannier/tree-sitter-spicy#97a998e5d07a53f5b7f4e05d386ae58676699960" +source = "git+https://github.com/bbannier/tree-sitter-spicy#c4c6900cba1fa80b32ddd7a495692d87a96ada9c" dependencies = [ "cc", "tree-sitter", diff --git a/corpus/unit.spicy b/corpus/unit.spicy index ec384a0..8ae0a1d 100644 --- a/corpus/unit.spicy +++ b/corpus/unit.spicy @@ -166,3 +166,15 @@ type Test = unit { on b %error {} }; on Test::b(msg: string) %error {} + +# Unit if/else blocks. +type X = unit { + if (True) { + a1: bytes &size=2; + } &max-size=42 &requires=True; + + if (True) { + a1: bytes &size=2; + a1: bytes &size=2; + } else {} &max-size=42 &requires=True; +}; diff --git a/corpus/unit.spicy.expected b/corpus/unit.spicy.expected index 67907d4..8ce360e 100644 --- a/corpus/unit.spicy.expected +++ b/corpus/unit.spicy.expected @@ -191,3 +191,16 @@ type Test = unit { on b %error {} }; on Test::b(msg: string) %error {} + +# Unit if/else blocks. +type X = unit { + if (True) { + a1: bytes &size=2; + } &max-size=42 &requires=True; + + if (True) { + a1: bytes &size=2; + a1: bytes &size=2; + } else { + } &max-size=42 &requires=True; +}; diff --git a/src/query.scm b/src/query.scm index b75effb..27a7dc2 100644 --- a/src/query.scm +++ b/src/query.scm @@ -261,6 +261,7 @@ (comment) (type_decl) (field_decl) + (unit_if_else) (unit_switch) (struct_decl) (sink_decl) @@ -371,6 +372,25 @@ ) @delete ) +; Unit `if`/`else` blocks. +(unit_if_else + "if" @append_space + "{" @prepend_space + ("else" @prepend_space @append_space)? +) +(unit_if_else + "{" @append_indent_start @append_hardline + . + (field_decl)* ; List explicitly so we match the correct {} pair. + . + "}" @prepend_indent_end @prepend_hardline +) +(unit_if_else + (field_decl) @append_empty_softline + . + (comment)? @do_nothing +) + ; Unit `switch` statement. (unit_switch (expression) ")" @append_space)