Skip to content

end clause capture/grouping #275

Open
@KaranAhlawat

Description

@KaranAhlawat

Commit of tree-sitter-scala you tested this on

236c7b2

A code sample showing the error

object C:
  given C =
    new C:
      def f = "!"
      end f
    end new
  end given
end C

Show the error node

(object_definition object body: (identifier)
  (template_body :
   (given_definition given return_type: (type_identifier) =
    body: 
     (instance_expression new arguments: (type_identifier)
      (template_body :
       (function_definition def name: (identifier) = body: (string))
       end _end_ident)))
   end new end given))
 end _end_ident

What do you expect the tree to look like

There is no ERROR node, but I strongly believe that the end clause of a given node should be captured as a child of that node (or some similar construct).
Particularly, looking at the second last line of the output, we can see that end new and end given are siblings. Meanwhile, the code suggests that new block is a child of the given block.
The improper grouping of the end clauses makes it so that a lot more of the parse tree has to be examined to find the proper indentation for that end clause.

For instance, you have to check if you're not already correctly indented by checking if the previous sibling is a matching block to the end clause. But since multiple nested end clauses are just represented as sibling nodes, you have to walk through all the previous children, and then you go one level up and so on.

Where are you experiencing this error?

treesit (GNU Emacs 29+)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/scala3Scala 3 syntaxbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions