diff --git a/libwccl/ops/match/applyoperator.cpp b/libwccl/ops/match/applyoperator.cpp index cdac9670df21dcbb10582ee305d7ab85213f1291..e40ddd8d8764363f7ed13ea270f84efc3048bd4e 100644 --- a/libwccl/ops/match/applyoperator.cpp +++ b/libwccl/ops/match/applyoperator.cpp @@ -1,4 +1,5 @@ #include <libwccl/ops/match/applyoperator.h> +#include <libwccl/values/matchvector.h> #include <libpwrutils/foreach.h> namespace Wccl { @@ -35,7 +36,7 @@ void ApplyOperator::execute(const ActionExecContext &context) const should_act = _conditions[i]->apply(context)->get_value(); } if (should_act) { - matches->append(match); + matches->append(match); // the match goes to $m:_M[0] foreach (const boost::shared_ptr<const MatchAction>& action, _actions) { action->execute(context); } diff --git a/libwccl/ops/match/matchoperator.cpp b/libwccl/ops/match/matchoperator.cpp index af296365a79341fd0808f35cc20e5bd1597da44f..4cb8ec90581d689e9b47903e9f67147d6eb2f2a3 100644 --- a/libwccl/ops/match/matchoperator.cpp +++ b/libwccl/ops/match/matchoperator.cpp @@ -1,5 +1,4 @@ #include <libwccl/ops/match/matchoperator.h> -#include <libpwrutils/foreach.h> #include <sstream> namespace Wccl { @@ -8,47 +7,25 @@ boost::shared_ptr<Match> MatchOperator::apply( boost::shared_ptr<Position> iter_pos, const FunExecContext& context) const { - boost::shared_ptr<MatchVector> matches(new MatchVector()); int orig_iter_pos = iter_pos->get_value(); - - foreach (const boost::shared_ptr<const MatchCondition>& cond, _conditions) { - MatchResult res = cond->apply(iter_pos, context); - if(res.matched()) { - matches->append(res.get_match()); - } else { - matches.reset(new MatchVector()); - iter_pos->set_value(orig_iter_pos + 1); - return matches; - } + MatchResult res = _conditions->apply(iter_pos, context); + if(res.matched()) { + return res.get_match(); } - return matches; + iter_pos->set_value(orig_iter_pos + 1); + return boost::make_shared<Match>(); } std::string MatchOperator::to_string(const Corpus2::Tagset& tagset) const { std::ostringstream ostream; - ostream << name() << "("; - for(size_t i = 0; i < _conditions.size(); ++i) { - if (i != 0) { - ostream << ", "; - } - ostream << _conditions[i]->to_string(tagset); - } - ostream << ")"; + ostream << name() << _conditions->to_string(tagset); return ostream.str(); } std::ostream& MatchOperator::write_to(std::ostream &ostream) const { - ostream << name() << "("; - for(size_t i = 0; i < _conditions.size(); ++i) { - if (i != 0) { - ostream << ", "; - } - ostream << *_conditions[i]; - } - ostream << ")"; - return ostream; + return ostream << name() << *_conditions; } } /* end ns Wccl */ diff --git a/libwccl/ops/match/matchoperator.h b/libwccl/ops/match/matchoperator.h index ff679ca481ddd26014a1a8122937ba211312fb91..dd6745b050a70210d760aa7069abca8a30653d87 100644 --- a/libwccl/ops/match/matchoperator.h +++ b/libwccl/ops/match/matchoperator.h @@ -1,8 +1,7 @@ #ifndef LIBWCCL_OPS_MATCH_MATCHOPERATOR_H #define LIBWCCL_OPS_MATCH_MATCHOPERATOR_H -#include <libwccl/ops/match/matchcondition.h> -#include <libwccl/values/matchvector.h> +#include <libwccl/ops/match/conditions/conjconditions.h> namespace Wccl { @@ -12,8 +11,9 @@ namespace Wccl { class MatchOperator : public Expression { public: - MatchOperator(const std::vector< boost::shared_ptr<const MatchCondition> >& conditions) + MatchOperator(const boost::shared_ptr<ConjConditions>& conditions) : _conditions(conditions) { + BOOST_ASSERT(_conditions); } /** @@ -52,7 +52,7 @@ protected: std::ostream& write_to(std::ostream& ostream) const; private: - const std::vector<boost::shared_ptr<const MatchCondition> > _conditions; + const boost::shared_ptr<ConjConditions> _conditions; }; } /* end ns Wccl */ diff --git a/libwccl/parser/grammar.g b/libwccl/parser/grammar.g index 712d2c042665d422f8d6531704f0694920b4393d..a0260238c477c5f59e71644977223ea49e93017c 100644 --- a/libwccl/parser/grammar.g +++ b/libwccl/parser/grammar.g @@ -70,6 +70,7 @@ header { // Match operators #include <libwccl/values/tokenmatch.h> #include <libwccl/values/annotationmatch.h> + #include <libwccl/values/matchvector.h> #include <libwccl/ops/match/applyoperator.h> // Unicode String