23 std::string read_id(std::istream& is)
28 while ((c = is.get()) != EOF && !isspace(c))
44 std::string file =
"file.fado";
62 bool is_transducer =
false;
64 std::string line, state;
67 std::getline(is, line,
'\n');
68 std::istringstream ss{line};
75 is_transducer = state ==
"@Transducer";
76 is_dfa = state ==
"@DFA";
77 if (!is_transducer && !is_dfa && state !=
"@NFA")
78 raise(file,
": bad automaton kind in first line: ", state);
80 while (!(state = read_id(ss)).empty())
84 else if (state ==
"*")
86 require(!is_dfa,
"fado: invalid '*' for DFA"
88 require(!init,
"fado: multiple '*' in first line");
108 edit.add_initial(s1);
111 if (l1 ==
"@epsilon")
113 require(!is_dfa,
"fado: unexpected '@epsilon' in DFA, in: ",
115 l2, s2.get().empty() ?
"" :
" ",
121 if (l2 ==
"@epsilon")
123 edit.add_transition(s1, s2, l1, l2,
string_t{});
128 "fado: unexpected trailing characters after: ", s1,
130 edit.add_transition(s1, l2, l1);
134 return edit.result();
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
void skip_space(std::istream &is)
Ignore spaces.
automaton read_fado(std::istream &is)
Build an automaton with unknown context.
bool open(bool o)
Whether unknown letters should be added, or rejected.