1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/Attribute.hpp>
8 [cpp]#include <sngcm/cmlexer/CmajorLexer.hpp>
9 [cpp]#include <sngcm/cmlexer/CmajorTokens.hpp>
10 [cpp]#include <sngcm/cmlexer/TokenValueParsers.hpp>
11
12 using namespace CmajorTokens;
13
14 parser api(SNGCM_PARSER_API) AttributeParser
15 {
16 uselexer CmajorLexer;
17
18 Attributes(var std::unique_ptr attributes) : sngcm::ast::Attributes*
19 ::= LBRACKET{ attributes.reset(new sngcm::ast::Attributes()); } (Attribute(attributes.get()):attribute % COMMA)? RBRACKET!
20 {
21 return attributes.release();
22 }
23 ;
24
25 Attribute(sngcm::ast::Attributes* attributes, var Span s, var std::u32string name, var std::u32string value)
26 ::=
27 (
28 empty{ value = U"true"; }
29 ID{ s = span; name = lexer.GetMatch(span); }
30 (
31 ASSIGN STRINGLIT
32 {
33 s.end = span.end;
34 ParseStringLiteral(lexer.FileName(), lexer.GetToken(pos), lexer.strLit, lexer.strLitPrefix);
35 value = lexer.strLit;
36 }
37 )?
38 )
39 {
40 attributes->AddAttribute(s, name, value);
41 }
42 ;
43
44 ruleinfo
45 {
46 (Attributes, "attributes"), (Attribute, "attribute")
47 }
48 }