Skip to content

Commit

Permalink
fix parsing of initcode in parse_macros
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 24, 2024
1 parent d539b71 commit cc185fd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
22 changes: 5 additions & 17 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,6 @@ function clear_type(m::Module)
TYPES[m] = nothing
end

function delete_bindings!(m::Module)
clear_type(m)
delete!(REACTIVE_STORAGE, m)
nothing
end

function bindings(m)
init_storage(m)
REACTIVE_STORAGE[m]
end

function delete_handlers_fn(m::Module)
if isdefined(m, :__GF_AUTO_HANDLERS__)
Base.delete_method.(methods(m.__GF_AUTO_HANDLERS__))
Expand Down Expand Up @@ -213,7 +202,6 @@ end
Deletes all reactive variables and code in a model.
"""
macro clear()
delete_bindings!(__module__)
delete_handlers!(__module__)
end

Expand Down Expand Up @@ -482,7 +470,7 @@ macro define_var()
end |> esc
end

function parse_macro_params(params)
function parse_mixin_params(params)
mixin, prefix, postfix = if length(params) == 1 && params[1] isa Expr && hasproperty(params[1], :head) && params[1].head == :(::)
params[1].args[2], string(params[1].args[1]), ""
elseif length(params) == 1
Expand Down Expand Up @@ -518,10 +506,10 @@ function parse_macros(expr::Expr, storage::LittleDict, m::Module)
end

reactive = flag != :non_reactive
ex = [expr isa Symbol ? expr : copy(expr)]

var, ex = parse_expression(params[1], mode, source)
storage[var] = ex
elseif fn == :mixin
mixin, prefix, postfix = parse_macro_params(params)
mixin, prefix, postfix = parse_mixin_params(params)
mixin_storage = Stipple.model_to_storage(@eval(m, $mixin), prefix, postfix)
merge!(storage, Stipple.merge_storage(storage, mixin_storage; context = m))
else
Expand Down Expand Up @@ -663,7 +651,7 @@ function get_varnames(app_expr::Vector, context::Module)
res = Stipple.parse_expression(ex)
push!(varnames, res isa Symbol ? res : res[1])
elseif ex.args[1] == Symbol("@mixin")
mixin, prefix, postfix = parse_macro_params(ex.args[2:end])
mixin, prefix, postfix = parse_mixin_params(ex.args[2:end])
fnames = setdiff(@eval(context, collect($mixin isa LittleDict ? keys($mixin) : propertynames($mixin()))), Stipple.AUTOFIELDS, Stipple.INTERNALFIELDS)
prefix === nothing || (fnames = Symbol.(prefix, fnames, postfix))
append!(varnames, fnames)
Expand Down
2 changes: 1 addition & 1 deletion src/stipple/reactivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function parse_expression!(expr::Expr, @nospecialize(mode) = nothing, source = n
Rtype = isnothing(m) || ! isdefined(m, :R) ? :(Stipple.R) : :R

(isa(expr, Expr) && contains(string(expr.head), "=")) ||
error("Invalid binding expression -- use it with variables assignment ex `@binding a = 2`")
error("Invalid binding expression -- use it with variables assignment ex `@in a = 2`")

source = (source !== nothing ? String(strip(string(source), collect("#= "))) : "")

Expand Down

0 comments on commit cc185fd

Please sign in to comment.