12 #include <vcsn/dyn/registries.hh> 20 const auto pos = is.tellg();
22 "cannot keep file position while guessing automaton file format");
25 const static auto probes = std::multimap<std::string, std::regex>
27 {
"efsm.bzip2",
r{
"^BZh"}},
28 {
"efsm.lzma",
r{
"\xFD""7zXZ""\x00"}},
29 {
"daut",
r{
"^\\s*context *="}},
30 {
"daut",
r{
"^\\s*(\\$|\\w+|\".*?\")\\s*->\\s*(\\$|\\w+|\".*?\")"}},
31 {
"dot",
r{
"^\\s*digraph"}},
32 {
"efsm",
r{
"^#! /bin/sh"}},
33 {
"fado",
r{
"^@([DN]FA|Transducer) "}},
34 {
"grail",
r{
"\\(START\\)"}},
36 const auto daut = std::regex();
40 std::getline(is, line,
'\n');
41 for (
const auto& p: probes)
42 if (std::regex_search(line, p.second))
45 require(is.good(),
"cannot rewind automaton file");
49 raise(
"cannot guess automaton format: ", is);
60 automaton read_auto(std::istream& is,
const location& loc)
65 automaton read_dot(std::istream& is,
const location&)
79 "automaton input format",
91 auto res = map[f](is, loc);
101 std::istream& is,
const std::string& f,
108 "expression input format",
112 std::istream& is,
const location& loc) {
117 return map[f](
ctx,
ids, is, loc);
127 const std::string& f)
131 "label input format",
140 bool is_quoted = map[f];
141 return detail::read_label_registry().call(ctx, is, is_quoted);
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
std::string guess_automaton_format(std::istream &is)
Guess the format of an automaton file.
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.
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true, const location &loc=location{})
Read an automaton from a stream.
automaton read_efsm_bzip2(std::istream &is, const location &loc)
An expressionset can implement several different sets of identities on expressions.
vcsn::rat::location location
Pairs of positions in a file/stream.
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
automaton read_fado(std::istream &is, const location &)
Provide a variadic mul on top of a binary mul(), and one().
State and public interface for Dot parsing.
automaton read_efsm(std::istream &is, const location &loc)
Template-less root for contexts.
std::ostream & daut(const Aut &aut, std::ostream &out=std::cout)
Print an automaton in Daut format.
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
automaton read_daut(std::istream &is, const location &l)
A mapping from strings to Values.
automaton read_efsm_lzma(std::istream &is, const location &loc)
static identities ids(const driver &d)
Get the identities of the driver.
::vcsn::rat::identities identities
Sets of identities on expressions.
void require(Bool b, Args &&... args)
If b is not verified, raise an error with args as message.
dyn::expression read(const dyn::context &ctx, rat::identities ids, std::istream &is, const location &l)
The expression in stream is.