Merge branch 'lua_versions' into main/rendor-staging
[ryzomcore.git] / ryzom / tools / pd_parser / parser_rules.cpp
blob4ae250f5995858f4e5f11e7c70ee54d7e150acec
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "parser_rules.h"
22 * Main Bloc
24 PARSE_START_NO_DESCRIPTION(Main, CParseNode)
26 while (!tokenizer.end())
28 PARSE_MARK
29 PARSE_ALTERNATIVE(Db)
30 PARSE_FAIL
33 PARSE_END
37 * Db Bloc
39 PARSE_START(Db, CDbNode)
41 PARSE_KEYWORD(Db)
42 PARSE_MARK
43 PARSE_IDENTIFIER(Name)
44 PARSE_MARK
46 PARSE_OPT_KEYWORD_IN(String, MainFile);
48 PARSE_START_BLOC
50 PARSE_MARK
52 PARSE_ALTERNATIVE(File)
53 PARSE_ALTERNATIVE(UsePch)
54 PARSE_FAIL
56 PARSE_MARK
58 PARSE_END_BLOC
60 PARSE_MARK
62 PARSE_END
66 * File Bloc
68 PARSE_START(File, CFileNode)
70 PARSE_OPT_BEFORE(File)
71 PARSE_OPT_IN(Separated, SeparatedFlag);
72 PARSE_END_OPT_BEFORE()
74 PARSE_KEYWORD(File)
75 PARSE_MARK
76 PARSE_STRING(Name)
77 PARSE_MARK
79 main->IncludeAs = main->Name;
81 PARSE_OPT_KEYWORD_IN(String, IncludeAs);
83 PARSE_START_BLOC
85 PARSE_MARK
87 PARSE_ALTERNATIVE(Include)
88 PARSE_ALTERNATIVE(Type)
89 PARSE_ALTERNATIVE(Class)
90 PARSE_ALTERNATIVE(Enum)
91 PARSE_ALTERNATIVE(Dimension)
92 //PARSE_ALTERNATIVE(CppCode)
93 PARSE_ALTERNATIVE(LogMsg)
94 PARSE_ALTERNATIVE(LogContext)
95 PARSE_FAIL
97 PARSE_MARK
99 PARSE_END_BLOC
101 PARSE_MARK
103 PARSE_END
107 * Include Bloc
109 PARSE_START(Include, CIncludeNode)
111 PARSE_KEYWORD(Include)
112 PARSE_MARK
113 PARSE_STRING(Name)
114 PARSE_MARK
116 PARSE_END
119 * Include Bloc
121 PARSE_START(UsePch, CUsePchNode)
123 PARSE_KEYWORD(UsePch)
124 PARSE_MARK
125 PARSE_STRING(Name)
126 PARSE_MARK
128 PARSE_END
132 * Cpp Code Bloc
134 PARSE_START(CppCode, CCppCodeNode)
136 PARSE_OPT_KEYWORD_IN(Identifier, Name)
137 PARSE_KEYWORD_IN(CppCode, RawCode)
138 PARSE_MARK
140 PARSE_END
144 * Type Bloc
146 PARSE_START(Type, CTypeNode)
148 PARSE_OPT_BEFORE(Type)
149 PARSE_OPT_IN(Extern, ExternFlag);
150 PARSE_END_OPT_BEFORE()
152 PARSE_KEYWORD(Type)
153 PARSE_MARK
154 if (main->ExternFlag)
156 PARSE_SCOPE_IDF(Name)
158 else
160 PARSE_IDENTIFIER(Name)
163 main->DisplayName = main->Name;
165 PARSE_MARK
166 if (tokenizer.current() == TokenOpenParenthesis)
168 tokenizer.next();
169 PARSE_MARK
170 PARSE_IDENTIFIER(CppType)
171 PARSE_MARK
172 PARSE_KEYWORD(Comma)
173 PARSE_MARK
174 PARSE_IDENTIFIER(StorageType)
175 PARSE_MARK
176 PARSE_KEYWORD(CloseParenthesis)
177 PARSE_MARK
179 if (tokenizer.current() == TokenOpenBrace)
181 tokenizer.next();
183 PARSE_MARK
184 PARSE_IDENTIFIER(Temp)
185 if (main->Temp == main->CppType)
187 PARSE_MARK
188 PARSE_KEYWORD(OpenParenthesis)
189 PARSE_MARK
190 PARSE_IDENTIFIER(Temp)
191 if (main->Temp != main->StorageType)
192 PARSE_FAIL
193 PARSE_MARK
194 PARSE_KEYWORD(CloseParenthesis)
195 PARSE_MARK
196 PARSE_NODE(CppCode, ToCppType)
197 PARSE_MARK
199 else if (main->Temp == main->StorageType)
201 PARSE_MARK
202 PARSE_KEYWORD(OpenParenthesis)
203 PARSE_MARK
204 PARSE_IDENTIFIER(Temp)
205 if (main->Temp != main->CppType)
206 PARSE_FAIL
207 PARSE_MARK
208 PARSE_KEYWORD(CloseParenthesis)
209 PARSE_MARK
210 PARSE_NODE(CppCode, ToStorageType)
211 PARSE_MARK
213 else
214 PARSE_FAIL
216 if (tokenizer.current() != TokenCloseBrace)
218 PARSE_IDENTIFIER(Temp)
219 PARSE_MARK
220 if (main->Temp == main->CppType && main->ToCppType == NULL)
222 PARSE_MARK
223 PARSE_KEYWORD(OpenParenthesis)
224 PARSE_MARK
225 PARSE_IDENTIFIER(Temp)
226 if (main->Temp != main->StorageType)
227 PARSE_FAIL
228 PARSE_MARK
229 PARSE_KEYWORD(CloseParenthesis)
230 PARSE_MARK
231 PARSE_NODE(CppCode, ToCppType)
232 PARSE_MARK
234 else if (main->Temp == main->StorageType && main->ToStorageType == NULL)
236 PARSE_MARK
237 PARSE_KEYWORD(OpenParenthesis)
238 PARSE_MARK
239 PARSE_IDENTIFIER(Temp)
240 if (main->Temp != main->CppType)
241 PARSE_FAIL
242 PARSE_MARK
243 PARSE_KEYWORD(CloseParenthesis)
244 PARSE_MARK
245 PARSE_NODE(CppCode, ToStorageType)
246 PARSE_MARK
248 else
249 PARSE_FAIL
252 PARSE_KEYWORD(CloseBrace)
254 else
256 PARSE_KEYWORD(SemiColon)
259 else
261 PARSE_IDENTIFIER(CppType)
262 main->StorageType = main->CppType;
263 PARSE_MARK
264 PARSE_KEYWORD(SemiColon)
267 PARSE_MARK
269 PARSE_END
273 * Class Bloc
275 PARSE_START(Class, CClassNode)
277 PARSE_OPT_BEFORE(Class)
278 PARSE_OPT_IN(Mapped, MappedFlag);
279 PARSE_OPT_IN(Derived, DerivatedFlag);
280 PARSE_END_OPT_BEFORE()
282 PARSE_KEYWORD(Class)
283 PARSE_MARK
284 PARSE_IDENTIFIER(Name)
285 PARSE_MARK
287 PARSE_OPT(Colon)
288 PARSE_MARK
289 PARSE_IDENTIFIER(Inherited)
290 PARSE_MARK
291 PARSE_END_OPT
293 PARSE_OPT(Key)
294 PARSE_MARK
295 PARSE_KEYWORD(OpenParenthesis)
296 PARSE_MARK
297 PARSE_IDENTIFIER(ClassKey)
298 PARSE_MARK
299 PARSE_KEYWORD(CloseParenthesis)
300 PARSE_MARK
301 PARSE_END_OPT
303 PARSE_OPT(Implements)
304 PARSE_MARK
305 PARSE_IDENTIFIER(Implements)
306 PARSE_MARK
307 PARSE_END_OPT
309 PARSE_OPT(Reserve)
310 PARSE_MARK
311 PARSE_KEYWORD(OpenParenthesis)
312 PARSE_MARK
313 PARSE_IDENTIFIER(Reserve)
314 PARSE_MARK
315 PARSE_KEYWORD(CloseParenthesis)
316 PARSE_MARK
317 PARSE_END_OPT
319 PARSE_START_BLOC
321 PARSE_MARK
323 PARSE_ALTERNATIVE(CppCode)
324 PARSE_ALTERNATIVE(Declaration)
325 PARSE_FAIL
327 PARSE_MARK
329 PARSE_END_BLOC
331 PARSE_MARK
333 PARSE_END
337 * Declaration Bloc
339 PARSE_START(Declaration, CDeclarationNode)
341 PARSE_OPT_BEFORE_2(Identifier, ScopedIdentifier)
342 PARSE_OPT_IN(WriteTrigger, WriteTriggerFlag);
343 PARSE_OPT_IN(InitFill, InitFillFlag);
344 PARSE_OPT_IN(Parent, ParentFlag);
345 PARSE_OPT_IN(Hidden, HiddenFlag);
346 PARSE_OPT_IN(Mirrored, MirroredFlag);
347 PARSE_END_OPT_BEFORE()
349 if (main->ParentFlag)
351 PARSE_IDENTIFIER(ParentClass);
352 PARSE_MARK
353 PARSE_KEYWORD(Colon)
354 PARSE_MARK
355 PARSE_IDENTIFIER(ParentField);
356 PARSE_MARK
357 PARSE_IDENTIFIER(Name);
358 PARSE_MARK
360 else
362 PARSE_SCOPE_IDF(Type);
363 PARSE_MARK
365 PARSE_OPT(Colon)
366 PARSE_MARK
367 PARSE_IDENTIFIER(ForwardRefAttribute);
368 PARSE_MARK
369 PARSE_END_OPT
371 PARSE_OPT(OpenBracket)
372 PARSE_MARK
373 PARSE_IDENTIFIER(ArrayIndex);
374 PARSE_MARK
375 main->ArrayFlag = true;
376 PARSE_KEYWORD(CloseBracket)
377 PARSE_MARK
379 PARSE_IDENTIFIER(Name);
380 PARSE_MARK
382 PARSE_NEXT_OPT(LessThan)
383 main->SetFlag = true;
384 PARSE_MARK
385 PARSE_KEYWORD(GreaterThan)
386 PARSE_MARK
388 PARSE_IDENTIFIER(Name);
389 PARSE_MARK
391 PARSE_LAST_OPT
393 PARSE_IDENTIFIER(Name);
394 PARSE_MARK
396 PARSE_OPT(Equal)
397 //PARSE_VALUE(DefaultValue)
398 PARSE_KEYWORD_IN(CppCode, DefaultValue)
399 PARSE_END_OPT
401 PARSE_END_OPT
404 if (tokenizer.current() == TokenOpenBrace)
406 PARSE_START_BLOC
407 PARSE_MARK
409 CDeclarationNode::CUserCode UCode;
411 PARSE_KEYWORD_IN_TEMP(Identifier, UCode.Event)
413 PARSE_OPT_LIST(OpenParenthesis, CloseParenthesis)
415 std::string UCodeAtom;
416 PARSE_KEYWORD_IN_TEMP(Identifier, UCodeAtom)
417 if (!UCode.CodeSpecializer.empty())
418 UCode.CodeSpecializer += ".";
419 UCode.CodeSpecializer += UCodeAtom;
421 PARSE_END_OPT_LIST(CloseParenthesis, Dot)
423 PARSE_KEYWORD_IN_TEMP(CppCode, UCode.UserCode)
425 main->UserCodes.push_back(UCode);
427 PARSE_MARK
428 PARSE_END_BLOC
430 else
432 PARSE_KEYWORD(SemiColon);
435 PARSE_MARK
437 PARSE_END
441 * Enum Bloc
443 PARSE_START(Enum, CEnumNode)
445 PARSE_KEYWORD(Enum)
446 PARSE_MARK
447 PARSE_IDENTIFIER(Name)
449 PARSE_START_LIST(OpenBrace, CloseBrace)
451 PARSE_MARK
453 PARSE_ALTERNATIVE(EnumRange)
454 PARSE_ALTERNATIVE(EnumSimpleValue)
455 PARSE_FAIL
457 PARSE_MARK
459 PARSE_END_LIST(CloseBrace, Comma)
461 PARSE_OPT_KEYWORD_IN(Identifier, EndRange)
463 PARSE_MARK
465 PARSE_END
468 PARSE_START(EnumSimpleValue, CEnumSimpleValueNode)
470 PARSE_LIST_KEYWORDS(Identifier, Names, Or)
472 PARSE_END
475 PARSE_START(EnumRange, CEnumRangeNode)
477 PARSE_IDENTIFIER(Name)
479 PARSE_START_LIST(OpenBrace, CloseBrace)
481 PARSE_MARK
483 PARSE_ALTERNATIVE(EnumRange)
484 PARSE_ALTERNATIVE(EnumSimpleValue)
485 PARSE_FAIL
487 PARSE_MARK
489 PARSE_END_LIST(CloseBrace, Comma)
490 PARSE_MARK
492 PARSE_OPT_KEYWORD_IN(Identifier, EndRange)
494 PARSE_MARK
496 PARSE_END
500 * Dimension Bloc
502 PARSE_START(Dimension, CDimensionNode)
504 PARSE_KEYWORD(Dimension)
505 PARSE_MARK
506 PARSE_IDENTIFIER(Name)
507 PARSE_MARK
508 PARSE_INT(Dimension)
509 PARSE_MARK
510 PARSE_KEYWORD(SemiColon);
511 PARSE_MARK
513 PARSE_END
517 * LogMsg Bloc
519 PARSE_START(LogMsg, CLogMsgNode)
521 PARSE_KEYWORD(LogMsg)
522 PARSE_MARK
523 PARSE_IDENTIFIER(Name)
524 PARSE_MARK
526 PARSE_KEYWORD(OpenParenthesis)
527 PARSE_MARK
528 PARSE_LIST_2_KEYWORDS(Identifier, Identifier, Params, Comma)
529 PARSE_KEYWORD(CloseParenthesis)
530 PARSE_MARK
532 PARSE_KEYWORD(OpenBrace)
533 PARSE_MARK
534 PARSE_LIST_KEYWORDS(String, Logs, Comma)
535 PARSE_MARK
537 PARSE_KEYWORD(CloseBrace)
538 PARSE_MARK
540 PARSE_END
542 PARSE_START(LogContext, CLogMsgNode)
544 PARSE_KEYWORD(LogContext)
545 PARSE_MARK
546 PARSE_IDENTIFIER(Name)
547 PARSE_MARK
549 main->Context = true;
551 PARSE_KEYWORD(OpenParenthesis)
552 PARSE_MARK
553 PARSE_LIST_2_KEYWORDS(Identifier, Identifier, Params, Comma)
554 PARSE_KEYWORD(CloseParenthesis)
555 PARSE_MARK
557 PARSE_KEYWORD(OpenBrace)
558 PARSE_MARK
559 PARSE_LIST_KEYWORDS(String, Logs, Comma)
560 PARSE_MARK
562 PARSE_KEYWORD(CloseBrace)
563 PARSE_MARK
565 PARSE_END