Skip to content

Commit

Permalink
feat: add conditional equations to the metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Oct 23, 2023
1 parent 6f59697 commit a32b0f0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/systems/model_parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -538,17 +538,16 @@ function handle_y_vars(y, dict, mod, varclass, kwargs)
conditional_y_expr, conditional_dict

Check warning on line 538 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L538

Added line #L538 was not covered by tests
end

function handle_if_x_equations!(ifexpr, condition, x)
function handle_if_x_equations!(condition, dict, ifexpr, x)
push!(ifexpr.args, condition, :(push!(equations, $(x.args...))))

Check warning on line 542 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L541-L542

Added lines #L541 - L542 were not covered by tests
# push!(dict[:equations], [:if, readable_code(condition), readable_code.(x.args)])
readable_code.(x.args)

Check warning on line 544 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L544

Added line #L544 was not covered by tests
end

function handle_if_y_equations!(ifexpr, y, dict)
if y.head == :elseif
elseifexpr = Expr(:elseif)
eq_entry = [:elseif, readable_code.(y.args[1].args)...]
push!(eq_entry, handle_if_x_equations!(elseifexpr, y.args[1], y.args[2]))
push!(eq_entry, handle_if_x_equations!(y.args[1], dict, elseifexpr, y.args[2]))
get(y.args, 3, nothing) !== nothing &&

Check warning on line 551 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L546-L551

Added lines #L546 - L551 were not covered by tests
push!(eq_entry, handle_if_y_equations!(elseifexpr, y.args[3], dict))
push!(ifexpr.args, elseifexpr)
Expand All @@ -558,30 +557,30 @@ function handle_if_y_equations!(ifexpr, y, dict)
readable_code.(y.args)

Check warning on line 557 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L556-L557

Added lines #L556 - L557 were not covered by tests
end
end

function parse_equations!(exprs, eqs, dict, body)
dict[:equations] = []
Base.remove_linenums!(body)

Check warning on line 562 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L561-L562

Added lines #L561 - L562 were not covered by tests
for arg in body.args
MLStyle.@match arg begin
Expr(:if, condition, x) => begin
ifexpr = Expr(:if)
eq_entry = handle_if_x_equations!(ifexpr, condition, x)
eq_entry = handle_if_x_equations!(condition, dict, ifexpr, x)
push!(exprs, ifexpr)
push!(dict[:equations], [:if, condition, eq_entry])
push!(dict[:equations], (:if, condition, eq_entry))

Check warning on line 569 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L564-L569

Added lines #L564 - L569 were not covered by tests
end
Expr(:if, condition, x, y) => begin
ifexpr = Expr(:if)
xeq_entry = handle_if_x_equations!(ifexpr, condition, x)
xeq_entry = handle_if_x_equations!(condition, dict, ifexpr, x)
yeq_entry = handle_if_y_equations!(ifexpr, y, dict)
push!(exprs, ifexpr)
push!(dict[:equations], [:if, condition, xeq_entry, yeq_entry])
push!(dict[:equations], (:if, condition, xeq_entry, yeq_entry))

Check warning on line 576 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L571-L576

Added lines #L571 - L576 were not covered by tests
end
_ => begin
push!(eqs, arg)
push!(dict[:equations], readable_code.(eqs)...)

Check warning on line 580 in src/systems/model_parsing.jl

View check run for this annotation

Codecov / codecov/patch

src/systems/model_parsing.jl#L578-L580

Added lines #L578 - L580 were not covered by tests
end
_ => push!(eqs, arg)
end
end
# TODO: does this work with TOML?
push!(dict[:equations], readable_code.(eqs)...)
end

function parse_icon!(icon, dict, mod, body::String)
Expand Down

0 comments on commit a32b0f0

Please sign in to comment.