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