1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/Project.hpp>
8 [cpp]#include <sngcm/cmlexer/ContainerFileLexer.hpp>
9 [cpp]#include <sngcm/cmlexer/ContainerFileTokens.hpp>
10
11 using namespace sngcm::ast;
12 using namespace ContainerFileTokens;
13
14 parser api(SNGCM_PARSER_API) ProjectFileParser
15 {
16 uselexer ContainerFileLexer;
17 main;
18
19 ProjectFile(std::string config, sngcm::ast::BackEnd backend, std::string toolChain, sngcm::ast::SystemDirKind systemDirKind, var std::unique_ptr project) :
20 sngcm::ast::Project*
21 ::=
22 (
23 PROJECT QualifiedId:name! SEMICOLON!{ project.reset(new Project(name, lexer.FileName(), config, backend, toolChain, systemDirKind)); }
24 (Declaration:declaration{ project->AddDeclaration(declaration); })*
25 )
26 {
27 return project.release();
28 }
29 ;
30
31 QualifiedId(var Span s) : std::u32string
32 ::=
33 (
34 ID{ s = span; } (DOT ID{ s.end = span.end; })*
35 )
36 {
37 return lexer.GetMatch(s);
38 }
39 ;
40
41 Declaration : ProjectDeclaration*
42 ::= ReferenceDeclaration:referenceDeclaration{ return referenceDeclaration; }
43 | SourceFileDeclaration:sourceFileDeclaration{ return sourceFileDeclaration; }
44 | ResourceFileDeclaration:resourceFileDeclaration{ return resourceFileDeclaration; }
45 | TextFileDeclaration:textFileDeclaration{ return textFileDeclaration; }
46 | TargetDeclaration:targetDeclaration{ return targetDeclaration; }
47 ;
48
49 ReferenceDeclaration(var std::string filePath) : ProjectDeclaration*
50 ::= REFERENCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::ReferenceDeclaration(filePath); }
51 ;
52
53 SourceFileDeclaration(var std::string filePath) : ProjectDeclaration*
54 ::= SOURCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::SourceFileDeclaration(filePath); }
55 ;
56
57 ResourceFileDeclaration(var std::string filePath) : ProjectDeclaration*
58 ::= RESOURCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::ResourceFileDeclaration(filePath); }
59 ;
60
61 TextFileDeclaration(var std::string filePath) : ProjectDeclaration*
62 ::= TEXT FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::TextFileDeclaration(filePath); }
63 ;
64
65 TargetDeclaration : ProjectDeclaration*
66 ::= TARGET ASSIGN! Target:target! SEMICOLON!{ return new sngcm::ast::TargetDeclaration(target); }
67 ;
68
69 Target : sngcm::ast::Target
70 ::= PROGRAM{ return sngcm::ast::Target::program; }
71 | WINGUIAPP{ return sngcm::ast::Target::winguiapp; }
72 | WINAPP{ return sngcm::ast::Target::winapp; }
73 | LIBRARY{ return sngcm::ast::Target::library; }
74 | WINLIB{ return sngcm::ast::Target::winlib; }
75 | UNITTEST{ return sngcm::ast::Target::unitTest; }
76 ;
77
78 ruleinfo
79 {
80 (ProjectFile, "project file"), (QualifiedId, "identifier"), (Declaration, "project file declaration"),
81 (ReferenceDeclaration, "reference declaration"), (SourceFileDeclaration, "source file declaration"),
82 (TextFileDeclaration, "text file declaration"), (TargetDeclaration, "target declaration"),
83 (Target, "target")
84 }
85 }