Browse Source

Fix import renaming of macros

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

9
src/runestone.jl

@ -1106,7 +1106,7 @@ function format_as(ctx::Context, node::Node)
# Alias-identifier # Alias-identifier
idx += 1 idx += 1
kid = kids[idx] kid = kids[idx]
@assert kind(kid) in KSet"Identifier $" @assert kind(kid) in KSet"Identifier $ @"
if !is_leaf(kid) if !is_leaf(kid)
@assert kind(first_leaf(kid)) !== K"Whitespace" @assert kind(first_leaf(kid)) !== K"Whitespace"
end end
@ -1115,6 +1115,13 @@ function format_as(ctx::Context, node::Node)
end end
accept_node!(ctx, kid) accept_node!(ctx, kid)
any_changes && push!(kids′, kid) any_changes && push!(kids′, kid)
if kind(kid) === K"@"
idx += 1
kid = kids[idx]
@assert kind(kid) === K"MacroName"
accept_node!(ctx, kid)
any_changes && push!(kids′, kid)
end
# Reset stream # Reset stream
seek(ctx.fmt_io, pos) seek(ctx.fmt_io, pos)
return any_changes ? make_node(node, kids′) : nothing return any_changes ? make_node(node, kids′) : nothing

2
test/runtests.jl

@ -829,6 +829,8 @@ end
@test format_string("quote\nimport A as \$a\nend") == "quote\n import A as \$a\nend" @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(":(import A as \$a)") == ":(import A as \$a)"
@test format_string("@eval import A as \$a") == "@eval import A as \$a" @test format_string("@eval import A as \$a") == "@eval import A as \$a"
# Macro-aliases
@test format_string("import A.@a as @b") == "import A.@a as @b"
end end
@testset "spaces in export/public" begin @testset "spaces in export/public" begin

Loading…
Cancel
Save