Skip to content

Commit 5254958

Browse files
authored
Replace functions with symbols in expressions for printing (#353)
1 parent 7683049 commit 5254958

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/printing.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ function pattern_match_apply_call(expr, frame)
7878
return new_expr
7979
end
8080

81+
# Replace functions with their symbol so that calls print like `f(x)` instead of `(f)(x)`.
82+
function replace_function_with_symbol(expr)
83+
if isexpr(expr, :call)
84+
f = expr.args[1]
85+
if f isa Function
86+
s = Symbol(f)
87+
if Base.isidentifier(s)
88+
expr.args[1] = s
89+
return expr
90+
end
91+
end
92+
end
93+
return expr
94+
end
95+
8196
function print_next_expr(io::IO, frame::Frame)
8297
expr = pc_expr(frame)
8398
@assert expr !== nothing
@@ -110,6 +125,7 @@ function print_next_expr(io::IO, frame::Frame)
110125
end
111126
expr = pattern_match_kw_call(expr)
112127
expr = pattern_match_apply_call(expr, frame)
128+
expr = replace_function_with_symbol(expr)
113129
limit_expr = repr_limited(expr, MAX_BYTES_REPR[], print)
114130
print(io, highlight_code(limit_expr; context=io))
115131
println(io)

0 commit comments

Comments
 (0)