Skip to content

Commit

Permalink
Revert _extract_kw_args
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Dec 18, 2023
1 parent 25ac0f3 commit fdd4b6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
22 changes: 22 additions & 0 deletions src/Containers/macro.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,3 +606,25 @@ macro container(input_args...)
end
return :($(esc(name)) = $code)
end

"""
_extract_kw_args(args)
!!! warning
This function is deprecated. Use [`parse_macro_arguments`](@ref) instead.
"""
function _extract_kw_args(args)
flat_args, kw_args, requested_container = Any[], Any[], :Auto
for arg in args
if Meta.isexpr(arg, :(=))
if arg.args[1] == :container
requested_container = arg.args[2]
else
push!(kw_args, arg)
end
else
push!(flat_args, arg)
end
end
return flat_args, kw_args, requested_container
end
30 changes: 3 additions & 27 deletions src/macros/@NL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,30 +223,6 @@ function _parse_generator_expression(code, x, operators)
return y
end

"""
_extract_kw_args(args)
Process the arguments to a macro, separating out the keyword arguments.
Return a tuple of (flat_arguments, keyword arguments, and requested_container),
where `requested_container` is a symbol to be passed to `container_code`.
"""
function _extract_kw_args(args)
flat_args, kw_args, requested_container = Any[], Any[], :Auto
for arg in args
if Meta.isexpr(arg, :(=))
if arg.args[1] == :container
requested_container = arg.args[2]
else
push!(kw_args, arg)
end
else
push!(flat_args, arg)
end
end
return flat_args, kw_args, requested_container
end

###
### @NLobjective(s)
###
Expand Down Expand Up @@ -321,7 +297,7 @@ macro NLconstraint(m, x, args...)
# Two formats:
# - @NLconstraint(m, a*x <= 5)
# - @NLconstraint(m, myref[a=1:5], sin(x^a) <= 5)
extra, kw_args, requested_container = _extract_kw_args(args)
extra, kw_args, requested_container = Containers._extract_kw_args(args)
if length(extra) > 1 || length(kw_args) > 0
error_fn("too many arguments.")
end
Expand Down Expand Up @@ -430,7 +406,7 @@ subexpression[5]: log(1.0 + (exp(subexpression[2]) + exp(subexpression[3])))
"""
macro NLexpression(args...)
error_fn = Containers.build_error_fn(:NLexpression, args, __source__)
args, kw_args, requested_container = _extract_kw_args(args)
args, kw_args, requested_container = Containers._extract_kw_args(args)
if length(args) <= 1
error_fn(
"To few arguments ($(length(args))); must pass the model and nonlinear expression as arguments.",
Expand Down Expand Up @@ -592,7 +568,7 @@ macro NLparameter(model, args...)
esc_m = esc(model)
error_fn =
Containers.build_error_fn(:NLparameter, (model, args...), __source__)
pos_args, kw_args, requested_container = _extract_kw_args(args)
pos_args, kw_args, requested_container = Containers._extract_kw_args(args)
value = missing
for arg in kw_args
if arg.args[1] == :value
Expand Down

0 comments on commit fdd4b6e

Please sign in to comment.