Skip to content

Commit

Permalink
Fix issues with equation parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic2020 committed Jul 8, 2024
1 parent aab0a16 commit e073151
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -824,14 +824,14 @@ function split_doc_tag_eqn(expr)
_, src, doc, expr = expr.args
end
# local tag, eqtyp, lhs, rhs
if @capture(expr, @eqtyp_ lhs_ = rhs_)
if @capture(expr, @eqtyp_ lhs_ = rhs_) || @capture(expr, (@eqtyp_ lhs_ = rhs_))
tag = :(:_unnamed_equation_)
eqn = Expr(:macrocall, eqtyp, expr.args[2], :($lhs = $rhs))
elseif @capture(expr, tag_ => @eqtyp_ lhs_ = rhs_)
elseif @capture(expr, tag_ => @eqtyp_ lhs_ = rhs_) || @capture(expr, tag_ => (@eqtyp_ lhs_ = rhs_))
eqn = Expr(:macrocall, eqtyp, expr.args[3].args[2], :($lhs = $rhs))
elseif @capture(expr, tag_ => lhs_ = rhs_)
elseif @capture(expr, tag_ => lhs_ = rhs_) || @capture(expr, tag_ => (lhs_ = rhs_))
eqn = :($lhs = $rhs)
elseif @capture(expr, lhs_ = rhs_)
elseif @capture(expr, lhs_ = rhs_) || @capture(expr, (lhs_ = rhs_))
tag = :(:_unnamed_equation_)
eqn = :($lhs = $rhs)
else
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1729,3 +1729,18 @@ end
@test 0 == eq.eval_resid(x)
end
end

@testset "equation_parentheses" begin
@test let model = Model()
@variables model x
@equations model begin
:EQ_x1 => (x[t] = 0)
(x[t] = 0)
:EQ_x1 => (@lin x[t] = 0)
(@lin x[t] = 0)
end
@initialize(model)
true
end
end
nothing

0 comments on commit e073151

Please sign in to comment.