1 #include "Parameter.hpp"
2 #include <soulng/util/Unicode.hpp>
3 #include <sngcm/cmparser/TypeExpr.hpp>
4 #include <sngcm/cmparser/Identifier.hpp>
5 #include <sngcm/cmlexer/CmajorLexer.hpp>
6 #include <sngcm/cmlexer/CmajorTokens.hpp>
7
8
9
10 using namespace soulng::unicode;
11 using namespace sngcm::ast;
12 using namespace CmajorTokens;
13
14 soulng::parser::Match ParameterParser::ParameterList(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::Node* owner)
15 {
16 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
17
18
19
20
21
22
23
24 #endif // SOULNG_PARSER_DEBUG_SUPPORT
25 std::unique_ptr<ParameterNode> param;
26 soulng::parser::Match match(false);
27 soulng::parser::Match* parentMatch0 = &match;
28 {
29 soulng::parser::Match match(false);
30 soulng::parser::Match* parentMatch1 = &match;
31 {
32 soulng::parser::Match match(false);
33 if (*lexer == LPAREN)
34 {
35 ++lexer;
36 match.hit = true;
37 }
38 *parentMatch1 = match;
39 }
40 if (match.hit)
41 {
42 soulng::parser::Match match(false);
43 soulng::parser::Match* parentMatch2 = &match;
44 {
45 soulng::parser::Match match(true);
46 int64_t save = lexer.GetPos();
47 soulng::parser::Match* parentMatch3 = &match;
48 {
49 soulng::parser::Match match(false);
50 soulng::parser::Match* parentMatch4 = &match;
51 {
52 soulng::parser::Match match(false);
53 soulng::parser::Match* parentMatch5 = &match;
54 {
55 soulng::parser::Match match(false);
56 soulng::parser::Match* parentMatch6 = &match;
57 {
58 int64_t pos = lexer.GetPos();
59 soulng::parser::Match match = ParameterParser::Parameter(lexer, moduleId, ctx);
60 param.reset(static_cast<ParameterNode*>(match.value));
61 if (match.hit)
62 {
63 owner->AddParameter(param.release());
64 }
65 *parentMatch6 = match;
66 }
67 *parentMatch5 = match;
68 }
69 if (match.hit)
70 {
71 soulng::parser::Match match(false);
72 soulng::parser::Match* parentMatch7 = &match;
73 {
74 soulng::parser::Match match(true);
75 soulng::parser::Match* parentMatch8 = &match;
76 {
77 while (true)
78 {
79 int64_t save = lexer.GetPos();
80 {
81 soulng::parser::Match match(false);
82 soulng::parser::Match* parentMatch9 = &match;
83 {
84 soulng::parser::Match match(false);
85 if (*lexer == COMMA)
86 {
87 ++lexer;
88 match.hit = true;
89 }
90 *parentMatch9 = match;
91 }
92 if (match.hit)
93 {
94 soulng::parser::Match match(false);
95 soulng::parser::Match* parentMatch10 = &match;
96 {
97 soulng::parser::Match match(false);
98 soulng::parser::Match* parentMatch11 = &match;
99 {
100 int64_t pos = lexer.GetPos();
101 soulng::parser::Match match = ParameterParser::Parameter(lexer, moduleId, ctx);
102 param.reset(static_cast<ParameterNode*>(match.value));
103 if (match.hit)
104 {
105 owner->AddParameter(param.release());
106 }
107 *parentMatch11 = match;
108 }
109 *parentMatch10 = match;
110 }
111 *parentMatch9 = match;
112 }
113 if (match.hit)
114 {
115 *parentMatch8 = match;
116 }
117 else
118 {
119 lexer.SetPos(save);
120 break;
121 }
122 }
123 }
124 }
125 *parentMatch7 = match;
126 }
127 *parentMatch5 = match;
128 }
129 *parentMatch4 = match;
130 }
131 if (match.hit)
132 {
133 *parentMatch3 = match;
134 }
135 else
136 {
137 lexer.SetPos(save);
138 }
139 }
140 *parentMatch2 = match;
141 }
142 *parentMatch1 = match;
143 }
144 *parentMatch0 = match;
145 }
146 if (match.hit)
147 {
148 soulng::parser::Match match(false);
149 soulng::parser::Match* parentMatch12 = &match;
150 {
151 soulng::parser::Match match(true);
152 soulng::parser::Match* parentMatch13 = &match;
153 {
154 soulng::lexer::Span span = lexer.GetSpan();
155 soulng::parser::Match match(false);
156 if (*lexer == RPAREN)
157 {
158 ++lexer;
159 match.hit = true;
160 }
161 if (match.hit)
162 {
163 *parentMatch13 = match;
164 }
165 else
166 {
167 lexer.ThrowExpectationFailure(span, ToUtf32(GetTokenInfo(RPAREN)));
168 }
169 }
170 *parentMatch12 = match;
171 }
172 *parentMatch0 = match;
173 }
174 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
175
176
177
178
179
180 #endif // SOULNG_PARSER_DEBUG_SUPPORT
181 if (!match.hit)
182 {
183 match.value = nullptr;
184 }
185 return match;
186 }
187
188 soulng::parser::Match ParameterParser::Parameter(CmajorLexer& lexer, boost::uuids::uuid* moduleId, ParsingContext* ctx)
189 {
190 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
191
192
193
194
195
196
197
198 #endif // SOULNG_PARSER_DEBUG_SUPPORT
199 Span s = Span();
200 std::unique_ptr<sngcm::ast::Node> type;
201 std::unique_ptr<IdentifierNode> id;
202 soulng::parser::Match match(false);
203 soulng::parser::Match* parentMatch0 = &match;
204 {
205 int64_t pos = lexer.GetPos();
206 soulng::parser::Match match(false);
207 soulng::parser::Match* parentMatch1 = &match;
208 {
209 soulng::parser::Match match(false);
210 soulng::parser::Match* parentMatch2 = &match;
211 {
212 soulng::parser::Match match(false);
213 soulng::parser::Match* parentMatch3 = &match;
214 {
215 int64_t pos = lexer.GetPos();
216 soulng::lexer::Span span = lexer.GetSpan();
217 soulng::parser::Match match = TypeExprParser::TypeExpr(lexer, moduleId, ctx);
218 type.reset(static_cast<sngcm::ast::Node*>(match.value));
219 if (match.hit)
220 {
221 s = span;
222 }
223 *parentMatch3 = match;
224 }
225 *parentMatch2 = match;
226 }
227 if (match.hit)
228 {
229 soulng::parser::Match match(false);
230 soulng::parser::Match* parentMatch4 = &match;
231 {
232 soulng::parser::Match match(true);
233 int64_t save = lexer.GetPos();
234 soulng::parser::Match* parentMatch5 = &match;
235 {
236 soulng::parser::Match match(false);
237 soulng::parser::Match* parentMatch6 = &match;
238 {
239 soulng::parser::Match match(false);
240 soulng::parser::Match* parentMatch7 = &match;
241 {
242 int64_t pos = lexer.GetPos();
243 soulng::lexer::Span span = lexer.GetSpan();
244 soulng::parser::Match match = IdentifierParser::Identifier(lexer, moduleId);
245 id.reset(static_cast<IdentifierNode*>(match.value));
246 if (match.hit)
247 {
248 s.end = span.end;
249 }
250 *parentMatch7 = match;
251 }
252 *parentMatch6 = match;
253 }
254 if (match.hit)
255 {
256 *parentMatch5 = match;
257 }
258 else
259 {
260 lexer.SetPos(save);
261 }
262 }
263 *parentMatch4 = match;
264 }
265 *parentMatch2 = match;
266 }
267 *parentMatch1 = match;
268 }
269 if (match.hit)
270 {
271 {
272 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
273
274 #endif // SOULNG_PARSER_DEBUG_SUPPORT
275 return soulng::parser::Match(true, new ParameterNode(s, *moduleId, type.release(), id.release()));
276 }
277 }
278 *parentMatch0 = match;
279 }
280 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
281
282
283
284
285
286 #endif // SOULNG_PARSER_DEBUG_SUPPORT
287 if (!match.hit)
288 {
289 match.value = nullptr;
290 }
291 return match;
292 }