refactored DoxygenParser: class Token is now nested in Doxygen parser because it is only used there, class TokenList has been removed - it more or less duplicated std::list, other code moved to DoxygenParser

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13722 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marko Klopcic 2012-08-26 13:00:52 +00:00
commit ed6df45c0a
8 changed files with 521 additions and 214 deletions

View file

@ -16,80 +16,128 @@
#include <map>
#include <set>
#include "DoxygenEntity.h"
#include "TokenList.h"
class DoxygenParser {
public:
DoxygenParser(bool noisy = false);
virtual ~DoxygenParser();
std::list < DoxygenEntity > createTree(std::string doxygen, std::string fileName, int lineNumber);
private:
/** This class contains parts of Doxygen comment as a token. */
class Token {
public:
// typedef enum {COMMAND, PLAINSTRING, END_LINE, PARAGRAPH_END} ETokenType;
DoxyCommandEnum m_tokenType;
std::string m_tokenString; /* the data , such as param for @param */
Token(DoxyCommandEnum tType, std::string tString) :
m_tokenType(tType),
m_tokenString(tString) {}
std::string toString() const {
switch (m_tokenType) {
case END_LINE:
return "{END OF LINE}";
case PARAGRAPH_END:
return "{END OF PARAGRAPH}";
case PLAINSTRING:
return "{PLAINSTRING :" + m_tokenString + "}";
case COMMAND:
return "{COMMAND : " + m_tokenString + "}";
default:
return "";
}
}
};
typedef std::list<Token> TokenList;
typedef TokenList::const_iterator TokenListCIt;
typedef TokenList::iterator TokenListIt;
TokenList m_tokenList;
TokenListCIt m_tokenListIt;
std::string m_fileName;
int m_fileLineNo;
/*
* Whether to print lots of debug info during parsing
*/
bool noisy;
/*
* Map of Doxygen commands to determine if a string is a
* command and how it needs to be parsed
*/
static std::map<std::string, DoxyCommandEnum> doxygenCommands;
static std::set<std::string> doxygenSectionIndicators;
/*
*Changes a std::string to all lower case
*/
std::string stringToLower(std::string &stringToConvert);
std::string stringToLower(const std::string &stringToConvert);
/*
* Finds out if a command exists (is a possible command)
* returns -1 if no match is found
*/
int findCommand(std::string smallString);
bool findCommand(const std::string &smallString);
/*
* isSectionIndicator returns a boolean if the command is a section indicator
* This is a helper method for finding the end of a paragraph
* by Doxygen's terms
*/
int isSectionIndicator(std::string smallString);
bool isSectionIndicator(const std::string &smallString);
/*
* Determines how a command should be handled (what group it belongs to
* for parsing rules
*/
int commandBelongs(std::string theCommand);
int commandBelongs(const std::string &theCommand);
/*
*prints the parse tree
*/
void printTree(std::list < DoxygenEntity > &rootList);
void printTree(const std::list <DoxygenEntity> &rootList);
/*
* Returns the next word ON THE CURRENT LINE ONLY
* if a new line is encountered, returns a blank std::string.
* Updates the index it is given if success.
*/
std::string getNextWord(TokenList & tokList);
std::string getNextWord(const TokenList &tokList);
/*
* Returns the location of the end of the line as
* an iterator.
*/
std::list < Token >::iterator getOneLine(TokenList & tokList);
TokenListCIt getOneLine(const TokenList &tokList);
/*
* Returns a properly formatted std::string
* up til ANY command or end of line is encountered.
*/
std::string getStringTilCommand(TokenList & tokList);
std::string getStringTilCommand(const TokenList &tokList);
/*
* Returns a properly formatted std::string
* up til the command specified is encountered
*/
//TODO check that this behaves properly for formulas
std::string getStringTilEndCommand(std::string theCommand, TokenList & tokList);
std::string getStringTilEndCommand(const std::string &theCommand,
const TokenList &tokList);
/*
* Returns the end of a Paragraph as an iterator-
* Paragraph is defined in Doxygen to be a paragraph of text
* separated by either a structural command or a blank line
*/
std::list < Token >::iterator getEndOfParagraph(TokenList & tokList);
TokenListCIt getEndOfParagraph(const TokenList &tokList);
/*
* 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
* if no end is encountered, returns the last token of the std::list.
*/
std::list < Token >::iterator getEndOfSection(std::string theCommand, TokenList & tokList);
TokenListCIt getEndOfSection(const std::string &theCommand,
const TokenList &tokList);
/*
* This method is for returning the end of a specific form of doxygen command
@ -98,12 +146,14 @@ private:
* progressTilEndCommand("endcode", tokenList);
* If the end is never encountered, it returns the end of the std::list.
*/
std::list < Token >::iterator getEndCommand(std::string theCommand, TokenList & tokList);
TokenListCIt getEndCommand(const std::string &theCommand,
const TokenList &tokList);
/*
* A specialty method for commands such as \arg that end at the end of a paragraph OR when another \arg is encountered
*/
//TODO getTilAnyCommand
std::list < Token >::iterator getTilAnyCommand(std::string theCommand, TokenList & tokList);
TokenListCIt getTilAnyCommand(const std::string &theCommand,
const TokenList &tokList);
*/
/*
* Method for Adding a Simple Command
@ -111,7 +161,8 @@ private:
* Plain commands, such as newline etc, they contain no other data
* \n \\ \@ \& \$ \# \< \> \%
*/
int addSimpleCommand(std::string theCommand, std::list < DoxygenEntity > &doxyList);
int addSimpleCommand(const std::string &theCommand,
std::list < DoxygenEntity > &doxyList);
/*
* CommandWord
* Format: @command <word>
@ -119,14 +170,18 @@ private:
* "a", "b", "c", "e", "em", "p", "def", "enum", "example", "package",
* "relates", "namespace", "relatesalso","anchor", "dontinclude", "include", "includelineno"
*/
int addCommandWord(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandWord(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* CommandLine
* Format: @command (line)
* Commands with a single LINE after then such as @var
* "addindex", "fn", "name", "line", "var", "skipline", "typedef", "skip", "until", "property"
*/
int addCommandLine(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandLine(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* CommandParagraph
* Format: @command {paragraph}
@ -134,7 +189,9 @@ private:
* "return", "remarks", "since", "test", "sa", "see", "pre", "post", "details", "invariant",
* "deprecated", "date", "note", "warning", "version", "todo", "bug", "attention", "brief", "arg", "author"
*/
int addCommandParagraph(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandParagraph(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* Command EndCommand
* Format: @command and ends at @endcommand
@ -143,68 +200,83 @@ private:
* "verbatim", "xmlonly", "cond", "if", "ifnot", "link"
* Returns 1 if success, 0 if the endcommand is never encountered.
*/
int addCommandEndCommand(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandEndCommand(const std::string &theCommand,
const TokenList & tokList,
std::list < DoxygenEntity > &doxyList);
/*
* CommandWordParagraph
* Format: @command <word> {paragraph}
* Commands such as param
* "param", "tparam", "throw", "throws", "retval", "exception"
*/
int addCommandWordParagraph(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandWordParagraph(const std::string &theCommand,
const TokenList & tokList,
std::list < DoxygenEntity > &doxyList);
/*
* CommandWordLine
* Format: @command <word> (line)
* Commands such as param
* "page", "subsection", "subsubsection", "section", "paragraph", "defgroup"
*/
int addCommandWordLine(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandWordLine(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* Command Word Optional Word Optional Word
* Format: @command <word> [<header-file>] [<header-name>]
* Commands such as class
* "category", "class", "protocol", "interface", "struct", "union"
*/
int addCommandWordOWordOWord(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandWordOWordOWord(const std::string &theCommand, const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* Command Optional Word
* Format: @command [<word>]
* Commands such as dir
* "dir", "file", "cond"
*/
int addCommandOWord(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandOWord(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
* Commands that should not be encountered (such as PHP only)
* goes til the end of line then returns
*/
int addCommandErrorThrow(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandErrorThrow(const std::string &theCommand,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
/*
*Adds the unique commands- different process for each unique command
*/
int addCommandUnique(std::string theCommand, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommandUnique(const std::string &theCommand, const TokenList &tokList, std::list < DoxygenEntity > &doxyList);
/*
* The actual "meat" of the doxygen parser. Calls the correct addCommand* function
*/
int addCommand(std::string commandString, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
int addCommand(const std::string &commandString,
const TokenList &tokList,
std::list < DoxygenEntity > &doxyList);
std::list < DoxygenEntity > parse(std::list < Token >::iterator endParsingIndex, TokenList & tokList, bool root=false);
std::list < DoxygenEntity > parse(TokenListCIt endParsingIndex,
const TokenList &tokList,
bool root = false);
/*
* Fill static doxygenCommands and sectionIndicators containers
*/
void fillTables();
/*
* Whether to print lots of debug info during parsing
*/
bool noisy;
/*
* Map of Doxygen commands to determine if a string is a
* command and how it needs to be parsed
*/
static std::map<std::string, DoxyCommandEnum> doxygenCommands;
static std::set<std::string> doxygenSectionIndicators;
TokenList tokenizeDoxygenComment(const std::string &doxygenComment,
const std::string &fileName,
int fileLine);
void printList();
void printListError(int warningType, const std::string &message);
public:
DoxygenParser(bool noisy = false);
virtual ~DoxygenParser();
std::list < DoxygenEntity > createTree(const std::string &doxygen,
const std::string &fileName,
int lineNumber);
};
#endif