From a68e6c0724f99dfa6cea25f7d56fb6077100fc85 Mon Sep 17 00:00:00 2001 From: albert-github Date: Sun, 26 Aug 2018 13:13:01 +0200 Subject: Correcting warning messages and echoing unknown command - In case an unknown command is given this was shown as a warning but not as normal text in the output, for this also a distinction between `\`and `@` commands has to be made - corrected command name in warning messages when handling arguments - making handling of some warning messages consistent --- src/docparser.cpp | 202 ++++++++++++++++------------------------------------- src/docparser.h | 2 +- src/doctokenizer.h | 3 +- src/doctokenizer.l | 19 ++--- 4 files changed, 72 insertions(+), 154 deletions(-) diff --git a/src/docparser.cpp b/src/docparser.cpp index 8efe8fa..2c51507 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -866,7 +866,30 @@ static bool findDocsForMemberOrCompound(const char *commandName, return FALSE; } //--------------------------------------------------------------------------- +inline void errorHandleDefaultToken(DocNode *parent,int tok, + QList &children,const char *txt) +{ + switch (tok) + { + case TK_COMMAND: + case TK_COMMAND1: + children.append(new DocWord(parent,(tok == TK_COMMAND ? '@' : '\\') + g_token->name)); + warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a %s", + qPrint((tok == TK_COMMAND ? '@' : '\\') + g_token->name), txt); + break; + case TK_SYMBOL: + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found found as part of a %s", + qPrint(g_token->name), txt); + break; + default: + children.append(new DocWord(parent,g_token->name)); + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s found as part of a %s", + tokToString(tok), txt); + break; + } +} +//--------------------------------------------------------------------------- // forward declaration static bool defaultHandleToken(DocNode *parent,int tok, QList &children,bool @@ -876,6 +899,7 @@ static int handleStyleArgument(DocNode *parent,QList &children, const QCString &cmdName) { DBG(("handleStyleArgument(%s)\n",qPrint(cmdName))); + QCString saveCmdName = cmdName; int tok=doctokenizerYYlex(); if (tok!=TK_WHITESPACE) { @@ -901,14 +925,6 @@ static int handleStyleArgument(DocNode *parent,QList &children, { switch (tok) { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command \\%s as the argument of a \\%s command", - qPrint(g_token->name),qPrint(cmdName)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found while handling command %s", - qPrint(g_token->name),qPrint(cmdName)); - break; case TK_HTMLTAG: if (insideLI(parent) && Mappers::htmlTagMapper->map(g_token->name) && g_token->endTag) { // ignore as the end of a style command @@ -917,8 +933,7 @@ static int handleStyleArgument(DocNode *parent,QList &children, return tok; break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s while handling command %s", - tokToString(tok),qPrint(cmdName)); + errorHandleDefaultToken(parent,tok,children,"\\" + saveCmdName + " command"); break; } break; @@ -1295,21 +1310,7 @@ static void defaultHandleTitleAndSize(const int cmd, DocNode *parent, QListname), Mappers::cmdMapper->find(cmd).data()); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; - } + errorHandleDefaultToken(parent,tok,children,Mappers::cmdMapper->find(cmd).data()); } } // parse size attributes @@ -1368,7 +1369,7 @@ static bool defaultHandleToken(DocNode *parent,int tok, QList &children { DBG(("token %s at %d",tokToString(tok),doctokenizerYYlineno)); if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || - tok==TK_COMMAND || tok==TK_HTMLTAG + tok==TK_COMMAND || tok==TK_COMMAND1 || tok==TK_HTMLTAG ) { DBG((" name=%s",qPrint(g_token->name))); @@ -1379,6 +1380,7 @@ reparsetoken: switch (tok) { case TK_COMMAND: + case TK_COMMAND1: switch (Mappers::cmdMapper->map(tokenName)) { case CMD_BSLASH: @@ -2308,21 +2310,7 @@ void DocSecRefItem::parse() { if (!defaultHandleToken(this,tok,m_children)) { - switch (tok) - { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a \\refitem", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; - } + errorHandleDefaultToken(this,tok,m_children,"\\refitem"); } } doctokenizerYYsetStatePara(); @@ -2370,7 +2358,7 @@ void DocSecRefList::parse() // handle items while (tok) { - if (tok==TK_COMMAND) + if (tok==TK_COMMAND || tok == TK_COMMAND1) { switch (Mappers::cmdMapper->map(g_token->name)) { @@ -2450,21 +2438,7 @@ void DocInternalRef::parse() { if (!defaultHandleToken(this,tok,m_children)) { - switch (tok) - { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a \\ref", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; - } + errorHandleDefaultToken(this,tok,m_children,"\\ref"); } } @@ -2608,19 +2582,10 @@ void DocRef::parse() { switch (tok) { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a \\ref", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; case TK_HTMLTAG: break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); + errorHandleDefaultToken(this,tok,m_children,"\\ref"); break; } } @@ -2732,6 +2697,7 @@ QCString DocLink::parse(bool isJavaLink,bool isXmlLink) switch (tok) { case TK_COMMAND: + case TK_COMMAND1: switch (Mappers::cmdMapper->map(g_token->name)) { case CMD_ENDLINK: @@ -2747,13 +2713,13 @@ QCString DocLink::parse(bool isJavaLink,bool isXmlLink) } break; case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found as part of a \\link", qPrint(g_token->name)); break; case TK_HTMLTAG: if (g_token->name!="see" || !isXmlLink) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected xml/html command %s found", + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected xml/html command %s found as part of a \\link", qPrint(g_token->name)); } goto endlink; @@ -2931,21 +2897,7 @@ void DocVhdlFlow::parse() { if (!defaultHandleToken(this,tok,m_children)) { - switch (tok) - { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a \\vhdlflow", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; - } + errorHandleDefaultToken(this,tok,m_children,"\\vhdlflow"); } } tok=doctokenizerYYlex(); @@ -2992,10 +2944,6 @@ int DocHtmlHeader::parse() { switch (tok) { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a tag", - qPrint(g_token->name),m_level); - break; case TK_HTMLTAG: { int tagId=Mappers::htmlTagMapper->map(g_token->name); @@ -3073,14 +3021,10 @@ int DocHtmlHeader::parse() } break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; + char tmp[20]; + sprintf(tmp,"tag",m_level); + errorHandleDefaultToken(this,tok,m_children,tmp); } } } @@ -3112,14 +3056,6 @@ int DocHRef::parse() { switch (tok) { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a .. block", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; case TK_HTMLTAG: { @@ -3136,8 +3072,7 @@ int DocHRef::parse() } break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok),doctokenizerYYlineno); + errorHandleDefaultToken(this,tok,m_children,".. block"); break; } } @@ -3271,6 +3206,7 @@ int DocIndexEntry::parse() } break; case TK_COMMAND: + case TK_COMMAND1: switch (Mappers::cmdMapper->map(g_token->name)) { case CMD_BSLASH: m_entry+='\\'; break; @@ -3358,14 +3294,6 @@ int DocHtmlCaption::parse() { switch (tok) { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a tag", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; case TK_HTMLTAG: { int tagId=Mappers::htmlTagMapper->map(g_token->name); @@ -3382,9 +3310,7 @@ int DocHtmlCaption::parse() } break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; + errorHandleDefaultToken(this,tok,m_children," tag"); } } } @@ -3898,6 +3824,7 @@ int DocHtmlDescTitle::parse() switch (tok) { case TK_COMMAND: + case TK_COMMAND1: { QCString cmdName=g_token->name; bool isJavaLink=FALSE; @@ -3908,7 +3835,7 @@ int DocHtmlDescTitle::parse() int tok=doctokenizerYYlex(); if (tok!=TK_WHITESPACE) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after \\%s command", qPrint(g_token->name)); } else @@ -3917,7 +3844,7 @@ int DocHtmlDescTitle::parse() tok=doctokenizerYYlex(); // get the reference id if (tok!=TK_WORD) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected token %s as the argument of %s", + warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected token %s as the argument of \\%s command", tokToString(tok),qPrint(cmdName)); } else @@ -3938,7 +3865,7 @@ int DocHtmlDescTitle::parse() int tok=doctokenizerYYlex(); if (tok!=TK_WHITESPACE) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after \\%s command", qPrint(cmdName)); } else @@ -3947,7 +3874,7 @@ int DocHtmlDescTitle::parse() tok=doctokenizerYYlex(); if (tok!=TK_WORD) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected token %s as the argument of %s", + warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected token %s as the argument of \\%s command", tokToString(tok),qPrint(cmdName)); } else @@ -3966,13 +3893,13 @@ int DocHtmlDescTitle::parse() break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a
tag", + warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command \\%s found as part of a
tag", qPrint(g_token->name)); } } break; case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol \\%s found as part of a
tag", qPrint(g_token->name)); break; case TK_HTMLTAG: @@ -4013,7 +3940,7 @@ int DocHtmlDescTitle::parse() } break; default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s found as part of a
tag", tokToString(tok)); break; } @@ -4518,21 +4445,7 @@ void DocTitle::parse() { if (!defaultHandleToken(this,tok,m_children)) { - switch (tok) - { - case TK_COMMAND: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a title section", - qPrint(g_token->name)); - break; - case TK_SYMBOL: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unsupported symbol %s found", - qPrint(g_token->name)); - break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", - tokToString(tok)); - break; - } + errorHandleDefaultToken(this,tok,m_children,"title section"); } } doctokenizerYYsetStatePara(); @@ -5393,7 +5306,7 @@ void DocPara::handleInheritDoc() } -int DocPara::handleCommand(const QCString &cmdName) +int DocPara::handleCommand(const QCString &cmdName, const int tok) { DBG(("handleCommand(%s)\n",qPrint(cmdName))); int retval = RetVal_OK; @@ -5401,6 +5314,7 @@ int DocPara::handleCommand(const QCString &cmdName) switch (cmdId) { case CMD_UNKNOWN: + m_children.append(new DocWord(this,(tok == TK_COMMAND ? '@' : '\\') + cmdName)); warn_doc_error(g_fileName,doctokenizerYYlineno,"Found unknown command `\\%s'",qPrint(cmdName)); break; case CMD_EMPHASIS: @@ -6491,7 +6405,7 @@ int DocPara::parse() reparsetoken: DBG(("token %s at %d",tokToString(tok),doctokenizerYYlineno)); if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || - tok==TK_COMMAND || tok==TK_HTMLTAG + tok==TK_COMMAND || tok == TK_COMMAND1 || tok==TK_HTMLTAG ) { DBG((" name=%s",qPrint(g_token->name))); @@ -6589,7 +6503,7 @@ reparsetoken: } else // other section { - tok = TK_COMMAND; + tok = TK_COMMAND1; } DBG(("reparsing command %s\n",qPrint(g_token->name))); goto reparsetoken; @@ -6635,6 +6549,7 @@ reparsetoken: } break; case TK_COMMAND: + case TK_COMMAND1: { // see if we have to start a simple section int cmd = Mappers::cmdMapper->map(g_token->name); @@ -6670,7 +6585,7 @@ reparsetoken: } // handle the command - retval=handleCommand(g_token->name); + retval=handleCommand(g_token->name,tok); DBG(("handleCommand returns %x\n",retval)); // check the return value @@ -6688,7 +6603,7 @@ reparsetoken: } else // other section { - tok = TK_COMMAND; + tok = TK_COMMAND1; } DBG(("reparsing command %s\n",qPrint(g_token->name))); goto reparsetoken; @@ -6961,6 +6876,7 @@ void DocText::parse() } break; case TK_COMMAND: + case TK_COMMAND1: switch (Mappers::cmdMapper->map(g_token->name)) { case CMD_BSLASH: diff --git a/src/docparser.h b/src/docparser.h index d7390c2..2e932be 100644 --- a/src/docparser.h +++ b/src/docparser.h @@ -1151,7 +1151,7 @@ class DocPara : public CompAccept bool isFirst() const { return m_isFirst; } bool isLast() const { return m_isLast; } - int handleCommand(const QCString &cmdName); + int handleCommand(const QCString &cmdName,const int tok); int handleHtmlStartTag(const QCString &tagName,const HtmlAttribList &tagHtmlAttribs); int handleHtmlEndTag(const QCString &tagName); int handleSimpleSection(DocSimpleSect::Type t,bool xmlContext=FALSE); diff --git a/src/doctokenizer.h b/src/doctokenizer.h index b3b9fa5..d0bdf06 100644 --- a/src/doctokenizer.h +++ b/src/doctokenizer.h @@ -34,12 +34,13 @@ enum Tokens TK_WHITESPACE = 3, TK_LISTITEM = 4, TK_ENDLIST = 5, - TK_COMMAND = 6, + TK_COMMAND = 6, //! Command starting with `@` TK_HTMLTAG = 7, TK_SYMBOL = 8, TK_NEWPARA = 9, TK_RCSTAG = 10, TK_URL = 11, + TK_COMMAND1 = 12, //! Command starting with `\` RetVal_OK = 0x10000, RetVal_SimpleSec = 0x10001, diff --git a/src/doctokenizer.l b/src/doctokenizer.l index a162fb3..dc56ca9 100644 --- a/src/doctokenizer.l +++ b/src/doctokenizer.l @@ -122,6 +122,7 @@ const char *tokToString(int token) case TK_NEWPARA: return "TK_NEWPARA"; case TK_RCSTAG: return "TK_RCSTAG"; case TK_URL: return "TK_URL"; + case TK_COMMAND1: return "TK_COMMAND1"; } return "ERROR"; } @@ -572,14 +573,14 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} bool ok; g_token->id = QCString(yytext).right((int)yyleng-6).toInt(&ok); ASSERT(ok); - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {CMD}"n"\n { /* \n followed by real newline */ yylineno++; g_token->name = yytext+1; g_token->name = g_token->name.stripWhiteSpace(); g_token->paramDir=TokenInfo::Unspecified; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {SPCMD1} | {SPCMD2} | @@ -587,7 +588,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} g_token->name = yytext+1; g_token->name = g_token->name.stripWhiteSpace(); g_token->paramDir=TokenInfo::Unspecified; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {PARAMIO} { /* param [in,out] command */ g_token->name = "param"; @@ -613,7 +614,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} { g_token->paramDir=TokenInfo::Unspecified; } - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } ("http:"|"https:"|"ftp:"|"file:"|"news:"){URLMASK}/\. { // URL. g_token->name=yytext; @@ -732,7 +733,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} } [\\@<>&$#%~] { g_token->name = yytext; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } ({BLANK}*\n)+{BLANK}*\n/{LISTITEM} { /* skip trailing paragraph followed by new list item */ if (g_insidePre || g_autoListLevel==0) @@ -925,7 +926,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} {SPCMD2} { /* special command */ g_token->name = yytext+1; g_token->paramDir=TokenInfo::Unspecified; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {ID}"=" { /* attribute */ if (yytext[0]=='%') // strip % if present @@ -959,7 +960,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} {SPCMD2} { /* special command */ g_token->name = yytext+1; g_token->paramDir=TokenInfo::Unspecified; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {WORD1NQ} | {WORD2NQ} { /* word */ @@ -1090,7 +1091,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} {SPCMD2} { /* special command */ g_token->name = yytext+1; g_token->paramDir=TokenInfo::Unspecified; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } {WORD1NQ} | {WORD2NQ} { @@ -1322,7 +1323,7 @@ REFWORD_NOCV {LABELID}|{REFWORD2_NOCV}|{REFWORD3}|{REFWORD4_NOCV} <*>[\\@<>&$#%~"=] { /* unescaped special character */ //warn(g_fileName,yylineno,"Unexpected character `%s', assuming command \\%s was meant.",yytext,yytext); g_token->name = yytext; - return TK_COMMAND; + return (yytext[0] == '@' ? TK_COMMAND : TK_COMMAND1); } <*>. { warn(g_fileName,yylineno,"Unexpected character `%s'",yytext); -- cgit v0.12