Small JavaDoc converter and doxygen parser improvements, now basic tags working
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2012-doxygen@13263 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
293c5cfc1f
commit
509cbd72b0
4 changed files with 543 additions and 578 deletions
|
|
@ -12,14 +12,12 @@
|
||||||
#include "DoxygenParser.h"
|
#include "DoxygenParser.h"
|
||||||
#include "DoxygenCommands.h"
|
#include "DoxygenCommands.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// Define static class members
|
// Define static class members
|
||||||
std::map<std::string, DoxyCommandEnum> DoxygenParser::doxygenCommands;
|
std::map<std::string, DoxyCommandEnum> DoxygenParser::doxygenCommands;
|
||||||
std::set<std::string> DoxygenParser::doxygenSectionIndicators;
|
std::set<std::string> DoxygenParser::doxygenSectionIndicators;
|
||||||
|
|
||||||
|
|
||||||
DoxygenParser::DoxygenParser() : noisy(false) {
|
DoxygenParser::DoxygenParser() : noisy(true) {
|
||||||
fillTables();
|
fillTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -579,7 +577,9 @@ int DoxygenParser::addCommand(std::string commandString, TokenList & tokList, st
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list < DoxygenEntity > DoxygenParser::parse(std::list < Token >::iterator endParsingIndex, TokenList & tokList) {
|
std::list < DoxygenEntity > DoxygenParser::parse(std::list < Token >::iterator endParsingIndex, TokenList & tokList, bool root) {
|
||||||
|
// if we are root, than any strings should be added as 'partofdescription', else as 'plainstd::string'
|
||||||
|
std::string currPlainstringCommandType = root ? "partofdescription" : "plainstd::string";
|
||||||
std::list < DoxygenEntity > aNewList;
|
std::list < DoxygenEntity > aNewList;
|
||||||
int currCommand;
|
int currCommand;
|
||||||
while (tokList.current() != endParsingIndex) {
|
while (tokList.current() != endParsingIndex) {
|
||||||
|
|
@ -594,47 +594,13 @@ std::list < DoxygenEntity > DoxygenParser::parse(std::list < Token >::iterator e
|
||||||
if (noisy)
|
if (noisy)
|
||||||
cout << "Unidentified Command " << currToken.tokenString << endl;
|
cout << "Unidentified Command " << currToken.tokenString << endl;
|
||||||
tokList.next();
|
tokList.next();
|
||||||
addCommand(std::string("plainstd::string"), tokList, aNewList);
|
addCommand(currPlainstringCommandType, tokList, aNewList);
|
||||||
} else {
|
} else {
|
||||||
tokList.next();
|
tokList.next();
|
||||||
addCommand(currToken.tokenString, tokList, aNewList);
|
addCommand(currToken.tokenString, tokList, aNewList);
|
||||||
}
|
}
|
||||||
} else if (currToken.tokenType == PLAINSTRING) {
|
} else if (currToken.tokenType == PLAINSTRING) {
|
||||||
addCommand(std::string("plainstd::string"), tokList, aNewList);
|
addCommand(currPlainstringCommandType, tokList, aNewList);
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return aNewList;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list < DoxygenEntity > DoxygenParser::parseRoot(std::list < Token >::iterator endParsingIndex, TokenList & tokList) {
|
|
||||||
|
|
||||||
std::list < DoxygenEntity > 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);
|
|
||||||
if (currCommand < 0) {
|
|
||||||
if (noisy) {
|
|
||||||
cout << "Unidentified Command " << currToken.tokenString << endl;
|
|
||||||
}
|
|
||||||
tokList.next();
|
|
||||||
addCommand(std::string("partofdescription"), tokList, aNewList);
|
|
||||||
} else {
|
|
||||||
tokList.next();
|
|
||||||
addCommand(currToken.tokenString, tokList, aNewList);
|
|
||||||
}
|
|
||||||
} else if (currToken.tokenType == PLAINSTRING) {
|
|
||||||
addCommand(std::string("partofdescription"), tokList, aNewList);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return aNewList;
|
return aNewList;
|
||||||
|
|
@ -647,7 +613,7 @@ std::list < DoxygenEntity > DoxygenParser::createTree(std::string doxygenBlob) {
|
||||||
tokList.printList();
|
tokList.printList();
|
||||||
}
|
}
|
||||||
std::list < DoxygenEntity > rootList;
|
std::list < DoxygenEntity > rootList;
|
||||||
rootList = parseRoot(tokList.end(), tokList);
|
rootList = parse(tokList.end(), tokList, true);
|
||||||
if (noisy) {
|
if (noisy) {
|
||||||
cout << "PARSED LIST" << endl;
|
cout << "PARSED LIST" << endl;
|
||||||
printTree(rootList);
|
printTree(rootList);
|
||||||
|
|
|
||||||
|
|
@ -213,8 +213,7 @@ private:
|
||||||
*/
|
*/
|
||||||
int addCommand(std::string commandString, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
|
int addCommand(std::string commandString, TokenList & tokList, std::list < DoxygenEntity > &doxyList);
|
||||||
|
|
||||||
std::list < DoxygenEntity > parse(std::list < Token >::iterator endParsingIndex, TokenList & tokList);
|
std::list < DoxygenEntity > parse(std::list < Token >::iterator endParsingIndex, TokenList & tokList, bool root=false);
|
||||||
std::list < DoxygenEntity > parseRoot(std::list < Token >::iterator endParsingIndex, TokenList & tokList);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill static doxygenCommands and sectionIndicators containers
|
* Fill static doxygenCommands and sectionIndicators containers
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,11 @@
|
||||||
#define TAB_SIZE 8 //current tab size in spaces
|
#define TAB_SIZE 8 //current tab size in spaces
|
||||||
//TODO {@link} {@linkplain} {@docRoot}, and other useful doxy commands that are not a javadoc tag
|
//TODO {@link} {@linkplain} {@docRoot}, and other useful doxy commands that are not a javadoc tag
|
||||||
|
|
||||||
// define static escape table, it is filled in JavaDocConverter's constructor
|
// define static tables, they are filled in JavaDocConverter's constructor
|
||||||
std::map<std::string, std::string> JavaDocConverter::escapeTable;
|
std::map<std::string, std::string> JavaDocConverter::escapeTable;
|
||||||
|
std::map<std::string, JavaDocConverter::tagHandler> JavaDocConverter::tagHandlers;
|
||||||
|
|
||||||
void JavaDocConverter::fillEscapeTable() {
|
void JavaDocConverter::fillStaticTables() {
|
||||||
if (escapeTable.size()) // fill only once
|
if (escapeTable.size()) // fill only once
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
@ -28,17 +29,11 @@ void JavaDocConverter::fillEscapeTable() {
|
||||||
escapeTable["\""] = """;
|
escapeTable["\""] = """;
|
||||||
escapeTable["<"] = "<";
|
escapeTable["<"] = "<";
|
||||||
escapeTable[">"] = ">";
|
escapeTable[">"] = ">";
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
JavaDocConverter::JavaDocConverter() : debug(false) {
|
|
||||||
|
|
||||||
fillEscapeTable();
|
|
||||||
|
|
||||||
// these commands insert HTML tags
|
// these commands insert HTML tags
|
||||||
tagHandlers["c"] = &handleTagC;
|
tagHandlers["c"] = &handleTagC;
|
||||||
tagHandlers["b"] = &handleTagB;
|
tagHandlers["b"] = &handleTagB;
|
||||||
// these commands insert just a single char, all of them need to be escaped
|
// these commands insert just a single char, some of them need to be escaped
|
||||||
tagHandlers["$"] = &handleTagChar;
|
tagHandlers["$"] = &handleTagChar;
|
||||||
tagHandlers["@"] = &handleTagChar;
|
tagHandlers["@"] = &handleTagChar;
|
||||||
tagHandlers["\\"] = &handleTagChar;
|
tagHandlers["\\"] = &handleTagChar;
|
||||||
|
|
@ -52,9 +47,9 @@ JavaDocConverter::JavaDocConverter() : debug(false) {
|
||||||
tagHandlers["."] = &handleTagChar;
|
tagHandlers["."] = &handleTagChar;
|
||||||
tagHandlers["::"] = &handleTagChar;
|
tagHandlers["::"] = &handleTagChar;
|
||||||
// these commands are stripped out
|
// these commands are stripped out
|
||||||
tagHandlers["brief"] = &handleTagStrip;
|
tagHandlers["brief"] = &handleParagraph;
|
||||||
tagHandlers["details"] = &handleTagStrip;
|
tagHandlers["details"] = &handleParagraph;
|
||||||
tagHandlers["partofdescription"] = &handleTagStrip;
|
tagHandlers["partofdescription"] = &handleParagraph;
|
||||||
// these commands are kept as-is, they are supported by JavaDoc
|
// these commands are kept as-is, they are supported by JavaDoc
|
||||||
tagHandlers["sa"] = &handleTagSeeAll;
|
tagHandlers["sa"] = &handleTagSeeAll;
|
||||||
tagHandlers["see"] = &handleTagSame;
|
tagHandlers["see"] = &handleTagSame;
|
||||||
|
|
@ -69,7 +64,12 @@ JavaDocConverter::JavaDocConverter() : debug(false) {
|
||||||
tagHandlers["deprecated"] = &handleTagSame;
|
tagHandlers["deprecated"] = &handleTagSame;
|
||||||
// this command just prints it's contents
|
// this command just prints it's contents
|
||||||
// (it is internal command of swig's parser, contains plain text)
|
// (it is internal command of swig's parser, contains plain text)
|
||||||
tagHandlers["plainstd::string"] = &handleTagData;
|
tagHandlers["plainstd::string"] = &handlePlainString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JavaDocConverter::JavaDocConverter() : debug(false) {
|
||||||
|
fillStaticTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string JavaDocConverter::formatCommand(std::string unformattedLine, int indent) {
|
std::string JavaDocConverter::formatCommand(std::string unformattedLine, int indent) {
|
||||||
|
|
@ -159,10 +159,10 @@ void JavaDocConverter::handleTagChar(JavaDocConverter* converter, DoxygenEntity&
|
||||||
void JavaDocConverter::handleTagSame(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
void JavaDocConverter::handleTagSame(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
||||||
translatedComment += converter->formatCommand(std::string("@" + tag.typeOfEntity + "\t" + converter->translateSubtree(tag)), 2);
|
translatedComment += converter->formatCommand(std::string("@" + tag.typeOfEntity + "\t" + converter->translateSubtree(tag)), 2);
|
||||||
}
|
}
|
||||||
void JavaDocConverter::handleTagStrip(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
void JavaDocConverter::handleParagraph(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
||||||
translatedComment += converter->formatCommand(converter->translateSubtree(tag), 0);
|
translatedComment += converter->formatCommand(converter->translateSubtree(tag), 0);
|
||||||
}
|
}
|
||||||
void JavaDocConverter::handleTagData(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
void JavaDocConverter::handlePlainString(JavaDocConverter* converter, DoxygenEntity& tag, std::string& translatedComment) {
|
||||||
translatedComment += tag.data + " ";
|
translatedComment += tag.data + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,17 +53,17 @@ protected:
|
||||||
/*
|
/*
|
||||||
* Print only the content and strip original tag
|
* Print only the content and strip original tag
|
||||||
*/
|
*/
|
||||||
static void handleTagStrip(JavaDocConverter *converter, DoxygenEntity &tag, std::string &translatedComment);
|
static void handleParagraph(JavaDocConverter *converter, DoxygenEntity &tag, std::string &translatedComment);
|
||||||
/*
|
/*
|
||||||
* Print only data part of code
|
* Print only data part of code
|
||||||
*/
|
*/
|
||||||
static void handleTagData(JavaDocConverter *converter, DoxygenEntity &tag, std::string &translatedComment);
|
static void handlePlainString(JavaDocConverter *converter, DoxygenEntity &tag, std::string &translatedComment);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool debug;
|
bool debug;
|
||||||
std::map<std::string, tagHandler> tagHandlers;
|
static std::map<std::string, tagHandler> tagHandlers;
|
||||||
static std::map<std::string, std::string> escapeTable;
|
static std::map<std::string, std::string> escapeTable;
|
||||||
void fillEscapeTable();
|
void fillStaticTables();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue