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

add astable macro #291

Closed
wants to merge 1 commit into from
Closed
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
35 changes: 35 additions & 0 deletions src/parsing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,33 @@ function replace_syms!(e::Expr, membernames)
end
end

is_col_lhs(x) = false
function is_col_lhs(x::Expr)
if x.head == :(=)
xa = x.args[1]
return xa isa QuoteNode || is_column_expr(xa)
else
return false
end
end

function modifiy_column_assignments(expr)
membernames = Dict{Any, Symbol}()

new_expr = MacroTools.postwalk(expr) do x
if x isa Expr && x.head == :(=)
x.args[1] = replace_syms!(x.args[1], membernames)
x
else
x
end
end
props_iterator = (:(Symbol($k) => $v) for (k, v) in membernames)
nt_expr = Expr(:call, :^, Expr(:tuple, Expr(:parameters, props_iterator...)))

Expr(:block, new_expr, nt_expr)
end

is_simple_non_broadcast_call(x) = false
function is_simple_non_broadcast_call(expr::Expr)
expr.head == :call &&
Expand Down Expand Up @@ -269,6 +296,14 @@ function fun_to_vec(ex::Expr;
end
end

if is_macro_head(ex, "@astable")
dest = :(AsTable)
source, fun = get_source_fun(modifiy_column_assignments(ex.args[3]))
return quote
$source => $fun => $dest
end
end

@assert ex.head == :kw || ex.head == :(=)
lhs = ex.args[1]

Expand Down