6 #include <boost/range/algorithm/mismatch.hpp>
7 #include <boost/algorithm/string/predicate.hpp>
21 template <
typename GenSet>
22 class wordset:
public detail::genset_labelset<GenSet>
31 using word_t =
typename genset_t::word_t;
43 :
wordset{std::make_shared<const genset_t>(gs)}
46 wordset(std::initializer_list<letter_t> letters)
63 auto gs = genset_t::make(is);
73 return this->
genset()->open(o);
82 template <
typename... Args>
85 return value_t{std::forward<Args>(args)...};
119 return genset_t::less(l, r);
133 return genset_t::less(l, r);
139 return genset_t::template special<value_t>();
157 static constexpr
bool
163 static constexpr
bool
169 static constexpr
bool
178 return genset_t::empty_word();
184 return genset_t::is_empty_word(l);
205 template <
typename GenSet_>
216 *
this,
": conv: invalid label: ",
str_escape(v));
221 template <
typename LabelSet_>
234 conv(std::istream& i,
bool =
true)
const
236 return this->
genset()->get_word(i);
248 template <
typename Fun>
249 void convs(std::istream& i, Fun fun)
const
261 this->
genset()->print(l, o, fmt);
271 this->
genset()->print_set(o, fmt);
276 this->
genset()->print_set(o, fmt);
281 this->genset()->print_set(o, fmt);
292 static value_t lgcd(const value_t& w1, const value_t& w2)
294 return {w1.begin(), boost::mismatch(w1, w2).first};
299 static value_t ldiv(const value_t& w1, const value_t& w2)
301 using boost::algorithm::starts_with;
302 VCSN_REQUIRE(starts_with(w2, w1),
303 sname(), ": ldiv: invalid arguments: ", str_escape(w1),
304 ", ", str_escape(w2));
305 return {begin(w2) + size(w1), end(w2)};
309 static value_t& ldiv_here(const value_t& w1, value_t& w2)
315 const value_t& conjunction(const value_t& l, const value_t& r) const
320 raise("conjunction: invalid operation (lhs and rhs are not equal)");
327 template <typename GenSet>
328 struct letterized_traits<wordset<GenSet>>
330 static constexpr bool is_letterized = false;
332 using labelset_t = nullableset<letterset<GenSet>>;
334 static labelset_t labelset(const wordset<GenSet>& ls)
336 return {ls.genset()};
341 template <typename GenSet>
342 struct nullableset_traits<wordset<GenSet>>
344 using type = wordset<GenSet>;
345 static type value(const wordset<GenSet>& ls)
351 template <typename GenSet>
352 struct law_traits<wordset<GenSet>>
354 using type = wordset<GenSet>;
355 static type value(const wordset<GenSet>& ls)
366 #define DEFINE(Lhs, Rhs) \
367 template <typename GenSet> \
368 struct join_impl<Lhs, Rhs> \
371 static type join(const Lhs& lhs, const Rhs& rhs) \
373 return {set_union(*lhs.genset(), *rhs.genset())}; \
378 DEFINE(letterset<GenSet>, wordset<GenSet>);
379 DEFINE(nullableset<letterset<GenSet>>, wordset<GenSet>);
380 DEFINE(wordset<GenSet>, wordset<GenSet>);
385 // FIXME: Factor in genset_labelset?
386 template <typename GenSet>
388 meet(const wordset<GenSet>& lhs, const wordset<GenSet>& rhs)
390 return {set_intersection(*lhs.genset(), *rhs.genset())};
value_t conv(std::istream &i, bool=true) const
Read a word from this stream.
value_t value(Args &&...args) const
Value constructor.
This class has no modeling purpose, it only serves to factor code common to letterset and wordset...
void convs(std::istream &i, Fun fun) const
Process a label class.
#define VCSN_REQUIRE(Cond,...)
A macro similar to require.
typename genset_t::word_t word_t
static constexpr bool is_expressionset()
Implementation of labels are words.
value_t conv(const nullableset< LabelSet_ > &ls, const typename nullableset< LabelSet_ >::value_t &v) const
typename genset_t::letters_t letters_t
std::ostream & print_set(std::ostream &o, format fmt={}) const
auto hash_value(const T &v) -> decltype(std::hash< T >
Following the naming convention of Boost.
Implementation of labels are nullables (letter or empty).
genset_ptr genset() const
static bool is_special(value_t v) ATTRIBUTE_PURE
static bool is_special(const value_t &v)
std::ostream & str_escape(std::ostream &os, const std::string &str, const char *special=nullptr)
Output a string, escaping special characters.
std::ostream & print(const value_t &l, std::ostream &o, format fmt={}) const
static bool less(const letter_t &l, const letter_t &r)
Whether l < r.
static wordset make(std::istream &is)
Build from the description in is.
weightset_mixin< detail::r_impl > r
An input/output format for valuesets.
char eat(std::istream &is, char c)
Check lookahead character and advance.
Provide a variadic mul on top of a binary mul(), and one().
bool is_valid(const value_t &v) const
static bool less(const value_t &l, const value_t &r)
Whether l < r.
static constexpr bool is_free()
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
static word_t letters_of_padded(const value_t &v, letter_t)
Prepare to iterate over the letters of v.
static constexpr bool has_one()
wordset(const genset_ptr &gs)
wordset(const genset_t &gs={})
value_t conv(const letterset< GenSet_ > &ls, typename letterset< GenSet_ >::value_t v) const
static constexpr bool is_letterized()
static ATTRIBUTE_PURE bool is_one(value_t l)
word_t word(const value_t &v) const
Convert to a word.
std::istringstream is
The input stream: the specification to translate.
bool open(bool o) const
Whether unknown letters should be added, or rejected.
wordset(std::initializer_list< letter_t > letters)
Print as a parsable type string.
static bool equal(const value_t &l, const value_t &r)
Whether l == r.
Implementation of labels are letters.
typename genset_t::letter_t letter_t
typename helper_t::value_t value_t
const labelset_ptr labelset() const
value_t conv(self_t, const value_t &v) const
static labelset_t::value_t get_value(const value_t &v)
The (inner) value when it (the outer value) is not one.
static bool is_one(const value_t &l) ATTRIBUTE_PURE
static size_t size(const value_t &v)
static size_t hash(const value_t &v)
static word_t letters_of(const value_t &v)
Prepare to iterate over the letters of v.
void convs_(std::istream &i, Fun fun) const
Read and process a class of letters.
std::shared_ptr< const genset_t > genset_ptr
ATTRIBUTE_PURE auto has(Args &&...args) const -> decltype(this->genset() -> has(std::forward< Args >(args)...))