8 #include <vcsn/dyn/registries.hh>
20 if (lbl.get().empty())
21 return labelset_type::empty;
22 else if (lbl ==
"\\e")
23 return labelset_type::lan;
24 else if (1 < lbl.get().size())
25 return labelset_type::law;
27 return labelset_type::lal;
34 case labelset_type::empty:
return {};
35 case labelset_type::lal:
return "lal<char>";
36 case labelset_type::lan:
return "lan<char>";
37 case labelset_type::law:
return "law<char>";
46 || s.get().size() == 1 && std::isalnum(s.get()[0]))
51 static auto re = std::regex{
"['\\\\]"};
53 + std::regex_replace(s.get(), re,
"\\$&")
58 std::string
weight(
const std::string& w)
60 return w.empty() ? std::string{} :
"<" + w +
">";
77 && w.get().find(
'.') != std::string::npos)
108 if (lbl2.get().empty())
185 edit->add_transition(std::get<0>(t), std::get<1>(t),
186 std::get<2>(t), std::get<3>(t));
188 catch (
const std::runtime_error& e)
190 raise(e,
" while adding transition: (", std::get<0>(t),
", ",
191 weight(std::get<3>(t)), std::get<2>(t),
", ",
192 std::get<1>(t),
')');
198 edit->add_initial(p.first, p.second);
200 catch (
const std::runtime_error& e)
202 raise(e,
" while setting initial state: ",
weight(p.second),
209 edit->add_final(p.first, p.second);
211 catch (
const std::runtime_error& e)
213 raise(e,
" while setting final state: ",
weight(p.second), p.first);
216 return edit->result();
bool weighted_
Whether we saw a non-empty weight.
void reset()
Get ready to build another automaton.
dyn::automaton result(const std::string &ctx={})
Return the built automaton.
void add_transition(string_t src, string_t dst, string_t lbl, string_t w=string_t{})
Add an acceptor transition from src to dst, labeled by lbl.
std::vector< transition_t > transitions_
value_impl< detail::weight_tag > weight
labelset_type
Labelset types, increasing generality.
context make_context(const std::string &name)
Build a context from its name.
void register_weight_(string_t w)
Record that this weight was seen.
bool open_
Whether the labelset is open.
std::string type(const automaton &a)
The implementation type of a.
labelset_type output_type_
Labelset type for output tape.
void add_final(string_t s, string_t w=string_t{})
Add s as a final state.
weightset_type weightset_type_
The weightset scale.
std::vector< std::pair< string_t, string_t > > initial_states_
The collected initial states: (State, Weight).
#define BUILTIN_UNREACHABLE()
labelset_type input_type_
Labelset type for input tape.
automaton_editor * make_automaton_editor(const context &ctx)
Build an automatonset from its context.
std::string to_string(direction d)
Conversion to string.
void add_initial(string_t s, string_t w=string_t{})
Add s as an initial state.
automaton_editor::string_t string_t
A hash-cons'ed string type.
bool real_
Whether we saw a period in a the weight.
std::string result_context() const
Return the context that was inferred.
std::string quote(const std::string &s)
Turn a label into a parsable label: escape special characters.
std::vector< std::pair< string_t, string_t > > final_states_
The collected final states: (State, Weight).
bool open(bool o)
Whether unknown letters should be added, or rejected.