Skip to content

Commit 7fcc82b

Browse files
committed
revert reaction_network reroute through network_component
1 parent c077cd6 commit 7fcc82b

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/reaction_network.jl

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,35 @@ emptyrn = @reaction_network
148148
149149
ReactionSystems generated through `@reaction_network` are complete.
150150
"""
151-
macro reaction_network(args...)
152-
return :(complete(@network_component $(args... )))
151+
# macro reaction_network(args...)
152+
# return :(complete(@network_component $(args... )))
153+
# end
154+
macro reaction_network(name::Symbol, ex::Expr)
155+
complete(make_reaction_system(MacroTools.striplines(ex); name = :($(QuoteNode(name)))))
156+
end
157+
158+
# allows @reaction_network $name begin ... to interpolate variables storing a name
159+
macro reaction_network(name::Expr, ex::Expr)
160+
complete(make_reaction_system(MacroTools.striplines(ex); name = :($(esc(name.args[1])))))
161+
end
162+
163+
macro reaction_network(ex::Expr)
164+
ex = MacroTools.striplines(ex)
165+
166+
# no name but equations: @reaction_network begin ... end ...
167+
if ex.head == :block
168+
complete(make_reaction_system(ex))
169+
else # empty but has interpolated name: @reaction_network $name
170+
networkname = :($(esc(ex.args[1])))
171+
return Expr(:block, :(@parameters t),
172+
:(complete(ReactionSystem(Reaction[], t, [], []; name = $networkname))))
173+
end
174+
end
175+
176+
#Returns a empty network (with, or without, a declared name)
177+
macro reaction_network(name::Symbol = gensym(:ReactionSystem))
178+
return Expr(:block, :(@parameters t),
179+
:(complete(ReactionSystem(Reaction[], t, [], []; name = $(QuoteNode(name))))))
153180
end
154181

155182
"""
@@ -161,25 +188,25 @@ macro network_component(name::Symbol, ex::Expr)
161188
make_reaction_system(MacroTools.striplines(ex); name = :($(QuoteNode(name))))
162189
end
163190

164-
# allows @reaction_network $name begin ... to interpolate variables storing a name
191+
# allows @network_component $name begin ... to interpolate variables storing a name
165192
macro network_component(name::Expr, ex::Expr)
166193
make_reaction_system(MacroTools.striplines(ex); name = :($(esc(name.args[1]))))
167194
end
168195

169196
macro network_component(ex::Expr)
170197
ex = MacroTools.striplines(ex)
171198

172-
# no name but equations: @reaction_network begin ... end ...
199+
# no name but equations: @network_component begin ... end ...
173200
if ex.head == :block
174201
make_reaction_system(ex)
175-
else # empty but has interpolated name: @reaction_network $name
202+
else # empty but has interpolated name: @network_component $name
176203
networkname = :($(esc(ex.args[1])))
177204
return Expr(:block, :(@parameters t),
178205
:(ReactionSystem(Reaction[], t, [], []; name = $networkname)))
179206
end
180207
end
181208

182-
#Returns a empty network (with, or without, a declared name)
209+
# Returns a empty network (with, or without, a declared name)
183210
macro network_component(name::Symbol = gensym(:ReactionSystem))
184211
return Expr(:block, :(@parameters t),
185212
:(ReactionSystem(Reaction[], t, [], []; name = $(QuoteNode(name)))))

0 commit comments

Comments
 (0)