23 next_here_doc(std::istream&
is)
25 static std::regex re(
"cat >\\$medir/([a-z]+)\\.[a-z]* <<\\\\EOFSM",
26 std::regex::extended);
31 std::getline(is, line,
'\n');
32 if (std::regex_match(line, res, re))
35 raise(
"invalid file: missing \"cat\" symbol");
42 swallow_symbol_table(std::istream& is)
49 std::getline(is, line,
'\n');
50 std::istringstream ss{line};
56 raise(
"invalid file");
57 if (val ==
"0" || res ==
"EOFSM")
61 while (line !=
"EOFSM" && is.good())
62 std::getline(is, line,
'\n');
65 "invalid file: missing closing EOFSM");
74 std::string file =
"file.efsm";
76 boost::flyweight<std::string, boost::flyweights::no_tracking>;
79 bool is_transducer =
false;
82 auto isyms = next_here_doc(is);
85 std::string ione = swallow_symbol_table(is);
88 std::string oone = ione;
89 if (isyms ==
"isymbols")
92 auto osyms = next_here_doc(is);
94 "invalid file: expected osymbols: ", osyms);
95 oone = swallow_symbol_table(is);
103 auto trans = next_here_doc(is);
104 require(trans ==
"transitions",
105 "invalid file: expected transitions: ", trans);
111 std::getline(is, line,
'\n');
114 std::istringstream ss{line};
116 ss >> s >> d >> l1 >> l2 >> w;
119 if (l1.get().empty())
142 file,
": bad input format, missing EOFSM");
144 while (is.get() != EOF)
154 REGISTER_DEFINE(
efsm);
159 detail::efsm_registry().call(aut, out);
bool open(bool o)
Whether unknown letters should be added, or rejected.
std::shared_ptr< detail::automaton_base > automaton
void add_initial(string_t s, string_t w=string_t{})
Add s as an initial state.
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.
void add_final(string_t s, string_t w=string_t{})
Add s as a final state.
boost::flyweight< std::string, boost::flyweights::no_tracking > string_t
std::istringstream is
The input stream: the specification to translate.
dyn::automaton result()
Return the built automaton.
std::ostream & efsm(const automaton &aut, std::ostream &out)
Output in Extended FSM format.
automaton read_efsm(std::istream &is)
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Build an automaton with unknown context.