1 // =================================
 2 // Copyright (c) 2021 Seppo Laakko
 3 // Distributed under the MIT license
 4 // =================================
 5 
 6 [hpp]#include <cmajor/build/BuildApi.hpp>
 7 [hpp]#include <cmajor/build/BuildOption.hpp>
 8 [cpp]#include <cmajor/build/BuildLangLexer.hpp>
 9 [cpp]#include <cmajor/build/BuildLangTokens.hpp>
10 [cpp]#include <cmajor/build/BuildLangOptionParser.hpp>
11 [hpp]#include <cmajor/build/ServerCommand.hpp>
12 [hpp]#include <memory>
13 
14 using namespace BuildLangTokens;
15 
16 parser api(BUILD_API) BuildLangServerParser
17 {
18     uselexer BuildLangLexer;
19     main;
20     using BuildLangOptionParser.Options;
21 
22     ServerSentence(cmajor::build::BuildOptionSetter* optionSetter) : cmajor::build::ServerCommand*
23         ::= Options(optionSetter):options?
24             ServerCommandSentence:sentence!{ return sentence; }
25         ;
26 
27     ServerCommandSentence : cmajor::build::ServerCommand*
28         ::=
29         (   AddServerSentence:addServerCommand{ return addServerCommand; }
30         |   RemoveServerSentence:removeServerCommand{ return removeServerCommand; }
31         |   RunServerSentence:runServerCommand{ return runServerCommand; }
32         |   ShowConfigurationSentence:showConfigurationCommand{ return showConfigurationCommand; }
33         )
34         ;
35 
36     AddServerSentence : cmajor::build::ServerCommand*
37         ::=
38         (
39             ADD SERVER! ServerId:server! PORT! Port:port
40         )
41         {
42             return new cmajor::build::AddServerServerCommand(server, port);
43         }
44         ;
45 
46     RemoveServerSentence : cmajor::build::ServerCommand*
47         ::=
48         (
49             REMOVE SERVER! ServerId:server!
50         )
51         {
52             return new cmajor::build::RemoveServerServerCommand(server);
53         }
54         ;
55 
56     RunServerSentence : cmajor::build::ServerCommand*
57         ::=
58         (
59             RUN SERVER ServerId:server!
60         )
61         {
62             return new cmajor::build::RunServerServerCommand(server);
63         }
64         ;
65 
66     ShowConfigurationSentence : cmajor::build::ServerCommand*
67         ::=
68         (
69             SHOW CONFIGURATION
70         )
71         {
72             return new cmajor::build::ShowConfigurationServerCommand();
73         }
74         ;
75 
76     ServerId : std::string
77         ::= ID{ return ToUtf8(lexer.GetToken(pos).match.ToString()); }
78         ;
79 
80 
81     Port(var std::string portStr) : int
82         ::= INTEGER{ portStr = ToUtf8(lexer.GetToken(pos).match.ToString()); return std::stoi(portStr); }
83         ;
84 
85     ruleinfo
86     {
87         (ServerSentence, "cmserver (add server | remove server | run server | show condiguration) ..."),
88         (ServerCommandSentence, "cmserver (add server | remove server | run server | show condiguration) ..."),
89         (AddServerSentence, "add server command"),
90         (RemoveServerSentence, "remove server command"),
91         (RunServerSentence, "run server command"),
92         (ShowConfigurationSentence, "show configuration command"),
93         (ServerId, "server name"),
94         (Port, "port number")
95     }
96 }