PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
parserClassConfig.cpp File Reference
#include <iostream>
#include "class_attribute_utils.h"
#include "parserClassConfig.h"
+ Include dependency graph for parserClassConfig.cpp:

Go to the source code of this file.

Functions

void errorUnexpectedToken (const PFileParser &parser, const PString &token)
 Affiche une erreur de token non attendu.
 
PString getClassName (PFileParser &parser)
 Get class name from parser.
 
bool parseClassConfigAttribut (PClassConfig &config, PFileParser &parser, PString &currentComment)
 Parse a PClassConfig.
 
bool parseEnumConfig (std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment)
 Parse an enum definition.
 
bool parseEnumValue (PClassConfig &config, PFileParser &parser, PString &currentComment)
 Parse enum attribute value.
 
bool parseParentOfClassConfig (PClassConfig &config, PFileParser &parser)
 Parse the parents of the PClassConfig.
 
bool parsePClassConfig (std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment, PVecString &listTemplate)
 Parse a PClassConfig.
 
bool parserClassConfig (std::vector< PClassConfig > &listClassConfig, PVecPath &listInclude, const PPath &fileName)
 Parser list class config.
 
bool updateCurrentComment (PFileParser &parser, PString &currentComment)
 Fonction qui met à jour un commentaire.
 
bool updateCurrentTemplate (PFileParser &parser, PVecString &currentTemplate)
 Update a template definition.
 

Function Documentation

◆ errorUnexpectedToken()

void errorUnexpectedToken ( const PFileParser & parser,
const PString & token )

Affiche une erreur de token non attendu.

Parameters
parser: file parser
token: token qui pose problème

Definition at line 16 of file parserClassConfig.cpp.

16 {
17 std::cerr << "errorUnexpectedToken : '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
18 std::cerr << "unexpected token '" << token << "'" << std::endl;
19}

Referenced by parseEnumConfig(), parseParentOfClassConfig(), parsePClassConfig(), and parserClassConfig().

+ Here is the caller graph for this function:

◆ getClassName()

PString getClassName ( PFileParser & parser)

Get class name from parser.

Parameters
parser: PFileParser to be used
Returns
class name

Definition at line 25 of file parserClassConfig.cpp.

25 {
26 return parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
27}

Referenced by parseEnumConfig(), parseEnumValue(), parseParentOfClassConfig(), and parsePClassConfig().

+ Here is the caller graph for this function:

◆ parseClassConfigAttribut()

bool parseClassConfigAttribut ( PClassConfig & config,
PFileParser & parser,
PString & currentComment )

Parse a PClassConfig.

Parameters
[out]config: PClassConfig
[out]parser: file parser
[out]currentComment: current commet
Returns
true on success, false otherwise

Definition at line 67 of file parserClassConfig.cpp.

67 {
68 parser.skipWhiteSpace();
69 PString attribut(parser.getUntilKeyWithoutPatern(";").eraseChar("\n"));
70 PVecString listToken(attribut.split(" \n\t"));
71 PString attributName(listToken.back());
72 listToken.pop_back();
73 PString attributType("");
74 for(PVecString::iterator it(listToken.begin()); it != listToken.end(); ++it){
75 attributType += *it + " ";
76 }
77 attributType = attributType.eraseFirstLastChar(" \n\t");
78 config.addAttribute(createClassAttribute(attributType, attributName, currentComment));
79 currentComment = "";
80 return true;
81}
void addAttribute(const PClassAttribute &attribute)
Adds an attribute to the class.
PClassAttribute createClassAttribute(const PString &type, const PString &name, const PString &documentation)
Creates a PClassAttribute.

References PClassConfig::addAttribute(), and createClassAttribute().

Referenced by parsePClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseEnumConfig()

bool parseEnumConfig ( std::vector< PClassConfig > & listClassConfig,
PFileParser & parser,
PString & currentComment )

Parse an enum definition.

Parameters
[out]listClassConfig: list of PClassConfig
[out]parser: file parser
[out]currentComment: current comment
Returns
true on success, false otherwise

Definition at line 132 of file parserClassConfig.cpp.

132 {
133 if(!parser.isMatchToken("enum")){return false;}
134 PClassConfig config;
135 config.setIsEnum(true);
136 PString enumName(getClassName(parser)); //Get the name of the enum
137 std::cout << "parseEnumConfig : find enum : '"<<enumName<<"'" << std::endl;
138 config.setName(enumName);
139 config.setClassDocumentation(currentComment);
140 currentComment = "";
141 parser.skipWhiteSpace();
142 if(!parser.isMatch("{")){
143 errorUnexpectedToken(parser, parser.getNextToken());
144 std::cerr << "\tExpect '{' after enum name '"<<enumName<<"'" << std::endl;
145 return false;
146 }
147 bool searchingData(true);
148 while(!parser.isEndOfFile() && searchingData && !parser.isMatch("}")){
149 if(updateCurrentComment(parser, currentComment)){}
150 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PDataGroup ou de PDataVar ou PDataTable
151 if(!parseEnumValue(config, parser, currentComment)){
152 errorUnexpectedToken(parser, parser.getNextToken());
153 return false;
154 }
155 }
156 }
157 listClassConfig.push_back(config);
158 return true;
159}
Class to describe a basic class.
void setClassDocumentation(const PString &classDocumentation)
Sets the class documentation.
void setIsEnum(bool isEnum)
Set if the current PClassConfig is an enum.
void setName(const PString &name)
Sets the class name.
bool updateCurrentComment(PFileParser &parser, PString &currentComment)
Fonction qui met à jour un commentaire.
bool parseEnumValue(PClassConfig &config, PFileParser &parser, PString &currentComment)
Parse enum attribute value.
PString getClassName(PFileParser &parser)
Get class name from parser.
void errorUnexpectedToken(const PFileParser &parser, const PString &token)
Affiche une erreur de token non attendu.

References errorUnexpectedToken(), getClassName(), parseEnumValue(), PClassConfig::setClassDocumentation(), PClassConfig::setIsEnum(), PClassConfig::setName(), and updateCurrentComment().

Referenced by parserClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseEnumValue()

bool parseEnumValue ( PClassConfig & config,
PFileParser & parser,
PString & currentComment )

Parse enum attribute value.

Parameters
[out]config: PClassConfig
[out]parser: file parser
[out]currentComment: current commet
Returns
true on success, false otherwise

Definition at line 113 of file parserClassConfig.cpp.

113 {
114 PString enumValue(getClassName(parser)), value("");
115 if(!parser.isMatch("=")){
116 value = parser.getStrComposedOf("0123456789xu");
117 }
118 PClassAttribute attr(createClassAttribute("int /* just to remember*/", enumValue, currentComment));
119 attr.setDefaultValue(value);
120 config.addAttribute(attr);
121 currentComment = "";
122 parser.isMatch(","); //We consume the comma if there is one
123 return true;
124}
Describes a class attribute.

References PClassConfig::addAttribute(), createClassAttribute(), getClassName(), and PClassAttribute::setDefaultValue().

Referenced by parseEnumConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parseParentOfClassConfig()

bool parseParentOfClassConfig ( PClassConfig & config,
PFileParser & parser )

Parse the parents of the PClassConfig.

Parameters
[out]config: PClassConfig
[out]parser: file parser
Returns
true on success, false otherwise

Definition at line 88 of file parserClassConfig.cpp.

88 {
89 if(!parser.isMatch("(")) return true;
90
91 while(!parser.isEndOfFile() && parser.isMatch(")")){
92 PString parentDef(getClassName(parser));
93 if(parentDef == ""){
94 break;
95 }
96 config.addParentClass(parentDef);
97 if(parser.isMatch(")")){break;}
98
99 if(!parser.isMatch(",")){
100 errorUnexpectedToken(parser, parser.getNextToken());
101 return false;
102 }
103 }
104 return true;
105}
void addParentClass(const PString &parentClass)
Add a parent class to the PClassConfig.

References PClassConfig::addParentClass(), errorUnexpectedToken(), and getClassName().

Referenced by parsePClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parsePClassConfig()

bool parsePClassConfig ( std::vector< PClassConfig > & listClassConfig,
PFileParser & parser,
PString & currentComment,
PVecString & listTemplate )

Parse a PClassConfig.

Parameters
[out]listClassConfig: list of PClassConfig
[out]parser: file parser
[out]currentComment: current comment
[out]listTemplate: list of the template to be used in the defined class
Returns
true on success, false otherwise

Definition at line 168 of file parserClassConfig.cpp.

168 {
169 PClassConfig config;
170 PString className(getClassName(parser));
171 std::cout << "parsePClassConfig : find className : '"<<className<<"'" << std::endl;
172 config.setName(className);
173 config.setClassDocumentation(currentComment);
174 config.setListTemplate(listTemplate);
175 currentComment = "";
176 listTemplate.clear();
177 parser.skipWhiteSpace();
178
179 if(!parseParentOfClassConfig(config, parser)){
180 std::cerr << "parsePClassConfig : file '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
181 std::cerr << "\tmissing ')' : can't parse parents of the class '"<<config.getName()<<"'" << std::endl;
182 }
183 if(parser.isEndOfFile()){
184 std::cerr << "parsePClassConfig : file '" << parser.getFileName() << "' line " << parser.getLine() << std::endl;
185 std::cerr << "\tmissing '}'" << std::endl;
186 return false;
187 }
188 if(!parser.isMatch("{")){
189 errorUnexpectedToken(parser, parser.getNextToken());
190 std::cerr << "\tExpect '{' after class name '"<<className<<"'" << std::endl;
191 return false;
192 }
193
194 bool searchingData(true);
195 while(!parser.isEndOfFile() && searchingData && !parser.isMatch("}")){
196 if(updateCurrentComment(parser, currentComment)){}
197 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PDataGroup ou de PDataVar ou PDataTable
198 if(!parseClassConfigAttribut(config, parser, currentComment)){
199 errorUnexpectedToken(parser, parser.getNextToken());
200 return false;
201 }
202 }
203 }
204 listClassConfig.push_back(config);
205 return true;
206}
const PString & getName() const
Returns the class name.
void setListTemplate(const PVecString &listTemplate)
Sets the list of template of the class.
bool parseClassConfigAttribut(PClassConfig &config, PFileParser &parser, PString &currentComment)
Parse a PClassConfig.
bool parseParentOfClassConfig(PClassConfig &config, PFileParser &parser)
Parse the parents of the PClassConfig.

References errorUnexpectedToken(), getClassName(), PClassConfig::getName(), parseClassConfigAttribut(), parseParentOfClassConfig(), PClassConfig::setClassDocumentation(), PClassConfig::setListTemplate(), PClassConfig::setName(), and updateCurrentComment().

Referenced by parserClassConfig().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parserClassConfig()

bool parserClassConfig ( std::vector< PClassConfig > & listClassConfig,
PVecPath & listInclude,
const PPath & fileName )

Parser list class config.

Parameters
[out]listClassConfig: list of class config
listInclude: list of include
fileName: file name of the config
Returns
true on success, false otherwise

Definition at line 214 of file parserClassConfig.cpp.

214 {
215 if(fileName == "") return false;
216 PFileParser parser;
217 parser.setWhiteSpace(" \t\n");
218 parser.setSeparator("{};/*");
219 if(!parser.open(fileName)) return false;
220 PString currentComment("");
221 PVecString listTemplate;
222 while(!parser.isEndOfFile()){
223 if(parser.isMatch("#")){
224 if(parser.isMatch("include")){
225 listInclude.push_back(parser.getUntilKeyWithoutPatern("\n").eraseChar(" \t\n"));
226 }
227 }else if(updateCurrentComment(parser, currentComment)){}
228 else if(updateCurrentTemplate(parser, listTemplate)){}
229 else if(parseEnumConfig(listClassConfig, parser, currentComment)){}
230 else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PClassConfig
231 if(!parsePClassConfig(listClassConfig, parser, currentComment, listTemplate)){
232 errorUnexpectedToken(parser, parser.getNextToken());
233 return false;
234 }
235 }
236 parser.skipWhiteSpace();
237 }
238 return true;
239}
bool parseEnumConfig(std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment)
Parse an enum definition.
bool parsePClassConfig(std::vector< PClassConfig > &listClassConfig, PFileParser &parser, PString &currentComment, PVecString &listTemplate)
Parse a PClassConfig.
bool updateCurrentTemplate(PFileParser &parser, PVecString &currentTemplate)
Update a template definition.

References errorUnexpectedToken(), parseEnumConfig(), parsePClassConfig(), updateCurrentComment(), and updateCurrentTemplate().

Referenced by simple_project_load_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateCurrentComment()

bool updateCurrentComment ( PFileParser & parser,
PString & currentComment )

Fonction qui met à jour un commentaire.

Parameters
parser: file parser
currentComment: commentaire que l'on veut mettre à jour
Returns
true si on l'a mis à jour, false sinon

Definition at line 34 of file parserClassConfig.cpp.

34 {
35 if(parser.isMatch("//")){
36 if(currentComment != ""){currentComment += "\n";}
37 currentComment += "//" + parser.getUntilKeyWithoutPatern("\n");
38 }else if(parser.isMatch("/*")){
39 if(currentComment != ""){currentComment += "\n";}
40 currentComment += "/*" + parser.getUntilKey("*/");
41 }else{
42 return false;
43 }
44 return true;
45}

Referenced by parseEnumConfig(), parsePClassConfig(), and parserClassConfig().

+ Here is the caller graph for this function:

◆ updateCurrentTemplate()

bool updateCurrentTemplate ( PFileParser & parser,
PVecString & currentTemplate )

Update a template definition.

Parameters
parser: file parser
currentTemplate: template to be updated
Returns
true on success, false otherwise

Definition at line 52 of file parserClassConfig.cpp.

52 {
53 if(!parser.isMatch("template")){return false;}
54 if(!parser.isMatch("<")){return false;}
55
56 currentTemplate = parser.getUntilKeyWithoutPaternRecurse(">", "<").split(',');
57
58 return true;
59}

Referenced by parserClassConfig().

+ Here is the caller graph for this function: