Browse Source

Allow no space before comment after `(`, `[`, `{`, fixes #81. (#84)

pull/85/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
63433c63b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      src/runestone.jl
  2. 5
      test/runtests.jl

4
src/runestone.jl

@ -3451,7 +3451,9 @@ function spaces_around_comments(ctx::Context, node::Node)
push!(kids′, kid′) push!(kids′, kid′)
end end
accept_node!(ctx, kid′) accept_node!(ctx, kid′)
prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs" || # Note: This allows (but doesn't require) no space after opening brackets, see
# https://github.com/fredrikekre/Runic.jl/issues/81
prev_kid_ends_with_ws = kind(kid′) in KSet"Whitespace NewlineWs ( { [" ||
(ll = last_leaf(kid′); ll !== nothing && kind(ll) in KSet"Whitespace NewlineWs") (ll = last_leaf(kid′); ll !== nothing && kind(ll) in KSet"Whitespace NewlineWs")
end end
# Reset the stream and return # Reset the stream and return

5
test/runtests.jl

@ -87,6 +87,11 @@ end
@test format_string("(a,$(sp)# comment\nb + b)") == @test format_string("(a,$(sp)# comment\nb + b)") ==
"(\n a,$(csp)# comment\n b + b,\n)" "(\n a,$(csp)# comment\n b + b,\n)"
@test format_string("if c$(sp)# a\n b\nend") == "if c$(csp)# a\n b\nend" @test format_string("if c$(sp)# a\n b\nend") == "if c$(csp)# a\n b\nend"
# Allow no space after opening brackets
# (https://github.com/fredrikekre/Runic.jl/issues/81)
for (o, c) in (("(", ")"), ("[", "]"), ("{", "}"))
@test format_string("$(o)$(sp)#= a =#$(sp)$(c)") == "$(o)$(sp)#= a =#$(c)"
end
end end
let str = "a = 1 # a comment\nab = 2 # ab comment\n" let str = "a = 1 # a comment\nab = 2 # ab comment\n"
@test format_string(str) == str @test format_string(str) == str

Loading…
Cancel
Save