Vcsn  2.4
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  {"daut", read_daut},
45  {"dot", read_dot},
46  {"efsm", read_efsm},
47  {"fado", read_fado},
48  }
49  };
50  auto res = map[f](is);
51  return strip_p ? strip(res) : res;
52 #endif
53  }
54 
55  /*-------------------.
56  | read_expression. |
57  `-------------------*/
58 
61  std::istream& is, const std::string& f)
62  {
63  using fun_t = auto (const context&, rat::identities,
64  std::istream&) -> expression;
65  static const auto map = getarg<std::function<fun_t>>
66  {
67  "expression input format",
68  {
69  {"default", "text"},
70  {"text", [](const context& ctx, rat::identities ids,
71  std::istream& is) {
72  return rat::read(ctx, ids, is);
73  }},
74  }
75  };
76  return map[f](ctx, ids, is);
77  }
78 
79  /*-------------.
80  | read_label. |
81  `-------------*/
82 
83  REGISTRY_DEFINE(read_label);
84  label
85  read_label(const dyn::context& ctx, std::istream& is,
86  const std::string& f)
87  {
88  static const auto map = getarg<bool>
89  {
90  "label input format",
91  {
92  // name, quoted
93  {"default", "text"},
94  {"text", false},
95  {"quoted", true},
96  }
97  };
98  // Lvalue needed by dyn::.
99  bool is_quoted = map[f];
100  return detail::read_label_registry().call(ctx, is, is_quoted);
101  }
102  }
103 } // vcsn::
return res
Definition: multiply.hh:398
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
std::string errors
The error messages.
Definition: driver.hh:36
expression read_expression(const context &ctx, identities ids, std::istream &is, const std::string &format="default")
Read an expression from a stream.
automaton read_efsm(std::istream &is)
Definition: efsm.cc:103
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
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true)
Read an automaton from a stream.
Definition: read.cc:34
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
Definition: read.cc:85
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Definition: strip.hh:46
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
Definition: driver.cc:30
Definition: a-star.hh:8
Template-less root for contexts.
Definition: context.hh:16
automaton read_fado(std::istream &is)
Definition: fado.cc:42
automaton read_daut(std::istream &is)
Definition: daut.cc:125
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
value_impl< detail::label_tag > label
Definition: fwd.hh:26
A mapping from strings to Values.
Definition: getargs.hh:33
State and public interface for Dot parsing.
Definition: driver.hh:20
value_impl< detail::expression_tag > expression
Definition: fwd.hh:25