JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
44.94k stars 5.42k forks source link

Error parsing Cmds that interpolate Cmds #54592

Open zot opened 1 month ago

zot commented 1 month ago

This occurs in (at least) 1.6, 1.10, and 1.11. It looks like $ expressions inside grave quotes cannot contain grave quotes. Or at least there's a problem with these cases (which all produce different error messages):

 `a $(`b`)`
`a $(`b $(`c`)`)`
`a b $(` c d  $(` e f`)`)`
julia> `a $(`b`)`
ERROR: LoadError: UndefVarError: `@b_cmd` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
in expression starting at REPL[1]:1

julia> `a $(`b $(`c`)`)`
ERROR: LoadError: parsing command `)`: special characters "#{}()[]<>|&*?~;" must be quoted in commands
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] shell_parse(str::String, interpolate::Bool; special::String, filename::String)
   @ Base ./shell.jl:134
 [3] shell_parse
   @ ./shell.jl:31 [inlined]
 [4] var"@cmd"(__source__::LineNumberNode, __module__::Module, str::Any)
   @ Base ./cmd.jl:508
in expression starting at REPL[2]:1

julia> `a b $(` c d  $(` e f`)`)`
ERROR: ParseError:
# Error @ REPL[3]:1:9
`a b $(` c d  $(` e f`)`)`
#       └────────────────┘ ── extra tokens after end of expression
Stacktrace:
 [1] top-level scope
   @ none:1
fingolfin commented 1 month ago

Out of curiosity: What should `a $(`b`)`produce if not `a b`? And then why would one try to enter it in the former form when the latter is simpler?

BTW one can already do ```a $(`b`)``` (which is the same as a b)

zot commented 1 month ago

Just reporting a parser bug here. That expression should not produce an error.