Browse Source

Fix indent of local/global variable lists, fixes #63 (#68)

pull/69/head
Fredrik Ekre 1 year ago committed by GitHub
parent
commit
5500f9bcdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 24
      src/chisels.jl
  2. 6
      test/runtests.jl

24
src/chisels.jl

@ -505,8 +505,28 @@ end @@ -505,8 +505,28 @@ end
# K"global" and K"local" nodes can be either `global a, b, c` or `global a = 1`. This method
# checks whether the node is of the former kind.
function is_global_local_list(node)
return kind(node) in KSet"global local" && !is_leaf(node) &&
all(x -> kind(x) in KSet"global local Identifier , Whitespace NewlineWs Comment", verified_kids(node))
if !(kind(node) in KSet"global local" && !is_leaf(node))
return false
end
kids = verified_kids(node)
# If it contains assignments it is not a list
if any(x -> is_assignment(x), kids)
return false
end
# If it contains K"," it is a list
if any(x -> kind(x) === K",", kids)
return true
end
# If we reach here we have a single item list (`local a`) or something like
# ```
# global function f()
# # ...
# end
# ```
# For now we only say it is a list if the item is in the subset below
idx = findfirst(x -> kind(x) in KSet"global local", kids)::Int
idx = findnext(x -> !JuliaSyntax.is_whitespace(x), kids, idx + 1)::Int
return kind(kids[idx]) in KSet"Identifier var"
end
function unwrap_to_call_or_tuple(x)

6
test/runtests.jl

@ -802,9 +802,9 @@ end @@ -802,9 +802,9 @@ end
@test format_string("$(verb) A:\n$(sp)a,\n$(sp)b") == "$(verb) A:\n a,\n b"
end
# export/public/global/local
for verb in ("export", "public", "global", "local")
@test format_string("$(verb) a,\n$(sp)b") == "$(verb) a,\n b"
@test format_string("$(verb)\n$(sp)a,\n$(sp)b") == "$(verb)\n a,\n b"
for verb in ("export", "public", "global", "local"), b in ("b", "var\"b\"")
@test format_string("$(verb) a,\n$(sp)$(b)") == "$(verb) a,\n $(b)"
@test format_string("$(verb)\n$(sp)a,\n$(sp)$(b)") == "$(verb)\n a,\n $(b)"
end
# ternary
@test format_string("a ?\n$(sp)b : c") == "a ?\n b : c"

Loading…
Cancel
Save