13 #include <vcsn/dyn/registries.hh> 21 const auto pos = is.tellg();
23 "cannot keep file position while guessing automaton file format");
26 const static auto probes = std::multimap<std::string, std::regex>
28 {
"daut",
r{
"^\\s*context *="}},
29 {
"daut",
r{
"^\\s*(\\$|\\w+|\".*?\")\\s*->\\s*(\\$|\\w+|\".*?\")"}},
30 {
"dot",
r{
"^\\s*digraph"}},
31 {
"efsm",
r{
"^#! /bin/sh"}},
32 {
"fado",
r{
"^@([DN]FA|Transducer) "}},
33 {
"grail",
r{
"\\(START\\)"}},
35 const auto daut = std::regex();
39 std::getline(is, line,
'\n');
40 for (
const auto& p: probes)
41 if (std::regex_search(line, p.second))
44 require(is.good(),
"cannot rewind automaton file");
48 raise(
"cannot guess automaton format: ", is);
59 automaton read_auto(std::istream& is,
const location& loc)
64 automaton read_dot(std::istream& is,
const location&)
78 "automaton input format",
88 auto res = map[f](is, loc);
98 std::istream& is,
const std::string& f,
105 "expression input format",
109 std::istream& is,
const location& loc) {
114 return map[f](
ctx,
ids, is, loc);
124 const std::string& f)
128 "label input format",
137 bool is_quoted = map[f];
138 return detail::read_label_registry().call(ctx, is, is_quoted);
::vcsn::rat::identities identities
Sets of identities on expressions.
expression read_expression(const context &ctx, identities ids, std::istream &is, const std::string &format="default", const location &loc=location{})
Read an expression from a stream.
dyn::expression read(const dyn::context &ctx, rat::identities ids, std::istream &is, const location &l)
The expression in stream is.
automaton read_efsm(std::istream &is, const location &)
std::ostream & daut(const Aut &aut, std::ostream &out=std::cout)
Print an automaton in Daut format.
An expressionset can implement several different sets of identities on expressions.
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
vcsn::rat::location location
Pairs of positions in a file/stream.
static identities ids(const driver &d)
Get the identities of the driver.
automaton read_fado(std::istream &is, const location &)
Provide a variadic mul on top of a binary mul(), and one().
automaton read_daut(std::istream &is, const location &l)
A mapping from strings to Values.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
std::string guess_automaton_format(std::istream &is)
Guess the format of an automaton file.
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Template-less root for contexts.
State and public interface for Dot parsing.
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true, const location &loc=location{})
Read an automaton from a stream.