diff --git a/libwccl/ops/match/conditions/tokencondition.cpp b/libwccl/ops/match/conditions/tokencondition.cpp index e6c0b0f2ae0bc5ae80acff45f13f209f63131489..51604e69fc20d8d7e8530b6999a94d9acdefd392 100644 --- a/libwccl/ops/match/conditions/tokencondition.cpp +++ b/libwccl/ops/match/conditions/tokencondition.cpp @@ -3,10 +3,10 @@ namespace Wccl { - TokenCondition::TokenCondition(const boost::shared_ptr<Function<Bool> >& predicate) : _predicate(predicate) { + BOOST_ASSERT(_predicate); } std::string TokenCondition::name() const @@ -21,14 +21,15 @@ std::string TokenCondition::to_string(const Corpus2::Tagset& tagset) const MatchResult TokenCondition::apply(boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const { + int orig_iter = iter_pos->get_value(); if (_predicate->apply(context)->get_value()) { - boost::shared_ptr<Match> match = boost::shared_ptr<Match>(new TokenMatch( - context.sentence_context().get_abs_position(*iter_pos))); + boost::shared_ptr<Match> match(new TokenMatch(context.sentence_context().get_abs_position(*iter_pos))); // increase the $_ variable by one after successful token match - iter_pos->set_value(iter_pos->get_value() + 1); - return MatchResult(true, match); + iter_pos->set_value(orig_iter + 1); + return MatchResult(match); } else { + iter_pos->set_value(orig_iter); return MatchResult(); } } diff --git a/libwccl/ops/match/matchresult.h b/libwccl/ops/match/matchresult.h index 5b3040d52a638f9f21515a93ddbb40f50072e911..84cdea586f63ba1bc04fa9ecdbd686357018cff4 100644 --- a/libwccl/ops/match/matchresult.h +++ b/libwccl/ops/match/matchresult.h @@ -12,7 +12,7 @@ namespace Wccl { class MatchResult { public: - MatchResult(bool matched, const boost::shared_ptr<Match>& match); + MatchResult(const boost::shared_ptr<Match>& match); MatchResult(); boost::shared_ptr<Match> get_match() const; bool matched() const; @@ -30,8 +30,8 @@ MatchResult::MatchResult() : _matched(false), _match() { } inline -MatchResult::MatchResult(bool matched, const boost::shared_ptr<Match>& match) - : _matched(matched), +MatchResult::MatchResult(const boost::shared_ptr<Match>& match) + : _matched(true), _match(match) { }