-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Macros juxtaposed with strings incorrectly(?) get raw string literal #509
Comments
This is due to a lexing difficulty: we need to know which strings are raw while lexing, and we use lexer state to guess (ie, a heuristic based on the previous token). In this case, it fails so we need to fix that. julia> collect(JuliaSyntax.Tokenize.tokenize("@m\"str\$x\""))
6-element Vector{JuliaSyntax.Tokenize.RawToken}:
0-0 @
1-1 Identifier
2-2 "
3-7 String
8-8 "
9-8 EndMarker
julia> collect(JuliaSyntax.Tokenize.tokenize("@m \"str\$x\""))
9-element Vector{JuliaSyntax.Tokenize.RawToken}:
0-0 @
1-1 Identifier
2-2 Whitespace
3-3 "
4-6 String
7-7 $
8-8 Identifier
9-9 "
10-9 EndMarker I think it'd be good enough to track the two previous tokens and check whether one was an (Unfortunately, Julia also allows syntax like |
😢 |
🤔 I actually think you could leave the Lexer as-is. Given the above tokens, i think we could still raise an Exception later on in parsing/lowering from the juxtaposed macro call and the string? That would be consistent with the 1.6 behavior:
I think you could parse
into either of these expressions, which could both error?: @(Identifier"String") # This seems to be what they parsed in 1.6, where Identifier"String" lowers into `@Identifier_str"String"` (@Identifier"String") # We could just disallow juxtaposing a macrocall with a string? It seems like both of those approaches would be robust to qualified names? |
But that said:
+1 |
If you directly juxtapose a macro with a string, the macro is supplied a raw literal version of the string as if the macro were a string macro, even though it's not.
Here is an example:
I think this is a bug. On julia 1.6, which I happen to have installed and which doesn't yet have JuliaSyntax, we get this error instead:
I believe the mistake is that the macro is being parsed as if it's a string macro, since the input matches what a string macro would see:
I see the current behavior on both julia 1.10 and 1.12:
The text was updated successfully, but these errors were encountered: