1
2
3
4
5
6 [hpp]#include <sngcpp/parser/ParserApi.hpp>
7 [hpp]#include <sngcpp/parser/ParsingContext.hpp>
8 [hpp]#include <sngcpp/parser/Declaration.hpp>
9 [cpp]#include <sngcpp/lexer/CppLexer.hpp>
10 [cpp]#include <sngcpp/lexer/CppTokens.hpp>
11
12 using namespace CppTokens;
13 using namespace soulng::lexer;
14
15 parser api(SNGCPP_PARSER_API) SourceFileParser
16 {
17 uselexer CppLexer;
18 main;
19
20 using DeclarationParser.Declaration;
21
22 SourceFile(sngcpp::ast::SourceFileNode* sourceFile, var sngcpp::cppparser::ParsingContext ctx)
23 ::= empty{ ctx.SetSourceFileNode(sourceFile); }
24 Declarations(&ctx, sourceFile->GlobalNs()):declarations
25 ;
26
27 Declarations(sngcpp::cppparser::ParsingContext* ctx, sngcpp::ast::NamespaceNode* ns)
28 ::= (Declaration(ctx):declaration{ ns->AddMember(span, declaration); })*
29 ;
30 }