Skip to content

Commit

Permalink
Fix trailing whitespace trim just before closing indent token
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Aug 22, 2024
1 parent e128bc9 commit 92a8d73
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/chisels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ function make_node(node::Node, kids′::Vector{Node}, tags = node.tags)
return Node(head(node), span′, kids′, tags)
end

function make_node(node::Node, span′::Integer, tags = node.tags)
@assert is_leaf(node)
return Node(head(node), span′, (), tags)
end

# TODO: Remove?
first_leaf(node::Node) = nth_leaf(node, 1)

Expand Down
5 changes: 2 additions & 3 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ function trim_trailing_whitespace(ctx::Context, node::Node)
nb = replace_bytes!(ctx, str′, span(node))
@assert nb != span(node)
# Create new node and return it
node′ = Node(head(node), nb)
return node′
return make_node(node, nb)
end

function replace_tabs_with_four_spaces(ctx::Context, node::Node)
Expand All @@ -39,7 +38,7 @@ function replace_tabs_with_four_spaces(ctx::Context, node::Node)
tabidx = findnext(x -> x == UInt8('\t'), bytes, tabidx + 4)
end
nb = replace_bytes!(ctx, bytes, span(node))
return Node(head(node), nb, tags(node))
return make_node(node, nb)
end

function format_hex_literals(ctx::Context, node::Node)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ end
println(io, " ")
str = String(take!(io))
@test format_string(str) == "a = 1\nb = 2\n\n\n"
# Trailing whitespace just before closing indent token
@test format_string("begin\n a = 1 \nend") == "begin\n a = 1\nend"
@test format_string("let\n a = 1 \nend") == "let\n a = 1\nend"
end

@testset "Hex/oct/bin literal integers" begin
Expand Down

0 comments on commit 92a8d73

Please sign in to comment.