Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure single space before module name #90

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/runestone.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,10 @@ end
# global, const
function spaces_around_keywords(ctx::Context, node::Node)
is_leaf(node) && return nothing
keyword_set = KSet"where do mutable struct abstract primitive type function if elseif catch while return local global const"
keyword_set = KSet"""
where do mutable struct abstract primitive type function if elseif catch while return
local global const module baremodule
"""
if !(kind(node) in keyword_set)
return nothing
end
Expand Down Expand Up @@ -1331,7 +1334,7 @@ function spaces_around_keywords(ctx::Context, node::Node)
@assert false # Unreachable?
else
# Reachable in e.g. `T where{T}`, `if(`, ... insert space
@assert kind(node) in KSet"where if elseif while do function return local global"
@assert kind(node) in KSet"where if elseif while do function return local global module baremodule"
any_changes = true
if kids′ === kids
kids′ = kids[1:(i - 1)]
Expand Down Expand Up @@ -3001,10 +3004,10 @@ function indent_module(ctx::Context, node::Node; do_indent::Bool = true)
space_idx = 2
space_node = kids[space_idx]
if kind(space_node) === K"Whitespace"
# Now we need an identifier or var"
# Now we need an identifier, var" or parens...
id_idx = 3
id_node = kids[id_idx]
@assert kind(id_node) in KSet"Identifier var"
@assert kind(id_node) in KSet"Identifier var parens"
block_idx = 4
else
# This can be reached if the module name is interpolated or parenthesized, for
Expand Down
7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ end
@test format_string("f()$(sp)do; y end") == "f() do;\n y\nend"
@test format_string("function f()\n return$(sp)1\nend") == "function f()\n return 1\nend"
@test format_string("function f()\n return$(sp)\nend") == "function f()\n return\nend"
@test format_string("module$(sp)A\nend") == "module A\nend"
@test format_string("module$(sp)(A)\nend") == "module (A)\nend"
for word in ("local", "global"), rhs in ("a", "a, b", "a = 1", "a, b = 1, 2")
word == "const" && rhs in ("a", "a, b") && continue
@test format_string("$(word)$(sp)$(rhs)") == "$(word) $(rhs)"
Expand All @@ -528,6 +530,7 @@ end
@test format_string("function f()\n return(1)\nend") == "function f()\n return (1)\nend"
@test format_string("local(a)") == "local (a)"
@test format_string("global(a)") == "global (a)"
@test format_string("module(A)\nend") == "module (A)\nend"
end

@testset "replace ∈ and = with in in for loops and generators" begin
Expand Down Expand Up @@ -712,8 +715,8 @@ end
@test format_string("$(b)module \$A\n$(sp)x\n$(sp)end\nf") ==
"$(b)module \$A\n x\nend\nf"
# parenthesized module name (Why....)
@test format_string("$(b)module(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module(A)\n x\nend\nf"
@test format_string("$(b)module$(sp)(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module (A)\n x\nend\nf"
@test format_string("$(b)module \$(A)\n$(sp)x\n$(sp)end\nf") ==
"$(b)module \$(A)\n x\nend\nf"
# single line module
Expand Down
Loading