Skip to content

Commit 16025fd

Browse files
committed
feat: add conditional equations to the metadata
1 parent 30dcc02 commit 16025fd

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/systems/model_parsing.jl

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,16 @@ function handle_y_vars(y, dict, mod, varclass, kwargs)
491491
conditional_y_expr, conditional_dict
492492
end
493493

494-
function handle_if_x_equations!(ifexpr, condition, x)
494+
function handle_if_x_equations!(condition, dict, ifexpr, x)
495495
push!(ifexpr.args, condition, :(push!(equations, $(x.args...))))
496496
# push!(dict[:equations], [:if, readable_code(condition), readable_code.(x.args)])
497497
readable_code.(x.args)
498498
end
499-
500499
function handle_if_y_equations!(ifexpr, y, dict)
501500
if y.head == :elseif
502501
elseifexpr = Expr(:elseif)
503502
eq_entry = [:elseif, readable_code.(y.args[1].args)...]
504-
push!(eq_entry, handle_if_x_equations!(elseifexpr, y.args[1], y.args[2]))
503+
push!(eq_entry, handle_if_x_equations!(y.args[1], dict, elseifexpr, y.args[2]))
505504
get(y.args, 3, nothing) !== nothing &&
506505
push!(eq_entry, handle_if_y_equations!(elseifexpr, y.args[3], dict))
507506
push!(ifexpr.args, elseifexpr)
@@ -511,30 +510,30 @@ function handle_if_y_equations!(ifexpr, y, dict)
511510
readable_code.(y.args)
512511
end
513512
end
514-
515513
function parse_equations!(exprs, eqs, dict, body)
516514
dict[:equations] = []
517515
Base.remove_linenums!(body)
518516
for arg in body.args
519517
MLStyle.@match arg begin
520518
Expr(:if, condition, x) => begin
521519
ifexpr = Expr(:if)
522-
eq_entry = handle_if_x_equations!(ifexpr, condition, x)
520+
eq_entry = handle_if_x_equations!(condition, dict, ifexpr, x)
523521
push!(exprs, ifexpr)
524-
push!(dict[:equations], [:if, condition, eq_entry])
522+
push!(dict[:equations], (:if, condition, eq_entry))
525523
end
526524
Expr(:if, condition, x, y) => begin
527525
ifexpr = Expr(:if)
528-
xeq_entry = handle_if_x_equations!(ifexpr, condition, x)
526+
xeq_entry = handle_if_x_equations!(condition, dict, ifexpr, x)
529527
yeq_entry = handle_if_y_equations!(ifexpr, y, dict)
530528
push!(exprs, ifexpr)
531-
push!(dict[:equations], [:if, condition, xeq_entry, yeq_entry])
529+
push!(dict[:equations], (:if, condition, xeq_entry, yeq_entry))
530+
end
531+
_ => begin
532+
push!(eqs, arg)
533+
push!(dict[:equations], readable_code.(eqs)...)
532534
end
533-
_ => push!(eqs, arg)
534535
end
535536
end
536-
# TODO: does this work with TOML?
537-
push!(dict[:equations], readable_code.(eqs)...)
538537
end
539538

540539
function parse_icon!(icon, dict, body::String)

0 commit comments

Comments
 (0)