Skip to content

Commit

Permalink
Give // the same binaryop whitespace exception as ^ (#288)
Browse files Browse the repository at this point in the history
* Give `//` the same binaryop whitespace exception as `^`

* Run formatter
  • Loading branch information
nickrobinson251 authored Sep 13, 2020
1 parent ba44cee commit 7ece8a2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/styles/default/pretty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1364,14 +1364,25 @@ function p_binaryopcall(
elseif op.kind === Tokens.EX_OR
add_node!(t, Whitespace(1), s)
add_node!(t, pretty(style, op, s), s, join_lines = true)
elseif (is_number(cst[1]) || op.kind === Tokens.CIRCUMFLEX_ACCENT) && op.dot
elseif (
is_number(cst[1]) ||
op.kind === Tokens.FWDFWD_SLASH ||
op.kind === Tokens.CIRCUMFLEX_ACCENT
) && op.dot
add_node!(t, Whitespace(1), s)
add_node!(t, pretty(style, op, s), s, join_lines = true)
nest ? add_node!(t, Placeholder(1), s) : add_node!(t, Whitespace(1), s)
elseif (
nospace ||
(CSTParser.precedence(op) in (8, 13, 14, 16) && op.kind !== Tokens.ANON_FUNC)
) && op.kind !== Tokens.IN
elseif op.kind !== Tokens.IN && (
nospace || (
op.kind !== Tokens.ANON_FUNC && CSTParser.precedence(op) in (
CSTParser.ColonOp,
CSTParser.RationalOp,
CSTParser.PowerOp,
CSTParser.DeclarationOp,
CSTParser.DotOp,
)
)
)
add_node!(t, pretty(style, op, s), s, join_lines = true)
else
add_node!(t, Whitespace(1), s)
Expand Down
4 changes: 4 additions & 0 deletions test/default_style.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
@test fmt("10.0 .^ a") == "10.0 .^ a"
@test fmt("a.^b") == "a .^ b"
@test fmt("a.^10.") == "a .^ 10.0"
@test fmt("a.//10") == "a .// 10"
end

@testset "toplevel" begin
Expand Down Expand Up @@ -376,6 +377,9 @@
str = "!(typ <: ArithmeticTypes)"
@test fmt(str) == str

# `//` and `^` are binary ops without whitespace around them
@test fmt("1 // 2 + 3 ^ 4") == "1//2 + 3^4"

# Function def

str_ = """foo() = if cond a else b end"""
Expand Down

0 comments on commit 7ece8a2

Please sign in to comment.