Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

end clause capture/grouping #275

Open
KaranAhlawat opened this issue Jun 3, 2023 · 2 comments
Open

end clause capture/grouping #275

KaranAhlawat opened this issue Jun 3, 2023 · 2 comments
Labels
area/scala3 Scala 3 syntax bug Something isn't working

Comments

@KaranAhlawat
Copy link
Contributor

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+)

@susliko
Copy link
Collaborator

susliko commented Jun 3, 2023

Thank you for reporting the issue @KaranAhlawat!

@susliko susliko added bug Something isn't working area/scala3 Scala 3 syntax labels Jun 3, 2023
@KaranAhlawat
Copy link
Contributor Author

Digging a bit more into it, it seems like nesting isn't the actual problem, as in some places that does work fine (nesting vals, within an object etc).
So, starting with looking at the given_definition and instance_expression might be a viable option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/scala3 Scala 3 syntax bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants