Changed quoted strings handling. Also not missing any doxygen commands now.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13563 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dmitry Kabak 2012-08-08 14:16:48 +00:00
commit 342bff6ec9
3 changed files with 52 additions and 48 deletions

View file

@ -21,7 +21,7 @@ check(doxygen_translate_all_tags.function.__doc__, ''
''
' SomeLatexIndex '
''
' someGroupSome title '
' someGroup"Some title" '
''
' theAnchor'
''
@ -84,8 +84,8 @@ check(doxygen_translate_all_tags.function.__doc__, ''
' digraph example { '
' node [shape=record, fontname=Helvetica, fontsize=10]; '
''
' b [ label="class B" URL="\ref B"]; '
' c [ label="class C" URL="\ref C"]; '
' b [ label="class B" URL=" B"]; '
' c [ label="class C" URL=" C"]; '
' b -> c [ arrowhead="open", style="dashed" ]; '
' } '
''
@ -171,9 +171,9 @@ check(doxygen_translate_all_tags.function.__doc__, ''
' someThing'
''
' Sender,Receiver; '
' Sender->Receiver [label="Command()", URL="\ref '
' Sender->Receiver [label="Command()", URL=" '
' Receiver::Command()"]; '
' Sender<-Receiver [label="Ack()", URL="\ref '
' Sender<-Receiver [label="Ack()", URL=" '
' Ack()", ID="1"]; '
''
' mscFile.mscThe caption'
@ -312,9 +312,10 @@ check(doxygen_translate_all_tags.function.__doc__, ''
''
' This will only appear in XML '
''
' todo"Todo"Todo List'
''
' Here goes test of symbols: '
' $@\&~<>#%".::'
''
' And here goes simple text '
)
)

View file

@ -106,7 +106,23 @@ int DoxygenParser::commandBelongs(std::string theCommand) {
std::string DoxygenParser::getNextWord(TokenList & tokList) {
Token nextToken = tokList.peek();
if (nextToken.tokenType == PLAINSTRING) {
nextToken = tokList.next();
// handle quoted strings as words
if (nextToken.tokenString[0] == '"'
&& nextToken.tokenString[nextToken.tokenString.size() - 1] != '"') {
string word = nextToken.tokenString + " ";
nextToken = tokList.next();
while (true) {
string nextWord = getNextWord(tokList);
if (!nextWord.size()) // maybe report unterminated string error
return word;
word += nextWord;
if (word[word.size() - 1] == '"') // strip quotes
return word.substr(1, word.size() - 2);
word += " ";
}
}
tokList.next();
return nextToken.tokenString;
}
return "";
@ -120,7 +136,6 @@ std::list < Token >::iterator DoxygenParser::getOneLine(TokenList & tokList) {
//endOfLine++;
return endOfLine;
}
//cout << (* endOfLine).toString();
endOfLine++;
}
@ -390,6 +405,7 @@ int DoxygenParser::addCommandUnique(std::string theCommand, TokenList & tokList,
aNewList.push_front(DoxygenEntity("plainstd::string", title));
aNewList.push_front(DoxygenEntity("plainstd::string", heading));
aNewList.push_front(DoxygenEntity("plainstd::string", key));
doxyList.push_back(DoxygenEntity(theCommand, aNewList));
return 1;
}
// \ingroup (<groupname> [<groupname> <groupname>])

View file

@ -28,57 +28,44 @@ TokenList TokenList::tokenizeDoxygenComment(const std::string &doxygenComment, c
bool isPlainString = false;
string::size_type pos, lastPos = 0;
char prevChar = doxygenComment[lastPos];
string currentWord;
while (true) {
isPlainString = false;
pos = doxygenComment.find_first_of("\t\n ", lastPos);
pos = doxygenComment.find_first_of("\\@\t\n ", lastPos);
if (pos == string::npos)
pos = doxygenComment.size();
if (pos > lastPos) {
currentWord = doxygenComment.substr(lastPos, pos-lastPos);
if (currentWord[0] == '\\' || currentWord[0] == '@') {
// it's a doxygen command
currentWord = currentWord.substr(1, currentWord.length() - 1);
tokList.m_tokenList.push_back(Token(COMMAND, currentWord));
}
else if (currentWord[0] == '!' || currentWord[0] == '*' || currentWord[0] == '/') {
// check if it's one of the '!!!', '***', '///' of any length
char c = currentWord[0];
isPlainString = false;
for (size_t i=0; i<currentWord.size(); i++)
if (currentWord[i] != c) {
isPlainString = true;
break;
}
}
else
isPlainString = true;
if (isPlainString) {
// handle quoted words
if (currentWord[0] == '"') {
pos = doxygenComment.find_first_of("\"\n", lastPos + 1);
if (pos == string::npos)
pos = doxygenComment.size();
if (pos == doxygenComment.size() || doxygenComment[pos] != '"') {
// hack to print error message before the list is constructed
tokList.m_tokenListIter = tokList.m_tokenList.end();
tokList.printListError("Unterminated string");
}
// also strip quotes
currentWord = doxygenComment.substr(lastPos + 1, pos-lastPos-1);
}
if (currentWord.size())
tokList.m_tokenList.push_back(Token(PLAINSTRING, currentWord));
}
currentWord = doxygenComment.substr(lastPos, pos-lastPos);
if (prevChar == '\n')
tokList.m_tokenList.push_back(Token(END_LINE, "\n"));
else if (prevChar == '\\' || prevChar == '@') {
// it's a doxygen command
// hack to get commands like \\ or \@ or @\ or @@
if (doxygenComment[pos] == '@' || doxygenComment[pos] == '\\')
currentWord += doxygenComment[pos];
tokList.m_tokenList.push_back(Token(COMMAND, currentWord));
}
else if (currentWord.size() && (currentWord[0] == '!' || currentWord[0] == '*' || currentWord[0] == '/')) {
// check if it's one of the '!!!', '***', '///' of any length
char c = currentWord[0];
isPlainString = false;
for (size_t i=0; i<currentWord.size(); i++)
if (currentWord[i] != c) {
isPlainString = true;
break;
}
}
else
isPlainString = true;
if (isPlainString && currentWord.size())
tokList.m_tokenList.push_back(Token(PLAINSTRING, currentWord));
prevChar = doxygenComment[pos];
lastPos = pos + 1;
if (lastPos >= doxygenComment.size())
break;
if (doxygenComment[pos] == '\n')
tokList.m_tokenList.push_back(Token(END_LINE, "\n"));
}
tokList.m_tokenListIter = tokList.m_tokenList.begin();
return tokList;