Vcsn  2.2a
Be Rational
signature-printer.cc
Go to the documentation of this file.
1 #include <ostream>
2 
5 
6 
7 namespace vcsn
8 {
9  namespace ast
10  {
11 
12  std::string normalize_context(const std::string& ctx, bool full)
13  {
14  std::ostringstream os;
15  ast::signature_printer printer(os, full);
16  std::istringstream is;
17  ast::context_parser parser(is);
18  is.str(ctx);
19  auto ast = parser.parse_context();
20  ast->accept(printer);
21  return os.str();
22  }
23 
24 #define DEFINE(Type) \
25  void signature_printer::visit(const Type& t)
26 
28  {
29  os_ << t.get_type() << '<';
30  bool first = true;
31  for (auto c: t.get_content())
32  {
33  if (!first)
34  os_ << ", ";
35  first = false;
36  c->accept(*this);
37  }
38  os_ << '>';
39  }
40 
41  DEFINE(context)
42  {
43  os_ << "context<";
44  t.get_labelset()->accept(*this);
45  os_ << ", ";
46  t.get_weightset()->accept(*this);
47  os_ << ">";
48  }
49 
50  DEFINE(tuple)
51  {
52  os_ << "std::tuple<";
53  auto v = t.get_sets();
54  for (unsigned int i = 0; i < v.size() - 1; ++i)
55  {
56  v[i]->accept(*this);
57  os_ << ", ";
58  }
59  v[v.size() - 1]->accept(*this);
60  os_ << '>';
61  }
62 
63  DEFINE(tupleset)
64  {
65  os_ << "lat<";
66  auto v = t.get_sets();
67  for (unsigned int i = 0; i < v.size() - 1; ++i)
68  {
69  v[i]->accept(*this);
70  os_ << ", ";
71  }
72  v[v.size() - 1]->accept(*this);
73  os_ << '>';
74  }
75 
76  DEFINE(nullableset)
77  {
78  os_ << "nullableset<";
79  t.get_labelset()->accept(*this);
80  os_ << '>';
81  }
82 
83  DEFINE(oneset)
84  {
85  (void) t;
86  os_ << "lao";
87  }
88 
89  DEFINE(genset)
90  {
91  os_ << t.letter_type();
92  if (full_)
93  os_ << t.generators();
94  }
95 
96  DEFINE(letterset)
97  {
98  os_ << "letterset<";
99  t.genset()->accept(*this);
100  os_ << '>';
101  }
102 
103  DEFINE(expansionset)
104  {
105  os_ << "expansionset<";
106  t.get_expressionset()->accept(*this);
107  os_ << '>';
108  }
109 
110  DEFINE(expressionset)
111  {
112  os_ << "expressionset<";
113  t.get_context()->accept(*this);
114  os_ << '>';
115  if (full_)
116  os_ << '(' << t.get_identities() << ')';
117  }
118 
119  DEFINE(weightset)
120  {
121  os_ << t.get_type();
122  }
123 
124  DEFINE(wordset)
125  {
126  os_ << "wordset<";
127  t.genset()->accept(*this);
128  os_ << '>';
129  }
130 
131  DEFINE(other)
132  {
133  os_ << t.get_type();
134  }
135 
136  DEFINE(polynomialset)
137  {
138  os_ << "polynomialset<";
139  t.get_content()->accept(*this);
140  os_ << '>';
141  }
142  }
143 }
std::istringstream is
The input stream: the specification to translate.
Definition: translate.cc:380
std::shared_ptr< ast_node > parse_context()
Accept only a valid context.
std::ostringstream os
The output stream: the corresponding C++ snippet to compile.
Definition: translate.cc:382
std::string normalize_context(const std::string &ctx, bool full=true)
A context, normalized.
#define DEFINE(Type)
static dyn::context ctx(const driver &d)
Get the context of the driver.
Definition: parse.cc:82
Definition: a-star.hh:8