-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.h
240 lines (164 loc) · 3.54 KB
/
parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#ifndef FRANCA_PARSER_H
#define FRANCA_PARSER_H
#include <string>
#include <vector>
#include <boost/variant.hpp>
#include <boost/optional.hpp>
namespace franca
{
namespace parser
{
struct version
{
int major_;
int minor_;
};
struct arg
{
std::string type_;
std::string name_;
};
struct attribute
{
attribute()
: readonly_(false)
, no_subscriptions_(false)
{
// NOOP
}
std::string type_;
std::string name_;
bool readonly_;
bool no_subscriptions_;
};
struct enum_value
{
enum_value()
: value_(0xFFFFFFDD)
{
// NOOP
}
std::string name_;
int value_;
};
struct enumeration
{
bool eval(const enum_value& value);
std::string name_;
boost::optional<std::string> base_;
std::vector<enum_value> values_;
};
struct typedef_
{
std::string name_;
std::string type_;
};
struct array
{
std::string name_;
std::string type_;
};
struct map
{
std::string name_;
std::string key_;
std::string value_;
};
struct struct_entry
{
std::string type_;
std::string name_;
};
struct struct_
{
bool eval(const struct_entry& item);
std::string name_;
boost::optional<std::string> base_;
std::vector<struct_entry> values_;
};
struct union_ : struct_
{
inline
bool eval(const struct_entry& item)
{
return true;
}
};
// TODO maybe merge with enumeration, the only difference is the missing name here
struct extended_error
{
bool eval(const enum_value& value);
boost::optional<std::string> base_;
std::vector<enum_value> values_;
};
typedef boost::variant<std::string, extended_error> method_error;
struct method
{
bool eval_in(const arg& argument);
bool eval_out(const arg& argument);
std::string name_;
std::vector<arg> in_;
std::vector<arg> out_;
boost::optional<method_error> error_;
};
struct fire_and_forget_method
{
bool eval_in(const arg& argument);
std::string name_;
std::vector<arg> in_;
};
struct broadcast
{
bool eval_out(const arg& argument);
std::string name_;
std::vector<arg> args_;
};
typedef boost::variant<method,
fire_and_forget_method,
broadcast,
attribute,
enumeration,
struct_,
union_,
array,
map,
typedef_
> interface_item_type;
struct interface
{
bool eval(const interface_item_type& new_item);
std::string name_;
version version_;
std::vector<interface_item_type> parseitems_;
};
typedef boost::variant<enumeration,
struct_,
union_,
array,
map,
typedef_
> tc_item_type;
struct typecollection
{
bool eval(const tc_item_type& new_item);
std::string name_;
std::vector<tc_item_type> parseitems_;
};
struct namespace_import
{
std::vector<std::string> items_;
std::string file_;
};
typedef boost::variant<interface, typecollection> doc_item_type;
typedef boost::variant<std::string, namespace_import> import_type;
struct document
{
bool eval(const doc_item_type& new_item);
std::vector<std::string> package_;
std::vector<import_type> imports_;
std::vector<doc_item_type> parseitems_;
};
document parse(const char* filename, const std::vector<std::string>& includes);
} // parser
} // franca
#endif // FRANCA_PARSER_H