From 5bd6b3cb4080915330d4396d75fe924a571e59dd Mon Sep 17 00:00:00 2001 From: ilor <kailoran@gmail.com> Date: Wed, 8 Dec 2010 12:23:19 +0100 Subject: [PATCH] The design doc for llook/rlook was incorrect, swapping the semantics per the updated docs and swapping argument order for llook. --- libwccl/ops/functions/bool/iterations/leftlook.cpp | 2 +- libwccl/ops/functions/bool/iterations/leftlook.h | 11 ++++++----- libwccl/ops/functions/bool/iterations/rightlook.cpp | 2 +- libwccl/ops/functions/bool/iterations/rightlook.h | 11 ++++++----- libwccl/parser/grammar.g | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/libwccl/ops/functions/bool/iterations/leftlook.cpp b/libwccl/ops/functions/bool/iterations/leftlook.cpp index 57cd4a8..c7f4d69 100644 --- a/libwccl/ops/functions/bool/iterations/leftlook.cpp +++ b/libwccl/ops/functions/bool/iterations/leftlook.cpp @@ -8,7 +8,7 @@ bool LeftLook::iterate( Wccl::Position &p, const Wccl::FunExecContext &context) const { - for(int i = left; i <= right; ++i) { + for(int i = right; i >= left; ++i) { p.set_value(i); if(evaluating_expr_->apply(context)->get_value()) { return true; diff --git a/libwccl/ops/functions/bool/iterations/leftlook.h b/libwccl/ops/functions/bool/iterations/leftlook.h index 5c07a39..92e42da 100644 --- a/libwccl/ops/functions/bool/iterations/leftlook.h +++ b/libwccl/ops/functions/bool/iterations/leftlook.h @@ -6,8 +6,9 @@ namespace Wccl { /** - * Iterative operator "llook", which looks for a first - * position from left that makes evaluating expression return true. + * Iterative operator "llook", which looks for the rightmost position + * in a range that makes the evaluating expression return true, i.e. + * it "looks to the left". */ class LeftLook : public Iteration { @@ -30,12 +31,12 @@ public: protected: /** - * @returns True if, when scanning from left, - * a position within range is found that makes + * @returns True if, when scanning right-to-left, + * a position within the range is found that makes * the evaluating function return true. False * otherwise. * @note Upon success, the iteration variable is - * set to the first position in range from left + * set to the rightmost position in range * that has made evaluation function return true * (that is the position that made the stop condition * true in this case). diff --git a/libwccl/ops/functions/bool/iterations/rightlook.cpp b/libwccl/ops/functions/bool/iterations/rightlook.cpp index 36bae48..70b4cda 100644 --- a/libwccl/ops/functions/bool/iterations/rightlook.cpp +++ b/libwccl/ops/functions/bool/iterations/rightlook.cpp @@ -8,7 +8,7 @@ bool RightLook::iterate( Wccl::Position &p, const Wccl::FunExecContext &context) const { - for(int i = right; i >= left; --i) { + for(int i = left; i <= right; ++i) { p.set_value(i); if(evaluating_expr_->apply(context)->get_value()) { return true; diff --git a/libwccl/ops/functions/bool/iterations/rightlook.h b/libwccl/ops/functions/bool/iterations/rightlook.h index b39251a..dcc5e5f 100644 --- a/libwccl/ops/functions/bool/iterations/rightlook.h +++ b/libwccl/ops/functions/bool/iterations/rightlook.h @@ -6,8 +6,9 @@ namespace Wccl { /** - * Iterative operator "rlook", which looks for a first - * position from right that makes evaluating expression return true. + * Iterative operator "rlook", which looks for the leftmost position + * in a range that makes the evaluating expression return true, i.e. + * it "looks to the right". */ class RightLook : public Iteration { @@ -30,12 +31,12 @@ public: protected: /** - * @returns True if, when scanning from right, - * a position within range is found that makes + * @returns True if, when scanning left-to-right, + * a position within the range is found that makes * the evaluating function return true. False * otherwise. * @note Upon success, the iteration variable is - * set to the first position in range from right + * set to the leftmost position in range * that has made evaluation function return true * (that is the position that made the stop condition * true in this case). diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index a4ac6c4..6763cbc 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -1078,9 +1078,9 @@ bool_iteration RPAREN { ret.reset(new AtLeast(lpos, rpos, *pacc, expr, min_match)); } - | "llook" LPAREN - lpos = position_operator [tagset, vars] COMMA + | "llook" LPAREN //note inverted rpos/lpos order rpos = position_operator [tagset, vars] COMMA + lpos = position_operator [tagset, vars] COMMA pacc = position_variable_acc [vars] COMMA expr = bool_operator [tagset, vars] RPAREN { -- GitLab