17 #ifndef AWALI_LABELSET_NULLABLESET_HH 
   18 # define AWALI_LABELSET_NULLABLESET_HH 
   32 #include <awali/common/json/node.cc> 
   33 #include <awali/common/parse_exception.cc> 
   36 namespace awali { 
namespace sttc {
 
   42     template <
typename LabelSet>
 
   47       using value_t = std::pair<typename labelset_t::value_t, bool>;
 
   48       using kind_t = 
typename LabelSet::kind_t;
 
   50       static null make(std::istream& is)
 
   57         auto ls = null::labelset_t::make(is);
 
   66         return value_t{null::labelset_t::special(), 
true};
 
   73         return value_t{null::labelset_t::special(), 
false};
 
   76       template <
typename Ls>
 
   78       static typename std::enable_if<Ls::has_one(), 
bool>::type
 
   81         return std::get<1>(l) || Ls::is_one(
get_value(l));
 
   84       template <
typename Ls>
 
   86       static typename std::enable_if<!Ls::has_one(), 
bool>::type
 
   89         return std::get<1>(l);
 
   96         return is_one_<labelset_t>(l);
 
   99       template <
typename... Args>
 
  103         return {ls.value(std::forward<Args>(args)...), 
false};
 
  107       static typename labelset_t::value_t
 
  110         return std::get<0>(v);
 
  116     template <
typename GenSet>
 
  136         if (is.peek() == 
'_')
 
  139           auto gs = genset_t::make(is);
 
  144         auto ls = labelset_t::make(is);
 
  153         return genset_t::special_letter();
 
  160         return genset_t::one_letter();
 
  170       template <
typename... Args>
 
  174         return ls.
value(std::forward<Args>(args)...);
 
  178       static typename labelset_t::value_t
 
  187   template <
typename LabelSet>
 
  210       return "lan<" + labelset_t::sname() + 
">";
 
  232     static constexpr 
bool 
  238     static constexpr 
bool 
  244     static constexpr 
bool 
  247       return labelset_t::is_letterized();
 
  286     template <
typename... Args>
 
  331       return !
is_one(l) && labelset_t::is_special(get_value(l));
 
  336       return is_one(v) ? 0 : labelset_t::size(get_value(v));
 
  342       std::hash_combine(res, labelset_t::hash(get_value(v)));
 
  362         res = 
value(ls_->conv(i));
 
  367     parse(
const std::string& s, 
size_t& p, 
bool fixed_domain=
true)
 const {
 
  369       if(s[p]==
'e' && p>0 && s[p-1]==
'\\'){
 
  374         return ls_->parse(s,++p, fixed_domain);
 
  381       auto l = ls_->convs(i);
 
  382       std::set<value_t> res;
 
  384         res.emplace(
value(v));
 
  390           const std::string& 
format = 
"text")
 const 
  393         o << (
format == 
"latex" ? 
"\\varepsilon" : 
"\\e");
 
  399     template<
unsigned version = version::fsm_json>
 
  402       version::check_fsmjson<version>();
 
  412           return ls_->template value_from_json<version>(p);
 
  421       is.get(kind, 
sizeof kind);
 
  422       if (strncmp(
"lan", kind, 4))
 
  423         raise(
"kind::make: unexpected: ",
str_escape(kind),
", expected: lan");
 
  435       return labelset()->is_zero(get_value(v));
 
  441       return labelset()->is_letter(get_value(v));
 
  449       return value(ls_->transpose(get_value(l)));
 
  461       else if (
format == 
"text")
 
  464         raise(
"invalid format: ", 
format);
 
  470     template<
unsigned version = version::fsm_json>
 
  474       version::check_fsmjson<version>();
 
  485     template<
unsigned version = version::fsm_json>
 
  490       version::check_fsmjson<version>();
 
  497             return ls_->template value_to_json<version>(
value);
 
  502     static typename labelset_t::value_t
 
  512 #define DEFINE(Func, Operation, Lhs, Rhs, Res)                \ 
  513   template <typename GenSet>                                  \ 
  515   Func(const Lhs& lhs, const Rhs& rhs)                        \ 
  517     return {Operation(lhs.genset(), rhs.genset())};           \ 
  530   template <typename Lls, typename Rls>
 
  535     return {
meet(*lhs.labelset(), *rhs.labelset())};
 
  548   template <typename Lls, typename Rls>
 
  553     return {
join(*lhs.labelset(), *rhs.labelset())};
 
unsigned empty() const
Definition: node.hh:467
 
virtual string_t const  * string() const
Casts this node to string_t.
Definition: node.hh:215
 
node_kind_t const kind
Definition: node.hh:196
 
virtual array_t const  * array() const
Casts this node to array_t.
Definition: node.hh:207
 
object_t * insert_before(std::string const &ref_key, std::string key, node_t *node)
 
std::string value
Definition: node.hh:531
 
The semiring of complex numbers.
Definition: c.hh:44
 
Implementation of labels are letters.
Definition: letterset.hh:43
 
letter_t value_t
Definition: letterset.hh:53
 
value_t value(Args &&... args) const
Value constructor.
Definition: letterset.hh:114
 
GenSet genset_t
Definition: letterset.hh:45
 
Implementation of labels are nullables (letter or empty).
Definition: nullableset.hh:189
 
static size_t hash(const value_t &v)
Definition: nullableset.hh:339
 
static constexpr bool is_letterized()
Definition: nullableset.hh:245
 
bool open(bool o) const
Whether unknown letters should be added, or rejected.
Definition: nullableset.hh:227
 
value_t parse(const std::string &s, size_t &p, bool fixed_domain=true) const
Definition: nullableset.hh:367
 
std::shared_ptr< const labelset_t > labelset_ptr
Definition: nullableset.hh:192
 
size_t size(const value_t &v) const
Definition: nullableset.hh:334
 
static constexpr bool is_ratexpset()
Definition: nullableset.hh:239
 
typename helper_t::value_t value_t
Definition: nullableset.hh:197
 
static bool less_than(const value_t &l, const value_t &r)
Whether l < r.
Definition: nullableset.hh:312
 
bool is_letter(const value_t &v) const
Definition: nullableset.hh:439
 
value_t zero() const
Definition: nullableset.hh:427
 
value_t transpose(const value_t &l) const
Definition: nullableset.hh:445
 
value_t conv(std::istream &i) const
Definition: nullableset.hh:349
 
static constexpr ATTRIBUTE_PURE value_t one()
Definition: nullableset.hh:257
 
const labelset_ptr labelset() const
Definition: nullableset.hh:281
 
std::ostream & print(value_t l, std::ostream &o, const std::string &format="text") const
Definition: nullableset.hh:389
 
static std::string sname()
Definition: nullableset.hh:208
 
json::node_t * to_json() const
Definition: nullableset.hh:471
 
bool is_valid(value_t v) const
Definition: nullableset.hh:270
 
json::node_t * value_to_json(value_t value) const
Definition: nullableset.hh:487
 
value_t value_from_json(json::node_t *p) const
Definition: nullableset.hh:401
 
static bool equals(const value_t &l, const value_t &r)
Whether l == r.
Definition: nullableset.hh:304
 
static nullableset make(std::istream &i)
Build from the description in is.
Definition: nullableset.hh:219
 
value_t conv(self_type, value_t v) const
Definition: nullableset.hh:276
 
static constexpr bool is_free()
Definition: nullableset.hh:250
 
nullableset(const labelset_t &ls)
Definition: nullableset.hh:200
 
static constexpr bool has_one()
Definition: nullableset.hh:233
 
LabelSet labelset_t
Definition: nullableset.hh:191
 
static ATTRIBUTE_PURE bool is_one(value_t l)
Definition: nullableset.hh:264
 
std::string vname(bool full=true) const
Definition: nullableset.hh:213
 
std::set< value_t > convs(std::istream &i) const
Definition: nullableset.hh:379
 
std::ostream & print_set(std::ostream &o, const std::string &format="text") const
Definition: nullableset.hh:453
 
static void make_nullableset_kind(std::istream &is)
Definition: nullableset.hh:418
 
typename helper_t::kind_t kind_t
Definition: nullableset.hh:195
 
static bool is_special(const value_t &l)
Definition: nullableset.hh:329
 
value_t value(Args &&... args) const
Definition: nullableset.hh:288
 
static value_t special()
Definition: nullableset.hh:323
 
nullableset(const std::shared_ptr< const labelset_t > &ls)
Definition: nullableset.hh:204
 
bool is_zero(const value_t &v) const
Definition: nullableset.hh:433
 
The semiring of floating Numbers.
Definition: r.hh:35
 
labelset_description nullableset(labelset_description ls1)
 
@ ARRAY
Definition: node.hh:94
 
@ STRING
Definition: node.hh:97
 
void eat(std::istream &is, char c)
Check lookahead character and advance.
Definition: stream.hh:62
 
RatExpSet::ratexp_t less_than(const RatExpSet &rs, const typename RatExpSet::ratexp_t &v)
Definition: less_than.hh:168
 
RatExpSet::ratexp_t equals(const RatExpSet &rs, const typename RatExpSet::ratexp_t &v)
Definition: equal_visit.hh:155
 
auto join(const ratexpset< Ctx1 > &a, const ratexpset< Ctx2 > &b) -> ratexpset< join_t< Ctx1, Ctx2 >>
The union of two ratexpsets.
Definition: ratexpset.hh:449
 
std::ostream & str_escape(std::ostream &os, const int c)
Definition: escape.hh:30
 
auto meet(const ratexpset< Ctx1 > &a, const ratexpset< Ctx2 > &b) -> ratexpset< meet_t< Ctx1, Ctx2 >>
The meet of two ratexpsets.
Definition: ratexpset.hh:438
 
set_alphabet< L2 > get_union(const set_alphabet< L2 > &lhs, const set_alphabet< L2 > &rhs)
Definition: setalpha.hh:364
 
set_alphabet< L2 > intersection(const set_alphabet< L2 > &lhs, const set_alphabet< L2 > &rhs)
Definition: setalpha.hh:357
 
auto format(const ValueSet &vs, const typename ValueSet::value_t &v, Args &&... args) -> std::string
Format v via vs.print.
Definition: stream.hh:109
 
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
 
static const std::string full
Completely version of Awali as a std::string.
Definition: version.hh:42
 
Main namespace of Awali.
Definition: ato.hh:22
 
#define DEFINE(Func, Operation, Lhs, Rhs, Res)
Definition: nullableset.hh:512
 
GenSet genset_t
Definition: nullableset.hh:120
 
static ATTRIBUTE_PURE bool is_one(value_t l)
Definition: nullableset.hh:165
 
static constexpr ATTRIBUTE_PURE null::value_t one()
Definition: nullableset.hh:158
 
static value_t value(const labelset_t &ls, Args &&... args)
Definition: nullableset.hh:172
 
static ATTRIBUTE_PURE labelset_t::value_t get_value(const value_t &v)
Definition: nullableset.hh:179
 
typename labelset_t::value_t value_t
Definition: nullableset.hh:122
 
static constexpr ATTRIBUTE_PURE null::value_t special()
Definition: nullableset.hh:151
 
static null make(std::istream &is)
Definition: nullableset.hh:126
 
Add support for an empty word to a LabelSet that does not provide such special label to this end.
Definition: nullableset.hh:44
 
std::pair< typename labelset_t::value_t, bool > value_t
Definition: nullableset.hh:47
 
static ATTRIBUTE_PURE bool is_one(value_t l)
Definition: nullableset.hh:94
 
static value_t value(const labelset_t &ls, Args &&... args)
Definition: nullableset.hh:101
 
LabelSet labelset_t
Definition: nullableset.hh:45
 
static ATTRIBUTE_PURE std::enable_if<!Ls::has_one(), bool >::type is_one_(value_t l)
Definition: nullableset.hh:87
 
static ATTRIBUTE_PURE std::enable_if< Ls::has_one(), bool >::type is_one_(value_t l)
Definition: nullableset.hh:79
 
static constexpr ATTRIBUTE_PURE value_t special()
Definition: nullableset.hh:71
 
static ATTRIBUTE_PURE labelset_t::value_t get_value(const value_t &v)
Definition: nullableset.hh:108
 
typename LabelSet::kind_t kind_t
Definition: nullableset.hh:48
 
static constexpr ATTRIBUTE_PURE value_t one()
Definition: nullableset.hh:64
 
static null make(std::istream &is)
Definition: nullableset.hh:50
 
marker type for labelsets where labels are nullable
Definition: kind.hh:78