diff --git a/Source/DoxygenTranslator/DoxygenEntity.h b/Source/DoxygenTranslator/DoxygenEntity.h index 734d09c8e..0605b1cc9 100644 --- a/Source/DoxygenTranslator/DoxygenEntity.h +++ b/Source/DoxygenTranslator/DoxygenEntity.h @@ -1,3 +1,5 @@ +#ifndef DOXYGENENTITY_H_ +#define DOXYGENENTITY_H_ #include #include @@ -12,7 +14,7 @@ public: DoxygenEntity(string typeEnt); DoxygenEntity(string typeEnt, string param1); DoxygenEntity(string typeEnt, list &entList ); - virtual ~DoxygenEntity(); + ~DoxygenEntity(); void printEntity(int level); string typeOfEntity; list entityList; @@ -21,3 +23,4 @@ public: }; +#endif /*TOKENLIST_H_*/ diff --git a/Source/DoxygenTranslator/DoxygenTranslator.cpp b/Source/DoxygenTranslator/DoxygenTranslator.cpp index 13a3c56fe..d6129cda0 100644 --- a/Source/DoxygenTranslator/DoxygenTranslator.cpp +++ b/Source/DoxygenTranslator/DoxygenTranslator.cpp @@ -1,106 +1,112 @@ -/* The main class for translating blobs of Doxygen for SWIG - * by Cheryl Foil, mentor Olly Betts, for Google's Summer of Code Program - * Currently the spacing/format on this is a bit goofy in places, due to shuffling code - * between 2 editors! Apologies for anyone combing through it :) - */ -//TODO DOH instead of STL? -//TODO Most commands are not fully implemented -#include -#include -#include -#include -#include -#include "DoxygenEntity.h" + + //THE TOKENIZER REWORK -using namespace std; - - -////////////////////////////////////////// -/*Set these to pick what internal functions -to test. */ - -//int testCommandParsingFunctions = 1;// not implemented - -int testCodeCrawlingFunctions = 0; -int demonstrateParsing = 1; -int runExamples = 1; -int noisy = 0; // set this to 1 for extra chatter from the parsing stage. -int addCommand(string commandName, int &startInd, list &doxyList, string doxygenString); -////////////////////////////////////////// - - - -/* Globals*/ - - -// An array of all the commands and my generic description tag, plaindescription - -string commandArray[] = {"a", "addindex", "addtogroup", "anchor", "arg", "attention", - "author", "b", "brief", "bug", "c", "callgraph", "callergraph", "category", - "class", "code", "cond", "copybrief", "copydetails", "copydoc", "date", "def", - "defgroup", "deprecated", "details", "dir", "dontinclude", "dot", "dotfile", "e", - "else", "elseif", "em", "endcode", "endcond", "enddot", "endhtmlonly", "endif", - "endlatexonly", "endlink", "endmanonly", "endmsc", "endverbatim", "endxmlonly", - "enum", "example", "exception", "f$", "f[", "f]", "f{", "f}", "file", "fn", "headerfile", - "hideinitializer", "htmlinclude", "htmlonly", "if", "ifnot", "image", "include", - "includelineno", "ingroup", "internal", "invariant", "interface", "latexonly", "li", - "line", "link", "mainpage", "manonly", "msc", "n", "name", "namespace", "nosubgrouping", - "note", "overload", "p", "package", "page", "par", "paragraph", "param", "post", "pre", - "private", "privatesection", "property", "protected", "protectedsection", "protocol", - "public", "publicsection", "ref", "relates", "relatesalso", "remarks", "return", "retval", - "sa", "section", "see", "showinitializer", "since", "skip", "skipline", "struct", "subpage", - "subsection", "subsubsection", "test", "throw", "todo", "tparam", "typedef", "union", "until", - "var", "verbatim", "verbinclude", "version", "warning", "weakgroup", "xmlonly", "xrefitem", - "$", "@", "//","&", "~", "<", ">", "#", "%"}; - - -string sectionIndicators[] = { "attention", "author", "brief", "bug", "cond", "date", "deprecated", "details", - "else", "elseif", "endcond", "endif", "exception", "if", "ifnot", "invariant", "note", "par", "param", - "tparam", "post" , "pre", "remarks", "return", "retval", "sa", "see", "since", "test", "throw", "todo", - "version", "warning", "xrefitem" }; - -/* All of the doxygen commands divided up by how they are parsed */ -string simpleCommands[] = {"n", "$", "@", "//", "&", "~", "<", ">", "#", "%"}; -string ignoredSimpleCommands[] = {"nothing at the moment"}; -string commandWords[] = {"a", "b", "c", "e", "em", "p", "def", "enum", "example", "package", - "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"}; -string ignoredCommandWords[] = {"copydoc", "copybrief", "copydetails", "verbinclude", "htmlinclude"}; -string commandLines[] = {"addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip", "until", "property"}; -string ignoreCommandLines[] = {"nothing at the moment"}; -string commandParagraph[] = {"return", "remarks", "since", "test", "sa", "see", "pre", "post", "details", "invariant", - "deprecated", "date", "note", "warning", "version", "todo", "bug", "attention", "brief", "arg", "author"}; -string ignoreCommandParagraphs[] = {"nothing at the moment"}; -string commandEndCommands[] = {"code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly", "latexonly", "manonly", - "verbatim", "xmlonly", "cond", "if", "ifnot", "link"}; -string commandWordParagraphs[] = {"param", "tparam", "throw", "retval", "exception"}; -string commandWordLines[] = {"page", "subsection", "subsubsection", "section", "paragraph", "defgroup"}; -string commandWordOWordOWords [] = {"category", "class", "protocol", "interface", "struct", "union"}; -string commandOWords[] = {"dir", "file", "cond"}; -string commandErrorThrowings[] = {"annotatedclasslist", "classhierarchy", "define", "functionindex", "header", - "headerfilelist", "inherit", "l", "postheader", "private", "privatesection", "protected", - "protectedsection", "public", "publicsection", "endcode", "enddot", "endmsc", "endhtmlonly", - "endlatexonly", "endmanonly", "endlink", "endverbatim", "endxmlonly", "f]", "f}", "endcond", - "endif"}; -string commandUniques[] = {"xrefitem", "ingroup", "par", "headerfile", "overload", "weakgroup", "ref", - "subpage", "dotfile", "image", "addtogroup", "li"}; - - //int startIndex = 0; - int isNewLine = 0; - int briefDescExists = 0; - - /* Entity list is the root list. - * it is arranged this way to help documentation modules, - * such as the javaDoc one, "sort" entities where they need to. + /* The main class for translating blobs of Doxygen for SWIG + * by Cheryl Foil, mentor Olly Betts, for Google's Summer of Code Program + * Currently the spacing/format on this is a bit goofy in places, due to shuffling code + * between 2 editors! Apologies for anyone combing through it :) */ + //TODO DOH instead of STL? +//TODO work in Brief descriptions, detailed descriptions for autobrief - list rootList; + #include + #include + #include + #include + #include + #include "DoxygenEntity.h" + #include "TokenList.h" + #include "JavaDocConverter.h" + #define SIMPLECOMMAND 1 + #define IGNOREDSIMPLECOMMAND 2 + #define COMMANDWORD 3 + #define IGNOREDCOMMANDWORD 4 + #define COMMANDLINE 5 + #define IGNOREDCOMMANDLINE 6 + #define COMMANDPARAGRAPH 7 + #define IGNORECOMMANDPARAGRAPH 8 + #define COMMANDENDCOMMAND 9 + #define COMMANDWORDPARAGRAPH 10 + #define COMMANDWORDLINE 11 + #define COMMANDWORDOWORDWORD 12 + #define COMMANDOWORD 13 + #define COMMANDERRORTHROW 14 + #define COMMANDUNIQUE 15 +#define END_LINE 101 +#define PARAGRAPH_END 102 +#define PLAINSTRING 103 +#define COMMAND 104 + using namespace std; -/* General (untested) assist methods */ + ////////////////////////////////////////// + /*Set these to pick what internal functions + to test. */ + //int testCommandParsingFunctions = 1;// not implemented + + + int noisy = 0; // set this to 1 for extra chatter from the parsing stage. + int addCommand(string currCommand, TokenList &tokList, list &aNewList); + list parse(list::iterator endParsingIndex, TokenList &tokList); + + ////////////////////////////////////////// + + + string commandArray[] = {"a", "addindex", "addtogroup", "anchor", "arg", "attention", + "author", "b", "brief", "bug", "c", "callgraph", "callergraph", "category", + "class", "code", "cond", "copybrief", "copydetails", "copydoc", "date", "def", + "defgroup", "deprecated", "details", "dir", "dontinclude", "dot", "dotfile", "e", + "else", "elseif", "em", "endcode", "endcond", "enddot", "endhtmlonly", "endif", + "endlatexonly", "endlink", "endmanonly", "endmsc", "endverbatim", "endxmlonly", + "enum", "example", "exception", "f$", "f[", "f]", "f{", "f}", "file", "fn", "headerfile", + "hideinitializer", "htmlinclude", "htmlonly", "if", "ifnot", "image", "include", + "includelineno", "ingroup", "internal", "invariant", "interface", "latexonly", "li", + "line", "link", "mainpage", "manonly", "msc", "n", "name", "namespace", "nosubgrouping", + "note", "overload", "p", "package", "page", "par", "paragraph", "param", "post", "pre", + "private", "privatesection", "property", "protected", "protectedsection", "protocol", + "public", "publicsection", "ref", "relates", "relatesalso", "remarks", "return", "retval", + "sa", "section", "see", "showinitializer", "since", "skip", "skipline", "struct", "subpage", + "subsection", "subsubsection", "test", "throw", "todo", "tparam", "typedef", "union", "until", + "var", "verbatim", "verbinclude", "version", "warning", "weakgroup", "xmlonly", "xrefitem", + "$", "@", "//","&", "~", "<", ">", "#", "%"}; + + + string sectionIndicators[] = { "attention", "author", "brief", "bug", "cond", "date", "deprecated", "details", + "else", "elseif", "endcond", "endif", "exception", "if", "ifnot", "invariant", "note", "par", "param", + "tparam", "post" , "pre", "remarks", "return", "retval", "sa", "see", "since", "test", "throw", "todo", + "version", "warning", "xrefitem" }; + + /* All of the doxygen commands divided up by how they are parsed */ + string simpleCommands[] = {"n", "$", "@", "//", "&", "~", "<", ">", "#", "%"}; + string ignoredSimpleCommands[] = {"nothing at the moment"}; + string commandWords[] = {"a", "b", "c", "e", "em", "p", "def", "enum", "example", "package", + "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"}; + string ignoredCommandWords[] = {"copydoc", "copybrief", "copydetails", "verbinclude", "htmlinclude"}; + string commandLines[] = {"addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip", "until", "property"}; + string ignoreCommandLines[] = {"nothing at the moment"}; + string commandParagraph[] = {"return", "remarks", "since", "test", "sa", "see", "pre", "post", "details", "invariant", + "deprecated", "date", "note", "warning", "version", "todo", "bug", "attention", "brief", "author"}; + string ignoreCommandParagraphs[] = {"nothing at the moment"}; + string commandEndCommands[] = {"code", "dot", "msc", "f$", "f[", "f{environment}{", "htmlonly", "latexonly", "manonly", + "verbatim", "xmlonly", "cond", "if", "ifnot", "link"}; + string commandWordParagraphs[] = {"param", "tparam", "throw", "retval", "exception"}; + string commandWordLines[] = {"page", "subsection", "subsubsection", "section", "paragraph", "defgroup"}; + string commandWordOWordOWords [] = {"category", "class", "protocol", "interface", "struct", "union"}; + string commandOWords[] = {"dir", "file", "cond"}; + string commandErrorThrowings[] = {"annotatedclasslist", "classhierarchy", "define", "functionindex", "header", + "headerfilelist", "inherit", "l", "postheader", "private", "privatesection", "protected", + "protectedsection", "public", "publicsection", "endcode", "enddot", "endmsc", "endhtmlonly", + "endlatexonly", "endmanonly", "endlink", "endverbatim", "endxmlonly", "f]", "f}", "endcond", + "endif"}; + string commandUniques[] = {"xrefitem", "arg", "ingroup", "par", "headerfile", "overload", "weakgroup", "ref", + "subpage", "dotfile", "image", "addtogroup", "li"}; + + + /* Changes a string to all lower case*/ string StringToLower(string stringToConvert) - {//change each element of the string to lower case + { for(unsigned int i=0;i= doxygenString.length()) return ""; - int startIndex = startInd; - int endIndex = startInd; - string description; - /* Find the End of the description */ - int keepLooping = 1; - int spareIndex = 0; - int counter; - int finalIndex; - while(keepLooping){ - if(endIndex >= doxygenString.length()){ - finalIndex = endIndex; - keepLooping = 0; - } - else if (doxygenString[endIndex] == '\n'){ - //cout << "1 "; - counter = endIndex; - if ( keepLooping && endIndex < doxygenString.length()-1) { - counter++; - //cout << "Counter :" << counter << endl; - while(keepLooping && endIndex < doxygenString.length() && (doxygenString[counter] == ' ' || - doxygenString[counter] == '*'|| doxygenString[counter] == '\n'|| doxygenString[counter] == '/' - || doxygenString[counter] == '!' || doxygenString[startIndex] == '\t') ){ - if(doxygenString[counter] == '\n') { - //cout << "Blank line found" << endl; - keepLooping = 0; - finalIndex = counter;} - else{ counter++;} - } - - } - //endIndex = counter; - } - else if (doxygenString[endIndex] == '\\' || doxygenString[endIndex] == '@'){ - finalIndex = endIndex; - keepLooping = 0; - } - else if(endIndex < doxygenString.length() -2 - && string("**/").compare(doxygenString.substr(endIndex , endIndex + 2)) == 0){ - finalIndex = endIndex; - //cout << "3 "; - keepLooping = 0; - } - if(keepLooping){ - //cout << "4 "; - endIndex++; - } - } - //cout << "Done with EndIndex" << endl; - while(doxygenString[startIndex] == '!' || doxygenString[startIndex] == ' ' - || doxygenString[startIndex] == '/' || doxygenString[startIndex] == '*' || doxygenString[startIndex] == '\t') startIndex++; - - for (int i = startIndex; i < endIndex; i++){ - - if (doxygenString[i] == '\n') { - - while ((doxygenString[i] == '\n' || doxygenString[startIndex] == '\t'|| doxygenString[i] == ' ' - || doxygenString[i] == '*' || doxygenString[i] == '/')&& endIndex < doxygenString.length() - 1){ - i++; - } - description.append(" "); - } - description.push_back(doxygenString[i]); - //cout << doxygenString[i]; - } - //if(noisy) cout << "Final Index is: " << finalIndex << endl; - startInd = finalIndex; - return description; - } - -/* Returns a Paragraph- defined in Doxygen to be a paragraph of text - * seperate by either a structural command or a blank line - * This method is VERY messy currently - */ - //TODO fix getStringTilEndOfParagraph to be more forgiving, work on ' ' characters - string getStringTilEndOfParagraph(int &startInd, string doxygenString){ - if (startInd >= doxygenString.length()) return ""; - int startIndex = startInd; - int endIndex = startInd; - string description; - /* Find the End of the description */ - int keepLooping = 1; - int spareIndex = 0; - int counter; - int finalIndex; - while(keepLooping){ - if(endIndex >= doxygenString.length()){ - finalIndex = endIndex; - keepLooping = 0; - } - else if (doxygenString[endIndex] == '\n'){ - //cout << "1 "; - counter = endIndex; - if ( keepLooping && endIndex < doxygenString.length()-1) { - counter++; - //cout << "Counter :" << counter << endl; - while(keepLooping && endIndex < doxygenString.length() && (doxygenString[counter] == ' ' || - doxygenString[counter] == '*'|| doxygenString[startIndex] == '\t' || doxygenString[counter] == '\n'|| doxygenString[counter] == '/' - || doxygenString[counter] == '!') ){ - if(doxygenString[counter] == '\n') { - //cout << "Blank line found" << endl; - keepLooping = 0; - finalIndex = counter;} - else{ counter++;} - } - - } - //endIndex = counter; - } - //todo this fix for not immediately exciting while parsing a paragraph seems somewhat cheap - else if (endIndex != startInd && doxygenString[endIndex] == '\\' || doxygenString[endIndex] == '@'){ - spareIndex = endIndex +1; - - if (isSectionIndicator(getNextWord(spareIndex, doxygenString))) { - keepLooping = 0; - finalIndex = endIndex;} - } - else if(endIndex < doxygenString.length() - 1 - && string("*/").compare(doxygenString.substr(endIndex , endIndex + 1)) == 0){ - keepLooping = 0; - finalIndex = endIndex; - } - if(keepLooping){ - endIndex++; - } - } - //cout << "Done with EndIndex" << endl; - while(doxygenString[startIndex] == '!' || doxygenString[startIndex] == ' ' || doxygenString[startIndex] == '\t' - || doxygenString[startIndex] == '/' || doxygenString[startIndex] == '*') startIndex++; - - for (int i = startIndex; i < endIndex; i++){ - - if (doxygenString[i] == '\n') { - - while ((doxygenString[i] == '\n' || doxygenString[startIndex] == '\t' || doxygenString[i] == ' ' ||doxygenString[startIndex] == '!' - || doxygenString[i] == '*' || doxygenString[i] == '/')&& endIndex < doxygenString.length() - 1){ - i++; - } - description.append(" "); - } - description.push_back(doxygenString[i]); - //cout << doxygenString[i]; - } - startInd = finalIndex; - return description; - } - - /* This method is for a specific form of doxygen command - * that begins with a \command and ends in \endcommand - * such as \code and \endcode. The proper usage is - * progressTilEndCommand("endcode", index) - * currently this method does NOT process what is in between the two commands - */ - //TODO Make progressTilCommand return a formatted string - int progressTilEndCommand(string theCommand, int &startInd, string doxygenString){ - int endIndex = startInd; - while (endIndex < doxygenString.length()){ - if (doxygenString[endIndex] == '\\' || doxygenString[endIndex] == '@'){ - //cout << doxygenString.substr(endIndex + 1 , theCommand.length())<< endl; - if (theCommand.compare(doxygenString.substr(endIndex + 1 , theCommand.length())) == 0){ - startInd = endIndex + theCommand.length() + 1; - return 1; - } - } - endIndex++; - } - //End command not found - return 0; - } - - /* A specialty method for commands such as \arg that end at the end of a paragraph OR when another \arg is encountered - */ - - string getStringTilAnyCommand(string theCommand, int &startInd, string doxygenString){ - if (startInd >= doxygenString.length()) return ""; - int startIndex = startInd; - int endIndex = startInd; - string description; - /* Find the End of the description */ - int keepLooping = 1; - int spareIndex = 0; - int counter; - int finalIndex; - while(keepLooping){ - if(endIndex >= theCommand.length()){ - finalIndex = endIndex; - keepLooping = 0; - } - else if (doxygenString[endIndex] == '\n'){ - //cout << "1 "; - counter = endIndex; - if ( keepLooping && endIndex < doxygenString.length()-1) { - counter++; - //cout << "Counter :" << counter << endl; - while(keepLooping && endIndex < doxygenString.length() && (doxygenString[counter] == ' ' || - doxygenString[counter] == '*'|| doxygenString[counter] == '\n'|| doxygenString[counter] == '/' - || doxygenString[counter] == '!' || doxygenString[startIndex] == '\t') ){ - if(doxygenString[counter] == '\n') { - //cout << "Blank line found" << endl; - keepLooping = 0; - finalIndex = counter;} - else{ counter++;} - } - - } - //endIndex = counter; - } - else if (doxygenString[endIndex] == '\\' || doxygenString[endIndex] == '@'){ - //cout << "2 "; - spareIndex = endIndex; - if (endIndex + theCommand.length() < theCommand.length() - && theCommand.compare(doxygenString.substr(endIndex, theCommand.length())) == 0) keepLooping = 0; - } - else if(endIndex < doxygenString.length() - 1 - && string("*/").compare(doxygenString.substr(endIndex , endIndex + 1)) == 0){ - //cout << "3 "; - keepLooping = 0; - } - if(keepLooping){ - //cout << "4 "; - endIndex++; - } - } - //cout << "Done with EndIndex" << endl; - while(doxygenString[startIndex] == '!' || doxygenString[startIndex] == ' ' - || doxygenString[startIndex] == '/' || doxygenString[startIndex] == '*' || doxygenString[startIndex] == '\t') startIndex++; - - for (int i = startIndex; i < endIndex; i++){ - - if (doxygenString[i] == '\n') { - - while ((doxygenString[i] == '\n' || doxygenString[i] == ' ' || doxygenString[startIndex] == '\t' - || doxygenString[i] == '*' || doxygenString[i] == '/')&& endIndex < doxygenString.length() - 1){ - i++; - } - description.append(" "); - } - description.push_back(doxygenString[i]); - //cout << doxygenString[i]; - } - startInd = finalIndex; - return description; - } - ///////////////TEST CLASSES AND MAIN BELOW///////////////// - - - /* Testing clearFluff(), a method to scan past all excess / * ! from beginning of - * a comment blob. Compartmentalised simply because this is a comment habit that - * differs wildly */ - - int testClearFluff(){ - string doxygenString; - string cases[] = {"/** WORD", "/*! WORD", "/******* WORD", "///// WORD", "//! WORD", "//! WORD", "///WORD", - "/**\nWORD", "/**\n*WORD", "/** \n WORD"}; - int testPassed = 1; - int placement = 0; - int casesSize = sizeof(cases)/sizeof(*cases); - for (int i = 0; i < casesSize; i++){ - placement = 0; - doxygenString = cases[i]; - if(cases[i][clearFluff(placement, doxygenString)] != 'W'){ - cout << "ClearFluff failed for string :" << doxygenString << "\t Displayed :" << cases[i][clearFluff(placement = 0, doxygenString)] << ": Instead." << endl; - testPassed = 0; - } - } - if(testPassed) cout << "+++ClearFluff passed for all tests+++\n" << endl; - else cout << "+++ClearFluff FAILED.+++" << endl; - return testPassed; - - }; - - int testGetNextWord(){ - string doxygenString; - string cases[] = {"/** WORD ", " * WORD ", "///!WORD ", " WORD ", "//! WORD ", " * WORD ", "*WORD "}; - int testPassed = 1; - string testWord; - int placement = 0; - int casesSize = sizeof(cases)/sizeof(*cases); - for (int i = 0; i < casesSize; i++){ - doxygenString = cases[i]; - placement = 0; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("WORD") != 0){ - cout << "GetNextWord failed for string :" << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0; - } - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - } - placement = 0; - doxygenString = " * @WORD "; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("@WORD") != 0){ - cout << "GetNextWord failed for string :" - << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = " * "; - testWord.push_back('\\'); - testWord = testWord + "WORD "; - string commandWord; - commandWord.push_back('\\'); - commandWord = commandWord + "WORD"; - doxygenString = testWord; - placement = 0; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare(commandWord) != 0){ - cout << "GetNextWord failed for string :" << doxygenString - << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - doxygenString = "WORD ANOTHER WORD1 WORD2 \n"; - placement = 0; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("WORD") != 0){ - cout << "GetNextWord failed for string :" << doxygenString - << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("ANOTHER") != 0){ - cout << "GetNextWord failed for string :" << doxygenString - << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("WORD1") != 0){ - cout << "GetNextWord failed for string :" << doxygenString - << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("WORD2") != 0){ - cout << "GetNextWord failed for string :" - << doxygenString << "\t Displayed :" << testWord - << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("") != 0){ - cout << "GetNextWord failed for string :" << doxygenString - << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - testWord = getNextWord(placement, doxygenString); - if(testWord.compare("") != 0){ - cout << "GetNextWord failed for string :" << doxygenString << - "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0;} - //else cout << "GetNextWord passed for string :" << doxygenString << endl; - if(testPassed) cout << "+++NextWord passed for all tests+++\n" << endl; - else cout << "+++NextWord FAILED+++\n" << endl; - return testPassed; - } - - int testGetOneLine(){ - string doxygenString; - string cases[] = {" * Crop this sentence after this period.\n", - " * Crop this sentence after this period.\n", - "Crop this sentence after this period.\n", - "//! Crop this sentence after this period.\n", - " Crop this sentence after this period.\n" - }; - int testPassed = 1; - string testWord; - int placement = 0; - int casesSize = sizeof(cases)/sizeof(*cases); - for (int i = 0; i < casesSize; i++){ - doxygenString = cases[i]; - placement = 0; - testWord = getOneLine(placement, doxygenString); - if(testWord.compare("Crop this sentence after this period.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0; - } - } - doxygenString = ("Get this line.\n * Now get this line."); - placement = 0; - testWord = getOneLine(placement, doxygenString); - if(testWord.compare("Get this line.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0; - } - testWord = getOneLine(placement, doxygenString); - if(testWord.compare("Now get this line.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0; - } - testWord = getOneLine(placement, doxygenString); - if(testWord.compare("") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testWord << ": Instead." << endl; - testPassed = 0; - } - - if(testPassed) cout << "+++GetOneLine passed for all tests+++\n" << endl; - else cout << "+++GetOneLine FAILED+++\n" << endl; - return testPassed; - } -//TODO Flesh testGetStringTilEndOfParagraph out, fix weird spacing problems - int testGetStringTilEndOfParagraph(){ - string doxygenString; - int placement = 0; - int testPassed = 1; - string testParagraph; - doxygenString = ("/* This is a description,\n * thus it continues on\n * for several lines.\n\n This Shouldn't be included.\n\n **/"); - testParagraph = getStringTilEndOfParagraph(placement, doxygenString); - if( testParagraph.compare("This is a description, thus it continues on for several lines.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testParagraph << ": Instead." << endl; - testPassed = 0; - } - //cout << "Curr Placement: " << placement<< endl; - testParagraph = getStringTilEndOfParagraph(placement, doxygenString); - //cout << "Curr Placement: " << placement<< endl; - if( testParagraph.compare(" This Shouldn't be included.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testParagraph << ": Instead." << endl; - testPassed = 0; - } - - //cout << "Curr Placement: " << placement<< endl; - //cout << "String Length: " << doxygenString.length() << endl; - - doxygenString = "/* This is a description,\n * thus it continues on\n * for several lines.\n * \n * "; - doxygenString.push_back('//'); - doxygenString += "author cheryl foil \n\n **/"; - placement = 0; - testParagraph = getStringTilEndOfParagraph(placement, doxygenString); - if( testParagraph.compare("This is a description, thus it continues on for several lines.") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testParagraph << ": Instead." << endl; - testPassed = 0; - } - - if(testPassed) cout << "+++GetGetStringTilEndOfParagraph passed for all tests+++\n" << endl; - else cout << "+++GetGetStringTilEndOfParagraphFAILED+++\n" << endl; - return testPassed; - } - - int testGetStringTilCommand(){ - string doxygenString; - int placement = 0; - int testPassed = 1; - string testParagraph; - doxygenString = ("/* This is a description,\n * thus it continues on\n * for several @b lines.\n\n This Shouldn't be included.\n\n **/"); - testParagraph = getStringTilCommand(placement, doxygenString); - if( testParagraph.compare("This is a description, thus it continues on for several ") != 0){ - cout << "GetOneLine failed for string :" << doxygenString << "\t Displayed :" << testParagraph << ": Instead." << endl; - testPassed = 0; - } - if(testPassed) cout << "+++GetStringTilCommand passed for all tests+++\n" << endl; - else cout << "+++GetStringTilCommand FAILED+++\n" << endl; - return testPassed; - - } - int testProgressTilEndCommand(){ - string doxygenString ; - int placement = 0; - int testPassed = 1; - string testParagraph; - doxygenString = "Let's pretend this \n * is a bunch of code to be ended in "; - doxygenString.push_back('\\'); - doxygenString += "endcodeSTOP"; - progressTilEndCommand("endcode", placement, doxygenString); - //cout << "Placement : " << placement << endl; - if( doxygenString[placement] != 'S'){ - cout << "GetOneLine failed for string :" << doxygenString << "\n\t Displayed :" << testParagraph << ": Instead." << endl; - testPassed = 0; - } - if(testPassed) cout << "+++ProgressTilEndCommand passed for all tests+++\n" << endl; - else cout << "+++ProgressTilEndCommand FAILED+++\n" << endl; - return testPassed; - } - - int testCCF(){ - cout << "TESTING COMMAND PARSING FUNCTIONS" << endl; - cout << "Testing clearFluff" << endl; - testClearFluff(); - - cout << "Testing getNextWord" << endl; - testGetNextWord(); - cout << "Testing getOneLine"<< endl; - testGetOneLine(); - - cout << "Testing getStringTilEndOfParagraph" << endl; - testGetStringTilEndOfParagraph(); - - cout << "Testing progressTilEndCommand" << endl; - testProgressTilEndCommand(); - - cout << "Testing GetStringTilCommand" << endl; - testGetStringTilCommand(); - return 1; - } - /* prints the parse tree * */ - void printTree(){ + void printTree( list &rootList){ list::iterator p = rootList.begin(); while (p != rootList.end()){ @@ -775,45 +160,217 @@ string getStringTilCommand(int &startInd, string doxygenString){ } - - - list parse(int startInd, string doxygenString){ - string currWord; - int startIndex = startInd; - int savedIndex; - list aNewList; - int endIndex = doxygenString.length(); - int currCommand; - while (startIndex < endIndex){ - savedIndex = startIndex; - currWord = getNextWord(startIndex, doxygenString); - if(noisy) cout << "Parsing for phrase starting in:" << currWord << endl; - if(currWord == ""){ - if (startIndex < endIndex) startIndex++; - } - else if(currWord[0] == '\\' || currWord[0] == '@'){ - currWord = currWord.substr(1, currWord.length() - 1); - currCommand = findCommand(currWord); - if (currCommand < 0 ){ if(noisy) cout << "BAD COMMAND: " << currWord << endl;} - //cout << "Command: " << currWord << " " << currCommand << endl; - else addCommand(currWord, startIndex, aNewList, doxygenString); - } - else{ - startIndex = savedIndex; - addCommand(string("plainstring"), startIndex, aNewList, doxygenString); + /* Determines how a command should be handled (what group it belongs to + * for parsing rules + */ + int commandBelongs(string theCommand){ + string smallString = StringToLower(theCommand ); + //cout << " Looking for command " << theCommand << endl; + int i = 0; + for ( i = 0; i < sizeof(simpleCommands)/sizeof(*simpleCommands); i++){ + if(smallString.compare(simpleCommands[i]) == 0){return SIMPLECOMMAND ;} + } + for ( i = 0; i < sizeof(ignoredSimpleCommands)/sizeof(*ignoredSimpleCommands); i++){ + if(smallString.compare(ignoredSimpleCommands[i]) == 0){return IGNOREDSIMPLECOMMAND;} + } + for ( i = 0; i < sizeof(commandWords)/sizeof(*commandWords); i++){ + if(smallString.compare( commandWords[i]) == 0){return COMMANDWORD;} + } + for ( i = 0; i < sizeof(ignoredCommandWords)/sizeof(*ignoredCommandWords); i++){ + if(smallString.compare( ignoredCommandWords[i]) == 0){return IGNOREDCOMMANDWORD;} + } + for ( i = 0; i < sizeof(commandLines)/sizeof(*commandLines); i++){ + if(smallString.compare( commandLines[i]) == 0){return COMMANDLINE;} + } + for ( i = 0; i < sizeof(ignoreCommandLines)/sizeof(*ignoreCommandLines); i++){ + if(smallString.compare( ignoreCommandLines[i]) == 0){return IGNOREDCOMMANDLINE;} + } + for ( i = 0; i < sizeof(commandParagraph)/sizeof(*commandParagraph); i++){ + if(smallString.compare( commandParagraph[i]) == 0){return COMMANDPARAGRAPH;} + } + /* IgnoreCommandParagraph */ + for ( i = 0; i < sizeof(ignoreCommandParagraphs)/sizeof(*ignoreCommandParagraphs); i++){ + if(smallString.compare( ignoreCommandParagraphs[i]) == 0){return IGNORECOMMANDPARAGRAPH;} + } + for ( i = 0; i < sizeof(commandEndCommands)/sizeof(*commandEndCommands); i++){ + if(smallString.compare( commandEndCommands[i]) == 0){return COMMANDENDCOMMAND ;} + } + for ( i = 0; i < sizeof(commandWordParagraphs)/sizeof(*commandWordParagraphs); i++){ + if(smallString.compare( commandWordParagraphs[i]) == 0){return COMMANDWORDPARAGRAPH;} + } + for ( i = 0; i < sizeof(commandWordLines)/sizeof(*commandWordLines); i++){ + if(smallString.compare( commandWordLines[i]) == 0){return COMMANDWORDLINE ;} + } + for ( i = 0; i < sizeof(commandWordOWordOWords)/sizeof(*commandWordOWordOWords); i++){ + if(smallString.compare( commandWordOWordOWords[i]) == 0){return COMMANDWORDOWORDWORD;} + } + for ( i = 0; i < sizeof(commandOWords)/sizeof(*commandOWords); i++){ + if(smallString.compare( commandOWords[i]) == 0){return COMMANDOWORD;} + } + for ( i = 0; i < sizeof(commandErrorThrowings)/sizeof(*commandErrorThrowings); i++){ + if(smallString.compare( commandErrorThrowings[i]) == 0){return COMMANDERRORTHROW;} + } + for ( i = 0; i < sizeof(commandUniques)/sizeof(*commandUniques); i++){ + if(smallString.compare( commandUniques[i]) == 0){return COMMANDUNIQUE;} + } + + return 0; + + } + /* Returns the next word ON THE CURRENT LINE ONLY + * if a new line is encountered, returns a blank string. + * Updates the index it is given if success. + */ + + string getNextWord(TokenList &tokList){ + Token nextToken = tokList.peek(); + if (nextToken.tokenType == PLAINSTRING ){ + nextToken = tokList.next(); + return nextToken.tokenString; + } + return ""; + } + + /* Returns the location of the end of the line as + * an iterator. + */ + list::iterator getOneLine(TokenList &tokList){ + list::iterator endOfParagraph = tokList.iteratorCopy(); + while(endOfParagraph != tokList.end()){ + if ((* endOfParagraph).tokenType == END_LINE){ + return endOfParagraph; + } + endOfParagraph++; + } + return tokList.end(); + } + + + +/* Returns a properly formatted string + * up til ANY command or end of paragraph is encountered. + */ +string getStringTilCommand(TokenList &tokList){ + string description; + if (tokList.peek().tokenType == 0) return ""; + while(tokList.peek().tokenType == PLAINSTRING || tokList.peek().tokenType == END_LINE ){ + Token currentToken = tokList.next(); + if(currentToken.tokenType == PLAINSTRING) { + description = description + currentToken.tokenString + " "; + } + else if (tokList.peek().tokenType == END_LINE) break; + } + + return description; + } + +/* Returns a properly formatted string + * up til the command specified is encountered + */ +//TODO check that this behaves properly for formulas + +string getStringTilEndCommand(string theCommand, TokenList &tokList){ + string description; + if (tokList.peek().tokenType == 0) return ""; + while(tokList.peek().tokenString.compare(theCommand) != 0 ){ + Token currentToken = tokList.next(); + description = description + currentToken.tokenString + " "; + + } + + return description; + } + +/* Returns the end of a Paragraph as an iterator- + * Paragraph is defined in Doxygen to be a paragraph of text + * seperate by either a structural command or a blank line + */ + +list::iterator getEndOfParagraph(TokenList &tokList){ + list::iterator endOfParagraph = tokList.iteratorCopy(); + while(endOfParagraph != tokList.end()){ + if ((* endOfParagraph).tokenType == COMMAND){ + if(isSectionIndicator((* endOfParagraph).tokenString)) return endOfParagraph; + else endOfParagraph++; + } + else if((* endOfParagraph).tokenType == PLAINSTRING) { + endOfParagraph++; + } + else if ((* endOfParagraph).tokenType == END_LINE){ + endOfParagraph++; + if ((* endOfParagraph).tokenType == END_LINE){ + endOfParagraph++; + return endOfParagraph; + } + } + + } + + return tokList.end(); + + } + +/* Returns the end of a section, defined as the first blank line OR first encounter of the same + * command. Example of this behaviour is \arg + */ + +list::iterator getEndOfSection(string theCommand, TokenList &tokList){ + list::iterator endOfParagraph = tokList.iteratorCopy(); + while(endOfParagraph != tokList.end()){ + if ((* endOfParagraph).tokenType == COMMAND){ + if(theCommand.compare((*endOfParagraph).tokenString) == 0) return endOfParagraph; + else endOfParagraph++; + } + else if((* endOfParagraph).tokenType == PLAINSTRING) { + endOfParagraph++; + } + else if ((* endOfParagraph).tokenType == END_LINE){ + endOfParagraph++; + if ((* endOfParagraph).tokenType == END_LINE){ + endOfParagraph++; + return endOfParagraph; + } + } + + } +} + /* This method is for returning the end of a specific form of doxygen command + * that begins with a \command and ends in \endcommand + * such as \code and \endcode. The proper usage is + * progressTilEndCommand("endcode", tokenList); + */ +list::iterator getEndCommand(string theCommand, TokenList &tokList){ + list::iterator endOfCommand = tokList.iteratorCopy(); + while (endOfCommand!= tokList.end()){ + if ((*endOfCommand).tokenType == COMMAND){ + if (theCommand.compare((* endOfCommand).tokenString) == 0){ + return endOfCommand; + } + endOfCommand++; } } - - return aNewList; + //End command not found + return tokList.end(); } + + /* A specialty method for commands such as \arg that end at the end of a paragraph OR when another \arg is encountered + */ + +list::iterator getTilAnyCommand(string theCommand, TokenList &tokList){ + list::iterator anIterator; + return anIterator; + } + + + /* Method for Adding a Simple Command * Format: @command * Plain commands, such as newline etc, they contain no other data * \n \\ \@ \& \$ \# \< \> \% */ - int addSimpleCommand(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addSimpleCommand(string theCommand, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; doxyList.push_back(DoxygenEntity(theCommand)); @@ -824,7 +381,7 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Format: @command * Plain commands, such as newline etc, they contain no other data */ - int ignoreSimpleCommand(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int ignoreSimpleCommand(string theCommand, list &doxyList){ if (noisy) cout << "Not Adding " << theCommand << endl; return 1; @@ -836,9 +393,9 @@ string getStringTilCommand(int &startInd, string doxygenString){ * "a", "b", "c", "e", "em", "p", "def", "enum", "example", "package", * "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno" */ - int addCommandWord(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandWord(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); if (!name.empty()){ doxyList.push_back(DoxygenEntity(theCommand, name)); return 1; @@ -851,9 +408,9 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands with a single WORD after then such as @b * "copydoc", "copybrief", "copydetails", "verbinclude", "htmlinclude" */ - int ignoreCommandWord(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int ignoreCommandWord(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Not Adding " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); if (!name.empty()){ return 1; } @@ -866,18 +423,14 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands with a single LINE after then such as @var * "addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip", "until", "property" */ - int addCommandLine(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandLine(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string line = getOneLine(startInd, doxygenString); - if(!line.empty()){ - int placement = 0; + list::iterator endOfLine = getOneLine(tokList); list aNewList; - aNewList = parse(placement, line); + aNewList = parse(endOfLine, tokList); doxyList.push_back( DoxygenEntity(theCommand, aNewList)); return 1; - } - else cout << "No line followed " << theCommand << " command. Not added" << endl; - return 0; + } /* NOT INCLUDED CommandLine @@ -885,14 +438,11 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands with a single LINE after then such as @var * */ - int ignoreCommandLine(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int ignoreCommandLine(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Not Adding " << theCommand << endl; - string line = getOneLine(startInd, doxygenString); - if(!line.empty()){ - return 1; - } - else cout << "WARNING: No line followed " << theCommand << " command." << endl; - return 0; + list::iterator endOfLine = getOneLine(tokList); + tokList.setIterator(endOfLine); + return 1; } /* CommandParagraph @@ -901,32 +451,28 @@ string getStringTilCommand(int &startInd, string doxygenString){ * "return", "remarks", "since", "test", "sa", "see", "pre", "post", "details", "invariant", * "deprecated", "date", "note", "warning", "version", "todo", "bug", "attention", "brief", "arg", "author" */ - int addCommandParagraph(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandParagraph(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string restOfParagraph = getStringTilEndOfParagraph(startInd, doxygenString); - if(!restOfParagraph.empty()){ - int placement = 0; - list aNewList; - aNewList = parse(placement, restOfParagraph); - doxyList.push_back( DoxygenEntity(theCommand, aNewList)); - return 1; - } - else cout << "No line followed " << theCommand << " command. Not added" << endl; - return 0; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + //if(!restOfParagraph.empty()){ + list aNewList; + aNewList = parse(endOfParagraph, tokList); + doxyList.push_back( DoxygenEntity(theCommand, aNewList)); + return 1; + // } + //else cout << "No line followed " << theCommand << " command. Not added" << endl; } /* CommandParagraph * Format: @command {paragraph} * Commands with a single LINE after then such as @var * */ - int ignoreCommandParagraph(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int ignoreCommandParagraph(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Not Adding " << theCommand << endl; - string restOfParagraph = getStringTilEndOfParagraph(startInd, doxygenString); - if(!restOfParagraph.empty()){ - return 1; - } - else cout << "WARNING: No line followed " << theCommand << " command." << endl; - return 0; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + tokList.setIterator(endOfParagraph); + //else cout << "WARNING: No line followed " << theCommand << " command." << endl; + return 1; } /* Command EndCommand * Format: @command and ends at @endcommand @@ -936,10 +482,11 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Returns 1 if success, 0 if the endcommand is never encountered. */ - int ignoreCommandEndCommand(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandEndCommand(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Not Adding " << theCommand << endl; - return progressTilEndCommand( "end" + theCommand, startInd, doxygenString); - + string description = getStringTilEndCommand( "end" + theCommand, tokList); + doxyList.push_back(DoxygenEntity(theCommand, description)); + return 1; } /* CommandWordParagraph @@ -947,23 +494,19 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands such as param * "param", "tparam", "throw", "retval", "exception" */ - int addCommandWordParagraph(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandWordParagraph(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); if (name.empty()){ cout << "No word followed " << theCommand << " command. Not added" << endl; return 0; } - string restOfParagraph = getStringTilEndOfParagraph(startInd, doxygenString); - int placement = 0; - if(!restOfParagraph.empty()){ + list::iterator endOfParagraph = getEndOfParagraph(tokList); + //if(!restOfParagraph.empty()){ list aNewList; - aNewList = parse(placement, restOfParagraph); + aNewList = parse(endOfParagraph, tokList); aNewList.push_front(DoxygenEntity("plainstring", name)); doxyList.push_back(DoxygenEntity(theCommand, aNewList)); - return 1; - } - else cout << "No paragraph followed " << theCommand << " command. Not added" << endl; return 0; } /* CommandWordLine @@ -971,40 +514,37 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands such as param * "page", "subsection", "subsubsection", "section", "paragraph", "defgroup" */ - int addCommandWordLine(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandWordLine(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); if (name.empty()){ cout << "No word followed " << theCommand << " command. Not added" << endl; return 0; } - string restOfLine = getStringTilEndOfParagraph(startInd, doxygenString); - int placement = 0; - if(!restOfLine.empty()){ - list aNewList; - aNewList = parse(placement, restOfLine); - aNewList.push_front(DoxygenEntity("plainstring", name)); - doxyList.push_back(DoxygenEntity(theCommand, aNewList)); - return 1; - } - else cout << "No line followed " << theCommand << " command. Not added" << endl; - return 0; + list::iterator endOfLine = getOneLine(tokList); + list aNewList; + aNewList = parse(endOfLine, tokList); + aNewList.push_front(DoxygenEntity("plainstring", name)); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + return 1; + + //else cout << "No line followed " << theCommand << " command. Not added" << endl; } - + /* Command Word Optional Word Optional Word * Format: @command [] [] * Commands such as class * "category", "class", "protocol", "interface", "struct", "union" */ - int addCommandWordOWordOWord(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandWordOWordOWord(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); if (name.empty()){ cout << "No word followed " << theCommand << " command. Not added" << endl; return 0; } - string headerfile = getNextWord(startInd, doxygenString); - string headername = getNextWord(startInd, doxygenString); + string headerfile = getNextWord(tokList); + string headername = getNextWord(tokList); list aNewList; aNewList.push_back(DoxygenEntity("plainstring", name)); if (!headerfile.empty()) aNewList.push_back(DoxygenEntity("plainstring", headerfile)); @@ -1018,12 +558,138 @@ string getStringTilCommand(int &startInd, string doxygenString){ * Commands such as dir * "dir", "file", "cond" */ - int addCommandOWord(string theCommand, int &startInd, list &doxyList, string doxygenString){ + int addCommandOWord(string theCommand, TokenList &tokList, list &doxyList){ if (noisy) cout << "Parsing " << theCommand << endl; - string name = getNextWord(startInd, doxygenString); + string name = getNextWord(tokList); doxyList.push_back(DoxygenEntity(theCommand, name)); return 1; } + + /* Commands that should not be encountered (such as PHP only) + */ + int addCommandErrorThrow(string theCommand, TokenList &tokList, list &doxyList){ + cout << "Encountered :" << theCommand << endl; + cout << "This command should not have been encountered. Behaviour past this may be unpredictable " << endl; + } + + + int addCommandUnique(string theCommand, TokenList &tokList, list &doxyList){ + list aNewList; + if (theCommand.compare("arg") == 0 || theCommand.compare("li") == 0){ + list::iterator endOfSection = getEndOfSection(theCommand, tokList); + list aNewList; + aNewList = parse(endOfSection, tokList); + doxyList.push_back( DoxygenEntity(theCommand, aNewList)); + } + + // \xrefitem "(heading)" "(list title)" {text} + else if (theCommand.compare("xrefitem") == 0){ + //TODO Implement xrefitem + if (noisy) cout << "Not Adding " << theCommand << endl; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + tokList.setIterator(endOfParagraph); + return 1; + } + // \ingroup ( [ ]) + else if (theCommand.compare("ingroup") == 0){ + string name = getNextWord(tokList); + aNewList.push_back(DoxygenEntity("plainstring", name)); + name = getNextWord(tokList); + if(!name.empty()) aNewList.push_back(DoxygenEntity("plainstring", name)); + name = getNextWord(tokList); + if(!name.empty()) aNewList.push_back(DoxygenEntity("plainstring", name)); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + return 1; + } + // \par [(paragraph title)] { paragraph } + else if (theCommand.compare("par") == 0){ + list::iterator endOfLine = getOneLine(tokList); + aNewList = parse(endOfLine, tokList); + list aNewList2; + aNewList2 = parse(endOfLine, tokList); + aNewList.splice(aNewList.end(), aNewList2); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + return 1; + } + // \headerfile [] + else if (theCommand.compare("headerfile") == 0){ + list aNewList; + string name = getNextWord(tokList); + aNewList.push_back(DoxygenEntity("plainstring", name)); + name = getNextWord(tokList); + if(!name.empty()) aNewList.push_back(DoxygenEntity("plainstring", name)); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + return 1; + } + // \overload [(function declaration)] + else if (theCommand.compare("overload") == 0){ + list::iterator endOfLine = getOneLine(tokList); + if (endOfLine != tokList.current()){ + list aNewList; + aNewList = parse(endOfLine, tokList); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + } + else doxyList.push_back(DoxygenEntity(theCommand)); + } + // \weakgroup [(title)] + else if (theCommand.compare("weakgroup") == 0){ + if (noisy) cout << "Parsing " << theCommand << endl; + string name = getNextWord(tokList); + if (name.empty()){ + cout << "No word followed " << theCommand << " command. Not added" << endl; + return 0; + } + list aNewList; + list::iterator endOfLine = getOneLine(tokList); + if (endOfLine != tokList.current()) { + aNewList = parse(endOfLine, tokList); + } + aNewList.push_front(DoxygenEntity("plainstring", name)); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + } + // \ref ["(text)"] + else if (theCommand.compare("ref") == 0){ + //TODO Implement ref + if (noisy) cout << "Not Adding " << theCommand << endl; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + tokList.setIterator(endOfParagraph); + } + // \subpage ["(text)"] + else if (theCommand.compare("subpage") == 0){ + //TODO implement subpage + if (noisy) cout << "Not Adding " << theCommand << endl; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + tokList.setIterator(endOfParagraph); + } + // \dotfile ["caption"] + else if (theCommand.compare("dotfile") == 0){ + //TODO implement dotfile + if (noisy) cout << "Not Adding " << theCommand << endl; + list::iterator endOfParagraph = getEndOfParagraph(tokList); + tokList.setIterator(endOfParagraph); + } + // \image ["caption"] [=] + else if (theCommand.compare("image") == 0){ + //todo implement image + } + // \addtogroup [(title)] + else if (theCommand.compare("addtogroup") == 0){ + if (noisy) cout << "Parsing " << theCommand << endl; + string name = getNextWord(tokList); + if (name.empty()){ + cout << "No word followed " << theCommand << " command. Not added" << endl; + return 0; + } + list aNewList; + list::iterator endOfLine = getOneLine(tokList); + if (endOfLine != tokList.current()) { + aNewList = parse(endOfLine, tokList); + } + aNewList.push_front(DoxygenEntity("plainstring", name)); + doxyList.push_back(DoxygenEntity(theCommand, aNewList)); + } + + } /* The actual "meat" of the doxygen parser. This is not yet fully implemented * with my current design- however the skeletal outline is contained in @@ -1031,121 +697,111 @@ string getStringTilCommand(int &startInd, string doxygenString){ */ - int addCommand(string commandString, int &startInd, list &doxyList, string doxygenString){ + int addCommand(string commandString, TokenList &tokList,list &doxyList){ string theCommand = StringToLower(commandString); - string voidArray[] = {""}; - /* @command */ - - + if (theCommand.compare("plainstring") == 0){ - string nextPhrase = getStringTilCommand(startInd, doxygenString); + string nextPhrase = getStringTilCommand( tokList); if (noisy) cout << "Parsing plain string :" << nextPhrase << endl; doxyList.push_back(DoxygenEntity("plainstring", nextPhrase )); return 1; } int commandNumber = commandBelongs(theCommand); - if (commandNumber == 1){ - return addSimpleCommand(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == SIMPLECOMMAND){ + return addSimpleCommand(theCommand, doxyList); } - if (commandNumber == 2){ - return ignoreSimpleCommand(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == IGNOREDSIMPLECOMMAND){ + return ignoreSimpleCommand(theCommand, doxyList); } - if (commandNumber == 3){ - return addCommandWord(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDWORD){ + return addCommandWord(theCommand, tokList, doxyList); } - if (commandNumber == 4){ - return ignoreCommandWord(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == IGNOREDCOMMANDWORD){ + return ignoreCommandWord(theCommand, tokList, doxyList); } - if (commandNumber == 5){ - return addCommandLine(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDLINE ){ + return addCommandLine(theCommand, tokList, doxyList); } - if (commandNumber == 6){ - return ignoreCommandLine(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == IGNOREDCOMMANDLINE ){ + return ignoreCommandLine(theCommand, tokList, doxyList); } - if (commandNumber == 7){ - return addCommandParagraph(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDPARAGRAPH){ + return addCommandParagraph(theCommand, tokList, doxyList); } - if (commandNumber == 8){ - return ignoreCommandParagraph(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == IGNORECOMMANDPARAGRAPH){ + return ignoreCommandParagraph(theCommand, tokList, doxyList); } - if (commandNumber == 9){ - return ignoreCommandEndCommand(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDENDCOMMAND){ + return addCommandEndCommand(theCommand, tokList, doxyList); } - if (commandNumber == 10){ - return addCommandWordParagraph(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDWORDPARAGRAPH){ + return addCommandWordParagraph(theCommand, tokList, doxyList); } - if (commandNumber == 11){ - return addCommandWordLine(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDWORDLINE){ + return addCommandWordLine(theCommand, tokList, doxyList); } - if (commandNumber == 12){ - return addCommandWordOWordOWord(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDWORDOWORDWORD){ + return addCommandWordOWordOWord(theCommand, tokList, doxyList); } - if (commandNumber == 13){ - return addCommandOWord(theCommand, startInd,doxyList, doxygenString); + if (commandNumber == COMMANDOWORD){ + return addCommandOWord(theCommand, tokList, doxyList); } - if (commandNumber == 14){ - return 0; + if (commandNumber == COMMANDERRORTHROW){ + return addCommandErrorThrow(theCommand, tokList, doxyList); } - if (commandNumber == 15){ - return 0; + if (commandNumber == COMMANDUNIQUE){ + return addCommandUnique(theCommand, tokList, doxyList); } return 0; } - int weirdTest(){ - string doxygenString = "this is a test."; - string restOfParagraph; - int startIndex = 0; - restOfParagraph = getStringTilEndOfParagraph(startIndex , doxygenString); - cout << restOfParagraph<< " " << startIndex << endl; - - startIndex = 0; - restOfParagraph = getStringTilCommand(startIndex, doxygenString); - cout << restOfParagraph<< " " << startIndex << endl; - } - + list parse(list::iterator endParsingIndex, TokenList &tokList){ + list aNewList; + int currCommand; + while (tokList.current() != endParsingIndex){ + Token currToken = tokList.peek(); + if(noisy) cout << "Parsing for phrase starting in:" << currToken.toString() << endl; + if(currToken.tokenType == END_LINE ){ + tokList.next(); + } + else if(currToken.tokenType == COMMAND){ + currCommand = findCommand(currToken.tokenString); + tokList.next(); + if (currCommand < 0 ){ if(noisy) cout << "BAD COMMAND: " << currToken.tokenString << endl;} + //cout << "Command: " << currWord << " " << currCommand << endl; + else addCommand(currToken.tokenString, tokList, aNewList); + } + else if (currToken.tokenType == PLAINSTRING){ + addCommand(string("plainstring"), tokList, aNewList); + } - int doRunExamples(){ - string line; - string filename; - string exampleNames[] = {"Examples/Example1","Examples/Example2", "Examples/Example3", "Examples/Example4", "Examples/Example5"}; - int placement; - string doxygenString; - ifstream doxCommentFile; - for (int i = 0; i < 5; i++){ - doxCommentFile.open(exampleNames[i].c_str()); - doxCommentFile >> doxygenString; - while(getline(doxCommentFile, line)){ - doxygenString += line + "\n";} - doxCommentFile.close(); - placement = 0; - cout << "---RAW CODE---" << endl << doxygenString << endl< convert(string doxygenBlob){ + TokenList tokList = TokenList(doxygenBlob); + if(noisy) { + cout << "---TOKEN LIST---" << endl; + tokList.printList(); + } + list rootList; + rootList = parse( tokList.end(), tokList); + cout << "PARSED LIST" << endl; + printTree(rootList); + return rootList; + } + +int main(int argc, char *argv[]){ + string doxygenString1 = "//! A normal member taking two arguments and returning an integer value.\n/*!\n \\param a an \\b integer argument. \\param s a constant character pointer\n\n\n\n \\return The test results\n \\sa Test(), ~Test(), testMeToo() and publicVar()\n */"; + list rootList = convert(doxygenString1); + JavaDocConverter jDC = JavaDocConverter(); + jDC.convertToJavaDoc(rootList); + return 1; +} + + diff --git a/Source/DoxygenTranslator/JavaDocConverter.cpp b/Source/DoxygenTranslator/JavaDocConverter.cpp new file mode 100644 index 000000000..4e6fd93e6 --- /dev/null +++ b/Source/DoxygenTranslator/JavaDocConverter.cpp @@ -0,0 +1,104 @@ +#include "JavaDocConverter.h" +#include +#include +#include +#include + +int printTree = 1; +JavaDocConverter::JavaDocConverter() +{ +} + +JavaDocConverter::~JavaDocConverter() +{ +} + +/* Sorts entities by javaDoc standard order for commands + * NOTE: will not behave entirely properly until "First level" comments + * such as brief descriptions are TAGGED as such + */ +bool compare_DoxygenEntities(DoxygenEntity first, DoxygenEntity second){ + if(first.typeOfEntity.compare("plainstring") == 0) return true; + if(second.typeOfEntity.compare("plainstring") == 0) return false; + if(first.typeOfEntity.compare("param") == 0){ + if(second.typeOfEntity.compare("param")== 0) return true; + if(second.typeOfEntity.compare("return")== 0) return true; + if(second.typeOfEntity.compare("exception")== 0) return true; + if(second.typeOfEntity.compare("author")== 0) return true; + if(second.typeOfEntity.compare("version")== 0)return true; + if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("since")== 0)return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("return")== 0){ + if(second.typeOfEntity.compare("return")== 0) return true; + if(second.typeOfEntity.compare("exception")== 0) return true; + if(second.typeOfEntity.compare("author")== 0) return true; + if(second.typeOfEntity.compare("version")== 0)return true; + if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("since")== 0)return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + + } + if(first.typeOfEntity.compare("exception")== 0){ + if(second.typeOfEntity.compare("exception")== 0) return true; + if(second.typeOfEntity.compare("author")== 0) return true; + if(second.typeOfEntity.compare("version")== 0)return true; + if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("since")== 0)return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("author")== 0){ + if(first.typeOfEntity.compare("author")== 0) return true; + if(first.typeOfEntity.compare("version")== 0)return true; + if(first.typeOfEntity.compare("see")== 0)return true; + if(first.typeOfEntity.compare("since")== 0)return true; + if(first.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("version")== 0){ + if(second.typeOfEntity.compare("version")== 0)return true; + if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("since")== 0)return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("see")== 0){ + if(second.typeOfEntity.compare("see")== 0)return true; + if(second.typeOfEntity.compare("since")== 0)return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("since")== 0){ + if(second.typeOfEntity.compare("since")== 0) return true; + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + if(first.typeOfEntity.compare("deprecated")== 0){ + if(second.typeOfEntity.compare("deprecated")== 0)return true; + return false; + } + return true; +} + +string JavaDocConverter:: convertToJavaDoc(list entityList){ + + list::iterator entityIterator = entityList.begin(); + entityList.sort(compare_DoxygenEntities); + + cout << "---RESORTED LIST---" << endl; + if (printTree ){ + list::iterator p = entityList.begin(); + while (p != entityList.end()){ + (*p).printEntity(0); + p++; + } + } + string javaDocString = "/**\n"; + + javaDocString += "*/\n"; + return javaDocString; +} diff --git a/Source/DoxygenTranslator/JavaDocConverter.h b/Source/DoxygenTranslator/JavaDocConverter.h new file mode 100644 index 000000000..b1c76ef17 --- /dev/null +++ b/Source/DoxygenTranslator/JavaDocConverter.h @@ -0,0 +1,17 @@ + #include + #include + #include "DoxygenEntity.h" + +#ifndef JAVADOCCONVERTER_H_ +#define JAVADOCCONVERTER_H_ + +class JavaDocConverter +{ +public: + + JavaDocConverter(); + string convertToJavaDoc(list entityList); + ~JavaDocConverter(); +}; + +#endif /*JAVADOCCONVERTER_H_*/ diff --git a/Source/DoxygenTranslator/Token.h b/Source/DoxygenTranslator/Token.h index d569f5f7b..e98686c14 100644 --- a/Source/DoxygenTranslator/Token.h +++ b/Source/DoxygenTranslator/Token.h @@ -13,8 +13,8 @@ class Token public: Token(int tType, string tString); ~Token(); - int tokenType; - string tokenString; + int tokenType; /* currently can be END_LINE, PLAINSTRING, or COMMAND */ + string tokenString; /* the data , such as param for @param*/ string toString(); }; diff --git a/Source/DoxygenTranslator/TokenList.cpp b/Source/DoxygenTranslator/TokenList.cpp index 6122328c4..0ace41c34 100644 --- a/Source/DoxygenTranslator/TokenList.cpp +++ b/Source/DoxygenTranslator/TokenList.cpp @@ -67,11 +67,8 @@ TokenList::TokenList(string doxygenString){ } Token TokenList::peek(){ - list::iterator p = tokenList.begin(); - if(p != tokenList.end()){ - p++; - Token returnedToken = (*p); - p--; + if(tokenListIterator!= tokenList.end()){ + Token returnedToken = (*tokenListIterator); return returnedToken; } else @@ -79,15 +76,22 @@ Token TokenList::peek(){ } Token TokenList::next(){ - list::iterator p = tokenList.begin(); - if(p != tokenList.end()){ - p++; - return (*p); + if(tokenListIterator != tokenList.end()){ + Token returnedToken = (*tokenListIterator); + tokenListIterator++; + return (returnedToken); } else return Token(0, ""); } +list::iterator TokenList::end(){ + return tokenList.end(); +} + +list::iterator TokenList::current(){ + return tokenListIterator; +} void TokenList::printList(){ list::iterator p = tokenList.begin(); int i = 1; @@ -100,4 +104,11 @@ void TokenList::printList(){ } } -TokenList:: ~TokenList(){} \ No newline at end of file +list::iterator TokenList::iteratorCopy(){ + list::iterator p = tokenListIterator; + return p; +} +void TokenList::setIterator(list::iterator newPosition){ + tokenListIterator = newPosition; +} +TokenList:: ~TokenList(){} diff --git a/Source/DoxygenTranslator/TokenList.h b/Source/DoxygenTranslator/TokenList.h index 153c69163..cc61f56e4 100644 --- a/Source/DoxygenTranslator/TokenList.h +++ b/Source/DoxygenTranslator/TokenList.h @@ -13,12 +13,15 @@ using namespace std; class TokenList{ public: - /* constructor takes a blob of Doxygen comment */ - TokenList(string doxygenString); + TokenList(string doxygenString); /* constructor takes a blob of Doxygen comment */ ~TokenList(); Token peek(); /* returns next token without advancing */ Token next(); /* returns next token and advances */ + list::iterator end(); /* returns an end iterator */ + list::iterator current(); /* returns the current iterator */ void printList(); /* prints out the sequence of tokens */ + list::iterator iteratorCopy(); /* returns a copy of the current iterator */ + void setIterator(list::iterator newPosition); /*moves up the iterator*/ }; #endif /*TOKENLIST_H_*/