Skip to content

Commit 71a8e9d

Browse files
committed
roundtrip print for connect
1 parent 968831c commit 71a8e9d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/systems/abstractsystem.jl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,24 @@ function round_trip_expr(t, var2name)
566566
args = map(Base.Fix2(round_trip_expr, var2name), arguments(t))
567567
return :($f($(args...)))
568568
end
569-
round_trip_eq(eq, var2name) = Expr(:call, :~, round_trip_expr(eq.lhs, var2name), round_trip_expr(eq.rhs, var2name))
569+
570+
function round_trip_eq(eq::Equation, var2name)
571+
if eq.lhs isa Connection
572+
syss = get_systems(eq.rhs)
573+
call = Expr(:call, connect)
574+
for sys in syss
575+
strs = split(string(nameof(sys)), "")
576+
s = Symbol(strs[1])
577+
for st in strs[2:end]
578+
s = Expr(:., s, Meta.quot(Symbol(st)))
579+
end
580+
push!(call.args, s)
581+
end
582+
call
583+
else
584+
Expr(:call, (~), round_trip_expr(eq.lhs, var2name), round_trip_expr(eq.rhs, var2name))
585+
end
586+
end
570587

571588
function push_eqs!(stmt, eqs, var2name)
572589
eqs_name = gensym(:eqs)

src/systems/connectors.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ end
5656

5757
const EMPTY_VEC = []
5858

59-
function Base.show(io::IO, c::Connection)
59+
function Base.show(io::IO, ::MIME"text/plain", c::Connection)
60+
# It is a bit unfortunate that the display of an array of `Equation`s won't
61+
# call this.
6062
@unpack outers, inners = c
6163
if outers === nothing && inners === nothing
6264
print(io, "<Connection>")
@@ -124,7 +126,11 @@ isconnector(s::AbstractSystem) = has_connector_type(s) && get_connector_type(s)
124126
isstreamconnector(s::AbstractSystem) = isconnector(s) && get_connector_type(s) isa StreamConnector
125127
isstreamconnection(c::Connection) = any(isstreamconnector, c.inners) || any(isstreamconnector, c.outers)
126128

127-
print_with_indent(n, x) = println(" " ^ n, x)
129+
function print_with_indent(n, x)
130+
print(" " ^ n)
131+
show(stdout, MIME"text/plain"(), x)
132+
println()
133+
end
128134

129135
function split_sys_var(var)
130136
var_name = string(getname(var))

0 commit comments

Comments
 (0)