From ab1b3d6396d9636b6deb0d1bb299cbe5fc4a29bf Mon Sep 17 00:00:00 2001 From: Adam Radziszewski <adam.radziszewski@pwr.wroc.pl> Date: Thu, 4 Aug 2011 13:37:48 +0200 Subject: [PATCH] iter semantics: always sets iter var to nowhere if False is returned --- libwccl/ops/functions/bool/iteration.cpp | 5 +-- tests/data/crossing.ccl | 55 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/libwccl/ops/functions/bool/iteration.cpp b/libwccl/ops/functions/bool/iteration.cpp index cb2034a..9a6982a 100644 --- a/libwccl/ops/functions/bool/iteration.cpp +++ b/libwccl/ops/functions/bool/iteration.cpp @@ -25,11 +25,8 @@ std::ostream& Iteration::write_to(std::ostream& os) const Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context) const { - // Set iteration variable to Nowhere - // Should be overridden if succeeded const boost::shared_ptr<Position>& iter_var = context.variables()->get_fast(iter_var_acc_); - iter_var->set_value(Position::Nowhere); const SentenceContext& sc = context.sentence_context(); // Proceed only if range extremes are not "nowhere". const boost::shared_ptr<const Position>& range_left = @@ -48,7 +45,7 @@ Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context } } } - // Failure. Make sure iteration variable points Nowhere and return False + // Failure. Set iteration variable to Nowhere and return False iter_var->set_value(Position::Nowhere); return Predicate::False(context); } diff --git a/tests/data/crossing.ccl b/tests/data/crossing.ccl index abae649..23dd82d 100644 --- a/tests/data/crossing.ccl +++ b/tests/data/crossing.ccl @@ -36,3 +36,58 @@ only(1, 0, $It, False) True It=nowhere --- +and(setvar($It,2), rlook(0, 1, $It, True)) + +True +It=0 +--- +and(setvar($It,2), llook(1, 0, $It, True)) + +True +It=1 +--- +and(setvar($It,2), rlook(1, 0, $It, True)) + +False +It=nowhere +--- +and(setvar($It,2), llook(0, 1, $It, True)) + +False +It=nowhere +--- +and(setvar($It,2), only(0, 1, $It, True)) + +True +It=1 +--- +and(setvar($It,2), only(1, 0, $It, True)) + +True +It=2 +--- +and(setvar($It,2), only(1, 0, $It, False)) + +True +It=2 +--- +and(setvar($It,2), only(0, 1, $It, False)) + +False +It=nowhere +--- +and(setvar($It,6), atleast(0, 3, $It, inside($It), 2)) + +True +It=1 +--- +and(setvar($It,6), atleast(3, 0, $It, inside($It), 2)) + +False +It=nowhere +--- +and(setvar($It,6), atleast(0, 3, $It, inside($It), 7)) + +False +It=nowhere +--- -- GitLab