diff options
Diffstat (limited to 'src/docparser.cpp')
-rw-r--r-- | src/docparser.cpp | 196 |
1 files changed, 148 insertions, 48 deletions
diff --git a/src/docparser.cpp b/src/docparser.cpp index aa14a08..a5c0cc7 100644 --- a/src/docparser.cpp +++ b/src/docparser.cpp @@ -55,6 +55,7 @@ #include "growbuf.h" #include "markdown.h" #include "htmlentity.h" +#include "emoji.h" #define TK_COMMAND_CHAR(token) ((token)==TK_COMMAND_AT ? '@' : '\\') @@ -268,7 +269,7 @@ static void unescapeCRef(QCString &s) * copies the image to the output directory (which depends on the \a type * parameter). */ -static QCString findAndCopyImage(const char *fileName,DocImage::Type type, bool warn = true) +static QCString findAndCopyImage(const char *fileName,DocImage::Type type, bool dowarn = true) { QCString result; bool ambig; @@ -336,7 +337,8 @@ static QCString findAndCopyImage(const char *fileName,DocImage::Type type, bool } else { - printf("Source and Destination are the same!\n"); + warn(g_fileName,doctokenizerYYlineno, + "Prevented to copy file %s onto itself!\n",qPrint(inputFile)); } } else @@ -364,7 +366,7 @@ static QCString findAndCopyImage(const char *fileName,DocImage::Type type, bool return baseName; } } - else if (ambig && warn) + else if (ambig && dowarn) { QCString text; text.sprintf("image file name %s is ambiguous.\n",qPrint(fileName)); @@ -375,7 +377,7 @@ static QCString findAndCopyImage(const char *fileName,DocImage::Type type, bool else { result=fileName; - if (result.left(5)!="http:" && result.left(6)!="https:" && warn) + if (result.left(5)!="http:" && result.left(6)!="https:" && dowarn) { warn_doc_error(g_fileName,doctokenizerYYlineno, "image file %s is not found in IMAGE_PATH: " @@ -429,7 +431,7 @@ static void checkArgumentName(const QCString &name,bool isParam) } if (!found && isParam) { - //printf("member type=%d\n",memberDef->memberType()); + //printf("member type=%d\n",g_memberDef->memberType()); QCString scope=g_memberDef->getScopeString(); if (!scope.isEmpty()) scope+="::"; else scope=""; QCString inheritedFrom = ""; @@ -868,7 +870,7 @@ static bool findDocsForMemberOrCompound(const char *commandName, return FALSE; } //--------------------------------------------------------------------------- -inline void errorHandleDefaultToken(DocNode *parent,int tok, +inline void errorHandleDefaultToken(DocNode *parent,int tok, QList<DocNode> &children,const char *txt) { switch (tok) @@ -880,7 +882,7 @@ inline void errorHandleDefaultToken(DocNode *parent,int tok, warn_doc_error(g_fileName,doctokenizerYYlineno,"Illegal command %s as part of a %s", qPrint(TK_COMMAND_CHAR(tok) + g_token->name), txt); break; - case TK_SYMBOL: + 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; @@ -1373,7 +1375,7 @@ static bool defaultHandleToken(DocNode *parent,int tok, QList<DocNode> &children handleWord) { DBG(("token %s at %d",tokToString(tok),doctokenizerYYlineno)); - if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || + if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || tok==TK_COMMAND_AT || tok==TK_COMMAND_BS || tok==TK_HTMLTAG ) { @@ -1784,6 +1786,27 @@ DocSymbol::SymType DocSymbol::decodeSymbol(const QCString &symName) //--------------------------------------------------------------------------- +DocEmoji::DocEmoji(DocNode *parent,const QCString &symName) : + m_symName(symName), m_index(-1) +{ + m_parent = parent; + QCString locSymName = symName; + int len=locSymName.length(); + if (len>0) + { + if (locSymName.at(len-1)!=':') locSymName.append(":"); + if (locSymName.at(0)!=':') locSymName.prepend(":"); + } + m_symName = locSymName; + m_index = EmojiEntityMapper::instance()->symbol2index(m_symName); + if (m_index==-1) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"Found unsupported emoji symbol '%s'\n",qPrint(m_symName)); + } +} + +//--------------------------------------------------------------------------- + static int internalValidatingParseDoc(DocNode *parent,QList<DocNode> &children, const QCString &doc) { @@ -2950,10 +2973,10 @@ void DocVhdlFlow::parse() //--------------------------------------------------------------------------- DocImage::DocImage(DocNode *parent,const HtmlAttribList &attribs,const QCString &name, - Type t,const QCString &url) : - m_attribs(attribs), m_name(name), + Type t,const QCString &url, bool inlineImage) : + m_attribs(attribs), m_name(name), m_type(t), m_relPath(g_relPath), - m_url(url) + m_url(url), m_inlineImage(inlineImage) { m_parent = parent; } @@ -3053,7 +3076,6 @@ int DocHtmlHeader::parse() warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected html tag <%s%s> found within <h%d> context", g_token->endTag?"/":"",qPrint(g_token->name),m_level); } - } break; default: @@ -3092,7 +3114,6 @@ int DocHRef::parse() switch (tok) { case TK_HTMLTAG: - { int tagId=Mappers::htmlTagMapper->map(g_token->name); if (tagId==HTML_A && g_token->endTag) // found </a> tag @@ -3240,32 +3261,32 @@ int DocIndexEntry::parse() } } break; - case TK_COMMAND_AT: + case TK_COMMAND_AT: // fall through - case TK_COMMAND_BS: - switch (Mappers::cmdMapper->map(g_token->name)) - { - case CMD_BSLASH: m_entry+='\\'; break; - case CMD_AT: m_entry+='@'; break; - case CMD_LESS: m_entry+='<'; break; - case CMD_GREATER: m_entry+='>'; break; - case CMD_AMP: m_entry+='&'; break; - case CMD_DOLLAR: m_entry+='$'; break; - case CMD_HASH: m_entry+='#'; break; - case CMD_DCOLON: m_entry+="::"; break; - case CMD_PERCENT: m_entry+='%'; break; - case CMD_NDASH: m_entry+="--"; break; - case CMD_MDASH: m_entry+="---"; break; - case CMD_QUOTE: m_entry+='"'; break; - case CMD_PUNT: m_entry+='.'; break; - case CMD_PLUS: m_entry+='+'; break; - case CMD_MINUS: m_entry+='-'; break; - case CMD_EQUAL: m_entry+='='; break; - default: - warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected command %s found as argument of \\addindex", - qPrint(g_token->name)); - break; - } + case TK_COMMAND_BS: + switch (Mappers::cmdMapper->map(g_token->name)) + { + case CMD_BSLASH: m_entry+='\\'; break; + case CMD_AT: m_entry+='@'; break; + case CMD_LESS: m_entry+='<'; break; + case CMD_GREATER: m_entry+='>'; break; + case CMD_AMP: m_entry+='&'; break; + case CMD_DOLLAR: m_entry+='$'; break; + case CMD_HASH: m_entry+='#'; break; + case CMD_DCOLON: m_entry+="::"; break; + case CMD_PERCENT: m_entry+='%'; break; + case CMD_NDASH: m_entry+="--"; break; + case CMD_MDASH: m_entry+="---"; break; + case CMD_QUOTE: m_entry+='"'; break; + case CMD_PUNT: m_entry+='.'; break; + case CMD_PLUS: m_entry+='+'; break; + case CMD_MINUS: m_entry+='-'; break; + case CMD_EQUAL: m_entry+='='; break; + default: + warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected command %s found as argument of \\addindex", + qPrint(g_token->name)); + break; + } break; default: warn_doc_error(g_fileName,doctokenizerYYlineno,"Unexpected token %s", @@ -3347,7 +3368,8 @@ int DocHtmlCaption::parse() } break; default: - errorHandleDefaultToken(this,tok,m_children,"<caption> tag"); + errorHandleDefaultToken(this,tok,m_children,"<caption> tag"); + break; } } } @@ -4483,7 +4505,7 @@ void DocTitle::parse() { if (!defaultHandleToken(this,tok,m_children)) { - errorHandleDefaultToken(this,tok,m_children,"title section"); + errorHandleDefaultToken(this,tok,m_children,"title section"); } } doctokenizerYYsetStatePara(); @@ -4939,6 +4961,35 @@ void DocPara::handleCite() doctokenizerYYsetStatePara(); } +void DocPara::handleEmoji() +{ + // get the argument of the emoji command. + int tok=doctokenizerYYlex(); + if (tok!=TK_WHITESPACE) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", + qPrint("emoji")); + return; + } + doctokenizerYYsetStateEmoji(); + tok=doctokenizerYYlex(); + if (tok==0) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected end of comment block while parsing the " + "argument of command %s\n", qPrint("emoji")); + return; + } + else if (tok!=TK_WORD) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"unexpected token %s as the argument of %s", + tokToString(tok),qPrint("emoji")); + return; + } + DocEmoji *emoji = new DocEmoji(this,g_token->name); + m_children.append(emoji); + doctokenizerYYsetStatePara(); +} + int DocPara::handleXRefItem() { int retval=doctokenizerYYlex(); @@ -5017,13 +5068,50 @@ void DocPara::handleIncludeOperator(const QCString &cmdName,DocIncOperator::Type void DocPara::handleImage(const QCString &cmdName) { QCString saveCmdName = cmdName; + bool inlineImage = FALSE; int tok=doctokenizerYYlex(); if (tok!=TK_WHITESPACE) { - warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", + if (tok==TK_WORD) + { + if (g_token->name == "{") + { + while ((tok=doctokenizerYYlex())==TK_WHITESPACE); + if (g_token->name != "}") // non-empty option string + { + if (g_token->name.lower() != "inline") + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"currently only 'inline' suported as option of %s command", + qPrint(saveCmdName)); + } + else + { + inlineImage = TRUE; + } + while ((tok=doctokenizerYYlex())==TK_WHITESPACE); + } + if (!((tok==TK_WORD) && (g_token->name == "}"))) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected closing '}' at option of %s command", + qPrint(saveCmdName)); + return; + } + tok=doctokenizerYYlex(); + if (tok!=TK_WHITESPACE) + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command with option", + qPrint(saveCmdName)); + return; + } + } + } + else + { + warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", qPrint(saveCmdName)); - return; + return; + } } tok=doctokenizerYYlex(); if (tok!=TK_WORD && tok!=TK_LNKWORD) @@ -5062,7 +5150,7 @@ void DocPara::handleImage(const QCString &cmdName) return; } HtmlAttribList attrList; - DocImage *img = new DocImage(this,attrList,findAndCopyImage(g_token->name,t),t); + DocImage *img = new DocImage(this,attrList,findAndCopyImage(g_token->name,t),t,"",inlineImage); m_children.append(img); img->parse(); } @@ -5156,6 +5244,7 @@ void DocPara::handleInclude(const QCString &cmdName,DocInclude::Type t) { DBG(("handleInclude(%s)\n",qPrint(cmdName))); int tok=doctokenizerYYlex(); + bool isBlock = false; if (tok==TK_WORD && g_token->name=="{") { doctokenizerYYsetStateOptions(); @@ -5180,6 +5269,14 @@ void DocPara::handleInclude(const QCString &cmdName,DocInclude::Type t) } tok=doctokenizerYYlex(); } + else if (tok==TK_WORD && g_token->name=="[") + { + doctokenizerYYsetStateBlock(); + tok=doctokenizerYYlex(); + isBlock = (g_token->name.stripWhiteSpace() == "block"); + doctokenizerYYsetStatePara(); + tok=doctokenizerYYlex(); + } else if (tok!=TK_WHITESPACE) { warn_doc_error(g_fileName,doctokenizerYYlineno,"expected whitespace after %s command", @@ -5238,7 +5335,7 @@ void DocPara::handleInclude(const QCString &cmdName,DocInclude::Type t) } else { - DocInclude *inc = new DocInclude(this,fileName,g_context,t,g_isExample,g_exampleName,blockId); + DocInclude *inc = new DocInclude(this,fileName,g_context,t,g_isExample,g_exampleName,blockId,isBlock); m_children.append(inc); inc->parse(); } @@ -5780,6 +5877,9 @@ int DocPara::handleCommand(const QCString &cmdName, const int tok) case CMD_CITE: handleCite(); break; + case CMD_EMOJI: + handleEmoji(); + break; case CMD_REF: // fall through case CMD_SUBPAGE: handleRef(cmdName); @@ -6457,7 +6557,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 || + if (tok==TK_WORD || tok==TK_LNKWORD || tok==TK_SYMBOL || tok==TK_URL || tok==TK_COMMAND_AT || tok == TK_COMMAND_BS || tok==TK_HTMLTAG ) { @@ -7353,7 +7453,7 @@ QString::Direction getTextDirByConfig(const DocPara *para, int nodeIndex) return QString::DirNeutral; } -QCString getDirHtmlClassOfNode(QString::Direction textDir, const char *initValue) +QCString getDirHtmlClassOfNode(QString::Direction textDir, const QCString &initValue) { QCString classFromDir; if (textDir == QString::DirLTR) @@ -7363,9 +7463,9 @@ QCString getDirHtmlClassOfNode(QString::Direction textDir, const char *initValue else classFromDir = ""; - if (initValue != NULL && !classFromDir.isEmpty()) + if (initValue && !classFromDir.isEmpty()) return QCString(" class=\"") + initValue + " " + classFromDir + "\""; - if (initValue != NULL) + if (initValue) return QCString(" class=\"") + initValue + "\""; if (!classFromDir.isEmpty()) return QCString(" class=\"") + classFromDir + "\""; |