JuliaLang / JuliaSyntax.jl

The Julia compiler frontend
Other
266 stars 32 forks source link

Triple-quoted var does not work #399

Open Liozou opened 6 months ago

Liozou commented 6 months ago

Using the var"..." syntax to construct a variable fails when using triple quotes, i.e. var"""...""". This is a regression compared to the previous parser so I believe this is a parsing problem that belongs here, but let me know if I should open this issue on the main Julia repo instead.

In julia v1.9 and before:

julia> var"""x""" = 12
12

julia> x
12

whereas in julia v1.10 and later:

julia> var"""x""" = 12
ERROR: LoadError: UndefVarError: `@var_str` not defined
in expression starting at REPL[1]:1
Liozou commented 6 months ago

For a tad more context, the documentation specifies in the Parsing / AST oddities and warts section

Triple quoted var"""##""" identifiers are allowed.

so the current behaviour is clearly a bug. The rest of the line says:

But it's not clear these are required or desired given that they come with the complex triple-quoted string deindentation rules.

so I guess we could also take this opportunity to address the deindentation rule behaviour in the var"""...""" syntax? I believe the only important thing is to document the chosen behaviour somewhere, typically in https://docs.julialang.org/en/v1/manual/strings/#Triple-Quoted-String-Literals or at least in the devdocs at https://docs.julialang.org/en/v1/devdocs/ast/#Strings.

Using var with a triple quote is rare enough, I don't think there are many (or any?) uses with multiple line anyway so the choice of the behaviour will probably have little to no impact. But it should nevertheless have a clear semantics.

I would err towards keeping the same behaviour as the previous parser and all the other @whatever_str macros, i.e. keep the deindentation rule. No need to make an exception for something so niche.