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

Improve AST structure for type parameters

Open mads-hartmann opened this issue 7 years ago • 0 comments

From a discussion during #1 :

Now that I'm seeing how much structure there is to type parameters, I think we should tweak their structure so that there is always a visible syntax node corresponding to each parameter (as opposed to the identifier and upper_bound node appearing as siblings within the type_parameters node).

==================
Type parameters
==================

class A[B, +C <: D, -E : F : G]

---

(compilation_unit
  (class_definition
    (identifier)
    (type_parameters
      (invariant_type_parameter (type_identifier))
      (covariant_type_parameter
        (type_identifier)
        (upper_bound (type_identifier)))
      (contravariant_type_parameter
        (type_identifier)
        (context_bound (type_identifier))
        (context_bound (type_identifier))))))

Does that make sense? We could have a hidden helper rule called _type_parameter that is shared between the three. In addition, we should add the _type_parameter to the inline section of the grammar. That will avoid actually creating that node at runtime for performance reasons.

mads-hartmann avatar Feb 25 '18 07:02 mads-hartmann