From d15650469203a749d02764a936a32e5608536444 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Thu, 25 Jul 2024 00:48:59 +0200 Subject: [PATCH] Fix interpolated vars as `as`-aliases --- src/runestone.jl | 8 +++++++- test/runtests.jl | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/runestone.jl b/src/runestone.jl index 4415f89..1a1d8d7 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -1106,7 +1106,13 @@ function format_as(ctx::Context, node::Node) # Alias-identifier idx += 1 kid = kids[idx] - @assert kind(kid) === K"Identifier" + @assert kind(kid) in KSet"Identifier $" + if !is_leaf(kid) + @assert kind(first_leaf(kid)) !== K"Whitespace" + end + if kind(kid) === K"$" + @assert findlast(x -> x in KSet"quote macrocall", ctx.lineage_kinds) !== nothing + end accept_node!(ctx, kid) any_changes && push!(kids′, kid) # Reset stream diff --git a/test/runtests.jl b/test/runtests.jl index b6bf8a1..9ec3181 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -825,6 +825,10 @@ end "$(verb) A: a, c as d" end end + # Interpolated aliases in quotes and macrocalls + @test format_string("quote\nimport A as \$a\nend") == "quote\n import A as \$a\nend" + @test format_string(":(import A as \$a)") == ":(import A as \$a)" + @test format_string("@eval import A as \$a") == "@eval import A as \$a" end @testset "spaces in export/public" begin