From 8e7af2db1018e488c3f7aec380abda937fb3d1fa Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Sat, 27 Jul 2024 02:16:31 +0200 Subject: [PATCH] Fix (unnecessary) parenthesized symbols in export/public --- src/runestone.jl | 7 +++++++ test/runtests.jl | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/runestone.jl b/src/runestone.jl index 2b33672..6263815 100644 --- a/src/runestone.jl +++ b/src/runestone.jl @@ -960,6 +960,7 @@ function spaces_in_export_public(ctx::Context, node::Node) accept_node!(ctx, kid′) push!(kids′, kid′) else + @assert kind(first_leaf(kid)) !== K"Whitespace" # Insert a space any_changes = true if kids′ === kids @@ -983,6 +984,12 @@ function spaces_in_export_public(ctx::Context, node::Node) if kind(kid) === K"$" @assert findlast(x -> x in KSet"quote macrocall", ctx.lineage_kinds) !== nothing end + elseif kind(kid) === K"parens" + # Parenthesized symbol gives a warning in JuliaSyntax but is allowed + # TODO: Runic could remove them... + @assert kind(first_leaf(kid)) !== K"Whitespace" + any_changes && push!(kids′, kid) + accept_node!(ctx, kid) elseif kind(kid) in KSet"Comment NewlineWs" any_changes && push!(kids′, kid) accept_node!(ctx, kid) diff --git a/test/runtests.jl b/test/runtests.jl index 9a568ab..c4be60b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -867,6 +867,8 @@ end @test_throws Exception format_string("export \$a") # Non-identifiers @test format_string("export ^, var\"x\"") == "export ^, var\"x\"" + # Parenthesized identifiers. JuliaSyntax gives a warning but it is still allowed. + @test format_string("export (a) , (^)") == "export (a), (^)" end @testset "parsing new syntax" begin