Skip to content

Commit

Permalink
allow transforming the Sym object in _parse_vars (@variables) (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
shashi authored Mar 29, 2021
1 parent 79a02ec commit c5421a0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function rename(x::Symbolic, name)
end

# Build variables more easily
function _parse_vars(macroname, type, x)
function _parse_vars(macroname, type, x, transform=identity)
ex = Expr(:block)
var_names = Symbol[]
# if parsing things in the form of
Expand Down Expand Up @@ -126,9 +126,9 @@ function _parse_vars(macroname, type, x)
@assert iscall || isarray || issym "@$macroname expects a tuple of expressions or an expression of a tuple (`@$macroname x y z(t) v[1:3] w[1:2,1:4]` or `@$macroname x y z(t) v[1:3] w[1:2,1:4] k=1.0`)"

if iscall
var_name, expr = construct_vars(v.args[1], type, v.args[2:end], val, options)
var_name, expr = construct_vars(v.args[1], type, v.args[2:end], val, options, transform)
else
var_name, expr = construct_vars(v, type, nothing, val, options)
var_name, expr = construct_vars(v, type, nothing, val, options, transform)
end

push!(var_names, var_name)
Expand All @@ -139,7 +139,7 @@ function _parse_vars(macroname, type, x)
return ex
end

function construct_vars(v, type, call_args, val, prop)
function construct_vars(v, type, call_args, val, prop, transform)
issym = v isa Symbol
isarray = isa(v, Expr) && v.head == :ref
if isarray
Expand All @@ -150,7 +150,7 @@ function construct_vars(v, type, call_args, val, prop)
var_name = v
expr = construct_var(var_name, type, call_args, val, prop)
end
var_name, :($var_name = $expr)
var_name, :($var_name = $transform($expr))
end

function option_to_metadata_type(::Val{opt}) where {opt}
Expand Down

0 comments on commit c5421a0

Please sign in to comment.