-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdsl_vlplot_macro.jl
More file actions
50 lines (40 loc) · 1.46 KB
/
dsl_vlplot_macro.jl
File metadata and controls
50 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function convert_curly_style_array(exprs, fragtype)
res = Expr(:vect)
for ex in exprs
if ex isa Expr && ex.head == :braces
push!(res.args, :($(convert_curly_style(ex.args, fragtype))))
else
push!(res.args, esc(ex))
end
end
return res
end
function convert_curly_style(exprs, fragtype)
new_expr = :($fragtype(Any[], OrderedDict{String,Any}()))
pos_args = new_expr.args[2].args
named_args = new_expr.args[3].args
for ex in exprs
if ex isa Expr && ex.head == :(=)
if ex.args[2] isa Expr && ex.args[2].head == :braces
push!(named_args, :($(string(ex.args[1])) => $(convert_curly_style(ex.args[2].args, fragtype))))
elseif ex.args[2] isa Expr && ex.args[2].head == :vect
push!(named_args, :($(string(ex.args[1])) => $(convert_curly_style_array(ex.args[2].args, fragtype))))
else
push!(named_args, :($(string(ex.args[1])) => $(esc(ex.args[2]))))
end
elseif ex isa Expr && ex.head == :braces
push!(pos_args, convert_curly_style(ex.args, fragtype))
else
push!(pos_args, esc(ex))
end
end
return new_expr
end
macro vgplot(ex...)
new_ex = convert_curly_style(ex, VGFrag)
return :(Vega.VGSpec(convert_frag_tree_to_dict(fix_shortcut_level_spec($new_ex))))
end
macro vgfrag(ex...)
new_ex = convert_curly_style(ex, VGFrag)
return new_ex
end