1 #include "Attribute.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmlexer/CmajorLexer.hpp>
4 #include <sngcm/cmlexer/CmajorTokens.hpp>
5 #include <sngcm/cmlexer/TokenValueParsers.hpp>
6
7
8
9 using namespace soulng::unicode;
10 using namespace CmajorTokens;
11
12 soulng::parser::Match AttributeParser::Attributes(CmajorLexer& lexer, boost::uuids::uuid* moduleId)
13 {
14 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
15
16
17
18
19
20
21
22 #endif // SOULNG_PARSER_DEBUG_SUPPORT
23 std::unique_ptr<sngcm::ast::AttributesNode> attributes = std::unique_ptr<sngcm::ast::AttributesNode>();
24 soulng::parser::Match match(false);
25 soulng::parser::Match* parentMatch0 = &match;
26 {
27 soulng::parser::Match match(false);
28 soulng::parser::Match* parentMatch1 = &match;
29 {
30 soulng::parser::Match match(false);
31 soulng::parser::Match* parentMatch2 = &match;
32 {
33 int64_t pos = lexer.GetPos();
34 soulng::lexer::Span span = lexer.GetSpan();
35 soulng::parser::Match match(false);
36 if (*lexer == LBRACKET)
37 {
38 ++lexer;
39 match.hit = true;
40 }
41 if (match.hit)
42 {
43 attributes.reset(new sngcm::ast::AttributesNode(span, *moduleId));
44 }
45 *parentMatch2 = match;
46 }
47 *parentMatch1 = match;
48 }
49 if (match.hit)
50 {
51 soulng::parser::Match match(false);
52 soulng::parser::Match* parentMatch3 = &match;
53 {
54 soulng::parser::Match match(true);
55 int64_t save = lexer.GetPos();
56 soulng::parser::Match* parentMatch4 = &match;
57 {
58 soulng::parser::Match match(false);
59 soulng::parser::Match* parentMatch5 = &match;
60 {
61 soulng::parser::Match match(false);
62 soulng::parser::Match* parentMatch6 = &match;
63 {
64 soulng::parser::Match match = AttributeParser::Attribute(lexer, attributes.get(), moduleId);
65 *parentMatch6 = match;
66 }
67 if (match.hit)
68 {
69 soulng::parser::Match match(false);
70 soulng::parser::Match* parentMatch7 = &match;
71 {
72 soulng::parser::Match match(true);
73 soulng::parser::Match* parentMatch8 = &match;
74 {
75 while (true)
76 {
77 int64_t save = lexer.GetPos();
78 {
79 soulng::parser::Match match(false);
80 soulng::parser::Match* parentMatch9 = &match;
81 {
82 soulng::parser::Match match(false);
83 if (*lexer == COMMA)
84 {
85 ++lexer;
86 match.hit = true;
87 }
88 *parentMatch9 = match;
89 }
90 if (match.hit)
91 {
92 soulng::parser::Match match(false);
93 soulng::parser::Match* parentMatch10 = &match;
94 {
95 soulng::parser::Match match = AttributeParser::Attribute(lexer, attributes.get(), moduleId);
96 *parentMatch10 = match;
97 }
98 *parentMatch9 = match;
99 }
100 if (match.hit)
101 {
102 *parentMatch8 = match;
103 }
104 else
105 {
106 lexer.SetPos(save);
107 break;
108 }
109 }
110 }
111 }
112 *parentMatch7 = match;
113 }
114 *parentMatch6 = match;
115 }
116 *parentMatch5 = match;
117 }
118 if (match.hit)
119 {
120 *parentMatch4 = match;
121 }
122 else
123 {
124 lexer.SetPos(save);
125 }
126 }
127 *parentMatch3 = match;
128 }
129 *parentMatch1 = match;
130 }
131 *parentMatch0 = match;
132 }
133 if (match.hit)
134 {
135 soulng::parser::Match match(false);
136 soulng::parser::Match* parentMatch11 = &match;
137 {
138 soulng::parser::Match match(false);
139 soulng::parser::Match* parentMatch12 = &match;
140 {
141 int64_t pos = lexer.GetPos();
142 soulng::parser::Match match(true);
143 soulng::parser::Match* parentMatch13 = &match;
144 {
145 soulng::lexer::Span span = lexer.GetSpan();
146 soulng::parser::Match match(false);
147 if (*lexer == RBRACKET)
148 {
149 ++lexer;
150 match.hit = true;
151 }
152 if (match.hit)
153 {
154 *parentMatch13 = match;
155 }
156 else
157 {
158 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(RBRACKET)));
159 }
160 }
161 if (match.hit)
162 {
163 {
164 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
165
166 #endif // SOULNG_PARSER_DEBUG_SUPPORT
167 return soulng::parser::Match(true, attributes.release());
168 }
169 }
170 *parentMatch12 = match;
171 }
172 *parentMatch11 = match;
173 }
174 *parentMatch0 = match;
175 }
176 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
177
178
179
180
181
182 #endif // SOULNG_PARSER_DEBUG_SUPPORT
183 if (!match.hit)
184 {
185 match.value = nullptr;
186 }
187 return match;
188 }
189
190 soulng::parser::Match AttributeParser::Attribute(CmajorLexer& lexer, sngcm::ast::AttributesNode* attributes, boost::uuids::uuid* moduleId)
191 {
192 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
193
194
195
196
197
198
199
200 #endif // SOULNG_PARSER_DEBUG_SUPPORT
201 Span s = Span();
202 std::u32string name = std::u32string();
203 std::u32string value = std::u32string();
204 soulng::parser::Match match(false);
205 soulng::parser::Match* parentMatch0 = &match;
206 {
207 int64_t pos = lexer.GetPos();
208 soulng::parser::Match match(false);
209 soulng::parser::Match* parentMatch1 = &match;
210 {
211 soulng::parser::Match match(false);
212 soulng::parser::Match* parentMatch2 = &match;
213 {
214 soulng::parser::Match match(false);
215 soulng::parser::Match* parentMatch3 = &match;
216 {
217 soulng::parser::Match match(false);
218 soulng::parser::Match* parentMatch4 = &match;
219 {
220 int64_t pos = lexer.GetPos();
221 soulng::parser::Match match(true);
222 if (match.hit)
223 {
224 value = U"true";
225 }
226 *parentMatch4 = match;
227 }
228 *parentMatch3 = match;
229 }
230 if (match.hit)
231 {
232 soulng::parser::Match match(false);
233 soulng::parser::Match* parentMatch5 = &match;
234 {
235 soulng::parser::Match match(false);
236 soulng::parser::Match* parentMatch6 = &match;
237 {
238 int64_t pos = lexer.GetPos();
239 soulng::lexer::Span span = lexer.GetSpan();
240 soulng::parser::Match match(false);
241 if (*lexer == ID)
242 {
243 ++lexer;
244 match.hit = true;
245 }
246 if (match.hit)
247 {
248 s = span;
249 name = lexer.GetMatch(span);
250 }
251 *parentMatch6 = match;
252 }
253 *parentMatch5 = match;
254 }
255 *parentMatch3 = match;
256 }
257 *parentMatch2 = match;
258 }
259 if (match.hit)
260 {
261 soulng::parser::Match match(false);
262 soulng::parser::Match* parentMatch7 = &match;
263 {
264 soulng::parser::Match match(true);
265 int64_t save = lexer.GetPos();
266 soulng::parser::Match* parentMatch8 = &match;
267 {
268 soulng::parser::Match match(false);
269 soulng::parser::Match* parentMatch9 = &match;
270 {
271 soulng::parser::Match match(false);
272 soulng::parser::Match* parentMatch10 = &match;
273 {
274 soulng::parser::Match match(false);
275 if (*lexer == ASSIGN)
276 {
277 ++lexer;
278 match.hit = true;
279 }
280 *parentMatch10 = match;
281 }
282 if (match.hit)
283 {
284 soulng::parser::Match match(false);
285 soulng::parser::Match* parentMatch11 = &match;
286 {
287 soulng::parser::Match match(false);
288 soulng::parser::Match* parentMatch12 = &match;
289 {
290 int64_t pos = lexer.GetPos();
291 soulng::lexer::Span span = lexer.GetSpan();
292 soulng::parser::Match match(false);
293 if (*lexer == STRINGLIT)
294 {
295 ++lexer;
296 match.hit = true;
297 }
298 if (match.hit)
299 {
300 s.end = span.end;
301 ParseStringLiteral(lexer.FileName(), lexer.GetToken(pos), lexer.strLit, lexer.strLitPrefix);
302 value = lexer.strLit;
303 }
304 *parentMatch12 = match;
305 }
306 *parentMatch11 = match;
307 }
308 *parentMatch10 = match;
309 }
310 *parentMatch9 = match;
311 }
312 if (match.hit)
313 {
314 *parentMatch8 = match;
315 }
316 else
317 {
318 lexer.SetPos(save);
319 }
320 }
321 *parentMatch7 = match;
322 }
323 *parentMatch2 = match;
324 }
325 *parentMatch1 = match;
326 }
327 if (match.hit)
328 {
329 attributes->AddAttribute(s, *moduleId, name, value);
330 }
331 *parentMatch0 = match;
332 }
333 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
334
335
336
337
338
339 #endif // SOULNG_PARSER_DEBUG_SUPPORT
340 if (!match.hit)
341 {
342 match.value = nullptr;
343 }
344 return match;
345 }