1 #ifndef VCSN_LABELSET_WORDSET_HH
2 # define VCSN_LABELSET_WORDSET_HH
7 # include <boost/algorithm/string/predicate.hpp>
20 template <
typename GenSet>
21 class wordset:
public detail::genset_labelset<GenSet>
30 using word_t =
typename genset_t::word_t;
42 :
wordset{std::make_shared<const genset_t>(gs)}
50 std::string
vname(
bool full =
true)
const
62 auto gs = genset_t::make(is);
72 return this->
genset().open(o);
81 template <
typename... Args>
84 return value_t{std::forward<Args>(args)...};
110 return (std::forward_as_tuple(l.size(), l)
111 < std::forward_as_tuple(r.size(),
r));
117 return genset_t::template special<value_t>();
135 static constexpr
bool
141 static constexpr
bool
147 static constexpr
bool
156 return genset_t::empty_word();
162 return genset_t::is_empty_word(l);
184 return this->
genset().get_word(i);
196 std::set<value_t> res;
207 o << (format ==
"latex" ?
"\\varepsilon" :
"\\e");
210 if (format ==
"latex" && ! this->
is_letter(l))
213 if (format ==
"latex" && ! this->
is_letter(l))
222 if (format ==
"latex")
224 this->
genset().print_set(o, format);
227 else if (format ==
"text")
230 raise(
"invalid format: ", format);
237 return {w1.begin(), std::mismatch(w1.begin(), w1.end(), w2.begin()).first};
244 using boost::algorithm::starts_with;
247 return w2.substr(
size(w1));
261 template <
typename GenSet>
271 template <
typename GenSet>
286 #define DEFINE(Lhs, Rhs) \
287 template <typename GenSet> \
288 struct join_impl<Lhs, Rhs> \
291 static type join(const Lhs& lhs, const Rhs& rhs) \
293 return {get_union(lhs.genset(), rhs.genset())}; \
306 template <
typename GenSet>
314 #endif // !VCSN_LABELSET_WORDSET_HH
static constexpr bool is_letterized()
std::shared_ptr< const genset_t > genset_ptr
static bool equals(const value_t l, const value_t r)
Whether l == r.
value_t conv(std::istream &i) const
static value_t & ldiv_here(const value_t &w1, value_t &w2)
w2 := w1 \ w2.
static value_t lgcd(const value_t &w1, const value_t &w2)
The longest common prefix.
std::set< letter_t > letters_t
std::ostream & print_set(std::ostream &o, symbol format=symbol{"text"}) const
bool open(bool o) const
Whether unknown letters should be added, or rejected.
value_t value(Args &&...args) const
Value constructor.
std::ostream & print(const value_t &l, std::ostream &o, symbol format=symbol{"text"}) const
Implementation of labels are nullables (letter or empty).
static type value(const wordset< GenSet > &ls)
boost::flyweight< std::string, boost::flyweights::no_tracking > symbol
An internalized string.
word_t word(const value_t &v) const
Convert to a word.
typename genset_t::word_t word_t
std::ostream & str_escape(std::ostream &os, const std::string &str)
Output a string, escaping special characters.
static std::string sname()
static constexpr bool is_ratexpset()
static bool is_special(const value_t &v)
This class has no modeling purpose, it only serves to factor code common to letterset, nullableset and wordset.
std::string vname(bool full=true) const
std::size_t hash_value(const T &v)
ATTRIBUTE_PURE auto is_letter(Args &&...args) const -> decltype(this->genset().is_letter(std::forward< Args >(args)...))
bool is_valid(const value_t &v) const
static type value(const wordset< GenSet > &ls)
static value_t ldiv(const value_t &w1, const value_t &w2)
Compute w1 \ w2 = w1^{-1}w2.
static std::string sname()
static size_t hash(const value_t &v)
#define DEFINE(Lhs, Rhs)
Declare that Lhs v Rhs => Rhs (on the union of alphabets).
auto meet(const ratexpset< Ctx1 > &a, const ratexpset< Ctx2 > &b) -> ratexpset< meet_t< Ctx1, Ctx2 >>
The meet of two ratexpsets.
std::istringstream is
The input stream: the specification to translate.
std::set< letter_t > convs_(std::istream &i) const
Read a range of letters.
wordset(const genset_t &gs={})
static bool less_than(const value_t l, const value_t r)
Whether l < r.
ATTRIBUTE_PURE auto has(Args &&...args) const -> decltype(this->genset().has(std::forward< Args >(args)...))
std::string vname(bool full=true) const
Provide a variadic mul on top of a binary mul(), and one().
std::set< T, Compare, Alloc > intersection(const std::set< T, Compare, Alloc > &set1, const std::set< T, Compare, Alloc > &set2)
The intersection of two sets.
static constexpr bool is_free()
static wordset make(std::istream &is)
Build from the description in is.
char eat(std::istream &is, char c)
Check lookahead character and advance.
static constexpr bool has_one()
static value_t conv(self_type, value_t v)
typename genset_t::letter_t letter_t
Implementation of labels are letters.
Implementation of labels are words.
static bool is_one(const value_t &l) ATTRIBUTE_PURE
std::set< value_t > convs(std::istream &i) const
Read a range of labels.
The smallest nullableset which includes LabelSet.
wordset(const genset_ptr &gs)
typename genset_t::word_t word_t
const genset_t & genset() const
variadic_mul_mixin< detail::r_impl > r
static size_t size(const value_t &v)
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
static word_t letters_of(word_t v)
Prepare to iterate over the letters of v.