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

AST of short form functions #465

Closed
c42f opened this issue Jul 19, 2024 · 2 comments · Fixed by #466
Closed

AST of short form functions #465

c42f opened this issue Jul 19, 2024 · 2 comments · Fixed by #466

Comments

@c42f
Copy link
Member

c42f commented Jul 19, 2024

A pain point when writing macros is detecting all the types of things which might be lowered to functions and correctly extracting the formal arguments. This is due to

  1. Existence of both short form and long form function definitions
  2. The argument lists of anonymous functions being parsed into varying inconsistent Expr forms

JuliaSyntax already deals with part (2) of this.

I wonder if we should also deal with part (1) by emitting a clearer AST.

Currently we have

julia> parsestmt(SyntaxNode, "f()::T = 1")
line:col│ tree                                   │ file_name
   1:1  │[=]
   1:1  │  [::-i]
   1:1  │    [call]
   1:1  │      f
   1:6  │    T
   1:101

But it would be easy to change this into

julia> parsestmt(SyntaxNode, "f() = 1")
line:col│ tree                                   │ file_name
   1:1  │[function-=]
   1:1  │  [call]
   1:1  │    f
   1:71

And to have a syntax flag "=" set on the function node to indicate it was short-form syntax.

@c42f c42f changed the title Parsing of short form functions AST of short form functions Jul 19, 2024
@c42f
Copy link
Member Author

c42f commented Jul 19, 2024

Well this was easy and I nerd sniped myself. so I just went and implemented it.

@JeffBezanson thoughts? Could be nice if macro authors didn't have to simulate this bit of lowering. It does depart from the surface syntax a little by adding semantics during parsing. That's always a hard call but I feel like the AST might be an improvement in this case.

@c42f
Copy link
Member Author

c42f commented Jul 23, 2024

Managed to chat to Jeff about this and he seems good with it. So I think we go for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant