From cc185fd043851b08e17c370fcfaa95b7f568dc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Sun, 24 Nov 2024 19:27:27 +0100 Subject: [PATCH] fix parsing of initcode in parse_macros --- src/ReactiveTools.jl | 22 +++++----------------- src/stipple/reactivity.jl | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/src/ReactiveTools.jl b/src/ReactiveTools.jl index 1514c08..bae15d2 100644 --- a/src/ReactiveTools.jl +++ b/src/ReactiveTools.jl @@ -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__)) @@ -213,7 +202,6 @@ end Deletes all reactive variables and code in a model. """ macro clear() - delete_bindings!(__module__) delete_handlers!(__module__) end @@ -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 @@ -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 @@ -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) diff --git a/src/stipple/reactivity.jl b/src/stipple/reactivity.jl index 7c266a3..e47da0f 100644 --- a/src/stipple/reactivity.jl +++ b/src/stipple/reactivity.jl @@ -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("#= "))) : "")