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

Add support to @nospecialize in function arguments

Open ronisbr opened this issue 2 years ago • 2 comments

Hi!

First of all, thank you very much for adding support for Julia in tree-sitter!

I think the current version of the grammar does not support the macro @nospecialize in function arguments like:

function teste(
    a,
    (@nospecialize b),
    c
)
    return a, b, c
end

The grammar says that there is an error in this snippet, but it is a valid Julia code.

ronisbr avatar Jan 02 '23 01:01 ronisbr

Yes, "open" macros in function parameters won't parse correctly (even if enclosed in parenthesis), but using function-like macros works OK:

function teste(
    a,
    @nospecialize(b),
    c
)
    return a, b, c
end

Hopefully this isn't very inconvenient.


The reason why only one of the two is allowed:

  • The grammar makes some effort to distinguish formal parameters from arguments (for static tools like smart renaming, not because Julia does it).
  • function-like macros are much easier to parse.
  • Using function-like macros as parameters is overwhelmingly more common than using open macros.

savq avatar Jan 02 '23 04:01 savq

Hi @savq !

I think the proposed work around is fine! Thank you very much!

ronisbr avatar Jan 02 '23 18:01 ronisbr