Vcsn  2.1
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/builtins.hh>
11 #include <vcsn/misc/getargs.hh>
12 
13 namespace vcsn
14 {
15  namespace dyn
16  {
17 
18  /*-----------------.
19  | read_automaton. |
20  `-----------------*/
21 
22  namespace
23  {
24  automaton read_dot(std::istream& is)
25  {
27  auto res = d.parse(is);
28  if (!d.errors.empty())
29  raise(d.errors);
30  return res;
31  }
32  }
33 
34  automaton
35  read_automaton(std::istream& is, const std::string& f,
36  bool strip_p)
37  {
38  enum fmt
39  {
40  dot,
41  efsm,
42  fado,
43  };
44  static const auto map
45  = std::map<std::string, std::function<automaton(std::istream&)>>
46  {
47  {"default", read_dot},
48  {"dot", read_dot},
49  {"efsm", read_efsm},
50  {"fado", read_fado},
51  };
52  auto read = getargs("automaton input format", map, f);
53  auto res = read(is);
54  return strip_p ? strip(res) : res;
55  }
56 
57  /*-------------------.
58  | read_expression. |
59  `-------------------*/
60 
63  std::istream& is, const std::string& f)
64  {
65  enum fmt
66  {
67  text,
68  };
69  static const auto map = std::map<std::string, fmt>
70  {
71  {"default", text},
72  {"text", text},
73  };
74  switch (getargs("expression input format", map, f))
75  {
76  case text:
77  return rat::read(ctx, ids, is);
78  }
80  }
81 
82  /*-------------.
83  | read_label. |
84  `-------------*/
85 
86  REGISTRY_DEFINE(read_label);
87  label
88  read_label(const dyn::context& ctx, std::istream& is,
89  const std::string& f)
90  {
91  enum fmt
92  {
93  text,
94  quoted
95  };
96  static const auto map = std::map<std::string, fmt>
97  {
98  {"default", text},
99  {"text", text},
100  {"quoted", quoted},
101  };
102  auto format = getargs("label input format", map, f);
103  bool is_quoted = format == quoted;
104  return detail::read_label_registry().call(ctx, is, is_quoted);
105  }
106  }
107 } // vcsn::
automaton read_fado(std::istream &is)
Definition: fado.cc:21
std::shared_ptr< const detail::label_base > label
Definition: fwd.hh:59
automaton strip(const automaton &a)
The automaton in a with its metadata layers removed.
Definition: strip.hh:51
std::shared_ptr< const detail::context_base > context
A dyn::context.
Definition: fwd.hh:41
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:62
C::mapped_type getargs(const std::string &kind, const C &map, const std::string &key)
Find a correspondance in a map.
Definition: getargs.hh:21
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:372
std::ostream & fado(const Aut &aut, std::ostream &out)
Definition: grail.hh:204
std::string errors
The error messages.
Definition: driver.hh:36
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:80
An input/output format.
Definition: format.hh:11
std::shared_ptr< detail::automaton_base > automaton
Definition: automaton.hh:69
static identities ids(const driver &d)
Get the identities of the driver.
Definition: parse.cc:87
label read_label(const context &ctx, std::istream &is, const std::string &format="default")
Read a label from a stream.
Definition: read.cc:88
An expressionset can implement several different sets of identities on expressions.
Definition: identities.hh:21
State and public interface for Dot parsing.
Definition: driver.hh:20
dyn::automaton parse(std::istream &is, const location_t &l=location_t{})
Parse this stream.
Definition: driver.cc:30
std::ostream & efsm(const Aut &aut, std::ostream &out)
Format automaton to EFSM format, based on FSM format.
Definition: efsm.hh:343
std::ostream & dot(const Aut &aut, std::ostream &out, bool dot2tex=false)
Definition: dot.hh:371
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
std::shared_ptr< detail::expression_base > expression
Definition: expression.hh:78
automaton read_automaton(std::istream &is, const std::string &format="default", bool strip=true)
Read an automaton from a stream.
Definition: read.cc:35
#define BUILTIN_UNREACHABLE()
Definition: builtins.hh:13
automaton read_efsm(std::istream &is)
Definition: efsm.cc:77