From 3645072700b02f9c66bd2158b1c914abcc6b337d Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Wed, 24 Jul 2024 02:02:46 +0200 Subject: [PATCH] Fix bug in formatting of export/public expressions with interpolated vars --- src/runestone.jl | 5 ++++- test/runtests.jl | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/runestone.jl b/src/runestone.jl index 2fc36a0..09a0196 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -974,12 +974,15 @@ function spaces_in_export_public(ctx::Context, node::Node) state = :expect_identifier elseif state === :expect_identifier state = :expect_comma - if kind(kid) in KSet"Identifier @ MacroName" + if kind(kid) in KSet"Identifier @ MacroName $" any_changes && push!(kids′, kid) accept_node!(ctx, kid) if kind(kid) === K"@" state = :expect_identifier end + if kind(kid) === K"$" + @assert findlast(x -> x === K"quote", ctx.lineage_kinds) !== nothing + end else @assert false end diff --git a/test/runtests.jl b/test/runtests.jl index 173361b..d8218ad 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ using Runic: Runic, format_string using Test: - @test, @testset, @test_broken, @inferred + @test, @testset, @test_broken, @inferred, @test_throws using JuliaSyntax: JuliaSyntax @@ -809,6 +809,10 @@ end @test format_string("$(verb) $(a)$(sp),\n$(b)") == "$(verb) $(a),\n $(b)" @test format_string("$(verb) \n$(a)$(sp),\n$(b)") == "$(verb)\n $(a),\n $(b)" end + # Interpolated identifiers (currently only expected in K"quote") + @test format_string(":(export \$a)") == ":(export \$a)" + @test format_string("quote\nexport \$a, \$b\nend") == "quote\n export \$a, \$b\nend" + @test_throws Exception format_string("export \$a") end @testset "parsing new syntax" begin