Skip to content

Commit 1b5a069

Browse files
authored
Merge pull request #287 from ReactiveBayes/272-meta-block-does-not-parse-lambda-expressions-within-arguments
Nested ->
2 parents ffc37d3 + 94e303a commit 1b5a069

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/plugins/meta/meta_macro.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export @meta
22
using MacroTools
33

44
check_for_returns_meta = (x) -> check_for_returns(x; tag = "meta")
5+
not_enter_call_walk = guarded_walk((x) -> x isa Expr && x.head == :call)
56

67
"""
78
add_meta_construction(e::Expr)
@@ -98,7 +99,6 @@ Converts all variable references on the left hand side of a meta specification t
9899
99100
# Examples
100101
"""
101-
102102
function convert_meta_variables(e::Expr)
103103
if @capture(e, (fform_(vars__) -> meta_obj_))
104104
vars = map(var -> __convert_to_indexed_statement(var), vars)
@@ -145,8 +145,10 @@ function convert_meta_object(e::Expr)
145145
end
146146
end
147147

148+
what_walk(::typeof(convert_meta_object)) = not_enter_call_walk
149+
148150
function meta_macro_interior(meta_body::Expr)
149-
meta_body = apply_pipeline(meta_body, (x) -> check_for_returns(x; tag = "meta"))
151+
meta_body = apply_pipeline(meta_body, check_for_returns_meta)
150152
meta_body = add_meta_construction(meta_body)
151153
meta_body = apply_pipeline(meta_body, create_submodel_meta)
152154
meta_body = apply_pipeline(meta_body, convert_meta_variables)

test/plugins/meta/meta_macro_tests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ end
299299
push!(__meta__, GraphPPL.MetaObject(GraphPPL.VariableMetaDescriptor(GraphPPL.IndexedVariable(:x, nothing)), some_meta()))
300300
end
301301
@test_expression_generating apply_pipeline(input, convert_meta_object) output
302+
303+
# Test 3: convert_meta_object with ->
304+
input = quote
305+
ContinuousTransition() -> CTMeta((H) -> reshape(H, dim, dim))
306+
end
307+
output = quote
308+
push!(__meta__, GraphPPL.MetaObject(GraphPPL.FactorMetaDescriptor(ContinuousTransition, ()), CTMeta((H -> reshape(H, dim, dim)))))
309+
end
310+
@test_expression_generating apply_pipeline(input, convert_meta_object) output
302311
end
303312

304313
@testitem "meta_macro_interior" begin

0 commit comments

Comments
 (0)