Vcsn  2.2
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::
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
Definition: driver.cc:30
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
Definition: a-star.hh:8
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true)
Read an automaton from a stream.
Definition: read.cc:34
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:61
A mapping from strings to Values.
Definition: getargs.hh:33
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Definition: strip.hh:46
automaton read_efsm(std::istream &is)
Definition: efsm.cc:103
std::shared_ptr< const detail::context_base > context
A dyn::context.
Definition: fwd.hh:43
automaton read_fado(std::istream &is)
Definition: fado.cc:21
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:380
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:82
expression read_expression(const context &ctx, rat::identities ids, std::istream &is, const std::string &format="default")
Read an expression from a stream.
Definition: read.cc:59
std::string errors
The error messages.
Definition: driver.hh:36
std::shared_ptr< detail::expression_base > expression
Definition: expression.hh:92
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
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:89
State and public interface for Dot parsing.
Definition: driver.hh:20
rat::identities identities(const expression &exp)
Bridge.
Definition: identities.hh:19
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
Definition: read.cc:84