Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit f4d5fa11 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Update and fix pdata class parsing

parent 7edd1cd8
Pipeline #99863 passed with stages
in 10 minutes and 5 seconds
......@@ -22,37 +22,39 @@ void errorUnexpectedToken(const PFileParser & parser, const std::string & token)
cerr << "unexpected token '" << token << "'" << endl;
}
///Get class name from parser
/** @param parser : PFileParser to be used
* @return class name
*/
std::string getClassName(PFileParser & parser){
return parser.getStrComposedOf("_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
}
///Fonction qui met à jour un commentaire
/** @param parser : file parser
* @param currentComment : commentaire que l'on veut mettre à jour
* @param token : token courant
* @return true si on l'a mis à jour, false sinon
*/
bool updateCurrentComment(PFileParser & parser, std::string & currentComment, std::string & token){
if(token == "/"){ //Si on trouve un début de commentaire
token = parser.getNextToken();
if(token == "/"){
currentComment = "//" + eraseCharsInStr(parser.getUntilKey("\n"), "\n");
return true;
}else if(token == "*"){
currentComment = "/*" + parser.getUntilKey("*/");
return true;
}else{
errorUnexpectedToken(parser, token);
}
bool updateCurrentComment(PFileParser & parser, std::string & currentComment){
if(parser.isMatch("//")){
currentComment = "//" + parser.getUntilKeyWithoutPatern("\n");
}else if(parser.isMatch("/*")){
currentComment = "/*" + parser.getUntilKey("*/");
}else{
return false;
}
return false;
return true;
}
///Parse a PClassConfig
/** @param[out] config : PClassConfig
* @param[out] parser : file parser
* @param[out] token : current token
* @param[out] currentComment : current commet
* @return true on success, false otherwise
*/
bool parseClassConfigAttribut(PClassConfig & config, PFileParser & parser, std::string & token, std::string & currentComment){
std::string attribut(eraseCharsInStr(token + parser.getUntilKey(";"), ";\n"));
bool parseClassConfigAttribut(PClassConfig & config, PFileParser & parser, std::string & currentComment){
parser.skipWhiteSpace();
std::string attribut(eraseCharsInStr(parser.getUntilKeyWithoutPatern(";"), "\n"));
std::list<std::string> listToken(cutStringOnSpacesList(attribut));
std::string attributName(listToken.back());
listToken.pop_back();
......@@ -68,45 +70,43 @@ bool parseClassConfigAttribut(PClassConfig & config, PFileParser & parser, std:
///Parse the parents of the PClassConfig
/** @param[out] config : PClassConfig
* @param[out] parser : file parser
* @param[out] token : current token
* @return true on success, false otherwise
*/
bool parseParentOfClassConfig(PClassConfig & config, PFileParser & parser, std::string & token){
if(token != "(") return true;
token = parser.getNextToken();
std::string parentDef(token);
while(!parser.isEndOfFile() && token != ")"){
token = parser.getNextToken();
if(token != ")"){
if(token == ","){
config.addParentClass(parentDef);
parentDef = "";
}else{
parentDef += token;
}
bool parseParentOfClassConfig(PClassConfig & config, PFileParser & parser){
if(!parser.isMatch("(")) return true;
while(!parser.isEndOfFile() && parser.isMatch(")")){
std::string parentDef(getClassName(parser));
if(parentDef == ""){
break;
}
config.addParentClass(parentDef);
if(parser.isMatch(")")){break;}
if(!parser.isMatch(",")){
errorUnexpectedToken(parser, parser.getNextToken());
return false;
}
}
if(parentDef != "") config.addParentClass(parentDef);
// cout << "parseParentOfClassConfig : parent of class '"<<config.getName()<<"' : " << config.getListParentClass() << endl;
return true;
}
///Parse a PClassConfig
/** @param[out] listClassConfig : list of PClassConfig
* @param[out] parser : file parser
* @param[out] token : current token
* @param[out] currentComment : current commet
* @return true on success, false otherwise
*/
bool parsePClassConfig(std::list<PClassConfig> & listClassConfig, PFileParser & parser, std::string & token, std::string & currentComment){
bool parsePClassConfig(std::list<PClassConfig> & listClassConfig, PFileParser & parser, std::string & currentComment){
PClassConfig config;
config.setName(token);
std::string className(getClassName(parser));
std::cout << "parsePClassConfig : find className : '"<<className<<"'" << std::endl;
config.setName(className);
config.setClassDocumentation(currentComment);
currentComment = "";
while(!parser.isEndOfFile() && token != "{" && token != "("){
token = parser.getNextToken();
}
if(!parseParentOfClassConfig(config, parser, token)){
parser.skipWhiteSpace();
if(!parseParentOfClassConfig(config, parser)){
cerr << "parsePClassConfig : file '" << parser.getFileName() << "' line " << parser.getLine() << endl;
cerr << "\tmissing ')' : can't parse parents of the class '"<<config.getName()<<"'" << endl;
}
......@@ -115,16 +115,20 @@ bool parsePClassConfig(std::list<PClassConfig> & listClassConfig, PFileParser &
cerr << "\tmissing '}'" << endl;
return false;
}
if(!parser.isMatch("{")){
errorUnexpectedToken(parser, parser.getNextToken());
std::cerr << "\tExpect '{' after class name '"<<className<<"'" << std::endl;
return false;
}
bool searchingData(true);
while(!parser.isEndOfFile() && searchingData){
token = parser.getNextToken();
if(parser.isChSeparator()){
if(token == "}"){
if(parser.isMatchRewind("}")){
searchingData = false;
}else updateCurrentComment(parser, currentComment, token);
}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
if(!parseClassConfigAttribut(config, parser, token, currentComment)){
errorUnexpectedToken(parser, token);
}else if(updateCurrentComment(parser, currentComment)){}
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
if(!parseClassConfigAttribut(config, parser, currentComment)){
errorUnexpectedToken(parser, parser.getNextToken());
return false;
}
}
......@@ -142,22 +146,23 @@ bool parsePClassConfig(std::list<PClassConfig> & listClassConfig, PFileParser &
bool parserClassConfig(std::list<PClassConfig> & listClassConfig, std::list<std::string> & listInclude, const std::string & fileName){
if(fileName == "") return false;
PFileParser parser;
parser.setWhiteSpace(" \t\n");
parser.setSeparator("{};/*");
if(!parser.open(fileName)) return false;
std::string currentComment("");
std::string token = parser.getNextToken();
while(!parser.isEndOfFile()){
if(token == "#"){
token = parser.getNextToken();
if(token == "include") listInclude.push_back(eraseCharsInStr(parser.getUntilKey("\n")," \t\n"));
}else if(parser.isChSeparator()){
updateCurrentComment(parser, currentComment, token);
}else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PClassConfig
if(!parsePClassConfig(listClassConfig, parser, token, currentComment)){
errorUnexpectedToken(parser, token);
while(!parser.isEndOfFile() && !parser.isMatch("}")){
if(parser.isMatch("#")){
if(parser.isMatch("include")){
listInclude.push_back(eraseCharsInStr(parser.getUntilKeyWithoutPatern("\n")," \t\n"));
}
}else if(updateCurrentComment(parser, currentComment)){}
else{ //Si ce n'est pas un séparateur, c'est que l'on a trouvé un nom, de PClassConfig
if(!parsePClassConfig(listClassConfig, parser, currentComment)){
errorUnexpectedToken(parser, parser.getNextToken());
return false;
}
}
token = parser.getNextToken();
parser.skipWhiteSpace();
}
return true;
}
......@@ -165,7 +170,7 @@ bool parserClassConfig(std::list<PClassConfig> & listClassConfig, std::list<std:
///Parser list class config
/** @param baseFileNameOutput : base of the output files
* @param fileName : file name of the config
* @param enableDataStream : true to enable the serialization/deserialization with DataStream, false otherwise
* @param enableDataStream : true to enable the serialization/deserialization with data
* @return true on success, false otherwise
*/
bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::string & fileName, bool enableDataStream){
......@@ -175,7 +180,7 @@ bool saveParserClassConfig(const std::string & baseFileNameOutput, const std::st
cerr << "saveParserClassConfig : can't load file '" << fileName << "'" << endl;
return false;
}
if(!saveClassImplDecl(listClassConfig, baseFileNameOutput, listInclude)){
if(!saveClassImplDecl(listClassConfig, baseFileNameOutput, listInclude, enableDataStream)){
cerr << "saveParserClassConfig : can't save files '" << baseFileNameOutput << "'[.h or .cpp]" << endl;
return false;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment