Vcsn  2.3
Be Rational
read.cc
Go to the documentation of this file.
1 #include <lib/vcsn/algos/fwd.hh>
3 #include <lib/vcsn/dot/driver.hh>
4 #include <lib/vcsn/rat/read.hh> // rat::read
5 #include <vcsn/algos/read.hh>
6 #include <vcsn/core/rat/expressionset.hh> // make_expressionset
7 #include <vcsn/ctx/fwd.hh>
8 #include <vcsn/dyn/algos.hh>
9 #include <vcsn/dyn/registries.hh>
10 #include <vcsn/misc/getargs.hh>
11 
12 namespace vcsn
13 {
14  namespace dyn
15  {
16 
17  /*-----------------.
18  | read_automaton. |
19  `-----------------*/
20 
21  namespace
22  {
23  automaton read_dot(std::istream& is)
24  {
26  auto res = d.parse(is);
27  if (!d.errors.empty())
28  raise(d.errors);
29  return res;
30  }
31  }
32 
33  automaton
34  read_automaton(std::istream& is, const std::string& f,
35  bool strip_p)
36  {
37 #if 1
38  static const auto map
40  {
41  "automaton input format",
42  {
43  {"default", "dot"},
44  {"dot", read_dot},
45  {"efsm", read_efsm},
46  {"fado", read_fado},
47  }
48  };
49  auto res = map[f](is);
50  return strip_p ? strip(res) : res;
51 #endif
52  }
53 
54  /*-------------------.
55  | read_expression. |
56  `-------------------*/
57 
60  std::istream& is, const std::string& f)
61  {
62  using fun_t = auto (const context&, rat::identities,
63  std::istream&) -> expression;
64  static const auto map = getarg<std::function<fun_t>>
65  {
66  "expression input format",
67  {
68  {"default", "text"},
69  {"text", [](const context& ctx, rat::identities ids,
70  std::istream& is) {
71  return rat::read(ctx, ids, is);
72  }},
73  }
74  };
75  return map[f](ctx, ids, is);
76  }
77 
78  /*-------------.
79  | read_label. |
80  `-------------*/
81 
82  REGISTRY_DEFINE(read_label);
83  label
84  read_label(const dyn::context& ctx, std::istream& is,
85  const std::string& f)
86  {
87  static const auto map = getarg<bool>
88  {
89  "label input format",
90  {
91  // name, quoted
92  {"default", "text"},
93  {"text", false},
94  {"quoted", true},
95  }
96  };
97  // Lvalue needed by dyn::.
98  bool is_quoted = map[f];
99  return detail::read_label_registry().call(ctx, is, is_quoted);
100  }
101  }
102 } // vcsn::
std::string errors
The error messages.
Definition: driver.hh:36
State and public interface for Dot parsing.
Definition: driver.hh:20
dyn::expression read(const dyn::context &ctx, rat::identities ids, std::istream &is, const location &l)
The expression in stream is.
Definition: read.cc:11
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
Definition: driver.cc:30
return res
Definition: multiply.hh:398
value_impl< detail::label_tag > label
Definition: fwd.hh:26
Template-less root for contexts.
Definition: context.hh:16
Definition: a-star.hh:8
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
automaton read_efsm(std::istream &is)
Definition: efsm.cc:103
expression read_expression(const context &ctx, identities ids, std::istream &is, const std::string &format="default")
Read an expression from a stream.
automaton read_fado(std::istream &is)
Definition: fado.cc:21
A mapping from strings to Values.
Definition: getargs.hh:33
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
Definition: read.cc:84
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true)
Read an automaton from a stream.
Definition: read.cc:34
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Definition: strip.hh:46