Skip to content

Allow decorators before and in type_declaration and let_binding #133

@aspeddro

Description

@aspeddro
@deriving
type foo = {
  bar: string
}
@deriving
and t = {bar: int}

What I tried but without success:

Add repeat($.decorator) in _type_declaration

_type_declaration: $ => seq(
      $.type_identifier,
      optional($.type_parameters),
      optional(seq(
        choice('=', '+='),
        optional('private'),
        $._type,
        optional(seq(
+          repeat($.decorator),
          'and',
          $._type_declaration
        )),
      )),
    ),
yarn tree-sitter generate
yarn tree-sitter parse ../test/file.res
decorated [0, 0] - [3, 1]
  decorator [0, 0] - [0, 9]
    decorator_identifier [0, 1] - [0, 9]
  type_declaration [1, 0] - [3, 1]
    type_identifier [1, 5] - [1, 8]
    record_type [1, 11] - [3, 1]
      record_type_field [2, 2] - [2, 13]
        property_identifier [2, 2] - [2, 5]
        type_annotation [2, 5] - [2, 13]
          type_identifier [2, 7] - [2, 13]
ERROR [4, 0] - [5, 7]
  decorator [4, 0] - [4, 9]
    decorator_identifier [4, 1] - [4, 9]
  ERROR [5, 4] - [5, 5]
expression_statement [5, 8] - [5, 18]
  record [5, 8] - [5, 18]
    record_field [5, 9] - [5, 17]
      property_identifier [5, 9] - [5, 12]
      value_identifier [5, 14] - [5, 17]

This works.

@deriving
type foo = {
  bar: string
} @deriving
and t = {bar: int}

And that works too:
Note Add a space after }

@deriving
type foo = {
  bar: string
+} 
@deriving
and t = {bar: int}

Maybe related this?

https://github.com/nkrkv/tree-sitter-rescript/blob/72fb207564e3d82f6edd974bce580535b183eeec/src/scanner.c#L208-L211

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions