Browse Source

Fix single line begin-end blocks

TODO: Should probably require leading and trailing newlines in such
blocks?
pull/19/head
Fredrik Ekre 1 year ago
parent
commit
e14aaa07f3
No known key found for this signature in database
GPG Key ID: DE82E6D5E364C0A2
  1. 7
      src/runestone.jl
  2. 5
      test/runtests.jl

7
src/runestone.jl

@ -1299,9 +1299,10 @@ function indent_begin(ctx::Context, node::Node, block_kind = K"begin") @@ -1299,9 +1299,10 @@ function indent_begin(ctx::Context, node::Node, block_kind = K"begin")
any_kid_changed = true
end
# Second node is the newline
ln_idx = 2
ln_node = kids[ln_idx]
@assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs"
# TODO: Require newline?
# ln_idx = 2
# ln_node = kids[ln_idx]
# @assert is_leaf(ln_node) && kind(ln_node) === K"NewlineWs"
# After the NewlineWs node we skip over all kids until the end
end_idx = findlast(x -> kind(x) === K"end", kids)
@assert end_idx == lastindex(kids) # ??

5
test/runtests.jl

@ -567,8 +567,11 @@ end @@ -567,8 +567,11 @@ end
@test format_string("$(t)[a b\n$(sp)c d]") == "$(t)[\n a b\n c d\n]"
@test format_string("$(t)[\n$(sp)a b\n$(sp)c d\n$(sp)]") == "$(t)[\n a b\n c d\n]"
end
# Single line begin-end
@test format_string("begin x\n$(sp)end") == "begin x\nend"
@test format_string("begin x end") == "begin x end"
@test format_string("begin\n x end") == "begin\n x end"
end
end
@testset "continuation/soft indentation" begin

Loading…
Cancel
Save