diff --git a/libwccl/values/matchvector.cpp b/libwccl/values/matchvector.cpp index a0f1b3bb2faa511423525b3583059db4826f72da..668267d9c2b19106f1cc3bcb29e305167925607d 100644 --- a/libwccl/values/matchvector.cpp +++ b/libwccl/values/matchvector.cpp @@ -29,16 +29,34 @@ std::string MatchVector::var_repr(const std::string &var_name) Position MatchVector::first_token() const { - Position p; - // TODO - return p; + if (matches_.empty()) { + return Position(Position::Nowhere); + } else { + Position p = matches_.front()->first_token(); + for (size_t i = 1; i < matches_.end(); ++i) { + Position c = matches_[i]->first_token(); + if (c.get_value() < p.get_value()) { + p = c; + } + } + return p; + } } Position MatchVector::last_token() const { - Position p; - // TODO - return p; + if (matches_.empty()) { + return Position(Position::Nowhere); + } else { + Position p = matches_.front()->last_token(); + for (size_t i = 1; i < matches_.end(); ++i) { + Position c = matches_[i]->last_token(); + if (c.get_value() > p.get_value()) { + p = c; + } + } + return p; + } } bool MatchVector::empty() const