tree-sitter-kotlin icon indicating copy to clipboard operation
tree-sitter-kotlin copied to clipboard

Annotations with commas cause errors

Open reddaly opened this issue 1 year ago • 1 comments

Example test case that fails:

==================
Comma in annotation property
==================

class EnvironmentSpec {
    @Option(
      names = ["--environment", "--env"],
      arity = "0..1",
      description = [
          "Which environment to use",
      ],
    )
    var environment: Environment
}

---

(source_file
  (class_declaration
    (type_identifier)
    (class_body
      (property_declaration
        (modifiers
          (annotation
            (constructor_invocation
              (user_type
                (type_identifier))
              (value_arguments
                (value_argument
                  (simple_identifier)
                  (collection_literal
                    (string_literal (string_content))
                    (string_literal (string_content))))
                (value_argument
                  (simple_identifier)
                  (string_literal (string_content)))
                (value_argument
                  (simple_identifier)
                  (collection_literal
                    (string_literal (string_content))
                  ))))))
        (binding_pattern_kind)
        (variable_declaration
          (simple_identifier)
          (user_type
            (type_identifier)))
      ))))

reddaly avatar Oct 08 '24 22:10 reddaly

Something like this might fix it:

// https://kotlinlang.org/spec/syntax-and-grammar.html#grammar-rule-collectionLiteral
    collection_literal: $ => seq(
      "[",
      $._expression,
      repeat(seq(",", $._expression)),
      optional(","),
      "]"),

reddaly avatar Oct 08 '24 22:10 reddaly