Browse Source

Fix (unnecessary) parenthesized symbols in export/public

pull/30/head
Fredrik Ekre 1 year ago
parent
commit
8e7af2db10
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 7
      src/runestone.jl
  2. 2
      test/runtests.jl

7
src/runestone.jl

@ -960,6 +960,7 @@ function spaces_in_export_public(ctx::Context, node::Node)
accept_node!(ctx, kid′) accept_node!(ctx, kid′)
push!(kids′, kid′) push!(kids′, kid′)
else else
@assert kind(first_leaf(kid)) !== K"Whitespace"
# Insert a space # Insert a space
any_changes = true any_changes = true
if kids′ === kids if kids′ === kids
@ -983,6 +984,12 @@ function spaces_in_export_public(ctx::Context, node::Node)
if kind(kid) === K"$" if kind(kid) === K"$"
@assert findlast(x -> x in KSet"quote macrocall", ctx.lineage_kinds) !== nothing @assert findlast(x -> x in KSet"quote macrocall", ctx.lineage_kinds) !== nothing
end 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" elseif kind(kid) in KSet"Comment NewlineWs"
any_changes && push!(kids′, kid) any_changes && push!(kids′, kid)
accept_node!(ctx, kid) accept_node!(ctx, kid)

2
test/runtests.jl

@ -867,6 +867,8 @@ end
@test_throws Exception format_string("export \$a") @test_throws Exception format_string("export \$a")
# Non-identifiers # Non-identifiers
@test format_string("export ^, var\"x\"") == "export ^, var\"x\"" @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 end
@testset "parsing new syntax" begin @testset "parsing new syntax" begin

Loading…
Cancel
Save