How does the string pkg"..." work?

What magic is involved when I write

macro pkg_str(s)
    return esc(s)
@info pkg"Top of the morning to you, squire!"

Does the macro compiler “know” that this means “call @pkg_str when you see pkg as a string prefix”?

I think from here it just knows how to parse it correctly, using

1 Like

Thanks, Daniel. Did I miss this in the Julia manual? Or is it there somewhere?

1 Like

I’m not sure if it’s specifically mentioned in the docs. The only place I can see it is here Julia ASTs · The Julia Language which technically shows the parsing I guess.


Cool, you’re a :mage:

1 Like

Here’s where JuliaSyntax.jl parses makes macro calls out of literals, since it seems it’ll be in 1.10+: The handling of the input string as raw or standard seems to come in a subsequent parse_julia_literal call.

See the manual section on Non-Standard String Literals