Vcsn  2.3
Be Rational
is-valid-expression.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstring> // strstr
4 #include <stdexcept>
5 
7 
8 namespace vcsn
9 {
10 
11  /*------------------------.
12  | is_valid(expression). |
13  `------------------------*/
14 
16  template <typename ExpSet>
17  bool
18  is_valid(const ExpSet& rs, const typename ExpSet::value_t& e)
19  {
20  try
21  {
22  // We check validity by checking whether constant_term succeeds:
23  // `1*` will raise.
24  constant_term(rs, e);
25  return true;
26  }
27  catch (const std::runtime_error& e)
28  {
29  // Some operators prevent the computation of the constant-term,
30  // and raise an exception. Forward that failure.
31  if (std::strstr(e.what(), "not supported:"))
32  raise("is_valid", strchr(e.what(), ':'));
33  // Make sure this is really the failure we are looking for.
34  if (!std::strstr(e.what(), "value is not starrable"))
35  std::cerr << "warning: is_valid: unexpected error: "
36  << e.what() << '\n';
37  return false;
38  }
39  }
40 
41  namespace dyn
42  {
43  namespace detail
44  {
46  template <typename ExpSet>
47  bool
49  {
50  const auto& e = exp->as<ExpSet>();
51  return ::vcsn::is_valid(e.valueset(), e.value());
52  }
53  }
54  }
55 } // namespace vcsn
auto rs
Definition: lift.hh:152
Definition: a-star.hh:8
bool is_valid(const Aut &aut)
Definition: is-valid.hh:139
weight_t_of< ExpSet > constant_term(const ExpSet &rs, const typename ExpSet::value_t &e)
The constant term of e.
bool is_valid_expression(const expression &exp)
Bridge (is_valid).
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25