While :(A.a"xx") is parsed as expected like below,
julia> dump(:(A.a"xx"))
Expr
head: Symbol macrocall
args: Array{Any}((3,))
1: Expr
head: Symbol .
args: Array{Any}((2,))
1: Symbol A
2: QuoteNode
value: Symbol @a_str
2: LineNumberNode
line: Int64 1
file: Symbol REPL[25]
3: String "xx"
:(:A.a"xx") with QuotedNode resulted into a bit cryptic error.
julia> :(:A.a"xx")
ERROR: syntax: cannot juxtapose string literal
It's something not expected as some similar uses of QuotedNode seem to work fine. Is this an intended behavior? Tested on Julia 1.4.2.
julia> dump(:(:A.a))
Expr
head: Symbol .
args: Array{Any}((2,))
1: QuoteNode
value: Symbol A
2: QuoteNode
value: Symbol a
julia> dump(:(:A.a(x, y)))
Expr
head: Symbol call
args: Array{Any}((3,))
1: Expr
head: Symbol .
args: Array{Any}((2,))
1: QuoteNode
value: Symbol A
2: QuoteNode
value: Symbol a
2: Symbol x
3: Symbol y
Just to be clear, the issue is about the precedence of quoting-: vs string literals? In general, for these kinds of odd cases, it's always better to use parentheses to indicate what you mean, but @JeffBezanson can chime in if he'd like to adjust the precedence relation here.
Not sure if this issue is only about precedence, since I tried some parentheses, still with no luck.
julia> dump(:((:A).a"xx"))
ERROR: syntax: cannot juxtapose string literal
julia> dump(:(:(A).a"xx"))
ERROR: syntax: cannot juxtapose string literal
Ok, I see what you're saying. The issue is this parse difference:
julia> dump(:((A).a"xx"))
Expr
head: Symbol macrocall
args: Array{Any}((3,))
1: Expr
head: Symbol .
args: Array{Any}((2,))
1: Symbol A
2: QuoteNode
value: Symbol @a_str
2: LineNumberNode
line: Int64 1
file: Symbol REPL[10]
3: String "xx"
julia> dump(:((:A).a"xx"))
ERROR: syntax: cannot juxtapose string literal
Stacktrace:
[1] top-level scope
@ none:1
I agree that looks a bit odd to me.
The idea is that the syntax A.b"..." is for using a string macro with a qualified name. What is (:A).a"XX" supposed to do?
Well, I wanted to have :A or something similar as a placeholder that could be later replaced by other symbols during macro processing.
The idea is that the syntax
A.b"..."is for using a string macro with a qualified name. What is(:A).a"XX"supposed to do?
I think the thing bothered me is that it just looks like a bit of "Spooky action at a distance", since it changes the interpretation of whether or not the thing is a string literal. Perhaps the only thing to do is to give a better parse error.
We could certainly change this to allow any dot expression juxtaposed before a string, and interpret it as a string macro call. Probably just one of those cases where we're giving an error to be conservative.
Most helpful comment
We could certainly change this to allow any dot expression juxtaposed before a string, and interpret it as a string macro call. Probably just one of those cases where we're giving an error to be conservative.