Input parsing for macros without "parantheses"

Let’s consider the macro @mymacro which parses some input arguments which are separated by commas as shown below.

macro mymacro(expr...)
    #   ... does something with expr
    return expr
end

@mymacro(x' = x, x∈X, dim=1)

If I use parentheses around the input argument, they are parsed as a Tuple, i.e. (:(x' = x), :(x ∈ X), :(dim = 1)) which is exactly what I like to obtain.

However, if I call the macro like this

@mymacro x' = x, x∈X, dim=1

because I like to leave out the parentheses which created to Tuple to reduce the verbosity of the macro, the input argument are parsed totally different. Because the precedence of = is higher than the one of ,, the inputs are parsed as (:(x' = ((x, x ∈ X, dim) = 1)),).

Is there a “best” or an “official” way to transform the parsed input (:(x' = ((x, x ∈ X, dim) = 1)),) obtaining from calling the macro without parantheses to the desired (:(x' = x), :(x ∈ X), :(dim = 1)) for an arbitrary number of comma separated inputs?

1 Like

Without parens, macros “arguments” are space-separated. So call it without the commas.

3 Likes

Thank you very much for your super fast answer! I missed this part of the documentation and tried to do some clever input parsing :see_no_evil: