Skip to content

Commit

Permalink
Fix an edgecase in operator chains with newlines hidden inside
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 29, 2024
1 parent fac7aa8 commit a2c3bf2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ function spaces_around_x(ctx::Context, node::JuliaSyntax.GreenNode, is_x::F) whe
end
push!(children′, child′)
end
elseif JuliaSyntax.haschildren(child) &&
JuliaSyntax.kind(first_leaf(child)) === K"NewlineWs"
# NewlineWs have to be accepted as is
@info " ... childs first leaf is NewlineWs I'll take it"
accept_node!(ctx, child)
any_changes && push!(children′, child)
looking_for_whitespace = JuliaSyntax.kind(last_leaf(child)) !== K"Whitespace"
@assert !is_x(child)::Bool
looking_for_x = true
else
# Not a whitespace node, insert one
any_changes = true
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ end
# Edgecase when using whitespace from the next leaf but the call chain continues
# after with more children.
@test format_string("$(sp)z$(sp)+$(sp)2x$(sp)+$(sp)z$(sp)") == "$(sp)z + 2x + z$(sp)"
# Edgecase where the NewlineWs ends up inside the second call in a chain
@test format_string("$(sp)a$(sp)\\$(sp)b$(sp)$(sp)\n$(sp)c$(sp)\\$(sp)d$(sp)") ==
"$(sp)a \\ b ≈\n$(sp)c \\ d$(sp)"
end
end

Expand Down

0 comments on commit a2c3bf2

Please sign in to comment.