Skip to content

Commit 9e46ed6

Browse files
committed
Add readable_code
1 parent 29e24f7 commit 9e46ed6

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ function toexpr(sys::AbstractSystem)
506506
striplines(expr) # keeping the line numbers is never helpful
507507
end
508508

509-
Base.write(io::IO, sys::AbstractSystem) = write(io, JuliaFormatter.format_text(string(toexpr(sys))))
509+
Base.write(io::IO, sys::AbstractSystem) = write(io, readable_code(toexpr(sys)))
510510

511511
function Base.show(io::IO, ::MIME"text/plain", sys::AbstractSystem)
512512
eqs = equations(sys)

src/utils.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,17 @@ function indepvar2depvar(s::Sym, args...)
8484
ns = Sym{T}(nameof(s))(args...)
8585
@set! ns.metadata = s.metadata
8686
end
87+
88+
function _readable_code(ex)
89+
ex isa Expr || return ex
90+
if ex.head === :call
91+
f, args = ex.args[1], ex.args[2:end]
92+
if f isa Function && (nf = nameof(f); Base.isoperator(nf))
93+
return Expr(:call, nf, args...)
94+
end
95+
end
96+
expr = Expr(ex.head)
97+
expr.args = map(_readable_code, ex.args)
98+
Base.remove_linenums!(expr)
99+
end
100+
readable_code(expr) = JuliaFormatter.format_text(string(_readable_code(expr)))

0 commit comments

Comments
 (0)