From a66caeb167ae34df8b50dc97c538e7127806aa9e Mon Sep 17 00:00:00 2001
From: Peter Deffebach
Date: Sat, 21 Aug 2021 15:23:35 -0400
Subject: [PATCH] add astable macro
---
src/parsing.jl | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/src/parsing.jl b/src/parsing.jl
index f881a0e1..b33bc4f8 100644
--- a/src/parsing.jl
+++ b/src/parsing.jl
@@ -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 &&
@@ -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]