5 #include <boost/algorithm/string/erase.hpp> 6 #include <boost/algorithm/string/predicate.hpp> 7 #include <boost/algorithm/string/replace.hpp> 12 #include <vcsn/dyn/registries.hh> 28 read_here_doc(std::istream& is)
31 = std::regex(
"cat >\\$medir/([a-z]+)\\.[a-z]* <<\\\\EOFSM",
32 std::regex::extended);
37 std::getline(is, line,
'\n');
38 if (std::regex_match(line, res, re))
41 raise(
"invalid efsm file: missing \"cat\" symbol");
48 read_symbol_table(std::istream& is)
55 std::getline(is, line,
'\n');
56 std::istringstream ss{line};
62 raise(
"invalid efsm file");
63 if (val ==
"0" || res ==
"EOFSM")
67 while (line !=
"EOFSM" && is.good())
68 std::getline(is, line,
'\n');
71 "invalid efsm file: missing closing EOFSM");
77 read_weightset_type(std::istream& is)
83 std::getline(is, line,
'\n');
84 if (boost::starts_with(line,
"arc_type="))
86 boost::algorithm::erase_first(line,
"arc_type=");
87 static auto map = getarg<weightset_type>
91 {
"log", weightset_type::logarithmic},
92 {
"log64", weightset_type::logarithmic},
93 {
"standard", weightset_type::tropical},
99 raise(
"invalid efsm file: missing \"arc_type=\"");
106 std::string file =
"file.efsm";
110 bool is_transducer =
false;
113 auto weightset = read_weightset_type(is);
116 auto isyms = read_here_doc(is);
119 std::string ione = read_symbol_table(is);
122 std::string oone = ione;
123 if (isyms ==
"isymbols")
125 is_transducer =
true;
126 auto osyms = read_here_doc(is);
128 "invalid efsm file: expected osymbols: ", osyms);
129 oone = read_symbol_table(is);
134 edit.weightset(weightset);
138 auto trans = read_here_doc(is);
139 require(trans ==
"transitions",
140 "invalid efsm file: expected transitions: ", trans);
146 std::getline(is, line,
'\n');
149 std::istringstream ss{line};
151 ss >> s >> d >> l1 >> l2 >> w;
154 if (l1.get().empty())
156 edit.add_final(s, d);
165 edit.add_transition(s, d, l1, l2, w);
170 edit.add_transition(s, d, l1, l2);
177 file,
": bad input format, missing EOFSM");
179 while (is.get() != EOF)
185 using boost::algorithm::replace_all_copy;
186 auto ctx = replace_all_copy(edit.result_context(),
187 "law<char>",
"lan<string>");
188 return edit.result(
ctx);
Build an automaton with unknown context.
auto map(const std::tuple< Ts... > &ts, Fun f) -> decltype(map_tuple_(f, ts, make_index_sequence< sizeof...(Ts)>()))
Map a function on a tuple, return tuple of the results.
automaton read_efsm(std::istream &is, const location &)
bool open(bool o)
Whether unknown letters should be added, or rejected.
boost::flyweight< std::string, boost::flyweights::no_tracking, boost::flyweights::intermodule_holder > symbol
An internalized string.
weightset_type
Weightset types.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.