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

Weird parsing of quoted macro names? #26750

Open
phipsgabler opened this issue Apr 8, 2018 · 1 comment
Open

Weird parsing of quoted macro names? #26750

phipsgabler opened this issue Apr 8, 2018 · 1 comment
Labels
macros @macros parser Language parsing and surface syntax

Comments

@phipsgabler
Copy link
Contributor

I stumbled upon this in 0.6.0 -- so maybe this has been changed in the mean time. Or maybe it's not weird at all, but it surprised me...

Basically, the following error came unexpectedly (I used it in actual syntax, the outer quoting is just for demonstration):

julia> :(simd ? :@simd : :@identity)
ERROR: syntax: space not allowed after ":" used for quoting

This can be fixed by using

julia> :(simd ? :(@simd) : :@identity)
:(if simd
        $(Expr(:quote, :(@simd)))
    else 
        $(Expr(:quote, :(@identity)))
    end)

I compared some other things, and the first one of these is definitely weird, too, but explains the above error:

julia> :(:@simd + 2)
:($(Expr(:quote, :(@simd +2))))

julia> :(:simd + 2)
:(:simd + 2)

julia> :(:(@simd) + 2)
:($(Expr(:quote, :(@simd))) + 2)

It seems that the @ makes the parsing of the following elements greedier?


Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.9.1 (ORCJIT, skylake)

@ararslan ararslan added parser Language parsing and surface syntax macros @macros labels Apr 8, 2018
@bramtayl
Copy link
Contributor

Your first statement is parsing as

(simd ? :(@simd : :@identity))

Which is why you need to specify the parens around :(@simd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macros @macros parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants