Added support for parsing of nested conditional comments and extended the test

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13317 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-07-12 17:02:04 +00:00
commit 6a54fe93ad
3 changed files with 91 additions and 28 deletions

View file

@ -29,20 +29,30 @@
* *
* \e italicword * \e italicword
* *
* \if ANOTHERCONDITION
* First part of comment
* \else
* Second part of comment
* \endif
*
* \example someFile.txt * \example someFile.txt
* Some details on using the example * Some details on using the example
* *
* \exception SuperError * \exception SuperError
* *
* \ifnot CONDITION * \if ANOTHERCONDITION
* Write something if not * First part of comment
* \endifnot * \if SECONDCONDITION
* Nested condition text
* \elseif THIRDCONDITION
* The third condition text
* \else
* The last text block
* \endif
* \else
* Second part of comment
* \if CONDITION
* Second part extended
* \endif
* \endif
*
* \ifnot SOMECONDITION
* This is printed if not
* \endif
* *
* \image html testImage.bmp * \image html testImage.bmp
* *

View file

@ -64,7 +64,7 @@ const char *ignoreCommandParagraphs[] = {
const int ignoreCommandParagraphsSize = sizeof(ignoreCommandParagraphs) / sizeof(*ignoreCommandParagraphs); const int ignoreCommandParagraphsSize = sizeof(ignoreCommandParagraphs) / sizeof(*ignoreCommandParagraphs);
const char *commandEndCommands[] = { const char *commandEndCommands[] = {
"code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly", "latexonly", "manonly", "verbatim", "xmlonly", "if", "ifnot", "link"}; "code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly", "latexonly", "manonly", "verbatim", "xmlonly", "link"};
const int commandEndCommandsSize = sizeof(commandEndCommands) / sizeof(*commandEndCommands); const int commandEndCommandsSize = sizeof(commandEndCommands) / sizeof(*commandEndCommands);
const char *commandWordParagraphs[] = { const char *commandWordParagraphs[] = {
@ -87,11 +87,12 @@ const char *commandErrorThrowings[] = {
"annotatedclassstd::list", "classhierarchy", "define", "functionindex", "header", "annotatedclassstd::list", "classhierarchy", "define", "functionindex", "header",
"headerfilestd::list", "inherit", "l", "postheader", "private", "privatesection", "protected", "headerfilestd::list", "inherit", "l", "postheader", "private", "privatesection", "protected",
"protectedsection", "public", "publicsection", "endcode", "enddot", "endmsc", "endhtmlonly", "protectedsection", "public", "publicsection", "endcode", "enddot", "endmsc", "endhtmlonly",
"endlatexonly", "endmanonly", "endlink", "endverbatim", "endxmlonly", "f]", "f}", "endif"}; "endlatexonly", "endmanonly", "endlink", "endverbatim", "endxmlonly", "f]", "f}", "endif", "else"};
const int commandErrorThrowingsSize = sizeof(commandErrorThrowings) / sizeof(*commandErrorThrowings); const int commandErrorThrowingsSize = sizeof(commandErrorThrowings) / sizeof(*commandErrorThrowings);
const char *commandUniques[] = { const char *commandUniques[] = {
"xrefitem", "arg", "ingroup", "par", "headerfile", "overload", "weakgroup", "ref", "subpage", "dotfile", "image", "addtogroup", "li"}; "xrefitem", "arg", "ingroup", "par", "headerfile", "overload", "weakgroup", "ref", "subpage", "dotfile", "image", "addtogroup", "li",
"if", "ifnot", "elseif", "else"};
const int commandUniquesSize = sizeof(commandUniques) / sizeof(*commandUniques); const int commandUniquesSize = sizeof(commandUniques) / sizeof(*commandUniques);
#endif #endif

View file

@ -164,7 +164,7 @@ std::string DoxygenParser::getStringTilEndCommand(std::string theCommand, TokenL
if (tokList.peek().tokenType == END_LINE) if (tokList.peek().tokenType == END_LINE)
description += "\n"; description += "\n";
if (tokList.peek().tokenString.compare(theCommand) == 0) { if (tokList.peek().tokenString == theCommand) {
tokList.next(); tokList.next();
return description; return description;
} }
@ -207,7 +207,7 @@ std::list < Token >::iterator DoxygenParser::getEndOfSection(std::string theComm
std::list < Token >::iterator endOfParagraph = tokList.iteratorCopy(); std::list < Token >::iterator endOfParagraph = tokList.iteratorCopy();
while (endOfParagraph != tokList.end()) { while (endOfParagraph != tokList.end()) {
if ((*endOfParagraph).tokenType == COMMAND) { if ((*endOfParagraph).tokenType == COMMAND) {
if (theCommand.compare((*endOfParagraph).tokenString) == 0) if (theCommand == (*endOfParagraph).tokenString)
return endOfParagraph; return endOfParagraph;
else else
endOfParagraph++; endOfParagraph++;
@ -228,7 +228,7 @@ std::list < Token >::iterator DoxygenParser::getEndCommand(std::string theComman
std::list < Token >::iterator endOfCommand = tokList.iteratorCopy(); std::list < Token >::iterator endOfCommand = tokList.iteratorCopy();
while (endOfCommand != tokList.end()) { while (endOfCommand != tokList.end()) {
if ((*endOfCommand).tokenType == COMMAND) { if ((*endOfCommand).tokenType == COMMAND) {
if (theCommand.compare((*endOfCommand).tokenString) == 0) { if (theCommand == (*endOfCommand).tokenString) {
return endOfCommand; return endOfCommand;
} }
endOfCommand++; endOfCommand++;
@ -399,14 +399,14 @@ int DoxygenParser::addCommandErrorThrow(std::string theCommand, TokenList & tokL
int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList) { int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList) {
std::list < DoxygenEntity > aNewList; std::list < DoxygenEntity > aNewList;
if (theCommand.compare("arg") == 0 || theCommand.compare("li") == 0) { if (theCommand == "arg" || theCommand == "li") {
std::list < Token >::iterator endOfSection = getEndOfSection(theCommand, tokList); std::list < Token >::iterator endOfSection = getEndOfSection(theCommand, tokList);
std::list < DoxygenEntity > aNewList; std::list < DoxygenEntity > aNewList;
aNewList = parse(endOfSection, tokList); aNewList = parse(endOfSection, tokList);
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
} }
// \xrefitem <key> "(heading)" "(std::list title)" {text} // \xrefitem <key> "(heading)" "(std::list title)" {text}
else if (theCommand.compare("xrefitem") == 0) { else if (theCommand == "xrefitem") {
//TODO Implement xrefitem //TODO Implement xrefitem
if (noisy) if (noisy)
cout << "Not Adding " << theCommand << endl; cout << "Not Adding " << theCommand << endl;
@ -415,7 +415,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
return 1; return 1;
} }
// \ingroup (<groupname> [<groupname> <groupname>]) // \ingroup (<groupname> [<groupname> <groupname>])
else if (theCommand.compare("ingroup") == 0) { else if (theCommand == "ingroup") {
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
name = getNextWord(tokList); name = getNextWord(tokList);
@ -428,7 +428,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
return 1; return 1;
} }
// \par [(paragraph title)] { paragraph } // \par [(paragraph title)] { paragraph }
else if (theCommand.compare("par") == 0) { else if (theCommand == "par") {
std::list < Token >::iterator endOfLine = getOneLine(tokList); std::list < Token >::iterator endOfLine = getOneLine(tokList);
aNewList = parse(endOfLine, tokList); aNewList = parse(endOfLine, tokList);
std::list < DoxygenEntity > aNewList2; std::list < DoxygenEntity > aNewList2;
@ -438,7 +438,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
return 1; return 1;
} }
// \headerfile <header-file> [<header-name>] // \headerfile <header-file> [<header-name>]
else if (theCommand.compare("headerfile") == 0) { else if (theCommand == "headerfile") {
std::list < DoxygenEntity > aNewList; std::list < DoxygenEntity > aNewList;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
aNewList.push_back(DoxygenEntity("plainstd::string", name)); aNewList.push_back(DoxygenEntity("plainstd::string", name));
@ -449,7 +449,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
return 1; return 1;
} }
// \overload [(function declaration)] // \overload [(function declaration)]
else if (theCommand.compare("overload") == 0) { else if (theCommand == "overload") {
std::list < Token >::iterator endOfLine = getOneLine(tokList); std::list < Token >::iterator endOfLine = getOneLine(tokList);
if (endOfLine != tokList.current()) { if (endOfLine != tokList.current()) {
std::list < DoxygenEntity > aNewList; std::list < DoxygenEntity > aNewList;
@ -460,7 +460,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
return 1; return 1;
} }
// \weakgroup <name> [(title)] // \weakgroup <name> [(title)]
else if (theCommand.compare("weakgroup") == 0) { else if (theCommand == "weakgroup") {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
@ -477,7 +477,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
} }
// \ref <name> ["(text)"] // \ref <name> ["(text)"]
else if (theCommand.compare("ref") == 0) { else if (theCommand == "ref") {
//TODO Implement ref //TODO Implement ref
if (noisy) if (noisy)
cout << "Not Adding " << theCommand << endl; cout << "Not Adding " << theCommand << endl;
@ -485,7 +485,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
tokList.setIterator(endOfParagraph); tokList.setIterator(endOfParagraph);
} }
// \subpage <name> ["(text)"] // \subpage <name> ["(text)"]
else if (theCommand.compare("subpage") == 0) { else if (theCommand == "subpage") {
//TODO implement subpage //TODO implement subpage
if (noisy) if (noisy)
cout << "Not Adding " << theCommand << endl; cout << "Not Adding " << theCommand << endl;
@ -493,7 +493,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
tokList.setIterator(endOfParagraph); tokList.setIterator(endOfParagraph);
} }
// \dotfile <file> ["caption"] // \dotfile <file> ["caption"]
else if (theCommand.compare("dotfile") == 0) { else if (theCommand == "dotfile") {
//TODO implement dotfile //TODO implement dotfile
if (noisy) if (noisy)
cout << "Not Adding " << theCommand << endl; cout << "Not Adding " << theCommand << endl;
@ -501,11 +501,11 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
tokList.setIterator(endOfParagraph); tokList.setIterator(endOfParagraph);
} }
// \image <format> <file> ["caption"] [<sizeindication>=<size>] // \image <format> <file> ["caption"] [<sizeindication>=<size>]
else if (theCommand.compare("image") == 0) { else if (theCommand == "image") {
//todo implement image //todo implement image
} }
// \addtogroup <name> [(title)] // \addtogroup <name> [(title)]
else if (theCommand.compare("addtogroup") == 0) { else if (theCommand == "addtogroup") {
if (noisy) if (noisy)
cout << "Parsing " << theCommand << endl; cout << "Parsing " << theCommand << endl;
std::string name = getNextWord(tokList); std::string name = getNextWord(tokList);
@ -521,12 +521,64 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
aNewList.push_front(DoxygenEntity("plainstd::string", name)); aNewList.push_front(DoxygenEntity("plainstd::string", name));
doxyList.push_back(DoxygenEntity(theCommand, aNewList)); doxyList.push_back(DoxygenEntity(theCommand, aNewList));
} }
// \if <cond> [\else ...] [\elseif <cond> ...] \endif
else if (theCommand == "if" || theCommand == "ifnot" ||
theCommand == "else" || theCommand == "elseif") {
if (noisy)
cout << "Parsing " << theCommand << endl;
std::string cond;
bool skipEndif = false; // if true then we skip endif after parsing block of code
bool needsCond = (theCommand == "if" || theCommand == "ifnot" || theCommand == "elseif");
if (needsCond) {
cond = getNextWord(tokList);
if (cond.empty()) {
tokList.printListError("No word followed " + theCommand + " command. Not added");
return 0;
}
}
int nestedCounter = 1;
std::list < Token >::iterator endCommand = tokList.end();
// go through the commands and find closing endif or else or elseif
std::list < Token >::iterator it=tokList.iteratorCopy();
for (; it!=tokList.end(); it++) {
if (it->tokenType == COMMAND) {
if (it->tokenString == "if" || it->tokenString == "ifnot")
nestedCounter++;
else if (it->tokenString == "endif")
nestedCounter--;
if (nestedCounter == 1 && (it->tokenString == "else" || it->tokenString == "elseif")) { // else found
endCommand = it;
break;
}
if (nestedCounter == 0) { // endif found
endCommand = it;
skipEndif = true;
break;
}
}
}
if (endCommand == tokList.end()) {
tokList.printListError("No corresponding endif found");
return 0;
}
std::list < DoxygenEntity > aNewList;
aNewList = parse(endCommand, tokList);
if (skipEndif)
tokList.next();
if (needsCond)
aNewList.push_front(DoxygenEntity("plainstd::string", cond));
doxyList.push_back(DoxygenEntity(theCommand, aNewList));
}
return 0; return 0;
} }
int DoxygenParser::addCommand(std::string commandString, TokenList & tokList, std::list < DoxygenEntity > &doxyList) { int DoxygenParser::addCommand(std::string commandString, TokenList & tokList, std::list < DoxygenEntity > &doxyList) {
std::string theCommand = StringToLower(commandString); std::string theCommand = StringToLower(commandString);
if (theCommand.compare("plainstd::string") == 0) { if (theCommand == "plainstd::string") {
std::string nextPhrase = getStringTilCommand(tokList); std::string nextPhrase = getStringTilCommand(tokList);
if (noisy) if (noisy)
cout << "Parsing plain std::string :" << nextPhrase << endl; cout << "Parsing plain std::string :" << nextPhrase << endl;