Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow transforming the Sym object in _parse_vars (@variables) #163

Merged
merged 1 commit into from
Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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