formatting updated

This commit is contained in:
Marko Klopcic 2013-02-23 16:46:14 +01:00
commit 00ff8886c6

View file

@ -29,15 +29,18 @@ std::set<std::string> DoxygenParser::doxygenSectionIndicators;
const int TOKENSPERLINE = 8; //change this to change the printing behaviour of the token list const int TOKENSPERLINE = 8; //change this to change the printing behaviour of the token list
const std::string END_HTML_TAG_MARK("/"); const std::string END_HTML_TAG_MARK("/");
DoxygenParser::DoxygenParser(bool noisy) : noisy(noisy) DoxygenParser::DoxygenParser(bool noisy) :
noisy(noisy)
{ {
fillTables(); fillTables();
} }
DoxygenParser::~DoxygenParser() { DoxygenParser::~DoxygenParser()
{
} }
void DoxygenParser::fillTables() { void DoxygenParser::fillTables()
{
// run it only once // run it only once
if (doxygenCommands.size()) if (doxygenCommands.size())
return; return;
@ -87,8 +90,8 @@ void DoxygenParser::fillTables() {
doxygenSectionIndicators.insert(sectionIndicators[i]); doxygenSectionIndicators.insert(sectionIndicators[i]);
} }
std::string DoxygenParser::stringToLower(const std::string &stringToConvert)
std::string DoxygenParser::stringToLower(const std::string &stringToConvert) { {
string result(stringToConvert.size(), ' '); string result(stringToConvert.size(), ' ');
@ -99,28 +102,28 @@ std::string DoxygenParser::stringToLower(const std::string &stringToConvert) {
return result; return result;
} }
bool DoxygenParser::findCommand(const std::string &smallString)
bool DoxygenParser::findCommand(const std::string &smallString) { {
// I'm not sure if we can really do so, because there are different commands // I'm not sure if we can really do so, because there are different commands
// in doxygenCommands and original commandArray // in doxygenCommands and original commandArray
std::map<std::string, DoxyCommandEnum>::iterator it = std::map<std::string, DoxyCommandEnum>::iterator it = doxygenCommands.find(
doxygenCommands.find(stringToLower(smallString)); stringToLower(smallString));
return it != doxygenCommands.end(); // returns true if command was found return it != doxygenCommands.end(); // returns true if command was found
} }
bool DoxygenParser::isSectionIndicator(const std::string &smallString)
{
bool DoxygenParser::isSectionIndicator(const std::string &smallString) { std::set<std::string>::iterator it = doxygenSectionIndicators.find(
stringToLower(smallString));
std::set<std::string>::iterator it =
doxygenSectionIndicators.find(stringToLower(smallString));
return it != doxygenSectionIndicators.end(); return it != doxygenSectionIndicators.end();
} }
void DoxygenParser::printTree(const DoxygenEntityList &rootList)
void DoxygenParser::printTree(const DoxygenEntityList &rootList) { {
DoxygenEntityList::const_iterator p = rootList.begin(); DoxygenEntityList::const_iterator p = rootList.begin();
while (p != rootList.end()) { while (p != rootList.end()) {
(*p).printEntity(0); (*p).printEntity(0);
@ -128,8 +131,8 @@ void DoxygenParser::printTree(const DoxygenEntityList &rootList) {
} }
} }
int DoxygenParser::commandBelongs(const std::string &theCommand)
int DoxygenParser::commandBelongs(const std::string &theCommand) { {
std::string smallString = stringToLower(theCommand); std::string smallString = stringToLower(theCommand);
//cout << " Looking for command " << theCommand << endl; //cout << " Looking for command " << theCommand << endl;
@ -141,7 +144,6 @@ int DoxygenParser::commandBelongs(const std::string &theCommand) {
return 0; return 0;
} }
std::string DoxygenParser::trim(const std::string &text) std::string DoxygenParser::trim(const std::string &text)
{ {
size_t start = text.find_first_not_of(" \t"); size_t start = text.find_first_not_of(" \t");
@ -153,7 +155,6 @@ std::string DoxygenParser::trim(const std::string &text)
return text.substr(start, end - start + 1); return text.substr(start, end - start + 1);
} }
bool DoxygenParser::isEndOfLine() bool DoxygenParser::isEndOfLine()
{ {
if (m_tokenListIt == m_tokenList.end()) { if (m_tokenListIt == m_tokenList.end()) {
@ -163,22 +164,22 @@ bool DoxygenParser::isEndOfLine()
return nextToken.m_tokenType == END_LINE; return nextToken.m_tokenType == END_LINE;
} }
void DoxygenParser::skipWhitespaceTokens() void DoxygenParser::skipWhitespaceTokens()
{ {
if (m_tokenListIt == m_tokenList.end()) { if (m_tokenListIt == m_tokenList.end()) {
return; return;
} }
while (m_tokenListIt != m_tokenList.end() && while (m_tokenListIt != m_tokenList.end()
(m_tokenListIt->m_tokenType == END_LINE || trim(m_tokenListIt->m_tokenString).empty())) { && (m_tokenListIt->m_tokenType == END_LINE
|| trim(m_tokenListIt->m_tokenString).empty())) {
m_tokenListIt++; m_tokenListIt++;
} }
} }
std::string DoxygenParser::getNextToken()
std::string DoxygenParser::getNextToken() { {
if (m_tokenListIt == m_tokenList.end()) { if (m_tokenListIt == m_tokenList.end()) {
return ""; return "";
@ -191,15 +192,15 @@ std::string DoxygenParser::getNextToken() {
return ""; return "";
} }
std::string DoxygenParser::getNextWord()
{
/* if (m_tokenListIt == m_tokenList.end()) {
std::string DoxygenParser::getNextWord() {
/* if (m_tokenListIt == m_tokenList.end()) {
return ""; return "";
} }
*/ */
while (m_tokenListIt != m_tokenList.end() && (m_tokenListIt->m_tokenType == PLAINSTRING)) { while (m_tokenListIt != m_tokenList.end()
&& (m_tokenListIt->m_tokenType == PLAINSTRING)) {
// handle quoted strings as words // handle quoted strings as words
string token = m_tokenListIt->m_tokenString; string token = m_tokenListIt->m_tokenString;
if (token == "\"") { if (token == "\"") {
@ -228,8 +229,8 @@ std::string DoxygenParser::getNextWord() {
return ""; return "";
} }
DoxygenParser::TokenListCIt DoxygenParser::getOneLine(const TokenList &tokList)
DoxygenParser::TokenListCIt DoxygenParser::getOneLine(const TokenList &tokList) { {
TokenListCIt endOfLineIt = m_tokenListIt; TokenListCIt endOfLineIt = m_tokenListIt;
@ -243,8 +244,8 @@ DoxygenParser::TokenListCIt DoxygenParser::getOneLine(const TokenList &tokList)
return tokList.end(); return tokList.end();
} }
std::string DoxygenParser::getStringTilCommand(const TokenList & tokList)
std::string DoxygenParser::getStringTilCommand(const TokenList & tokList) { {
if (m_tokenListIt == tokList.end()) { if (m_tokenListIt == tokList.end()) {
return ""; return "";
@ -261,8 +262,9 @@ std::string DoxygenParser::getStringTilCommand(const TokenList & tokList) {
return description; return description;
} }
std::string DoxygenParser::getStringTilEndCommand(
std::string DoxygenParser::getStringTilEndCommand(const std::string & theCommand, const TokenList & tokList) { const std::string & theCommand, const TokenList & tokList)
{
if (m_tokenListIt == tokList.end()) { if (m_tokenListIt == tokList.end()) {
return ""; return "";
@ -283,20 +285,23 @@ std::string DoxygenParser::getStringTilEndCommand(const std::string & theCommand
m_tokenListIt++; m_tokenListIt++;
} }
printListError(WARN_DOXYGEN_COMMAND_EXPECTED, theCommand + " command expected"); printListError(WARN_DOXYGEN_COMMAND_EXPECTED,
theCommand + " command expected");
return description; return description;
} }
DoxygenParser::TokenListCIt DoxygenParser::getEndOfParagraph(
DoxygenParser::TokenListCIt DoxygenParser::getEndOfParagraph(const TokenList & tokList) { const TokenList & tokList)
{
TokenListCIt endOfParagraph = m_tokenListIt; TokenListCIt endOfParagraph = m_tokenListIt;
while (endOfParagraph != tokList.end()) { while (endOfParagraph != tokList.end()) {
if (endOfParagraph->m_tokenType == END_LINE) { if (endOfParagraph->m_tokenType == END_LINE) {
endOfParagraph++; endOfParagraph++;
if (endOfParagraph != tokList.end() && endOfParagraph->m_tokenType == END_LINE) { if (endOfParagraph != tokList.end()
&& endOfParagraph->m_tokenType == END_LINE) {
endOfParagraph++; endOfParagraph++;
//cout << "ENCOUNTERED END OF PARA" << endl; //cout << "ENCOUNTERED END OF PARA" << endl;
return endOfParagraph; return endOfParagraph;
@ -320,9 +325,9 @@ DoxygenParser::TokenListCIt DoxygenParser::getEndOfParagraph(const TokenList & t
return tokList.end(); return tokList.end();
} }
DoxygenParser::TokenListCIt DoxygenParser::getEndOfSection(
DoxygenParser::TokenListCIt DoxygenParser::getEndOfSection(const std::string & theCommand, const std::string & theCommand, const TokenList & tokList)
const TokenList & tokList) { {
TokenListCIt endOfParagraph = m_tokenListIt; TokenListCIt endOfParagraph = m_tokenListIt;
@ -345,9 +350,9 @@ DoxygenParser::TokenListCIt DoxygenParser::getEndOfSection(const std::string & t
return tokList.end(); return tokList.end();
} }
DoxygenParser::TokenListCIt DoxygenParser::getEndCommand(
DoxygenParser::TokenListCIt DoxygenParser::getEndCommand(const std::string & theCommand, const std::string & theCommand, const TokenList & tokList)
const TokenList & tokList) { {
TokenListCIt endOfCommand = m_tokenListIt; TokenListCIt endOfCommand = m_tokenListIt;
@ -363,18 +368,17 @@ DoxygenParser::TokenListCIt DoxygenParser::getEndCommand(const std::string & the
return tokList.end(); return tokList.end();
} }
void DoxygenParser::skipEndOfLine() void DoxygenParser::skipEndOfLine()
{ {
if (m_tokenListIt != m_tokenList.end() && if (m_tokenListIt != m_tokenList.end()
m_tokenListIt->m_tokenType == END_LINE) { && m_tokenListIt->m_tokenType == END_LINE) {
m_tokenListIt++; m_tokenListIt++;
} }
} }
int DoxygenParser::addSimpleCommand(const std::string &theCommand, int DoxygenParser::addSimpleCommand(const std::string &theCommand,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -382,10 +386,10 @@ int DoxygenParser::addSimpleCommand(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandWord(const std::string &theCommand, int DoxygenParser::addCommandWord(const std::string &theCommand,
const TokenList &, const TokenList &,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -401,16 +405,16 @@ int DoxygenParser::addCommandWord(const std::string &theCommand,
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1; return 1;
} else { } else {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + printListError(WARN_DOXYGEN_COMMAND_ERROR,
theCommand + " command. Not added"); "No word followed " + theCommand + " command. Not added");
} }
return 0; return 0;
} }
int DoxygenParser::addCommandLine(const std::string &theCommand, int DoxygenParser::addCommandLine(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
TokenListCIt endOfLine = getOneLine(tokList); TokenListCIt endOfLine = getOneLine(tokList);
@ -420,10 +424,10 @@ int DoxygenParser::addCommandLine(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandParagraph(const std::string &theCommand, int DoxygenParser::addCommandParagraph(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -434,10 +438,10 @@ int DoxygenParser::addCommandParagraph(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandEndCommand(const std::string &theCommand, int DoxygenParser::addCommandEndCommand(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
TokenListCIt endCommand = getEndCommand("end" + theCommand, tokList); TokenListCIt endCommand = getEndCommand("end" + theCommand, tokList);
@ -452,17 +456,18 @@ int DoxygenParser::addCommandEndCommand(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandWordParagraph(const std::string &theCommand, int DoxygenParser::addCommandWordParagraph(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
TokenListCIt endOfParagraph = getEndOfParagraph(tokList); TokenListCIt endOfParagraph = getEndOfParagraph(tokList);
@ -473,15 +478,16 @@ int DoxygenParser::addCommandWordParagraph(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandWordLine(const std::string &theCommand, int DoxygenParser::addCommandWordLine(const std::string &theCommand,
const TokenList & tokList, const TokenList & tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
@ -494,16 +500,17 @@ int DoxygenParser::addCommandWordLine(const std::string &theCommand,
//else cout << "No line followed " << theCommand << " command. Not added" << endl; //else cout << "No line followed " << theCommand << " command. Not added" << endl;
} }
int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand, int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand,
const TokenList &, const TokenList &,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string headerfile = getNextWord(); std::string headerfile = getNextWord();
@ -518,10 +525,10 @@ int DoxygenParser::addCommandWordOWordOWord(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandOWord(const std::string &theCommand, int DoxygenParser::addCommandOWord(const std::string &theCommand,
const TokenList &, const TokenList &,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
@ -532,18 +539,18 @@ int DoxygenParser::addCommandOWord(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandErrorThrow(const std::string &theCommand, int DoxygenParser::addCommandErrorThrow(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &) { DoxygenEntityList &)
{
printListError(WARN_DOXYGEN_COMMAND_ERROR, "Encountered: " + theCommand + printListError(WARN_DOXYGEN_COMMAND_ERROR,
"\nThis command should not have been encountered. Behaviour past this may be unpredictable"); "Encountered: " + theCommand
+ "\nThis command should not have been encountered. Behaviour past this may be unpredictable");
m_tokenListIt = getOneLine(tokList); m_tokenListIt = getOneLine(tokList);
return 0; return 0;
} }
int DoxygenParser::addCommandHtml(const std::string &theCommand, int DoxygenParser::addCommandHtml(const std::string &theCommand,
const TokenList &, const TokenList &,
DoxygenEntityList &doxyList) DoxygenEntityList &doxyList)
@ -556,7 +563,6 @@ int DoxygenParser::addCommandHtml(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandHtmlEntity(const std::string &theCommand, int DoxygenParser::addCommandHtmlEntity(const std::string &theCommand,
const TokenList &, const TokenList &,
DoxygenEntityList &doxyList) DoxygenEntityList &doxyList)
@ -569,10 +575,10 @@ int DoxygenParser::addCommandHtmlEntity(const std::string &theCommand,
return 1; return 1;
} }
int DoxygenParser::addCommandUnique(const std::string &theCommand, int DoxygenParser::addCommandUnique(const std::string &theCommand,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
static std::map<std::string, std::string> endCommands; static std::map<std::string, std::string> endCommands;
DoxygenEntityList aNewList; DoxygenEntityList aNewList;
@ -588,17 +594,20 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string key = getNextWord(); std::string key = getNextWord();
if (key.empty()) { if (key.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No key followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No key followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string heading = getNextWord(); std::string heading = getNextWord();
if (key.empty()) { if (key.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No heading followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No heading followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string title = getNextWord(); std::string title = getNextWord();
if (title.empty()) { if (title.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No title followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No title followed " + theCommand + " command. Not added");
return 0; return 0;
} }
TokenListCIt endOfParagraph = getEndOfParagraph(tokList); TokenListCIt endOfParagraph = getEndOfParagraph(tokList);
@ -661,7 +670,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
DoxygenEntityList aNewList; DoxygenEntityList aNewList;
@ -678,7 +688,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No key followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No key followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string text = getNextWord(); std::string text = getNextWord();
@ -693,7 +704,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No name followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No name followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string text = getNextWord(); std::string text = getNextWord();
@ -711,9 +723,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
// \f{env}{ ... \f} // \f{env}{ ... \f}
// \f$ ... \f$ // \f$ ... \f$
else if (theCommand == "code" || theCommand == "verbatim" else if (theCommand == "code" || theCommand == "verbatim"
|| theCommand == "dot" || theCommand == "msc" || theCommand == "dot" || theCommand == "msc" || theCommand == "f["
|| theCommand == "f[" || theCommand == "f{" || theCommand == "f{" || theCommand == "f$") {
|| theCommand == "f$") {
if (!endCommands.size()) { if (!endCommands.size()) {
// fill in static table of end commands // fill in static table of end commands
endCommands["f["] = "f]"; endCommands["f["] = "f]";
@ -724,7 +735,7 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string endCommand; std::string endCommand;
std::map <std::string, std::string>::iterator it; std::map<std::string, std::string>::iterator it;
it = endCommands.find(theCommand); it = endCommands.find(theCommand);
if (it != endCommands.end()) if (it != endCommands.end())
endCommand = it->second; endCommand = it->second;
@ -742,7 +753,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string file = getNextWord(); std::string file = getNextWord();
if (file.empty()) { if (file.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No file followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No file followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string caption = getNextWord(); std::string caption = getNextWord();
@ -757,12 +769,14 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string format = getNextWord(); std::string format = getNextWord();
if (format.empty()) { if (format.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No format followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No format followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string file = getNextWord(); std::string file = getNextWord();
if (file.empty()) { if (file.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No name followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No name followed " + theCommand + " command. Not added");
return 0; return 0;
} }
std::string caption = getNextWord(); std::string caption = getNextWord();
@ -783,7 +797,9 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(); std::string name = getNextWord();
if (name.empty()) { if (name.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "There should be at least one word following the '" + theCommand + "' command. Command ignored."); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"There should be at least one word following the '" + theCommand
+ "' command. Command ignored.");
return 0; return 0;
} }
DoxygenEntityList aNewList; DoxygenEntityList aNewList;
@ -796,18 +812,20 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
skipEndOfLine(); skipEndOfLine();
} }
// \if <cond> [\else ...] [\elseif <cond> ...] \endif // \if <cond> [\else ...] [\elseif <cond> ...] \endif
else if (theCommand == "if" || theCommand == "ifnot" || else if (theCommand == "if" || theCommand == "ifnot" || theCommand == "else"
theCommand == "else" || theCommand == "elseif") { || theCommand == "elseif") {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string cond; std::string cond;
bool skipEndif = false; // if true then we skip endif after parsing block of code bool skipEndif = false; // if true then we skip endif after parsing block of code
bool needsCond = (theCommand == "if" || theCommand == "ifnot" || theCommand == "elseif"); bool needsCond = (theCommand == "if" || theCommand == "ifnot"
|| theCommand == "elseif");
if (needsCond) { if (needsCond) {
cond = getNextWord(); cond = getNextWord();
if (cond.empty()) { if (cond.empty()) {
printListError(WARN_DOXYGEN_COMMAND_ERROR, "No word followed " + theCommand + " command. Not added"); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"No word followed " + theCommand + " command. Not added");
return 0; return 0;
} }
} }
@ -822,7 +840,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
nestedCounter++; nestedCounter++;
else if (it->m_tokenString == "endif") else if (it->m_tokenString == "endif")
nestedCounter--; nestedCounter--;
if (nestedCounter == 1 && (it->m_tokenString == "else" || it->m_tokenString == "elseif")) { // else found if (nestedCounter == 1
&& (it->m_tokenString == "else" || it->m_tokenString == "elseif")) { // else found
endCommand = it; endCommand = it;
break; break;
} }
@ -835,7 +854,8 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
} }
if (endCommand == tokList.end()) { if (endCommand == tokList.end()) {
printListError(WARN_DOXYGEN_COMMAND_EXPECTED, "No corresponding endif found"); printListError(WARN_DOXYGEN_COMMAND_EXPECTED,
"No corresponding endif found");
return 0; return 0;
} }
@ -850,10 +870,10 @@ int DoxygenParser::addCommandUnique(const std::string &theCommand,
return 0; return 0;
} }
int DoxygenParser::addCommand(const std::string &commandString, int DoxygenParser::addCommand(const std::string &commandString,
const TokenList &tokList, const TokenList &tokList,
DoxygenEntityList &doxyList) { DoxygenEntityList &doxyList)
{
string theCommand = stringToLower(commandString); string theCommand = stringToLower(commandString);
@ -896,15 +916,15 @@ int DoxygenParser::addCommand(const std::string &commandString,
return 0; return 0;
} }
/** /**
* This method converts TokenList to DoxygenEntryList. * This method converts TokenList to DoxygenEntryList.
*/ */
DoxygenEntityList DoxygenParser::parse(TokenListCIt endParsingIndex, DoxygenEntityList DoxygenParser::parse(TokenListCIt endParsingIndex,
const TokenList &tokList, const TokenList &tokList, bool root)
bool root) { {
// if we are root, than any strings should be added as 'partofdescription', else as 'plainstd::string' // if we are root, than any strings should be added as 'partofdescription', else as 'plainstd::string'
std::string currPlainstringCommandType = root ? "partofdescription" : "plainstd::string"; std::string currPlainstringCommandType =
root ? "partofdescription" : "plainstd::string";
DoxygenEntityList aNewList; DoxygenEntityList aNewList;
while (m_tokenListIt != endParsingIndex) { while (m_tokenListIt != endParsingIndex) {
@ -926,17 +946,18 @@ DoxygenEntityList DoxygenParser::parse(TokenListCIt endParsingIndex,
if (endParsingIndex != tokList.end() && m_tokenListIt == tokList.end()) { if (endParsingIndex != tokList.end() && m_tokenListIt == tokList.end()) {
// this could happen if we can't reach the original endParsingIndex // this could happen if we can't reach the original endParsingIndex
printListError(WARN_DOXYGEN_UNEXPECTED_END_OF_COMMENT, "Unexpected end of comment encountered"); printListError(WARN_DOXYGEN_UNEXPECTED_END_OF_COMMENT,
"Unexpected end of comment encountered");
break; break;
} }
} }
return aNewList; return aNewList;
} }
DoxygenEntityList DoxygenParser::createTree(const std::string &doxygenBlob, DoxygenEntityList DoxygenParser::createTree(const std::string &doxygenBlob,
const std::string &fileName, const std::string &fileName,
int lineNumber) { int lineNumber)
{
tokenizeDoxygenComment(doxygenBlob, fileName, lineNumber); tokenizeDoxygenComment(doxygenBlob, fileName, lineNumber);
if (noisy) { if (noisy) {
@ -953,12 +974,12 @@ DoxygenEntityList DoxygenParser::createTree(const std::string &doxygenBlob,
return rootList; return rootList;
} }
/* /*
* Splits 'text' on 'separator' chars. Separator chars are not part of the * Splits 'text' on 'separator' chars. Separator chars are not part of the
* strings. * strings.
*/ */
DoxygenParser::StringVector DoxygenParser::split(const std::string &text, char separator) DoxygenParser::StringVector DoxygenParser::split(const std::string &text,
char separator)
{ {
StringVector lines; StringVector lines;
size_t prevPos = 0, pos = 0; size_t prevPos = 0, pos = 0;
@ -972,7 +993,6 @@ DoxygenParser::StringVector DoxygenParser::split(const std::string &text, char s
return lines; return lines;
} }
/* /*
* Returns true, if 'c' is one of doxygen comment block start * Returns true, if 'c' is one of doxygen comment block start
* characters: *, /, or ! * characters: *, /, or !
@ -982,14 +1002,14 @@ bool DoxygenParser::isStartOfDoxyCommentChar(char c)
return (strchr("*/!", c) != NULL); return (strchr("*/!", c) != NULL);
} }
/* /*
* Adds token with Doxygen command to token list, but only if command is one of * Adds token with Doxygen command to token list, but only if command is one of
* Doxygen commands. In that case true is returned. If the command is not * Doxygen commands. In that case true is returned. If the command is not
* recognized as a doxygen command, it is ignored and false is returned. * recognized as a doxygen command, it is ignored and false is returned.
*/ */
bool DoxygenParser::addDoxyCommand(DoxygenParser::TokenList &tokList, bool DoxygenParser::addDoxyCommand(DoxygenParser::TokenList &tokList,
const std::string &cmd) { const std::string &cmd)
{
if (findCommand(cmd)) { if (findCommand(cmd)) {
tokList.push_back(Token(COMMAND, cmd)); tokList.push_back(Token(COMMAND, cmd));
return true; return true;
@ -1004,7 +1024,6 @@ bool DoxygenParser::addDoxyCommand(DoxygenParser::TokenList &tokList,
return false; return false;
} }
/* /*
* This method copies comment text to output as it is - no processing is * This method copies comment text to output as it is - no processing is
* done, Doxygen commands are ignored. It is used for commands \verbatim, * done, Doxygen commands are ignored. It is used for commands \verbatim,
@ -1013,33 +1032,41 @@ bool DoxygenParser::addDoxyCommand(DoxygenParser::TokenList &tokList,
size_t DoxygenParser::processVerbatimText(size_t pos, const std::string &line) size_t DoxygenParser::processVerbatimText(size_t pos, const std::string &line)
{ {
if (line[pos] == '\\' || line[pos] == '@') { // check for end commands if (line[pos] == '\\' || line[pos] == '@') { // check for end commands
pos++; pos++;
// characters '$[]{}' are used in commands \f$, \f[, and \f{ // characters '$[]{}' are used in commands \f$, \f[, and \f{
size_t endOfWordPos = line.find_first_not_of("abcdefghijklmnopqrstuvwxyz$[]{}", pos); size_t endOfWordPos = line.find_first_not_of(
"abcdefghijklmnopqrstuvwxyz$[]{}", pos);
string cmd = line.substr(pos, endOfWordPos - pos); string cmd = line.substr(pos, endOfWordPos - pos);
if (cmd == CMD_END_HTML_ONLY || cmd == CMD_END_VERBATIM || if (cmd == CMD_END_HTML_ONLY || cmd == CMD_END_VERBATIM
cmd == CMD_END_LATEX_1 || cmd == CMD_END_LATEX_2 || cmd == CMD_END_LATEX_3) { || cmd == CMD_END_LATEX_1 || cmd == CMD_END_LATEX_2
|| cmd == CMD_END_LATEX_3) {
m_isVerbatimText = false; m_isVerbatimText = false;
addDoxyCommand(m_tokenList, cmd); addDoxyCommand(m_tokenList, cmd);
} else { } else {
m_tokenList.push_back(Token(PLAINSTRING, m_tokenList.push_back(Token(PLAINSTRING,
// include '\' or '@' // include '\' or '@'
line.substr(pos - 1, endOfWordPos - pos + 1))); line.substr(pos - 1, endOfWordPos - pos + 1)));
} }
pos = endOfWordPos; pos = endOfWordPos;
} else { } else {
// whitespaces are stored as plain strings // whitespaces are stored as plain strings
size_t startOfPossibleEndCmd = line.find_first_of("\\@", pos); size_t startOfPossibleEndCmd = line.find_first_of("\\@", pos);
m_tokenList.push_back(Token(PLAINSTRING, m_tokenList.push_back(
line.substr(pos, startOfPossibleEndCmd - pos))); Token(PLAINSTRING, line.substr(pos, startOfPossibleEndCmd - pos)));
pos = startOfPossibleEndCmd; pos = startOfPossibleEndCmd;
} }
return pos; return pos;
} }
/* /*
* Processes doxy commands for escaped characters: \$ \@ \\ \& \~ \< \> \# \% \" \. \:: * Processes doxy commands for escaped characters: \$ \@ \\ \& \~ \< \> \# \% \" \. \::
* Handling this separately supports documentation text like \@someText. * Handling this separately supports documentation text like \@someText.
@ -1059,11 +1086,14 @@ bool DoxygenParser::processEscapedChars(size_t &pos, const std::string &line)
// these chars can be escaped for doxygen // these chars can be escaped for doxygen
string escapedChars = "$@\\&~<>#%\"."; string escapedChars = "$@\\&~<>#%\".";
if (escapedChars.find(line[pos + 1]) != string::npos) { if (escapedChars.find(line[pos + 1]) != string::npos) {
addDoxyCommand(m_tokenList, line.substr(pos + 1, 1)); addDoxyCommand(m_tokenList, line.substr(pos + 1, 1));
pos += 2; pos += 2;
return true; return true;
} else if ((pos + 2) < line.size() &&
line[pos + 1] == ':' && line[pos + 2] == ':') { } else if ((pos + 2) < line.size() && line[pos + 1] == ':'
&& line[pos + 2] == ':') {
// add command \:: - handling this separately supports documentation // add command \:: - handling this separately supports documentation
// text like \::someText // text like \::someText
addDoxyCommand(m_tokenList, line.substr(pos + 1, 2)); addDoxyCommand(m_tokenList, line.substr(pos + 1, 2));
@ -1074,7 +1104,6 @@ bool DoxygenParser::processEscapedChars(size_t &pos, const std::string &line)
return false; return false;
} }
/* /*
* Processes word doxygen commands, like \arg, \c, \b, \return, ... * Processes word doxygen commands, like \arg, \c, \b, \return, ...
*/ */
@ -1082,12 +1111,17 @@ void DoxygenParser::processWordCommands(size_t &pos, const std::string &line)
{ {
pos++; pos++;
// characters '$[]{}' are used in commands \f$, \f[, ... // characters '$[]{}' are used in commands \f$, \f[, ...
size_t endOfWordPos = line.find_first_not_of("abcdefghijklmnopqrstuvwxyz$[]{}", pos); size_t endOfWordPos = line.find_first_not_of("abcdefghijklmnopqrstuvwxyz$[]{}", pos);
string cmd = line.substr(pos , endOfWordPos - pos);
string cmd = line.substr(pos, endOfWordPos - pos);
addDoxyCommand(m_tokenList, cmd); addDoxyCommand(m_tokenList, cmd);
if (cmd == CMD_HTML_ONLY || cmd == CMD_VERBATIM ||
cmd == CMD_LATEX_1 || cmd == CMD_LATEX_2 || cmd == CMD_LATEX_3) { if (cmd == CMD_HTML_ONLY || cmd == CMD_VERBATIM || cmd == CMD_LATEX_1
|| cmd == CMD_LATEX_2 || cmd == CMD_LATEX_3) {
m_isVerbatimText = true; m_isVerbatimText = true;
} else { } else {
// skip any possible spaces after command, because some commands have parameters, // skip any possible spaces after command, because some commands have parameters,
// and spaces between command and parameter must be ignored. // and spaces between command and parameter must be ignored.
@ -1098,7 +1132,6 @@ void DoxygenParser::processWordCommands(size_t &pos, const std::string &line)
pos = endOfWordPos; pos = endOfWordPos;
} }
void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line) void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line)
{ {
bool isEndHtmlTag = false; bool isEndHtmlTag = false;
@ -1132,7 +1165,8 @@ void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line)
} }
// add args of HTML command, like link URL, image URL, ... // add args of HTML command, like link URL, image URL, ...
m_tokenList.push_back(Token(PLAINSTRING, line.substr(pos, endHtmlPos - pos))); m_tokenList.push_back(
Token(PLAINSTRING, line.substr(pos, endHtmlPos - pos)));
pos = endHtmlPos; pos = endHtmlPos;
} else { } else {
if (isEndHtmlTag) { if (isEndHtmlTag) {
@ -1154,15 +1188,14 @@ void DoxygenParser::processHtmlTags(size_t &pos, const std::string &line)
} }
} }
void DoxygenParser::processHtmlEntities(size_t &pos, const std::string &line) void DoxygenParser::processHtmlEntities(size_t &pos, const std::string &line)
{ {
size_t endOfWordPos = line.find_first_not_of("abcdefghijklmnopqrstuvwxyz", pos + 1); size_t endOfWordPos = line.find_first_not_of("abcdefghijklmnopqrstuvwxyz",
pos + 1);
if (endOfWordPos != string::npos) { if (endOfWordPos != string::npos) {
if (line[endOfWordPos] == ';' && (endOfWordPos - pos) > 1) if (line[endOfWordPos] == ';' && (endOfWordPos - pos) > 1) {
{
// if entity is not recognized by Doxygen (not in the list of // if entity is not recognized by Doxygen (not in the list of
// commands) nothing is added (here and in Doxygen). // commands) nothing is added (here and in Doxygen).
addDoxyCommand(m_tokenList, line.substr(pos, endOfWordPos - pos)); addDoxyCommand(m_tokenList, line.substr(pos, endOfWordPos - pos));
@ -1172,14 +1205,13 @@ void DoxygenParser::processHtmlEntities(size_t &pos, const std::string &line)
// it is not an entity - add entity for ampersand and the rest of string // it is not an entity - add entity for ampersand and the rest of string
addDoxyCommand(m_tokenList, "&amp"); addDoxyCommand(m_tokenList, "&amp");
m_tokenList.push_back(Token(PLAINSTRING, m_tokenList.push_back(
line.substr(pos + 1, endOfWordPos - pos - 1))); Token(PLAINSTRING, line.substr(pos + 1, endOfWordPos - pos - 1)));
} }
} }
pos = endOfWordPos; pos = endOfWordPos;
} }
/* /*
* This method processes normal comment, which has to be tokenized. * This method processes normal comment, which has to be tokenized.
*/ */
@ -1199,10 +1231,11 @@ size_t DoxygenParser::processNormalComment(size_t pos, const std::string &line)
case '\t': { case '\t': {
// whitespaces are stored as plain strings // whitespaces are stored as plain strings
size_t startOfNextWordPos = line.find_first_not_of(" \t", pos + 1); size_t startOfNextWordPos = line.find_first_not_of(" \t", pos + 1);
m_tokenList.push_back(Token(PLAINSTRING, m_tokenList.push_back(
line.substr(pos, startOfNextWordPos - pos))); Token(PLAINSTRING, line.substr(pos, startOfNextWordPos - pos)));
pos = startOfNextWordPos; pos = startOfNextWordPos;
} break; }
break;
case '<': case '<':
processHtmlTags(pos, line); processHtmlTags(pos, line);
@ -1221,13 +1254,13 @@ size_t DoxygenParser::processNormalComment(size_t pos, const std::string &line)
break; break;
default: default:
m_tokenListIt = m_tokenList.end(); m_tokenListIt = m_tokenList.end();
printListError(WARN_DOXYGEN_COMMAND_ERROR, "Unknown special character: " + line[pos]); printListError(WARN_DOXYGEN_COMMAND_ERROR,
"Unknown special character: " + line[pos]);
} }
return pos; return pos;
} }
/* /*
* This is the main method, which tokenizes Doxygen comment to words and * This is the main method, which tokenizes Doxygen comment to words and
* doxygen commands. * doxygen commands.
@ -1248,7 +1281,9 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
// comment, which is wrong, because these spaces are space preceding // comment, which is wrong, because these spaces are space preceding
// end of comment : ' */' // end of comment : ' */'
if (!doxygenComment.empty() && doxygenComment[doxygenComment.size() - 1] == ' ') { if (!doxygenComment.empty() && doxygenComment[doxygenComment.size() - 1] == ' ') {
string lastLine = lines[lines.size() - 1]; string lastLine = lines[lines.size() - 1];
if (trim(lastLine).empty()) { if (trim(lastLine).empty()) {
lines.pop_back(); // remove trailing empy line lines.pop_back(); // remove trailing empy line
} }
@ -1296,7 +1331,8 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
} }
if (isStartOfCommentLineCharFound && firstWordPos > pos) { if (isStartOfCommentLineCharFound && firstWordPos > pos) {
m_tokenList.push_back(Token(PLAINSTRING, line.substr(pos, firstWordPos - pos))); m_tokenList.push_back(
Token(PLAINSTRING, line.substr(pos, firstWordPos - pos)));
} }
pos = firstWordPos; pos = firstWordPos;
@ -1317,7 +1353,8 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
string punctuations(".,:"); string punctuations(".,:");
size_t textSize = text.size(); size_t textSize = text.size();
if (!text.empty() && punctuations.find(text[text.size() - 1]) != string::npos && if (!text.empty()
&& punctuations.find(text[text.size() - 1]) != string::npos &&
// but do not break ellipsis (...) // but do not break ellipsis (...)
!(textSize > 1 && text[textSize - 2] == '.')) { !(textSize > 1 && text[textSize - 2] == '.')) {
m_tokenList.push_back(Token(PLAINSTRING, text.substr(0, text.size() - 1))); m_tokenList.push_back(Token(PLAINSTRING, text.substr(0, text.size() - 1)));
@ -1328,10 +1365,8 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
} }
pos = doxyCmdOrHtmlTagPos; pos = doxyCmdOrHtmlTagPos;
if (pos != string::npos) if (pos != string::npos) {
{ if (m_isVerbatimText) {
if (m_isVerbatimText)
{
pos = processVerbatimText(pos, line); pos = processVerbatimText(pos, line);
} else if (m_isInQuotedString) { } else if (m_isInQuotedString) {
@ -1339,8 +1374,7 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
if (line[pos] == '"') { if (line[pos] == '"') {
m_isInQuotedString = false; m_isInQuotedString = false;
} }
m_tokenList.push_back(Token(PLAINSTRING, m_tokenList.push_back(Token(PLAINSTRING, line.substr(pos, 1)));
line.substr(pos, 1)));
pos++; pos++;
} else { } else {
@ -1354,8 +1388,8 @@ void DoxygenParser::tokenizeDoxygenComment(const std::string &doxygenComment,
m_tokenListIt = m_tokenList.begin(); m_tokenListIt = m_tokenList.begin();
} }
void DoxygenParser::printList()
void DoxygenParser::printList() { {
int tokNo = 0; int tokNo = 0;
for (TokenListCIt it = m_tokenList.begin(); it != m_tokenList.end(); for (TokenListCIt it = m_tokenList.begin(); it != m_tokenList.end();
@ -1369,9 +1403,8 @@ void DoxygenParser::printList() {
} }
} }
void DoxygenParser::printListError(int warningType, const std::string &message)
void DoxygenParser::printListError(int warningType, {
const std::string &message) {
int curLine = m_fileLineNo; int curLine = m_fileLineNo;
for (TokenListCIt it = m_tokenList.begin(); it != m_tokenListIt; it++) { for (TokenListCIt it = m_tokenList.begin(); it != m_tokenListIt; it++) {
if (it->m_tokenType == END_LINE) { if (it->m_tokenType == END_LINE) {