gleam-lang / tree-sitter-gleam

🌳 A tree-sitter grammar for the Gleam programming language
Apache License 2.0
78 stars 15 forks source link

Add support for annotating argument in use() syntax #56

Closed marcinkoziej closed 1 year ago

marcinkoziej commented 1 year ago

Assuming wrapper accepts a callback with a generic argument (eg fn (event) -> Nil):

I can do this:

fn test() {
  wrapper(fn (event : ClickEvent) {  do_something(event) })
}

but I also can do this:

fn test() {
  use event : ClickEvent <- wrapper()
  do_something(event)
}

TS parsing will break down on such code - removal of : ClickEvent fixes it, but it's necessary.

lpil commented 1 year ago

Sorry to butt in, I'm not the maintainer of this grammar, but is it not supported? Looks like it is getting highlighted correctly in your code there, and GitHub uses tree sitter.

marcinkoziej commented 1 year ago

I have just created a test for it:

$ npm run test 

> tree-sitter-gleam@0.27.0 test
> tree-sitter test

  expressions:
(...)
    ✗ Use 
(...)

1 failure:

expected / actual

  1. Use:

    (source_file
      (use
        (function_call
          (identifier)
          (arguments)))
      (use
        (identifier)
        (function_call
          (identifier)
          (arguments)))
      (use
        (identifier)
        (identifier)
        (identifier)
        (identifier)
        (identifier)
        (function_call
          (identifier)
          (arguments)))
      (use
        (tuple_pattern
          (identifier)
          (identifier))
        (identifier))
      (use
        (ERROR  <---- this is red :)
          (identifier))  
        (record_pattern
          (constructor_name)) <--- red until here
        (identifier)  <----  this is green
        (type
          (type_identifier)) <--- green
        (function_call
          (identifier)
          (arguments))))

In both helix and emacs (and I've pulled grammars for both I get):

Screenshot from 2023-06-01 09-05-10 Screenshot from 2023-06-01 09-04-56