diff --git a/libwccl/ops/actions/delete.cpp b/libwccl/ops/actions/delete.cpp index 6deb0518053790a7e66deb7824d0888fec1bb856..e6b8b3eca6ebabcb37a40466e4038097a2d73069 100644 --- a/libwccl/ops/actions/delete.cpp +++ b/libwccl/ops/actions/delete.cpp @@ -1,5 +1,6 @@ #include <libwccl/ops/actions/delete.h> #include <libwccl/ops/functions/constant.h> +#include <libpwrutils/foreach.h> #include <sstream> namespace Wccl { @@ -7,7 +8,23 @@ namespace Wccl { Bool Delete::execute(const ActionExecContext& context) const { Bool changed(false); - //@todo: implement + const boost::shared_ptr<const Position> pos = pos_->apply(context); + int abs_pos = context.sentence_context().get_abs_position(*pos); + if (context.sentence_context().is_inside(abs_pos)) { + Corpus2::Token& token = *context.sentence_context().at(abs_pos); + std::vector<Corpus2::Lexeme> original(token.lexemes()); + std::vector<Corpus2::Lexeme> remaining; + token.lexemes() = remaining; + foreach (const Corpus2::Lexeme& lexeme, original) { + token.add_lexeme(lexeme); + if (!condition_->apply(context)->get_value()) { + remaining.push_back(lexeme); + } + token.lexemes().pop_back(); + } + changed.set_value((remaining.size() > 0) && (remaining.size() < original.size())); + token.lexemes() = changed.get_value() ? remaining : original; + } return changed; }