JuliaLang / JuliaLang/JuliaSyntax.jl

Allow whitespace in macros wrapped by parenthesis

Open
#436 1 comment 3 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
293
Forks
50
PR merge metrics
No merged PRs in 30d

Description

Copying from https://github.com/JuliaLang/julia/issues/52842:

Minimal example:
```julia
macro var"let"(bindings, body)
bindings.head == :tuple || error("malformed let bindings $bindings")
bindings.head = :block
esc(Expr(:let, bindings, body))
end
```
```julia
julia> (@let (x=1, y=2) (x + y))
3

julia> (@let (x=1, y=2)
(x + y))
ERROR: ParseError:
# Error @ REPL[14]:1:17
(@let (x=1, y=2)
# └ ── whitespace is not allowed here
Stacktrace:
[1] top-level scope
@ none:1
```

Kinda a weird case, but I was thinking about how it'd be nice to be able to use the form `(@foo x y)` instead of `@foo(x, y)` to avoid having to write commas, but currently the parser demands that there's no whitespace in the middle of a macro arguments.

Maybe a more realistic example of where one might want to do this would be
```julia
julia> (@inline
function foo(x)
x + 1
end)
ERROR: ParseError:
# Error @ REPL[16]:2:1
(@inline
function foo(x)
└────────────┘ ── Expected `)`
Stacktrace:
[1] top-level scope
@ none:1
```

Is this something we could reasonably allow? I guess the worry is that it could alternatively be interpreted as `(@foo(x); y)` instead of `(@foo(x, y))`, but I think the parsing as `(@foo(x, y))` is more consistent with how we handle infix operators, e.g.
```julia
julia> (1
+2)
3
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.