Skip to content

Commit

Permalink
Fix whitespace in dotted comparison chains
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed May 29, 2024
1 parent 4d54e37 commit fac7aa8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/chisels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,16 @@ function infix_op_call_op(node::JuliaSyntax.GreenNode)
return children[op_index]
end

# Comparison leaf or a dotted comparison leaf (.<)
function is_comparison_leaf(node::JuliaSyntax.GreenNode)
return is_leaf(node) && JuliaSyntax.is_prec_comparison(node)
if is_leaf(node) && JuliaSyntax.is_prec_comparison(node)
return true
elseif !is_leaf(node) && JuliaSyntax.kind(node) === K"." &&
n_children(node) == 2 && is_comparison_leaf(verified_children(node)[2])
return true
else
return false
end
end

function is_operator_leaf(node::JuliaSyntax.GreenNode)
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ end
@test format_string("a$(sp)<=$(sp)b$(sp)>=$(sp)c") == "a <= b >= c"
@test format_string("a$(sp)<$(sp)b$(sp)>=$(sp)c") == "a < b >= c"
@test format_string("a$(sp)<$(sp)b$(sp)<$(sp)c") == "a < b < c"
# Dotted chains
@test format_string("a$(sp).<=$(sp)b$(sp).>=$(sp)c") == "a .<= b .>= c"
@test format_string("a$(sp).<$(sp)b$(sp).<$(sp)c") == "a .< b .< c"
end
end

Expand Down

0 comments on commit fac7aa8

Please sign in to comment.