1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/CompileUnit.hpp>
8 [hpp]#include <sngcm/cmparser/ParsingContext.hpp>
9 [hpp]#include <memory>
10 [cpp]#include <sngcm/cmparser/Typedef.hpp>
11 [cpp]#include <sngcm/cmparser/Identifier.hpp>
12 [cpp]#include <sngcm/cmparser/Concept.hpp>
13 [cpp]#include <sngcm/cmparser/Function.hpp>
14 [cpp]#include <sngcm/cmparser/Class.hpp>
15 [cpp]#include <sngcm/cmparser/Interface.hpp>
16 [cpp]#include <sngcm/cmparser/Enumeration.hpp>
17 [cpp]#include <sngcm/cmparser/Constant.hpp>
18 [cpp]#include <sngcm/cmparser/Delegate.hpp>
19 [cpp]#include <sngcm/cmparser/GlobalVariable.hpp>
20 [cpp]#include <sngcm/cmparser/Template.hpp>
21 [cpp]#include <sngcm/cmlexer/CmajorLexer.hpp>
22 [cpp]#include <sngcm/cmlexer/CmajorTokens.hpp>
23
24 using namespace sngcm::ast;
25 using namespace CmajorTokens;
26
27 parser api(SNGCM_PARSER_API) CompileUnitParser
28 {
29 main;
30 uselexer CmajorLexer;
31
32 using IdentifierParser.Identifier;
33 using IdentifierParser.QualifiedId;
34 using ConceptParser.Concept;
35 using FunctionParser.Function;
36 using ClassParser.Class;
37 using InterfaceParser.Interface;
38 using TypedefParser.Typedef;
39 using EnumerationParser.EnumType;
40 using ConstantParser.Constant;
41 using DelegateParser.Delegate;
42 using DelegateParser.ClassDelegate;
43 using GlobalVariableParser.GlobalVariable;
44 using TemplateParser.InstantiationRequest;
45
46 CompileUnit(boost::uuids::uuid* moduleId, ParsingContext* ctx, var std::unique_ptr compileUnit) : sngcm::ast::CompileUnitNode*
47 ::= empty{ compileUnit.reset(new CompileUnitNode(span, *moduleId, lexer.FileName())); }
48 NamespaceContent(moduleId, ctx, compileUnit.get(), compileUnit->GlobalNs()):content{ return compileUnit.release(); }
49 ;
50
51 NamespaceContent(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu, sngcm::ast::NamespaceNode* ns)
52 ::= UsingDirectives(moduleId, ctx, ns):usingDirectives
53 Definitions(moduleId, ctx, cu, ns):definitions
54 ;
55
56 UsingDirectives(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::NamespaceNode* ns)
57 ::= UsingDirective(moduleId, ctx, ns):usingDirective*
58 ;
59
60 UsingDirective(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::NamespaceNode* ns)
61 ::= UsingAliasDirective(moduleId):usingAlias{ ns->AddMember(usingAlias); }
62 | UsingNamespaceDirective(moduleId, ctx):usingNs{ ns->AddMember(usingNs); }
63 ;
64
65 UsingAliasDirective(boost::uuids::uuid* moduleId, var Span s) : Node*
66 ::= USING{ s = span; } Identifier(moduleId):id ASSIGN QualifiedId(moduleId):qid! SEMICOLON!
67 {
68 s.end = span.end;
69 return new AliasNode(s, *moduleId, id, qid);
70 }
71 ;
72
73 UsingNamespaceDirective(boost::uuids::uuid* moduleId, ParsingContext* ctx, var Span s) : Node*
74 ::= USING{ s = span; } QualifiedId(moduleId):ns! SEMICOLON!
75 {
76 s.end = span.end;
77 return new NamespaceImportNode(s, *moduleId, ns);
78 }
79 ;
80
81 Definitions(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu, sngcm::ast::NamespaceNode* ns)
82 ::= (Definition(moduleId, ctx, cu, ns):definition{ ns->AddMember(definition); })*
83 ;
84
85 Definition(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu, sngcm::ast::NamespaceNode* ns) : Node*
86 ::= NamespaceDefinition(moduleId, ctx, cu, ns):nsDefinition{ return nsDefinition; }
87 | TypedefDeclaration(moduleId, ctx):typedefDeclaration{ return typedefDeclaration; }
88 | ConceptDefinition(moduleId, ctx):conceptDefinition{ return conceptDefinition; }
89 | FunctionDefinition(moduleId, ctx):functionDefinition{ return functionDefinition; }
90 | ClassDefinition(moduleId, ctx):classDefinition{ return classDefinition; }
91 | InterfaceDefinition(moduleId, ctx):interfaceDefinition{ return interfaceDefinition; }
92 | EnumTypeDefinition(moduleId, ctx):enumTypeDefinition{ return enumTypeDefinition; }
93 | ConstantDefinition(moduleId, ctx):constantDefinition{ return constantDefinition; }
94 | DelegateDefinition(moduleId, ctx):delegateDefinition{ return delegateDefinition; }
95 | ClassDelegateDefinition(moduleId, ctx):classDelegateDefinition{ return classDelegateDefinition; }
96 | GlobalVariableDefinition(moduleId, ctx, cu):globalVariableDefinition{ return globalVariableDefinition; }
97 | InstantiationRequestDeclaration(moduleId, ctx):instantiationRequestDeclaration{ return instantiationRequestDeclaration; }
98 ;
99
100 NamespaceDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu, sngcm::ast::NamespaceNode* ns, var std::unique_ptr nsNode, var Span s) : NamespaceNode*
101 ::= NAMESPACE{ s = span; } (QualifiedId(moduleId):nsName{ s.end = span.end; nsNode.reset(new NamespaceNode(s, *moduleId, nsName)); } | empty{ nsNode.reset(new NamespaceNode(s, *moduleId, nullptr)); })
102 LBRACE! NamespaceContent(moduleId, ctx, cu, nsNode.get()):content! RBRACE!
103 {
104 return nsNode.release();
105 }
106 ;
107
108 TypedefDeclaration(boost::uuids::uuid* moduleId, ParsingContext* ctx) : TypedefNode*
109 ::= Typedef(moduleId, ctx):typedefDeclaration{ return typedefDeclaration; }
110 ;
111
112 ConceptDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : ConceptNode*
113 ::= Concept(moduleId, ctx):conceptDefinition{ return conceptDefinition; }
114 ;
115
116 FunctionDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : FunctionNode*
117 ::= Function(moduleId, ctx):functionDefinition{ return functionDefinition; }
118 ;
119
120 ClassDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : ClassNode*
121 ::= Class(moduleId, ctx):classDefinition{ return classDefinition; }
122 ;
123
124 InterfaceDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : InterfaceNode*
125 ::= Interface(moduleId, ctx):interfaceDefinition{ return interfaceDefinition; }
126 ;
127
128 EnumTypeDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : EnumTypeNode*
129 ::= EnumType(moduleId, ctx):enumTypeDefinition{ return enumTypeDefinition; }
130 ;
131
132 ConstantDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : ConstantNode*
133 ::= Constant(moduleId, ctx):constantDefinition{ return constantDefinition; }
134 ;
135
136 DelegateDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : DelegateNode*
137 ::= Delegate(moduleId, ctx):delegateDefinition{ return delegateDefinition; }
138 ;
139
140 ClassDelegateDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx) : ClassDelegateNode*
141 ::= ClassDelegate(moduleId, ctx):classDelegateDefinition{ return classDelegateDefinition; }
142 ;
143
144 GlobalVariableDefinition(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu) : GlobalVariableNode*
145 ::= GlobalVariable(moduleId, ctx, cu):globalVariableDefinition{ return globalVariableDefinition; }
146 ;
147
148 InstantiationRequestDeclaration(boost::uuids::uuid* moduleId, ParsingContext* ctx) : FullInstantiationRequestNode*
149 ::= InstantiationRequest(moduleId, ctx):instantiationRequest{ return instantiationRequest; }
150 ;
151
152 ruleinfo
153 {
154 (CompileUnit, "compile unit"), (NamespaceContent, "namespace content"), (UsingDirectives, "using directives"), (UsingDirective, "using directive"),
155 (UsingAliasDirective, "using alias directive"), (UsingNamespaceDirective, "using namespace directive"), (Definitions, "definitions"),
156 (Definition, "definition"), (NamespaceDefinition, "namespace definition"), (TypedefDeclaration , "typedef declaration"), (ConceptDefinition, "concept definition"),
157 (FunctionDefinition, "function definition"), (ClassDefinition, "class definition"), (InterfaceDefinition, "interface definition"), (EnumTypeDefinition, "enumerated type definition"),
158 (ConstantDefinition, "constant definition"), (DelegateDefinition, "delegate definition"), (ClassDelegateDefinition, "class delegate definition"),
159 (GlobalVariableDefinition, "global variable definition")
160 }
161 }
162
163