Skip to content

Commit

Permalink
Fix (unnecessary) parenthesized symbols in export/public
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 27, 2024
1 parent 0fdfc27 commit 8e7af2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e7af2d

Please sign in to comment.