From 46ba32f0383f79e44a37f4d885b785f703bf6b41 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 31 Jan 2019 16:38:53 -0600 Subject: [PATCH] FEATURE: Allow more expressions in the functional builtins. --- .../functional_processing_test.ucg | 19 +++++++++++++++++++ src/parse/mod.rs | 8 ++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/integration_tests/functional_processing_test.ucg b/integration_tests/functional_processing_test.ucg index 4a24079..424da95 100644 --- a/integration_tests/functional_processing_test.ucg +++ b/integration_tests/functional_processing_test.ucg @@ -143,4 +143,23 @@ assert { assert { ok = reduce((char_iter), [], "foo") == ["f", "o", "o"], desc = "We can use arbitrary expressions to refer to the macro.", +}; + +let tpl_with_list = { + list = [1, 2, 3], +}; + +assert { + ok = reduce(func(acc, s) => acc + [s + 1], [], tpl_with_list.list) == [2, 3, 4], + desc = "We can use full expressions for any of the arguments to reduce", +}; + +assert { + ok = map(func(item) => item + 1, tpl_with_list.list) == [2, 3, 4], + desc = "We can use full expressions for any of the arguments to map", +}; + +assert { + ok = filter(func(item) => item != 1, tpl_with_list.list) == [2, 3], + desc = "We can use full expressions for any of the arguments to map", }; \ No newline at end of file diff --git a/src/parse/mod.rs b/src/parse/mod.rs index bf12fd1..1534458 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -577,9 +577,9 @@ make_fn!( _ => must!(punct!("(")), func => must!(expression), _ => must!(punct!(",")), - acc => must!(trace_parse!(non_op_expression)), + acc => must!(trace_parse!(expression)), _ => must!(punct!(",")), - tgt => must!(trace_parse!(non_op_expression)), + tgt => must!(trace_parse!(expression)), _ => must!(punct!(")")), (Expression::FuncOp(FuncOpDef::Reduce(ReduceOpDef{ func: Box::new(func), @@ -598,7 +598,7 @@ make_fn!( _ => must!(punct!("(")), func => must!(expression), _ => must!(punct!(",")), - list => must!(trace_parse!(non_op_expression)), + list => must!(trace_parse!(expression)), _ => must!(punct!(")")), (Expression::FuncOp(FuncOpDef::Map(MapFilterOpDef{ func: Box::new(func), @@ -616,7 +616,7 @@ make_fn!( _ => must!(punct!("(")), func => must!(expression), _ => must!(punct!(",")), - list => must!(trace_parse!(non_op_expression)), + list => must!(trace_parse!(expression)), _ => must!(punct!(")")), (Expression::FuncOp(FuncOpDef::Filter(MapFilterOpDef{ func: Box::new(func),