|
|
|
@ -293,16 +293,15 @@ end |
|
|
|
# TODO: Why did this function become sooo complicated? |
|
|
|
# TODO: Why did this function become sooo complicated? |
|
|
|
function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
if !( |
|
|
|
if !( |
|
|
|
kind(node) === K"tuple" || |
|
|
|
kind(node) in KSet"tuple parameters curly braces bracescat" || |
|
|
|
(kind(node) === K"call" && flags(node) == 0) || # Flag check rules out op-calls |
|
|
|
(kind(node) === K"call" && flags(node) == 0) || # Flag check rules out op-calls |
|
|
|
(kind(node) === K"dotcall" && flags(node) == 0) || |
|
|
|
(kind(node) === K"dotcall" && flags(node) == 0) |
|
|
|
kind(node) === K"parameters" |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
return nothing |
|
|
|
return nothing |
|
|
|
end |
|
|
|
end |
|
|
|
if kind(node) === K"parameters" |
|
|
|
if kind(node) === K"parameters" |
|
|
|
# TODO: Can probably show up elsewhere but... |
|
|
|
# TODO: Can probably show up elsewhere but... |
|
|
|
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall" |
|
|
|
@assert ctx.lineage_kinds[end] in KSet"tuple call dotcall curly" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@assert !is_leaf(node) |
|
|
|
@assert !is_leaf(node) |
|
|
|
@ -323,6 +322,10 @@ function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
end |
|
|
|
end |
|
|
|
closing_leaf_idx = findnext(x -> kind(x) === K")", kids, opening_leaf_idx + 1)::Int |
|
|
|
closing_leaf_idx = findnext(x -> kind(x) === K")", kids, opening_leaf_idx + 1)::Int |
|
|
|
closing_leaf_idx == opening_leaf_idx + 1 && return nothing # empty |
|
|
|
closing_leaf_idx == opening_leaf_idx + 1 && return nothing # empty |
|
|
|
|
|
|
|
elseif kind(node) in KSet"curly braces bracescat" |
|
|
|
|
|
|
|
opening_leaf_idx = findfirst(x -> kind(x) === K"{", kids)::Int |
|
|
|
|
|
|
|
closing_leaf_idx = findnext(x -> kind(x) === K"}", kids, opening_leaf_idx + 1)::Int |
|
|
|
|
|
|
|
closing_leaf_idx == opening_leaf_idx + 1 && return nothing # empty |
|
|
|
else |
|
|
|
else |
|
|
|
@assert kind(node) === K"parameters" |
|
|
|
@assert kind(node) === K"parameters" |
|
|
|
opening_leaf_idx = findfirst(x -> kind(x) === K";", kids)::Int |
|
|
|
opening_leaf_idx = findfirst(x -> kind(x) === K";", kids)::Int |
|
|
|
@ -348,6 +351,8 @@ function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
require_trailing_comma = false |
|
|
|
require_trailing_comma = false |
|
|
|
if kind(node) === K"tuple" && n_items == 1 |
|
|
|
if kind(node) === K"tuple" && n_items == 1 |
|
|
|
require_trailing_comma = true |
|
|
|
require_trailing_comma = true |
|
|
|
|
|
|
|
elseif kind(node) === K"bracescat" |
|
|
|
|
|
|
|
require_trailing_comma = false # Leads to parser error |
|
|
|
elseif kind(node) === K"parameters" |
|
|
|
elseif kind(node) === K"parameters" |
|
|
|
# For parameters the trailing comma is configured from the parent |
|
|
|
# For parameters the trailing comma is configured from the parent |
|
|
|
require_trailing_comma = has_tag(node, TAG_TRAILING_COMMA) |
|
|
|
require_trailing_comma = has_tag(node, TAG_TRAILING_COMMA) |
|
|
|
@ -430,7 +435,7 @@ function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
state = state_after_item(i) |
|
|
|
state = state_after_item(i) |
|
|
|
end |
|
|
|
end |
|
|
|
elseif state === :expect_comma |
|
|
|
elseif state === :expect_comma |
|
|
|
if kind(kid′) === K"," |
|
|
|
if kind(kid′) === K"," || (kind(kid′) === K";" && kind(node) === K"bracescat") |
|
|
|
before_last_item = i < last_item_idx |
|
|
|
before_last_item = i < last_item_idx |
|
|
|
if before_last_item || expect_trailing_comma |
|
|
|
if before_last_item || expect_trailing_comma |
|
|
|
# Nice, just accept it. |
|
|
|
# Nice, just accept it. |
|
|
|
@ -479,7 +484,7 @@ function spaces_in_listlike(ctx::Context, node::Node) |
|
|
|
accept_node!(ctx, kid′) |
|
|
|
accept_node!(ctx, kid′) |
|
|
|
any_kid_changed && push!(kids′, kid′) |
|
|
|
any_kid_changed && push!(kids′, kid′) |
|
|
|
elseif kind(kid′) === K"parameters" |
|
|
|
elseif kind(kid′) === K"parameters" |
|
|
|
@assert kind(node) in KSet"call dotcall" # TODO: Can this happen for named tuples? |
|
|
|
@assert kind(node) in KSet"call dotcall curly" # TODO: Can this happen for named tuples? |
|
|
|
@assert i === last_item_idx |
|
|
|
@assert i === last_item_idx |
|
|
|
@assert findnext( |
|
|
|
@assert findnext( |
|
|
|
!JuliaSyntax.is_whitespace, @view(kids[1:closing_leaf_idx - 1]), i + 1, |
|
|
|
!JuliaSyntax.is_whitespace, @view(kids[1:closing_leaf_idx - 1]), i + 1, |
|
|
|
|