summaryrefslogtreecommitdiffstats
path: root/src/commentscan.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/commentscan.l')
-rw-r--r--src/commentscan.l84
1 files changed, 47 insertions, 37 deletions
diff --git a/src/commentscan.l b/src/commentscan.l
index 5a71b14..e636aa6 100644
--- a/src/commentscan.l
+++ b/src/commentscan.l
@@ -148,7 +148,8 @@ enum class CommandSpacing
{
Invisible, // command sets some property but does not appear in the output.
Inline, // command appears inline in the output which can be a brief description.
- Block // command starts a new paragraphs / ends a brief description.
+ Block, // command starts a new paragraphs / ends a brief description.
+ XRef // command is a cross reference (todo, bug, test, xrefitem).
};
struct DocCmdMap
@@ -170,7 +171,7 @@ static const std::map< std::string, DocCmdMap > docCmdMap =
{ "author", { 0, CommandSpacing::Block }},
{ "authors", { 0, CommandSpacing::Block }},
{ "brief", { &handleBrief, CommandSpacing::Invisible }},
- { "bug", { &handleBug, CommandSpacing::Block }},
+ { "bug", { &handleBug, CommandSpacing::XRef }},
{ "callergraph", { &handleCallergraph, CommandSpacing::Invisible }},
{ "callgraph", { &handleCallgraph, CommandSpacing::Invisible }},
{ "category", { &handleCategory, CommandSpacing::Invisible }},
@@ -283,10 +284,10 @@ static const std::map< std::string, DocCmdMap > docCmdMap =
{ "subsection", { &handleSection, CommandSpacing::Block }},
{ "subsubsection", { &handleSection, CommandSpacing::Block }},
{ "tableofcontents", { &handleToc, CommandSpacing::Invisible }},
- { "test", { &handleTest, CommandSpacing::Block }},
+ { "test", { &handleTest, CommandSpacing::XRef }},
{ "throw", { 0, CommandSpacing::Block }},
{ "throws", { 0, CommandSpacing::Block }},
- { "todo", { &handleTodo, CommandSpacing::Block }},
+ { "todo", { &handleTodo, CommandSpacing::XRef }},
{ "tparam", { 0, CommandSpacing::Block }},
{ "typedef", { &handleFn, CommandSpacing::Invisible }},
{ "union", { &handleUnion, CommandSpacing::Invisible }},
@@ -299,7 +300,7 @@ static const std::map< std::string, DocCmdMap > docCmdMap =
{ "weakgroup", { &handleWeakGroup, CommandSpacing::Invisible }},
{ "xmlinclude", { 0, CommandSpacing::Inline }},
{ "xmlonly", { &handleFormatBlock, CommandSpacing::Invisible }},
- { "xrefitem", { &handleXRefItem, CommandSpacing::Block }}
+ { "xrefitem", { &handleXRefItem, CommandSpacing::XRef }}
};
#define YY_NO_INPUT 1
@@ -438,6 +439,8 @@ static void handleGuard(yyscan_t yyscanner,const QCString &expr);
static yy_size_t yyread(yyscan_t yyscanner,char *buf,yy_size_t max_size);
static void addCite(yyscan_t yyscanner);
+#define unput_string(yytext,yyleng) do { for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]); } while(0)
+
//-----------------------------------------------------------------------------
#undef YY_INPUT
@@ -666,6 +669,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
optList = QCStringList::split(',',optStr);
}
auto it = docCmdMap.find(cmdName.data());
+ //printf("lookup command '%s' found=%d\n",cmdName.data(),it!=docCmdMap.end());
if (it!=docCmdMap.end()) // special action is required
{
int i=0;
@@ -871,9 +875,9 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
yyextra->briefEndsAtDot=FALSE;
}
}
-<Comment>\n { // newline
- addOutput(yyscanner,*yytext);
- yyextra->lineNr++;
+<Comment>{DOCNL} { // newline
+ addOutput(yyscanner,yytext);
+ if (*yytext == '\n') yyextra->lineNr++;
}
<Comment>. { // catch-all for anything else
addOutput(yyscanner,*yytext);
@@ -884,7 +888,11 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
<HtmlComment>"--"[!]?">"{B}* { BEGIN( Comment ); }
<HtmlComment>{DOCNL} {
- if (*yytext=='\n') yyextra->lineNr++;
+ if (*yytext=='\n')
+ {
+ addOutput(yyscanner,*yytext);
+ yyextra->lineNr++;
+ }
}
<HtmlComment>[^\\\n\-]+ { // ignore unimportant characters
}
@@ -953,7 +961,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
warn(yyextra->fileName,yyextra->lineNr,
"missing argument after \\enum."
);
- unput('\n');
+ unput_string(yytext,yyleng);
//addOutput(yyscanner,'\n');
//if (*yytext=='\n') yyextra->lineNr++;
BEGIN( Comment );
@@ -976,7 +984,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
"missing argument after "
"\\namespace."
);
- unput('\n');
+ unput_string(yytext,yyleng);
//addOutput(yyscanner,'\n');
//if (*yytext=='\n') yyextra->lineNr++;
BEGIN( Comment );
@@ -999,7 +1007,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
"missing argument after "
"\\package."
);
- unput('\n');
+ unput_string(yytext,yyleng);
//addOutput(yyscanner,'\n');
//if (*yytext=='\n') yyextra->lineNr++;
BEGIN( Comment );
@@ -1037,12 +1045,18 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
);
//addOutput(yyscanner,'\n');
//if (*yytext=='\n') yyextra->lineNr++;
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<ClassDocArg1,CategoryDocArg1>. { // ignore other stuff
}
+<ClassDocArg2>{DOCNL} {
+ //addOutput(yyscanner,'\n');
+ //if (*yytext=='\n') yyextra->lineNr++;
+ unput_string(yytext,yyleng);
+ BEGIN( Comment );
+ }
<ClassDocArg2>{FILE}|"<>" { // second argument; include file
yyextra->current->includeFile = yytext;
BEGIN( ClassDocArg3 );
@@ -1051,12 +1065,6 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
yyextra->lineNr++;
addOutput(yyscanner,'\n');
}
-<ClassDocArg2>{DOCNL} {
- //addOutput(yyscanner,'\n');
- //if (*yytext=='\n') yyextra->lineNr++;
- unput('\n');
- BEGIN( Comment );
- }
<ClassDocArg2>. { // ignore other stuff
}
@@ -1070,7 +1078,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
}
<ClassDocArg3>{DOCNL} {
//if (*yytext=='\n') yyextra->lineNr++;
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<ClassDocArg3>. { // ignore other stuff
@@ -1101,7 +1109,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
);
//addOutput(yyscanner,'\n');
//if (*yytext=='\n') yyextra->lineNr++;
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<GroupDocArg1>. { // ignore other stuff
@@ -1124,7 +1132,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
"\\defgroup %s", yyextra->current->name.data()
);
}
- unput('\n');
+ unput_string(yytext,yyleng);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
BEGIN( Comment );
@@ -1149,7 +1157,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
"missing argument after "
"\\page."
);
- unput('\n');
+ unput_string(yytext,yyleng);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
BEGIN( Comment );
@@ -1157,7 +1165,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
<PageDocArg1>. { // ignore other stuff
}
<PageDocArg2>{DOCNL} { // second argument; page title
- unput('\n');
+ unput_string(yytext,yyleng);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
BEGIN( Comment );
@@ -1191,7 +1199,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
/* --------- handle arguments of the file/dir/example command ------------ */
<FileDocArg1>{DOCNL} { // no file name specified
- unput('\n');
+ unput_string(yytext,yyleng);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
BEGIN( Comment );
@@ -1289,7 +1297,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
warn(yyextra->fileName,yyextra->lineNr,
"Missing argument of '\\%s' command",yyextra->currentCmd.data()
);
- unput('\n');
+ unput_string(yytext,yyleng);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
BEGIN( Comment );
@@ -1303,7 +1311,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
<LineParam>{DOCNL} { // end of argument
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<LineParam>{LC} { // line continuation
@@ -1667,7 +1675,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
<NameParam>{DOCNL} { // end of argument
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<NameParam>{LC} { // line continuation
@@ -1705,7 +1713,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
}
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<InGroupParam>{LC} { // line continuation
@@ -1723,7 +1731,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
{
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
yyextra->langParser->parsePrototype(yyextra->functionProto);
BEGIN( Comment );
}
@@ -1810,7 +1818,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<ExtendsParam>. { // ignore other stuff
@@ -1847,7 +1855,7 @@ RCSTAG "$"{ID}":"[^\n$]+"$"
);
//if (*yytext=='\n') yyextra->lineNr++;
//addOutput(yyscanner,'\n');
- unput('\n');
+ unput_string(yytext,yyleng);
BEGIN( Comment );
}
<CiteLabel>. { // invalid character for cite label
@@ -2782,6 +2790,7 @@ static bool makeStructuralIndicator(yyscan_t yyscanner,Entry::Sections s)
yyextra->current->section = s;
yyextra->current->fileName = yyextra->fileName;
yyextra->current->startLine = yyextra->lineNr;
+ yyextra->current->docLine = yyextra->lineNr;
return FALSE;
}
}
@@ -2823,28 +2832,29 @@ static void addXRefItem(yyscan_t yyscanner,
RefList *refList = RefListManager::instance().add(listName,listTitle,itemTitle);
RefItem *item = 0;
- for (RefItem *i : yyextra->current->sli)
+ for (auto it = yyextra->current->sli.rbegin(); it != yyextra->current->sli.rend(); ++it)
{
+ RefItem *i = *it;
if (i && qstrcmp(i->list()->listName(),listName)==0)
{
- //printf("found %s lii->type=%s\n",listName,lii->type);
+ //printf("found %s lii->type=%s\n",listName,i->list()->listName().data());
item = i;
break;
}
}
if (item && append) // already found item of same type just before this one
{
- //printf("listName=%s item id = %d existing\n",listName,lii->itemId);
+ //printf("listName=%s item id = %d existing\n",listName,item->id());
item->setText(item->text() + " <p>" + yyextra->outputXRef);
//printf("%s: text +=%s\n",listName,item->text.data());
}
else // new item
{
- //printf("listName=%s item id = %d new yyextra->current=%p\n",listName,itemId,yyextra->current);
// if we have already an item from the same list type (e.g. a second @todo)
// in the same Entry (i.e. lii!=0) then we reuse its link anchor.
item = refList->add();
+ //printf("listName=%s item id = %d new yyextra->current=%p\n",listName,item->id(),yyextra->current);
QCString anchorLabel;
anchorLabel.sprintf("_%s%06d",listName,item->id());
item->setText(yyextra->outputXRef);
@@ -3234,7 +3244,7 @@ bool CommentScanner::parseCommentBlock(/* in */ OutlineParserInterface *pars
yyextra->guards = std::stack<GuardedSection>();
yyextra->langParser = parser;
yyextra->current = curEntry;
- yyextra->current->docLine = (lineNr > 1 ? lineNr-1: 1);
+ yyextra->current->docLine = (lineNr > 1 ? lineNr : 1);
if (comment.isEmpty()) return FALSE; // avoid empty strings
yyextra->inputString = comment;
yyextra->inputString.append(" ");