Skip to content

Conversation

@c42f
Copy link
Member

@c42f c42f commented Jul 19, 2024

Fix #465 - see rationale there.

Fixing this turned out to be quite easy.

Compat:

  • This is a breaking change to the JuliaSyntax AST
  • Non-breaking for Expr

@c42f c42f changed the title Use K"function" for short form funtion AST Use K"function" for short form function AST Jul 19, 2024
@domluna
Copy link

domluna commented Jul 20, 2024

looks good to me. Does it handle all 4 of these?

f(x) = 10
f(x)::R = 10
f(x::T) where T = 10
f(x::T)::R where T = 10

@c42f c42f mentioned this pull request Jul 23, 2024
c42f added 3 commits July 25, 2024 08:09
This is semantically incorrect and will be caught by lowering. But
technically making it a parser error would be breaking :-(
This is a simple fix for the tests, but a better solution is to make
Expr equivalence more permissive to accommodate having better line
information in the new parser!
@c42f c42f force-pushed the caf/short-form-function-head branch from 6eab9b6 to 6694b89 Compare July 24, 2024 22:09
@c42f
Copy link
Member Author

c42f commented Jul 24, 2024

Does it handle all 4 of these?

Yes!

c42f added 3 commits July 29, 2024 15:33
This form isn't a short form function definition, so should be parsed
with `=` kind.
@c42f c42f merged commit 25f8eb2 into main Jul 30, 2024
@c42f c42f deleted the caf/short-form-function-head branch July 30, 2024 04:43
c42f added a commit to JuliaLang/julia that referenced this pull request Oct 17, 2025
…jl#466)

A pain point when writing macros is detecting all the types of things which might be lowered to functions. This is partly due to the existence of short form function definitions which in Julia's classic AST parse with `:(=)` rather than a `:function` head - to detect the meaning of `=`, one needs to traverse recursively into the left hand side of the expression.

This change modifies the parsing of short form functions to use the `K"function"` kind. A new syntax flag `SHORT_FORM_FUNCTION_FLAG` is set to enable AST consumers to detect short vs long form functions.
topolarity pushed a commit to JuliaLang/julia that referenced this pull request Nov 14, 2025
…jl#466)

A pain point when writing macros is detecting all the types of things which might be lowered to functions. This is partly due to the existence of short form function definitions which in Julia's classic AST parse with `:(=)` rather than a `:function` head - to detect the meaning of `=`, one needs to traverse recursively into the left hand side of the expression.

This change modifies the parsing of short form functions to use the `K"function"` kind. A new syntax flag `SHORT_FORM_FUNCTION_FLAG` is set to enable AST consumers to detect short vs long form functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AST of short form functions

2 participants