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, var std::unique_ptr project) : sngcm::ast::Project*
20 ::=
21 (
22 PROJECT QualifiedId:name! SEMICOLON!{ project.reset(new Project(name, lexer.FileName(), config, backend)); }
23 (Declaration:declaration{ project->AddDeclaration(declaration); })*
24 )
25 {
26 return project.release();
27 }
28 ;
29
30 QualifiedId(var Span s) : std::u32string
31 ::=
32 (
33 ID{ s = span; } (DOT ID{ s.end = span.end; })*
34 )
35 {
36 return lexer.GetMatch(s);
37 }
38 ;
39
40 Declaration : ProjectDeclaration*
41 ::= ReferenceDeclaration:referenceDeclaration{ return referenceDeclaration; }
42 | SourceFileDeclaration:sourceFileDeclaration{ return sourceFileDeclaration; }
43 | ResourceFileDeclaration:resourceFileDeclaration{ return resourceFileDeclaration; }
44 | TextFileDeclaration:textFileDeclaration{ return textFileDeclaration; }
45 | TargetDeclaration:targetDeclaration{ return targetDeclaration; }
46 ;
47
48 ReferenceDeclaration(var std::string filePath) : ProjectDeclaration*
49 ::= REFERENCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::ReferenceDeclaration(filePath); }
50 ;
51
52 SourceFileDeclaration(var std::string filePath) : ProjectDeclaration*
53 ::= SOURCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::SourceFileDeclaration(filePath); }
54 ;
55
56 ResourceFileDeclaration(var std::string filePath) : ProjectDeclaration*
57 ::= RESOURCE FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::ResourceFileDeclaration(filePath); }
58 ;
59
60 TextFileDeclaration(var std::string filePath) : ProjectDeclaration*
61 ::= TEXT FILEPATH!{ filePath = lexer.filePath; } SEMICOLON!{ return new sngcm::ast::TextFileDeclaration(filePath); }
62 ;
63
64 TargetDeclaration : ProjectDeclaration*
65 ::= TARGET ASSIGN! Target:target! SEMICOLON!{ return new sngcm::ast::TargetDeclaration(target); }
66 ;
67
68 Target : sngcm::ast::Target
69 ::= PROGRAM{ return sngcm::ast::Target::program; }
70 | WINGUIAPP{ return sngcm::ast::Target::winguiapp; }
71 | WINAPP{ return sngcm::ast::Target::winapp; }
72 | LIBRARY{ return sngcm::ast::Target::library; }
73 | WINLIB{ return sngcm::ast::Target::winlib; }
74 | UNITTEST{ return sngcm::ast::Target::unitTest; }
75 ;
76
77 ruleinfo
78 {
79 (ProjectFile, "project file"), (QualifiedId, "identifier"), (Declaration, "project file declaration"),
80 (ReferenceDeclaration, "reference declaration"), (SourceFileDeclaration, "source file declaration"),
81 (TextFileDeclaration, "text file declaration"), (TargetDeclaration, "target declaration"),
82 (Target, "target")
83 }
84 }