22 std::string read_id(std::istream& is)
27 while ((c = is.get()) != EOF && !isspace(c))
43 std::string file =
"file.fado";
61 bool is_transducer =
false;
63 std::string line, state;
66 std::getline(is, line,
'\n');
67 std::istringstream ss{line};
74 is_transducer = state ==
"@Transducer";
75 is_dfa = state ==
"@DFA";
76 if (!is_transducer && !is_dfa && state !=
"@NFA")
77 raise(file,
": bad automaton kind in first line: ", state);
79 while (!(state = read_id(ss)).empty())
83 else if (state ==
"*")
85 require(!is_dfa,
"fado: invalid '*' for DFA" 87 require(!init,
"fado: multiple '*' in first line");
107 edit.add_initial(s1);
110 if (l1 ==
"@epsilon")
112 require(!is_dfa,
"fado: unexpected '@epsilon' in DFA, in: ",
114 l2, s2.get().empty() ?
"" :
" ",
120 if (l2 ==
"@epsilon")
122 edit.add_transition(s1, s2, l1, l2,
string_t{});
127 "fado: unexpected trailing characters after: ", s1,
129 edit.add_transition(s1, l2, l1);
133 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.
bool open(bool o)
Whether unknown letters should be added, or rejected.
void skip_space(std::istream &is)
Ignore spaces.
Build an automaton with unknown context.
automaton read_fado(std::istream &is, const location &)