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