From b6aa7163581ba7fba2a9c40e93ff94ae97c702a5 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Thu, 5 Oct 2023 10:01:19 +0200 Subject: [PATCH] Fix formatting of bitfields with literal fields --- Cargo.lock | 2 +- corpus/bitfield.spicy | 6 ++++++ corpus/bitfield.spicy.expected | 6 ++++++ src/query.scm | 10 +++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5444247..b0b5475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1064,7 +1064,7 @@ dependencies = [ [[package]] name = "tree-sitter-spicy" version = "0.1.0" -source = "git+https://github.com/bbannier/tree-sitter-spicy#e9ad86ec2a8325c680843c3d4b67d615d7aed630" +source = "git+https://github.com/bbannier/tree-sitter-spicy#39f159bff900090045dbd02a2618f6dfa4c7de04" dependencies = [ "cc", "tree-sitter", diff --git a/corpus/bitfield.spicy b/corpus/bitfield.spicy index 305de85..9900104 100644 --- a/corpus/bitfield.spicy +++ b/corpus/bitfield.spicy @@ -6,3 +6,9 @@ type X = unit { b: 0..8; # bar }; }; + +type X = bitfield(8) { + a: 0..3=2; + b: 4..7; + c: 7 = 1; + }; diff --git a/corpus/bitfield.spicy.expected b/corpus/bitfield.spicy.expected index 45459dd..7c54db4 100644 --- a/corpus/bitfield.spicy.expected +++ b/corpus/bitfield.spicy.expected @@ -6,3 +6,9 @@ type X = unit { b: 0..8; # bar }; }; + +type X = bitfield(8) { + a: 0..3 = 2; + b: 4..7; + c: 7 = 1; +}; diff --git a/src/query.scm b/src/query.scm index 759728e..2a42a02 100644 --- a/src/query.scm +++ b/src/query.scm @@ -322,14 +322,22 @@ (sink) ) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Bitfields. + ( "bitfield" (_) "{" @prepend_space ) +; All bitfield fields go on a new line. +(bitfield + (bitfield_field) @prepend_hardline +) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; Preprocessor macros +; Preprocessor macros. ; Empty lines before preprocessor blocks are fine. (preproc) @allow_blank_line_before