Skip to content

Allow whitespace in macros wrapped by parenthesis

Open

Description

Copying from JuliaLang/julia#52842:

Minimal example:

 macro var"let"(bindings, body)
    bindings.head == :tuple || error("malformed let bindings $bindings")
    bindings.head = :block
    esc(Expr(:let, bindings, body))
end
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> (@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> (1
       +2)
3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions