1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/Interface.hpp>
8 [hpp]#include <sngcm/cmparser/ParsingContext.hpp>
9 [cpp]#include <sngcm/cmparser/Attribute.hpp>
10 [cpp]#include <sngcm/cmparser/Specifier.hpp>
11 [cpp]#include <sngcm/cmparser/Identifier.hpp>
12 [cpp]#include <sngcm/cmparser/TypeExpr.hpp>
13 [cpp]#include <sngcm/cmparser/Parameter.hpp>
14 [hpp]#include <sngcm/ast/Class.hpp>
15 [cpp]#include <sngcm/cmlexer/CmajorLexer.hpp>
16 [cpp]#include <sngcm/cmlexer/CmajorTokens.hpp>
17
18 using namespace sngcm::ast;
19 using namespace CmajorTokens;
20
21 parser api(SNGCM_PARSER_API) InterfaceParser
22 {
23 uselexer CmajorLexer;
24
25 using AttributeParser.Attributes;
26 using SpecifierParser.Specifiers;
27 using IdentifierParser.Identifier;
28 using TypeExprParser.TypeExpr;
29 using ParameterParser.ParameterList;
30
31 Interface(ParsingContext* ctx, var std::unique_ptr intf, var Span s, var Span specifierSpan, var Span beginBraceSpan, var Span endBraceSpan) : InterfaceNode*
32 ::=
33 ( empty{ s = span; } Attributes:attrs? Specifiers:specifiers{ specifierSpan = span; } INTERFACE Identifier:id!
34 {
35 s.end = span.end;
36 intf.reset(new InterfaceNode(s, specifiers, id, attrs));
37 intf->SetSpecifierSpan(specifierSpan);
38 }
39 LBRACE!{ beginBraceSpan = span; } InterfaceContent(ctx, intf.get()):content RBRACE!{ endBraceSpan = span; intf->SetBeginBraceSpan(beginBraceSpan); intf->SetEndBraceSpan(endBraceSpan); }
40 )
41 {
42 return intf.release();
43 }
44 ;
45
46 InterfaceContent(ParsingContext* ctx, sngcm::ast::InterfaceNode* intf)
47 ::= (InterfaceMemFun(ctx):intfMemFun{ intf->AddMember(intfMemFun); })*
48 ;
49
50 InterfaceMemFun(ParsingContext* ctx, var std::unique_ptr memFun, var Span s) : Node*
51 ::= empty{ s = span; } Attributes:attrs? TypeExpr(ctx):returnType InterfaceFunctionGroupId:groupId!
52 {
53 s.end = span.end;
54 memFun.reset(new MemberFunctionNode(s, Specifiers(), returnType, groupId, attrs));
55 }
56 ParameterList(ctx, memFun.get()):paramList! SEMICOLON!
57 {
58 return memFun.release();
59 }
60 ;
61
62 InterfaceFunctionGroupId : std::u32string
63 ::= ID{ return lexer.GetMatch(span); }
64 ;
65
66 ruleinfo
67 {
68 (Interface, "interface"), (InterfaceContent, "interface content"), (InterfaceMemFun, "interface member function"), (InterfaceFunctionGroupId, "interface function group identifier")
69 }
70 }