~rockorager/tree-sitter-hare

be449eac307d4268d4847bce459cc27f03fd3b74 — Tim Culverhouse 1 year, 6 months ago 678e76b
struct: add @packed

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
3 files changed, 42 insertions(+), 2 deletions(-)

A corpus/types.txt
M grammar.js
M queries/highlights.scm
A corpus/types.txt => corpus/types.txt +35 -0
@@ 0,0 1,35 @@
================================================================================
Struct
================================================================================

type foo = struct { x: int, y: int };
--------------------------------------------------------------------------------
(unit
  (type_declaration
    (identifier)
    (struct_type
      (struct_union_fields
        (struct_union_field
          (identifier)
          (integer_type))
        (struct_union_field
          (identifier)
          (integer_type))))))

================================================================================
Struct @packed
================================================================================

type foo = struct @packed { x: int, y: int };
--------------------------------------------------------------------------------
(unit
  (type_declaration
    (identifier)
    (struct_type
      (struct_union_fields
        (struct_union_field
          (identifier)
          (integer_type))
        (struct_union_field
          (identifier)
          (integer_type))))))

M grammar.js => grammar.js +6 -2
@@ 241,7 241,8 @@ module.exports = grammar({
    pointer_type: ($) =>
      choice(seq("*", $._type), seq("nullable", "*", $._type)),

    struct_type: ($) => seq("struct", "{", $.struct_union_fields, "}"),
    struct_type: ($) =>
      seq("struct", optional("@packed"), "{", $.struct_union_fields, "}"),
    union_type: ($) => seq("union", "{", $.struct_union_fields, "}"),

    struct_union_fields: ($) =>


@@ 526,7 527,10 @@ module.exports = grammar({
      )),

    error_propagation: ($) =>
      prec.left(PREC.ERROR, seq($._expression, field("operator", choice("?", "!")))),
      prec.left(
        PREC.ERROR,
        seq($._expression, field("operator", choice("?", "!"))),
      ),

    variadic_expression: ($) =>
      choice(

M queries/highlights.scm => queries/highlights.scm +1 -0
@@ 44,6 44,7 @@
 ] @function.builtin

[
 "@packed"
 (decl_attr)
 (fndec_attr)
 (fntype_attr)