Commit 6bac8354 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Update parsing with other code

parent 6c9369b3
......@@ -53,8 +53,8 @@ void HeaderParser::copyHeaderParser(const HeaderParser & other){
bool HeaderParser::parseFile(){
if(!p_run) return false;
p_lastDocString = "";
PSource source;
source.setName(getFileName(p_parser->getFileName()));
p_otherCode = "";
p_currentSource.setName(getFileName(p_parser->getFileName()));
p_parser->skipWhiteSpace();
//To parse the file we need to read char by char until we get something we know
while(!p_parser->isEndOfFile() && p_run){ //If we are not at the end of the file
......@@ -62,14 +62,13 @@ bool HeaderParser::parseFile(){
if(parseDocString()){}
else if(p_parser->isMatch("//")){p_parser->getUntilKeyWithoutPatern("\n");} //Skip comment
else if(parseFunction(function)){
source.getVecFunction().push_back(function);
p_currentSource.getVecFunction().push_back(function);
}else{
errorAt();
std::cerr << "HeaderParser::parseFile : unexpected token '"<<p_parser->getNextToken()<<"'" << std::endl;
incrementCurrentChar();
}
p_parser->skipWhiteSpace();
}
p_vecSource.push_back(source);
p_vecSource.push_back(p_currentSource);
return true;
}
......@@ -90,6 +89,27 @@ void HeaderParser::initialisationHeaderParser(){
}
///Increment current char position
/** @param[out] textObj : obh to be used to store text
*/
void HeaderParser::incrementCurrentChar(){
//If nothing is known I need to save the current char in the other code
char ch = p_parser->getCurrentCh();
if(ch == '~'){ch = ' ';}
p_otherCode += ch;
p_parser->getNextChar();
}
///Add the other code parsed into the current PSource
void HeaderParser::playOtherCode(){
if(p_otherCode != ""){
PFunction other;
other.setOtherCode(p_otherCode);
p_currentSource.getVecFunction().push_back(other);
p_otherCode = "";
}
}
///Parse a doc string
/** @return true on success, false otherwise
*/
......@@ -132,6 +152,7 @@ bool HeaderParser::parseFunction(PFunction & function){
}
p_parser->skipWhiteSpace();
}
playOtherCode();
return true;
}
......@@ -154,9 +175,9 @@ void HeaderParser::parseTemplateDef(std::string & templateDef){
templateDef += " ";
templateDef += p_parser->getNextToken(); //Some T
if(p_parser->isMatch(">")){isTemplate = false;}
else if(!p_parser->isMatch(">")){
else if(!p_parser->isMatch(",")){
errorAt();
std::cerr << "HeaderParser::parseTemplateDef : expect ',' or ',' after template definition '"<<templateDef<<"'" << std::endl;
std::cerr << "HeaderParser::parseTemplateDef : expect '>' or ',' after template definition '"<<templateDef<<"'" << std::endl;
return;
}
}
......
......@@ -30,6 +30,9 @@ class HeaderParser : public PMultiFileParser{
private:
void initialisationHeaderParser();
void incrementCurrentChar();
void playOtherCode();
bool parseDocString();
bool parseFunction(PFunction & function);
void parseTemplateDef(std::string & templateDef);
......@@ -38,7 +41,10 @@ class HeaderParser : public PMultiFileParser{
///Last documentation string
std::string p_lastDocString;
///Other code which is not a function prototype
std::string p_otherCode;
///Current source to be parsed
PSource p_currentSource;
///Vector of parsed PSource
PVecSource p_vecSource;
};
......
......@@ -188,6 +188,13 @@ void PFunction::setTemplateDef(const std::string & templateDef){
p_templateDef = templateDef;
}
///Sets the otherCode of the PFunction
/** @param otherCode : otherCode of the PFunction
*/
void PFunction::setOtherCode(const std::string & otherCode){
p_otherCode = otherCode;
}
///Gets the name of the PFunction
/** @return name of the PFunction
*/
......@@ -258,6 +265,20 @@ std::string & PFunction::getTemplateDef(){
return p_templateDef;
}
///Gets the otherCode of the PFunction
/** @return otherCode of the PFunction
*/
const std::string & PFunction::getOtherCode() const{
return p_otherCode;
}
///Gets the otherCode of the PFunction
/** @return otherCode of the PFunction
*/
std::string & PFunction::getOtherCode(){
return p_otherCode;
}
///Copy Function of class PFunction
/** @param other : PFunction we want ot copy
*/
......@@ -267,6 +288,7 @@ void PFunction::copyPFunction(const PFunction & other){
p_vecArgument = other.p_vecArgument;
p_outputType = other.p_outputType;
p_templateDef = other.p_templateDef;
p_otherCode = other.p_otherCode;
}
///Constructor of class PSource
......
......@@ -54,6 +54,7 @@ class PFunction{
void setVecArgument(const std::vector<PArgument> & vecArgument);
void setOutputType(const std::string & outputType);
void setTemplateDef(const std::string & templateDef);
void setOtherCode(const std::string & otherCode);
const std::string & getName() const;
std::string & getName();
const std::string & getDocString() const;
......@@ -64,6 +65,8 @@ class PFunction{
std::string & getOutputType();
const std::string & getTemplateDef() const;
std::string & getTemplateDef();
const std::string & getOtherCode() const;
std::string & getOtherCode();
protected:
void copyPFunction(const PFunction & other);
private:
......@@ -77,6 +80,8 @@ class PFunction{
std::string p_outputType;
///Template definition of the function
std::string p_templateDef;
///Other code which is not a function prototype
std::string p_otherCode;
};
///@brief Configuration file which will produce a source and header in C++
......
......@@ -26,6 +26,8 @@ PFunction{
std::string outputType;
///Template definition of the function
std::string templateDef;
///Other code which is not a function prototype
std::string otherCode;
}
///@brief Configuration file which will produce a source and header in C++
......
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