Doxygen
Loading...
Searching...
No Matches
commentcnv.l File Reference
#include <stdint.h>
#include "commentcnv.h"
#include <algorithm>
#include <deque>
#include <stack>
#include <string>
#include <string_view>
#include <vector>
#include "aliases.h"
#include "condparser.h"
#include "config.h"
#include "debug.h"
#include "doxygen.h"
#include "filedef.h"
#include "fileinfo.h"
#include "filename.h"
#include "fortranscanner.h"
#include "message.h"
#include "section.h"
#include "stringutil.h"
#include "util.h"
#include "doxygen_lex.h"
#include "commentcnv.l.h"
Include dependency graph for commentcnv.l:

Go to the source code of this file.

Classes

struct  commentcnvYY_CondCtx
struct  CommentCtx
struct  commentcnv_FileState
struct  commentcnv_Repl
struct  commentcnvYY_state

Macros

#define YY_BUF_SIZE   10*1024*1024
#define YY_TYPEDEF_YY_SCANNER_T
#define yyguts_t   commentcnvYYguts_t
#define YY_NO_INPUT   1
#define YY_NO_UNISTD_H   1
#define YY_INPUT(buf, result, max_size)

Typedefs

typedef yyguts_t * yyscan_t

Functions

static const char * stateToString (int state)
static int computeIndent (const char *s)
static void replaceCommentMarker (yyscan_t yyscanner, std::string_view s)
static void copyToOutput (yyscan_t yyscanner, std::string_view s)
static void copyToOutput (yyscan_t yyscanner, const char *s, int len)
static void startCondSection (yyscan_t yyscanner, const DString &sectId)
static void endCondSection (yyscan_t yyscanner)
static void handleCondSectionId (yyscan_t yyscanner, const char *expression)
static void replaceAliases (yyscan_t yyscanner, std::string_view s, bool replaceCppComment, bool replaceCComment)
 copies string s with length len to the output, while replacing any alias commands found in the string.
static int yyread (yyscan_t yyscanner, char *buf, int max_size)
static void replaceComment (yyscan_t yyscanner, int offset)
static void clearCommentStack (yyscan_t yyscanner)
static bool readIncludeFile (yyscan_t yyscanner, const DString &inc, const DString &blockId)
static void insertCommentStart (yyscan_t yyscanner)
static bool parseIncludeOptions (yyscan_t yyscanner, std::string_view s)
static const char * getLexerFILE ()
int yylex (yyscan_t yyscanner)
static int lineBlock (const DString &text, const DString &marker)
 Returns the line number of the line following the line with the marker.
static DString extractBlock (const DString &text, const DString &marker, size_t &blockPos)
 Returns the section of text, in between a pair of markers.
void convertCppComments (const std::string &inBuf, std::string &outBuf, const std::string &fn)
 Converts the comments in a file.

Macro Definition Documentation

◆ YY_BUF_SIZE

#define YY_BUF_SIZE   10*1024*1024

◆ YY_INPUT

#define YY_INPUT ( buf,
result,
max_size )
Value:
result=yyread(yyscanner,buf,max_size);
static int yyread(yyscan_t yyscanner, char *buf, int max_size)

Definition at line 181 of file commentcnv.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 63 of file commentcnv.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 64 of file commentcnv.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 29 of file commentcnv.l.

◆ yyguts_t

#define yyguts_t   commentcnvYYguts_t

Definition at line 30 of file commentcnv.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 32 of file commentcnv.l.

Function Documentation

◆ clearCommentStack()

void clearCommentStack ( yyscan_t yyscanner)
static

Definition at line 1875 of file commentcnv.l.

1876{
1877 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1878 while (!yyextra->commentStack.empty()) yyextra->commentStack.pop();
#define yyguts_t
Definition code.l:23
1879}

References yyguts_t.

Referenced by convertCppComments().

◆ computeIndent()

int computeIndent ( const char * s)
inlinestatic

Definition at line 1813 of file commentcnv.l.

1814{
1815 int col=0;
1816 int tabSize=Config_getInt(TAB_SIZE);
1817 const char *p=s;
1818 char c = 0;
1819 while ((c=*p++))
1820 {
1821 if (c==' ') col++;
1822 else if (c=='\t') col+=tabSize-(col%tabSize);
1823 else break;
1824 }
1825 return col;
#define Config_getInt(name)
Definition config.h:34
1826}

References Config_getInt.

Referenced by replaceComment().

◆ convertCppComments()

void convertCppComments ( const std::string & inBuf,
std::string & outBuf,
const std::string & fn )

Converts the comments in a file.

This function does three things:

  1. It converts multi-line C++ style comment blocks (that are aligned) to C style comment blocks (if MULTILINE_CPP_IS_BRIEF is set to NO).
  2. It replaces aliases with their definition (see ALIASES)
  3. It handles conditional sections (cond...endcond blocks)
Parameters
inBufinput buffer holding the file content.
outBufoutput buffer to which the results after conversion are written to.
fnthe name of the file from which the comments originate.

The following is converted:

  • C++ style multiline doxygen comments are converted to C style doxygen comments.
  • conditional sections are processed.
  • aliases are expanded.

Definition at line 2403 of file commentcnv.l.

2404{
2405 DString fileName { fn };
2406 yyscan_t yyscanner;
2407 commentcnvYY_state extra(&inBuf,outBuf);
2408 commentcnvYYlex_init_extra(&extra,&yyscanner);
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
yyguts_t * yyscan_t
Definition code.l:25
2409#ifdef FLEX_DEBUG
2410 commentcnvYYset_debug(Debug::isFlagSet(Debug::Lex_commentcnv)?1:0,yyscanner);
@ Lex_commentcnv
Definition debug.h:55
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
2411#endif
2412 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2413 //printf("convertCppComments(%s)\n",qPrint(fileName));
2414 yyextra->inBufPos = 0;
2415 yyextra->col = 0;
2416 yyextra->mlBrief = Config_getBool(MULTILINE_CPP_IS_BRIEF);
2417 yyextra->skip = false;
2418 yyextra->fileName = fileName;
2419 yyextra->lang = getLanguageFromFileName(fileName);
2420 yyextra->pythonDocString = false;
2421 yyextra->lineNr = 1;
2422 yyextra->raiseLevel = 0;
2423 yyextra->raiseLabel = "";
2424 yyextra->raiseIncrement = 0;
2425 yyextra->raisePrefix = "";
2426 yyextra->insertCppCommentMarker=false;
2427 yyextra->expandedAliases.clear();
2428 yyextra->replacements.clear();
2429 while (!yyextra->condStack.empty()) yyextra->condStack.pop();
2430 clearCommentStack(yyscanner);
2431 yyextra->vhdl = false;
static void clearCommentStack(yyscan_t yyscanner)
#define Config_getBool(name)
Definition config.h:33
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4177
2432
2433 DebugLex debugLex(Debug::Lex_commentcnv,__FILE__, qPrint(fileName));
2434 yyextra->isFixedForm = false;
2435 if (yyextra->lang==SrcLangExt::Fortran)
2436 {
2438 yyextra->isFixedForm = recognizeFixedForm(inBuf,fmt);
2439 }
const char * qPrint(const char *s)
Definition dstring.h:783
bool recognizeFixedForm(const DString &contents, FortranFormat format)
FortranFormat convertFileNameFortranParserCode(const DString &fn)
Definition message.h:146
FortranFormat
Definition types.h:614
2440
2441 if (yyextra->lang==SrcLangExt::Markdown)
2442 {
2443 yyextra->nestingCount=0;
2444 BEGIN(CComment);
2445 yyextra->commentStack.push(yyextra->lineNr);
2446 }
2447 else
2448 {
2449 BEGIN(Scan);
2450 }
2451 yylex(yyscanner);
2452 while (!yyextra->condStack.empty())
2453 {
2454 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
2455 DString sectionInfo(" ");
2456 if (ctx.sectionId!=" ") sectionInfo.sprintf(" with label '%s' ",ctx.sectionId.stripWhiteSpace().data());
2457 warn(yyextra->fileName,ctx.lineNr,"Conditional section{}does not have "
2458 "a corresponding \\endcond command within this file.",sectionInfo.data());
2459 yyextra->condStack.pop();
2460 }
2461 if (yyextra->nestingCount>0 && yyextra->lang!=SrcLangExt::Markdown && yyextra->lang!=SrcLangExt::Fortran)
2462 {
2463 DString lines;
2464 bool first = true;
2465 while (!yyextra->commentStack.empty())
2466 {
2467 int lineNr = yyextra->commentStack.top();
2468 if (!first) lines += ", ";
2469 lines += DString().setNum(lineNr);
2470 first = false;
2471 yyextra->commentStack.pop();
2472 }
2473 warn(yyextra->fileName,yyextra->lineNr,"Reached end of file while still inside a (nested) comment. "
2474 "Nesting level {} (possible line reference(s): {})",yyextra->nestingCount,lines);
2475 }
2476 yyextra->nestingCount = 0;
2478 {
2479 Debug::print(Debug::CommentCnv,0,"-----------\nCommentCnv: {}\n"
2480 "output=[\n{}]\n-----------\n",fileName,yyextra->outBuf
2481 );
2482 }
2483 commentcnvYYlex_destroy(yyscanner);
DString & setNum(short n)
Definition dstring.h:552
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
@ CommentCnv
Definition debug.h:32
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
int yylex(void)
#define warn(file, line, fmt,...)
Definition message.h:97
2484}

References clearCommentStack(), Debug::CommentCnv, Config_getBool, convertFileNameFortranParserCode(), DString::data(), getLanguageFromFileName(), Debug::isFlagSet(), Debug::Lex_commentcnv, commentcnvYY_CondCtx::lineNr, Debug::print(), qPrint(), recognizeFixedForm(), commentcnvYY_CondCtx::sectionId, DString::setNum(), DString::sprintf(), DString::stripWhiteSpace(), warn, yyguts_t, and yylex().

Referenced by generateHtmlForComment(), and parseFile().

◆ copyToOutput() [1/2]

void copyToOutput ( yyscan_t yyscanner,
const char * s,
int len )
inlinestatic

Definition at line 1870 of file commentcnv.l.

1871{
1872 copyToOutput(yyscanner,std::string_view{s,(size_t)len});
static void copyToOutput(yyscan_t yyscanner, std::string_view s)
1873}

References copyToOutput().

◆ copyToOutput() [2/2]

void copyToOutput ( yyscan_t yyscanner,
std::string_view s )
inlinestatic

Definition at line 1828 of file commentcnv.l.

1829{
1830 int tabSize=Config_getInt(TAB_SIZE);
1831 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1832 size_t len = s.length();
1833 if (yyextra->skip) // only add newlines.
1834 {
1835 for (size_t i=0;i<len;i++)
1836 {
1837 switch(s[i])
1838 {
1839 case '\n':
1840 yyextra->outBuf+='\n';
1841 yyextra->lineNr++;
1842 yyextra->col=0;
1843 break;
1844 case '\t':
1845 yyextra->col+=tabSize-(yyextra->col%tabSize);
1846 break;
1847 default:
1848 yyextra->col++;
1849 break;
1850 }
1851 }
1852 }
1853 else if (len>0)
1854 {
1855 yyextra->outBuf+=s;
1856 for (size_t i=0;i<len;i++)
1857 {
1858 switch (s[i])
1859 {
1860 case '\n': yyextra->col=0;
1861 //fprintf(stderr,"---> copy %d\n",g_lineNr);
1862 yyextra->lineNr++; break;
1863 case '\t': yyextra->col+=tabSize-(yyextra->col%tabSize); break;
1864 default: yyextra->col++; break;
1865 }
1866 }
1867 }
1868}

References Config_getInt, and yyguts_t.

Referenced by copyToOutput(), insertCommentStart(), readIncludeFile(), replaceAliases(), and replaceComment().

◆ endCondSection()

void endCondSection ( yyscan_t yyscanner)
static

Definition at line 1894 of file commentcnv.l.

1895{
1896 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1897 if (yyextra->condStack.empty())
1898 {
1899 warn(yyextra->fileName,yyextra->lineNr,"Found \\endcond command without matching \\cond");
1900 yyextra->skip=false;
1901 }
1902 else
1903 {
1904 const commentcnvYY_CondCtx &ctx = yyextra->condStack.top();
1905 yyextra->skip=ctx.skip;
1906 yyextra->condStack.pop();
1907 }
1908 //printf("endCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1909}

References commentcnvYY_CondCtx::skip, warn, and yyguts_t.

◆ extractBlock()

DString extractBlock ( const DString & text,
const DString & marker,
size_t & blockPos )
static

Returns the section of text, in between a pair of markers.

Full lines are returned, excluding the lines on which the markers appear.

See also
routine lineBlock

Definition at line 1967 of file commentcnv.l.

1968{
1969 DString result;
1970 size_t p=0, i = DString::npos;
1971 bool found = false;
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
1972
1973 // find the character positions of the markers
1974 size_t m1 = text.find(marker);
1975 if (m1==DString::npos) return result;
1976 size_t m2 = text.find(marker,m1+marker.length());
1977 if (m2==DString::npos) return result;
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
1978
1979 // find start and end line positions for the markers
1980 size_t l1=DString::npos, l2=DString::npos;
1981 while (!found && (i=text.find('\n',p))!=DString::npos)
1982 {
1983 found = (p<=m1 && m1<i); // found the line with the start marker
1984 p=i+1;
1985 }
1986 l1=p;
1987 blockPos=p;
1988 size_t lp=i;
1989 if (found)
1990 {
1991 while ((i=text.find('\n',p))!=DString::npos)
1992 {
1993 if (p<=m2 && m2<i) // found the line with the end marker
1994 {
1995 l2=p;
1996 break;
1997 }
1998 p=i+1;
1999 lp=i;
2000 }
2001 }
2002 if (l2==DString::npos) // marker at last line without newline (see bug706874)
2003 {
2004 l2=lp;
2005 }
2006 return l1!=DString::npos && l2!=DString::npos && l2>l1 ? text.mid(l1,l2-l1) : DString();
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
2007}

References DString::find(), DString::length(), DString::mid(), and DString::npos.

Referenced by readIncludeFile().

◆ getLexerFILE()

const char * getLexerFILE ( )
inlinestatic

Definition at line 184 of file commentcnv.l.

184{return __FILE__;}

◆ handleCondSectionId()

void handleCondSectionId ( yyscan_t yyscanner,
const char * expression )
static

Definition at line 1911 of file commentcnv.l.

1912{
1913 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1914 bool oldSkip=yyextra->skip;
1915 startCondSection(yyscanner,expression);
1916 if ((yyextra->condCtx==CComment || yyextra->readLineCtx==SComment) &&
1917 !oldSkip && yyextra->skip)
1918 {
1919 if (yyextra->lang!=SrcLangExt::Python &&
1920 yyextra->lang!=SrcLangExt::VHDL &&
1921 yyextra->lang!=SrcLangExt::Markdown &&
1922 yyextra->lang!=SrcLangExt::Fortran)
1923 {
1924 yyextra->outBuf+='*';
1925 yyextra->outBuf+='/';
1926 yyextra->col+=2;
1927 }
1928 }
1929 if (yyextra->readLineCtx==SComment)
1930 {
1931 BEGIN(SComment);
1932 }
1933 else
1934 {
1935 BEGIN(yyextra->condCtx);
1936 }
static void startCondSection(yyscan_t yyscanner, const DString &sectId)
1937}

References startCondSection(), and yyguts_t.

◆ insertCommentStart()

void insertCommentStart ( yyscan_t yyscanner)
static

Definition at line 2009 of file commentcnv.l.

2010{
2011 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2012 size_t startCol=yyextra->blockHeadCol;
2013 size_t contentCol=yyextra->insertCommentCol;
2014 size_t markerSpace=contentCol-startCol;
2015 //printf("insertCommentStart startCol=%d contentCol=%d mlBrief=%d insertCppCommentMarker=%d\n",
2016 // yyextra->blockHeadCol,yyextra->insertCommentCol,yyextra->mlBrief,yyextra->insertCppCommentMarker);
2017 std::string marker;
2018 if (yyextra->lang==SrcLangExt::Python) // need to insert # or space
2019 {
2020 if (yyextra->pythonDocString) // """! style comment
2021 {
2022 marker=" ";
2023 }
2024 else
2025 {
2026 marker="# ";
2027 }
2028 }
2029 else if (yyextra->lang==SrcLangExt::Fortran) // need to insert !!
2030 {
2031 marker="!! ";
2032 }
2033 else if (yyextra->lang==SrcLangExt::Markdown)
2034 {
2035 marker=" ";
2036 }
2037 else if (yyextra->insertCppCommentMarker) // need to insert ///
2038 {
2039 marker="/// ";
2040 if (startCol>0)
2041 {
2042 // insert `///` instead of '* '
2043 startCol--;
2044 markerSpace++;
2045 }
2046 }
2047 else // need to insert *
2048 {
2049 marker="* ";
2050 }
2051 size_t i=0;
2052 for (;i<startCol;i++)
2053 {
2054 copyToOutput(yyscanner," ");
2055 }
2056 if (marker.length()<=markerSpace && !yyextra->firstIncludeLine)
2057 {
2058 copyToOutput(yyscanner,marker);
2059 i+=static_cast<int>(marker.length());
2060 }
2061 for (;i<contentCol;i++)
2062 {
2063 copyToOutput(yyscanner," ");
2064 }
2065 yyextra->firstIncludeLine = false;
2066}

References copyToOutput(), and yyguts_t.

Referenced by readIncludeFile().

◆ lineBlock()

int lineBlock ( const DString & text,
const DString & marker )
static

Returns the line number of the line following the line with the marker.

See also
routine extractBlock

Definition at line 1942 of file commentcnv.l.

1943{
1944 int result = 1;
1945
1946 // find the character positions of the first marker
1947 size_t m1 = text.find(marker);
1948 if (m1==DString::npos) return result;
1949
1950 // find start line positions for the markers
1951 bool found=false;
1952 size_t p=0, i=0;
1953 while (!found && (i=text.find('\n',p))!=DString::npos)
1954 {
1955 found = (p<=m1 && m1<i); // found the line with the start marker
1956 p=i+1;
1957 result++;
1958 }
1959 return result;
1960}

References DString::find(), and DString::npos.

Referenced by readIncludeFile().

◆ parseIncludeOptions()

bool parseIncludeOptions ( yyscan_t yyscanner,
std::string_view s )
static

Definition at line 1679 of file commentcnv.l.

1680{
1681 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1682
1683 //printf("parseIncludeOptions=%s\n",qPrint(s));
1684 size_t optIdxStart = s.find('{');
1685 size_t optIdxEnd = optIdxStart!=std::string::npos ? s.find("}",optIdxStart+1) : std::string::npos;
1686 std::string cmdName;
1687 StringVector optList;
1688 if (optIdxStart == std::string::npos) // no options
1689 {
1690 cmdName = stripWhiteSpace(s.substr(1)); // to remove {CMD}
1691 }
1692 else // options present
1693 {
1694 cmdName = stripWhiteSpace(s.substr(1,optIdxStart-1)); // to remove {CMD}
1695 optList = split(std::string{s.substr(optIdxStart+1,optIdxEnd-optIdxStart-1)},",");
1696 }
1697 DString docOption;
1698 bool isDoc = cmdName=="includedoc" || cmdName=="snippetdoc";
1699 for (const auto &opt : optList)
1700 {
1701 if (stripWhiteSpace(opt)==std::string_view{"doc"})
1702 {
1703 isDoc=true;
1704 docOption = "{doc}";
1705 break;
1706 }
1707 }
std::vector< std::string > StringVector
Definition containers.h:33
std::string_view stripWhiteSpace(std::string_view s)
Given a string view s, returns a new, narrower view on that string, skipping over any leading or trai...
Definition stringutil.h:75
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
Definition stringutil.h:119
1708
1709 if (isDoc)
1710 {
1711 yyextra->replacements.clear();
1712 for (const auto &opt : optList)
1713 {
1714 std::string_view locOpt = stripWhiteSpace(opt);
1715 size_t posEqual = locOpt.find('=');
1716 auto option = std::string{posEqual!=std::string::npos ? stripWhiteSpace(locOpt.substr(0,posEqual)) : locOpt};
1717 auto value = std::string{posEqual!=std::string::npos ? stripWhiteSpace(locOpt.substr(posEqual+1)) : std::string()};
Definition dstring.h:913
1718
1719 if (option=="doc" && value.empty())
1720 {
1721 // ok
1722 }
1723 else if (option=="raise" && !value.empty())
1724 {
1725 yyextra->raiseIncrement = atoi(value.data());
1726 if (yyextra->raiseLevel+yyextra->raiseIncrement>=SectionType::MaxLevel) // check range
1727 {
1728 warn(yyextra->fileName,yyextra->lineNr,"Raising section level from {} to {}, exceeds allowed range [0-{}], adjusting",
1729 yyextra->raiseLevel,yyextra->raiseLevel+yyextra->raiseIncrement,SectionType::MaxLevel-1);
1730 yyextra->raiseIncrement = std::max(0,SectionType::MaxLevel-1-yyextra->raiseLevel);
1731 }
1732 }
1733 else if (option=="prefix" && !value.empty())
1734 {
1735 yyextra->raisePrefix = value;
1736 }
1737 else if (option=="replace" && !value.empty())
1738 {
1739 bool global = false;
1740 StringVector replVec = split(value, std::string{value[0]}, true);
1741 size_t replSize = replVec.size();
1742 if ((replSize!=2 && replSize!=3) || (replSize==3 && replVec[2]!="g"))
1743 {
1744 warn(yyextra->fileName,yyextra->lineNr,"Incorrect replace option '{}' for {} command with value '{}'",option, cmdName, value);
1745 }
1746 else
1747 {
1748 if (replSize==3 && !replVec[0].empty())
1749 {
1750 global = !(replVec[0][0]=='^' || replVec[0][replVec[0].length()-1]=='$');
1751 }
1752 yyextra->replacements.emplace_back(std::move(replVec[0]), std::move(replVec[1]), global);
1753 }
1754 }
1755 else
1756 {
1757 warn(yyextra->fileName,yyextra->lineNr,"Unsupported option '{}' for {}{} command",option, cmdName, docOption);
1758 }
1759 }
1760 }
static constexpr int MaxLevel
Definition section.h:39
1761
1762 return isDoc;
1763}

References SectionType::MaxLevel, split(), stripWhiteSpace(), warn, and yyguts_t.

◆ readIncludeFile()

bool readIncludeFile ( yyscan_t yyscanner,
const DString & inc,
const DString & blockId )
static

Definition at line 2068 of file commentcnv.l.

2069{
2070 //printf("readIncludeFile(inc=%s,blockId=%s)\n",qPrint(inc),qPrint(blockId));
2071 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2072 bool ambig = false;
2073 DString absFileName = findExampleFilePath(inc,ambig);
2074 FileInfo fi(absFileName.str());
2075 if (!absFileName.empty() && fi.exists() && fi.isFile())
2076 {
2077 if (ambig)
2078 {
2079 warn_doc_error(yyextra->fileName,yyextra->lineNr,"included file name '{}' is ambiguous"
2080 "Possible candidates:\n{}",inc, Doxygen::exampleNameLinkedMap->showFileDefMatches(inc));
2081 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2082 copyToOutput(yyscanner,lineStr.view());
2083 }
2084 bool alreadyProcessed = std::any_of(
2085 yyextra->includeStack.begin(),
2086 yyextra->includeStack.end(),
2087 [&absFileName,&blockId](const auto &lfs)
2088 { return lfs->fileName==absFileName && lfs->blockId==blockId; }
2089 );
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
std::string_view view() const
Definition dstring.h:162
const std::string & str() const
Definition dstring.h:645
static FileNameLinkedMap * exampleNameLinkedMap
Definition doxygen.h:95
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
DString showFileDefMatches(const DString &n) const
Returns a list of file definitions in fnMap that match the file name n.
Definition filename.cpp:131
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
DString findExampleFilePath(const DString &file, bool &ambig)
Definition util.cpp:2460
2090
2091 if (alreadyProcessed)
2092 {
2093 if (!blockId.empty())
2094 {
2095 warn_doc_error(yyextra->fileName,yyextra->lineNr,"recursive usage of '\\snippet{{doc}}' block with name '{}' and file name '{}', skipping",
2096 blockId,absFileName);
2097 }
2098 else
2099 {
2100 warn_doc_error(yyextra->fileName,yyextra->lineNr,"recursive usage of '\\include{{doc}}' with file name '{}', skipping", absFileName);
2101 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2102 copyToOutput(yyscanner,lineStr.view());
2103 }
2104 return false;
2105 }
2106
2107 auto fs = std::make_unique<commentcnv_FileState>();
2108 if (!readInputFile(absFileName,fs->fileBuf,ReadInputFileOptions().setFilter(false)))
2109 {
2110 warn_doc_error(yyextra->fileName,yyextra->lineNr,"\\{}{{doc}} file '{}' could not be read",blockId.empty()?"include":"snippet",absFileName);
2111 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2112 copyToOutput(yyscanner,lineStr.view());
2113 fs.reset();
2114 return false;
2115 }
2116 int lineNr=1;
2117 DString incText { fs->fileBuf };
2118 if (!blockId.empty())
2119 {
2120 if (blockId == "[]")
2121 {
2122 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2123 copyToOutput(yyscanner,lineStr.view());
2124 warn_doc_error(yyextra->fileName,yyextra->lineNr,"no block identification found in \\snippet{{doc}} command, skipping");
2125 return false;
2126 }
bool readInputFile(const DString &fileName, std::string &contents, const ReadInputFileOptions &options)
read a file name fileName and optionally filter and transcode it
Definition util.cpp:4383
2127
2128 int count = incText.contains(blockId.data());
2129 if (count!=2)
2130 {
2131 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2132 copyToOutput(yyscanner,lineStr.view());
2133 warn_doc_error(yyextra->fileName,yyextra->lineNr,"block marked with {} for \\snippet{{doc}} should appear twice in file {}, found it {:d} times, skipping",
2134 blockId,absFileName,count);
2135 return false;
2136 }
2137 lineNr = lineBlock(incText, blockId);
2138 size_t blockPos = 0;
2139 incText = extractBlock(incText, blockId, blockPos);
2140 }
int contains(char c, bool cs=true) const
Definition dstring.cpp:85
static DString extractBlock(const DString &text, const DString &marker, size_t &blockPos)
Returns the section of text, in between a pair of markers.
static int lineBlock(const DString &text, const DString &marker)
Returns the line number of the line following the line with the marker.
2141
2142 if (!yyextra->replacements.empty())
2143 {
2144 StringVector txtVec = split(incText.str(), "\n", true);
2145 for (const auto &replElem : yyextra->replacements)
2146 {
2147 reg::Ex re(replElem.re);
2148 size_t pos = 0;
2150 int i = 0;
2151 for (const auto &line : txtVec)
2152 {
2153 std::string newLine;
2154 if (replElem.re == "^")
2155 {
2156 newLine += replElem.replacement;
2157 newLine += line;
2158 }
2159 else if (replElem.re == "$")
2160 {
2161 newLine += line;
2162 newLine += replElem.replacement;
2163 }
2164 else if ((replElem.re == "^$") && (line.length() == 0))
2165 {
2166 newLine += replElem.replacement;
2167 }
2168 else // normal case
2169 {
2170 pos = 0;
2171 while (reg::search(line,match,re,pos))
2172 {
2173 if (match.length() == 0) break; // e.g. re="a*"
2174 newLine += line.substr(pos,match.position() - pos);
2175 newLine += replElem.replacement;
2176 pos=match.position()+match.length();
2177 if (!replElem.global) break; // single replacement only
2178 }
2179 newLine += line.substr(pos);
2180 }
2181 txtVec[i++] = newLine;
2182 }
2183 }
2184 fs->fileBuf.clear();
2185 if (!incText.empty())
2186 {
2187 fs->fileBuf.append(join(txtVec,"\n"));
2188 fs->fileBuf.append("\n");
2189 }
2190 }
2191 else
2192 {
2193 fs->fileBuf.clear();
2194 if (!incText.empty())
2195 {
2196 fs->fileBuf.append(incText.str());
2197 }
2198 }
Class representing a regular expression.
Definition regex.h:39
Object representing the matching results.
Definition regex.h:160
bool search(std::string_view str, Match &match, const Ex &re, size_t pos)
Search in a given string str starting at position pos for a match against regular expression re.
Definition regex.cpp:850
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861
std::string join(const StringVector &sv, const std::string &delimiter)
create a string where the string in the vector are joined by the given delimiter
Definition stringutil.h:165
2199
2200 int oldRaiseLevel = yyextra->raiseLevel;
2201 DString oldRaiseLabel = yyextra->raiseLabel;
2202 yyextra->raiseLevel+=yyextra->raiseIncrement;
2203 yyextra->raiseLabel+=yyextra->raisePrefix;
2204 DString lineStr=" \\ifile \""+absFileName+"\" \\iline " + std::to_string(lineNr)+" ";
2205 if (yyextra->raiseLevel>0)
2206 {
2207 lineStr+="\\iraise " + std::to_string(yyextra->raiseLevel)+" ";
2208 }
2209 if (!yyextra->raiseLabel.empty())
2210 {
2211 lineStr+="\\iprefix \"" + yyextra->raiseLabel + "\" ";
2212 }
2213 lineStr+="\\ilinebr ";
2214 copyToOutput(yyscanner,lineStr.view());
2215
2216 fs->fileName = absFileName;
2217 fs->bufState = YY_CURRENT_BUFFER;
2218 fs->oldLineNr = yyextra->lineNr;
2219 fs->oldFileName = yyextra->fileName;
2220 fs->oldState = yyextra->includeCtx;
2221 fs->oldFileBuf = yyextra->inBuf;
2222 fs->oldFileBufPos = yyextra->inBufPos;
2223 fs->oldIncludeCtx = yyextra->includeCtx;
2224 fs->oldRaiseLvl = oldRaiseLevel;
2225 fs->oldRaiseLbl = oldRaiseLabel;
2226 fs->blockId = blockId;
2227 yy_switch_to_buffer(yy_create_buffer(nullptr, YY_BUF_SIZE, yyscanner),yyscanner);
2228 yyextra->fileName = absFileName;
2229 yyextra->lineNr = lineNr;
2230 yyextra->inBuf = &fs->fileBuf;
2231 yyextra->inBufPos = 0;
2232 yyextra->includeStack.push_back(std::move(fs));
2233 insertCommentStart(yyscanner);
2234 //printf("switched to %s\n",qPrint(fileName));
2235 }
2236 else
2237 {
2238 warn_doc_error(yyextra->fileName,yyextra->lineNr,"\\{}{{doc}} file '{}' not found",blockId.empty()?"include":"snippet",inc);
2239 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
2240 copyToOutput(yyscanner,lineStr.view());
2241 return false;
2242 }
2243 return true;
void push_back(char c)
Definition dstring.h:202
static void insertCommentStart(yyscan_t yyscanner)
#define YY_BUF_SIZE
Definition commentcnv.l:19
2244}

References DString::contains(), copyToOutput(), DString::data(), DString::empty(), Doxygen::exampleNameLinkedMap, FileInfo::exists(), extractBlock(), findExampleFilePath(), insertCommentStart(), FileInfo::isFile(), join(), lineBlock(), DString::push_back(), readInputFile(), reg::search(), DString::setNum(), FileNameLinkedMap::showFileDefMatches(), split(), DString::str(), DString::view(), warn_doc_error, YY_BUF_SIZE, and yyguts_t.

◆ replaceAliases()

void replaceAliases ( yyscan_t yyscanner,
std::string_view s,
bool replaceCppComment = false,
bool replaceCComment = false )
static

copies string s with length len to the output, while replacing any alias commands found in the string.

Definition at line 2249 of file commentcnv.l.

2250{
2251 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2252 if (s.empty()) return;
2253 size_t pos = s.find('{');
2254 std::string cmd { s.substr(1, pos!=std::string::npos ? pos-1 : s.length()-1) };
2255 auto &expAlias = yyextra->expandedAliases;
2256 if (std::find(expAlias.begin(),expAlias.end(),cmd)!=std::end(expAlias))
2257 {
2258 copyToOutput(yyscanner,s);
2259 return; // prevent recursive expansion
2260 }
2261 else if (cmd=="ialias")
2262 {
2263 if (s.length()>cmd.length()+3) // \cmd{value}
2264 {
2265 std::string value { s.substr(cmd.length()+2,s.length()-cmd.length()-3) };
2266 //printf("removing value '%s'\n",qPrint(value));
2267 expAlias.erase(std::remove(expAlias.begin(),expAlias.end(),value),expAlias.end());
2268 }
2269 return;
2270 }
2271 std::string result = resolveAliasCmd(s);
2272 if (yyextra->inVerbatim) // inside verbatim blocks (like @code...@endcode) only expand aliases if
2273 // their expansion contains the matching end block marker.
2274 {
2275 std::string blk = yyextra->blockName.str();
2276 ASSERT(!blk.empty());
2277 bool isNamedCommand=isId(blk[0]); // true for e.g. @endcode, false for e.g. ~~~
2278 size_t i=0,p=0;
2279 bool found=false;
2280 while ((i=result.find(blk,p))!=std::string::npos && !found) // for each match of blk in result
2281 {
2282 found = !isNamedCommand || // e.g. '~~~' or '-->'
2283 (i>0 && (result[i-1]=='\\' || result[i-1]=='@') && !isId(result[i+blk.length()])); // e.g. '@endcode' but not ~endcode or @endcodex
2284 p = i+yyextra->blockName.length();
2285 }
2286 //printf("blk=%s result=%s found=%d\n",qPrint(blk),qPrint(result),found);
2287 if (!found) // treat alias as part of the verbatim block
2288 {
2289 copyToOutput(yyscanner,s);
2290 return;
2291 }
2292 }
2293 //printf("replaceAliases(%s)->'%s' replaceCppComment=%d replaceCComment=%d\n",qPrint(s),qPrint(result),replaceCppComment,replaceCComment);
2294 if (result!=s)
2295 {
2296 size_t numSpaces = yyextra->blockHeadCol>1 ? yyextra->blockHeadCol-1 : 0;
2297 std::string spaces(numSpaces,' ');
2298 if (replaceCppComment) // In case we are replacing a multiline /// comment by a C style comment
2299 // and we have new lines in the alias argument, we need to place back a /// for each new line
2300 // to prevent breaking the multiline comment into multiple C style comments
2301 {
2302 std::string replacement = "\n"+spaces+"///";
2303 result = substituteStringView(result,"\n",replacement);
2304 }
2305 else if (replaceCComment)
2306 {
2307 std::string replacement = "\n"+spaces+" * ";
2308 result = substituteStringView(result,"\n",replacement);
2309 }
2310 expAlias.push_back(cmd);
2311 // add a ialias command to allow expansion of cmd again
2312 result += " \\ilinebr \\ialias{";
2313 result += cmd;
2314 result += "}";
2315 for (int i=(int)result.length()-1; i>=0; i--)
2316 {
2317 unput(result[i]);
2318 }
2319 }
2320 else
2321 {
2322 copyToOutput(yyscanner,result);
2323 }
std::string resolveAliasCmd(std::string_view aliasCmd)
Definition aliases.cpp:495
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
#define ASSERT(x)
Definition message.h:142
std::string substituteStringView(std::string_view s, std::string_view toReplace, std::string_view replaceWith)
Returns a new string where occurrences of substring toReplace in string s are replaced by string repl...
Definition stringutil.h:53
2324}

References ASSERT, copyToOutput(), isId(), resolveAliasCmd(), substituteStringView(), and yyguts_t.

◆ replaceComment()

void replaceComment ( yyscan_t yyscanner,
int offset )
static

Definition at line 2337 of file commentcnv.l.

2338{
2339 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2340 if (yyextra->mlBrief || yyextra->skip)
2341 {
2342 copyToOutput(yyscanner,yytext,yyleng);
2343 }
2344 else
2345 {
2346 size_t i=computeIndent(&yytext[offset]);
2347 // A line in another column starts a new block, since it may document something
2348 // else. If both the block and the line have a marker ending in '<' (//!< or ///<),
2349 // they both document the member in front of them. The line then still starts a new
2350 // block, but a C style one: handed back to the scanner as a single //!< line it
2351 // would become the brief description, ahead of the lines that come before it
2352 // (see issue #5266).
2353 bool afterMember = yyleng>0 && yytext[yyleng-1]=='<';
2354 // The '<' of the line that started the block is not part of the text matched at that
2355 // point, so look at what was written for it: "/*!" or "/**", then '<' if it had one.
2356 bool headAfterMember = yyextra->blockHeadPos!=std::string::npos &&
2357 yyextra->blockHeadPos+3<yyextra->outBuf.size() &&
2358 yyextra->outBuf[yyextra->blockHeadPos+3]=='<';
2359 bool sameEntity = afterMember && headAfterMember;
2360 //printf("i=%d blockHeadCol=%d\n",i,yyextra->blockHeadCol);
2361 if (i==yyextra->blockHeadCol || i+1==yyextra->blockHeadCol)
2362 {
2363 replaceCommentMarker(yyscanner,std::string_view(yytext,yyleng));
2364 }
2365 else if (sameEntity)
2366 {
2367 // start the new block on this line, after the newline and the indentation
2368 size_t p=offset;
2369 while (p<(size_t)yyleng && (yytext[p]==' ' || yytext[p]=='\t')) p++;
2370 bool javadoc = yytext[p+2]=='/';
2371 copyToOutput(yyscanner," */");
2372 copyToOutput(yyscanner,std::string_view(yytext,p));
2373 yyextra->blockHeadCol=i+1;
2374 yyextra->blockHeadPos=yyextra->outBuf.size();
2375 // With AUTOBRIEF the first sentence of this block would become the brief description
2376 // when the lines before it did not give one, so use the style AUTOBRIEF does not apply to.
2377 bool qtAuto = Config_getBool(QT_AUTOBRIEF);
2378 bool jdAuto = Config_getBool(JAVADOC_AUTOBRIEF);
2379 if (javadoc && jdAuto && !qtAuto) javadoc=false;
2380 else if (!javadoc && qtAuto && !jdAuto) javadoc=true;
2381 copyToOutput(yyscanner,javadoc ? "/**<" : "/*!<");
2382 }
2383 else
2384 {
2385 copyToOutput(yyscanner," */");
2386 for (i = yyleng; i>0; )
2387 {
2388 --i;
2389 unput(yytext[i]);
2390 }
2391 yyextra->inSpecialComment=false;
2392 BEGIN(Scan);
2393 }
2394 }
static int computeIndent(const char *s)
static void replaceCommentMarker(yyscan_t yyscanner, std::string_view s)
2395}

References computeIndent(), Config_getBool, copyToOutput(), replaceCommentMarker(), and yyguts_t.

◆ replaceCommentMarker()

void replaceCommentMarker ( yyscan_t yyscanner,
std::string_view s )
static

Definition at line 1766 of file commentcnv.l.

1767{
1768 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1769 if (s.empty()) return;
1770 size_t p = 0;
1771 size_t len = s.length();
1772 char c = 0;
1773 // copy leading blanks
1774 while (p<len && (c=s[p]) && (c==' ' || c=='\t' || c=='\n'))
1775 {
1776 yyextra->outBuf+=c;
1777 if (c=='\n') { yyextra->lineNr++; yyextra->col=0; } else { yyextra->col++; }
1778 p++;
1779 }
1780 // replace start of comment marker by blanks and the last character by a *
1781 int blanks=0;
1782 while (p<len && (c=s[p]) && (c=='/' || c=='!' || c=='#'))
1783 {
1784 blanks++;
1785 p++;
1786 if (p<len && s[p]=='<') // comment-after-item marker
1787 {
1788 blanks++;
1789 p++;
1790 }
1791 if (c=='!') // end after first !
1792 {
1793 break;
1794 }
1795 }
1796 if (blanks>0)
1797 {
1798 while (blanks>2)
1799 {
1800 yyextra->outBuf+=' ';
1801 yyextra->col++;
1802 blanks--;
1803 }
1804 if (blanks>1) { yyextra->outBuf+='*'; yyextra->col++; }
1805 yyextra->outBuf+=' ';
1806 yyextra->col++;
1807 }
1808 // copy comment line to output
1809 yyextra->outBuf+=s.substr(p);
1810 yyextra->col+=static_cast<int>(s.substr(p).length());
1811}

References yyguts_t.

Referenced by replaceComment().

◆ startCondSection()

void startCondSection ( yyscan_t yyscanner,
const DString & sectId )
static

Definition at line 1881 of file commentcnv.l.

1882{
1883 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1884 //printf("startCondSection: skip=%d stack=%d\n",g_skip,g_condStack.count());
1885 CondParser prs;
1886 bool expResult = prs.parse(yyextra->fileName,yyextra->lineNr,sectId);
1887 yyextra->condStack.emplace(yyextra->lineNr,sectId,yyextra->skip);
1888 if (!expResult) // not enabled
1889 {
1890 yyextra->skip=true;
1891 }
Copyright (C) 1997-2026 by Dimitri van Heesch.
Definition condparser.h:29
bool parse(const DString &fileName, int lineNr, const DString &expr)
parses and evaluates the given expression.
1892}

References CondParser::parse(), and yyguts_t.

Referenced by handleCondSectionId().

◆ stateToString()

const char * stateToString ( int state)
static

◆ yylex()

int yylex ( yyscan_t yyscanner)

Definition at line 276 of file commentcnv.l.

278 {NUMBER} { //Note similar code in code.l
279 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
280 copyToOutput(yyscanner,yytext,yyleng);
281 }
282<Scan>{RAWBEGIN} {
283 if (yyextra->lang!=SrcLangExt::Cpp) REJECT;
284 copyToOutput(yyscanner,yytext,yyleng);
285 BEGIN(RawString);
286 }
287<Scan>[^"'!\/\n\\#,\-=; \t@$]* { /* eat anything that is not " / , or \n */
288 copyToOutput(yyscanner,yytext,yyleng);
289 }
290<Scan>[,= ;\t] { /* eat , so we have a nice separator in long initialization lines */
291 copyToOutput(yyscanner,yytext,yyleng);
292 }
293<Scan>"'''"! |
294<Scan>"\"\"\""! { /* start of python long comment */
295 if (yyextra->lang!=SrcLangExt::Python)
296 {
297 REJECT;
298 }
299 else
300 {
301 yyextra->pythonDocString = true;
302 yyextra->pythonDocStringChar = yytext[0];
303 yyextra->nestingCount=1;
304 clearCommentStack(yyscanner); /* to be on the save side */
305 copyToOutput(yyscanner,yytext,yyleng);
306 BEGIN(CComment);
307 yyextra->commentStack.push(yyextra->lineNr);
308 }
309 }
310<Scan>"'''" |
311<Scan>"\"\"\"" { /* start of python long comment */
312 if (yyextra->lang!=SrcLangExt::Python)
313 {
314 REJECT;
315 }
316 else if (Config_getBool(PYTHON_DOCSTRING))
317 {
318 REJECT;
319 }
320 else
321 { /* handle as if """! */
322 yyextra->pythonDocString = true;
323 yyextra->pythonDocStringChar = yytext[0];
324 yyextra->nestingCount=1;
325 clearCommentStack(yyscanner); /* to be on the save side */
326 copyToOutput(yyscanner,yytext,yyleng);
327 BEGIN(CComment);
328 yyextra->commentStack.push(yyextra->lineNr);
329 }
330 }
331<Scan>{B}*![><!]/.*\n {
332 if (yyextra->lang!=SrcLangExt::Fortran)
333 {
334 REJECT;
335 }
336 else
337 {
338 yyextra->nestingCount=0; // Fortran doesn't have an end comment
339 clearCommentStack(yyscanner); /* to be on the save side */
340 yyextra->specialComment=true;
341 copyToOutput(yyscanner,yytext,yyleng);
342 yyextra->blockHeadCol=yyextra->col-2;
343 BEGIN(CComment);
344 yyextra->commentStack.push(yyextra->lineNr);
345 }
346 }
347<Scan>[Cc\*][><!]/.*\n {
348 if (yyextra->lang!=SrcLangExt::Fortran)
349 {
350 REJECT;
351 }
352 else
353 {
354 /* check for fixed format; we might have some conditional as part of multiline if like C<5 .and. & */
355 if (yyextra->isFixedForm && (yyextra->col == 0))
356 {
357 yyextra->nestingCount=0; // Fortran doesn't have an end comment
358 clearCommentStack(yyscanner); /* to be on the save side */
359 yyextra->specialComment=true;
360 copyToOutput(yyscanner,yytext,yyleng);
361 yyextra->blockHeadCol=yyextra->col-1;
362 BEGIN(CComment);
363 yyextra->commentStack.push(yyextra->lineNr);
364 }
365 else
366 {
367 REJECT;
368 }
369 }
370 }
371<Scan>!.*\n {
372 if (yyextra->lang!=SrcLangExt::Fortran)
373 {
374 REJECT;
375 }
376 else
377 {
378 copyToOutput(yyscanner,yytext,yyleng);
379 }
380 }
381<Scan>[Cc\*].*\n {
382 if (yyextra->lang!=SrcLangExt::Fortran)
383 {
384 REJECT;
385 }
386 else
387 {
388 if (yyextra->col == 0)
389 {
390 copyToOutput(yyscanner,yytext,yyleng);
391 }
392 else
393 {
394 REJECT;
395 }
396 }
397 }
398<Scan>[$]?"@\"" { /* start of an interpolated verbatim C# string */
399 if (yyextra->lang!=SrcLangExt::CSharp) REJECT
400 copyToOutput(yyscanner,yytext,yyleng);
401 yyextra->stringContext = YY_START;
402 BEGIN(SkipVerbString);
403 }
404<Scan>"\"" { /* start of a string */
405 copyToOutput(yyscanner,yytext,yyleng);
406 yyextra->stringContext = YY_START;
407 BEGIN(SkipString);
408 }
409<Scan>' {
410 copyToOutput(yyscanner,yytext,yyleng);
411 yyextra->charContext = YY_START;
412 if (yyextra->lang!=SrcLangExt::VHDL)
413 {
414 BEGIN(SkipChar);
415 }
416 }
417<Scan>\n { /* new line */
418 copyToOutput(yyscanner,yytext,yyleng);
419 }
420<Scan>{CPPC}[!/]/.*\n[ \t]*{CPPC}[!/][ \t]*{CMD}"}" { // see bug #8731, don't treat multiline C++ comment as detailed description
421 // if the next line is an end of group marker.
422 yyextra->inSpecialComment=true;
423 yyextra->blockHeadCol=yyextra->col+1;
424 yyextra->insertCppCommentMarker=true;
425 copyToOutput(yyscanner,yytext,yyleng);
426 yyextra->readLineCtx=YY_START;
427 BEGIN(ReadLine);
428 }
429<Scan>{CPPC}"!"/.*\n[ \t]*{CPPC}[\/!][^\/] | /* start C++ style special comment block */
430<Scan>({CPPC}"/"[/]*)/[^/].*\n[ \t]*{CPPC}[\/!][^\/] { /* start C++ style special comment block */
431 if (yyextra->mlBrief)
432 {
433 REJECT; // bail out if we do not need to convert
434 }
435 else
436 {
437 int i=3;
438 if (yytext[2]=='/')
439 {
440 while (i<(int)yyleng && yytext[i]=='/') i++;
441 }
442 yyextra->blockHeadCol=yyextra->col+1;
443 yyextra->blockHeadPos=yyextra->skip ? std::string::npos : yyextra->outBuf.size(); // see replaceComment()
444 if (yytext[2] == '!')
445 {
446 copyToOutput(yyscanner,"/*!");
447 }
448 else
449 {
450 copyToOutput(yyscanner,"/**");
451 }
452 if (i<yyleng) replaceAliases(yyscanner,yytext+i);
453 yyextra->inSpecialComment=true;
454 //BEGIN(SComment);
455 yyextra->readLineCtx=SComment;
456 BEGIN(ReadLine);
457 }
458 }
static void replaceAliases(yyscan_t yyscanner, std::string_view s, bool replaceCppComment=false, bool replaceCComment=false)
copies string s with length len to the output, while replacing any alias commands found in the string...
459<Scan>{CPPC}"##Documentation"{ANYopt}/\n { /* Start of Rational Rose ANSI C++ comment block */
460 if (yyextra->mlBrief) REJECT;
461 int i=17; //=strlen("//##Documentation");
462 yyextra->blockHeadCol=yyextra->col+1;
463 yyextra->blockHeadPos=yyextra->skip ? std::string::npos : yyextra->outBuf.size(); // see replaceComment()
464 copyToOutput(yyscanner,"/**");
465 if (i<yyleng) replaceAliases(yyscanner,yytext+i);
466 yyextra->inRoseComment=true;
467 BEGIN(SComment);
468 }
469<Scan>{CPPC}[!\/]/.*\n[ \t]*{CPPC}[|\/][ \t]*{CMD}"}" { // next line contains an end marker, see bug 752712
470 yyextra->inSpecialComment=yytext[2]=='/' || yytext[2]=='!';
471 if (yyextra->inSpecialComment)
472 {
473 yyextra->blockHeadCol=yyextra->col+1;
474 }
475 copyToOutput(yyscanner,yytext,yyleng);
476 yyextra->readLineCtx=YY_START;
477 BEGIN(ReadLine);
478 }
479<Scan>{CPPC}[!/]/.*\n { /* one line special C++ comment */
480 yyextra->inSpecialComment=true;
481 yyextra->blockHeadCol=yyextra->col+1;
482 yyextra->insertCppCommentMarker=true;
483 copyToOutput(yyscanner,yytext,yyleng);
484 yyextra->readLineCtx=YY_START;
485 BEGIN(ReadLine);
486 }
487<Scan>{CPPC}/.*\n { /* one line normal C++ comment */
488 yyextra->inSpecialComment=false;
489 copyToOutput(yyscanner,yytext,yyleng);
490 yyextra->readLineCtx=YY_START;
491 BEGIN(CopyLine);
492 }
493<Scan>{CCS}{CCE} { /* avoid matching next rule for empty C comment, see bug 711723 */
494 copyToOutput(yyscanner,yytext,yyleng);
495 }
496<Scan>{CCS}[*!]? { /* start of a C comment */
497 if (yyextra->lang==SrcLangExt::Python)
498 {
499 REJECT;
500 }
501 yyextra->specialComment=(int)yyleng==3;
502 yyextra->nestingCount=1;
503 clearCommentStack(yyscanner); /* to be on the save side */
504 copyToOutput(yyscanner,yytext,yyleng);
505 if (yyextra->specialComment)
506 {
507 yyextra->blockHeadCol=0;
508 BEGIN(CComment);
509 }
510 else
511 {
512 BEGIN(CNComment);
513 }
514 yyextra->commentStack.push(yyextra->lineNr);
515 }
516<Scan>"#"[^\n]*\n {
517 if (yyextra->lang!=SrcLangExt::PHP)
518 {
519 REJECT;
520 }
521 copyToOutput(yyscanner,yytext,yyleng);
522 }
523<Scan>"#"("#")? {
524 if (yyextra->lang!=SrcLangExt::Python)
525 {
526 REJECT;
527 }
528 else
529 {
530 yyextra->nestingCount=0; // Python doesn't have an end comment for #
531 clearCommentStack(yyscanner); /* to be on the save side */
532 yyextra->specialComment=(int)yyleng==2;
533 if (yyextra->specialComment)
534 {
535 yyextra->blockHeadCol=yyextra->col;
536 }
537 yyextra->commentStack.push(yyextra->lineNr);
538 copyToOutput(yyscanner,yytext,yyleng);
539 BEGIN(CComment);
540 }
541 }
542<Scan>"--"[^!][^\n]* {
543 if (yyextra->lang!=SrcLangExt::VHDL)
544 {
545 REJECT;
546 }
547 else
548 {
549 copyToOutput(yyscanner,yytext,yyleng);
550 }
551 }
552<Scan>"--!" {
553 if (yyextra->lang!=SrcLangExt::VHDL)
554 {
555 REJECT;
556 }
557 else
558 {
559 yyextra->specialComment=true;
560 yyextra->blockHeadCol=yyextra->col;
561 yyextra->vhdl = true;
562 yyextra->nestingCount=0; // VHDL doesn't have an end comment
563 clearCommentStack(yyscanner); /* to be on the save side */
564 yyextra->commentStack.push(yyextra->lineNr);
565 copyToOutput(yyscanner,yytext,yyleng);
566 BEGIN(CComment);
567 }
568 }
569<Scan>{B}*![><!] {
570 if (yyextra->lang!=SrcLangExt::Fortran)
571 {
572 REJECT;
573 }
574 else
575 {
576 yyextra->nestingCount=0; // Fortran doesn't have an end comment
577 clearCommentStack(yyscanner); /* to be on the save side */
578 yyextra->specialComment=true;
579 yyextra->blockHeadCol=yyextra->col;
580 yyextra->commentStack.push(yyextra->lineNr);
581 copyToOutput(yyscanner,yytext,yyleng);
582 BEGIN(CComment);
583 }
584 }
585<RawString>{RAWEND} {
586 copyToOutput(yyscanner,yytext,yyleng);
587 if (extractEndRawStringDelimiter(yytext)==yyextra->delimiter)
588 {
589 BEGIN(Scan);
590 }
591 }
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5399
592<RawString>[^)\n]+ { copyToOutput(yyscanner,yytext,yyleng); }
593<RawString>\n { copyToOutput(yyscanner,yytext,yyleng); }
594<RawString>. { copyToOutput(yyscanner,yytext,yyleng); }
595
596<CComment,CNComment,ReadLine,IncludeFile>{MAILADDR} |
597<CComment,CNComment,ReadLine,IncludeFile>"<"{MAILADDR}">" { // Mail address, to prevent seeing e.g x@code-factory.org as start of a code block
598 copyToOutput(yyscanner,yytext,yyleng);
599 }
600<CComment,IncludeFile>"{"[ \t]*"@code"/[ \t\n] {
601 copyToOutput(yyscanner,"@iliteral{code}");
602 yyextra->lastCommentContext = YY_START;
603 yyextra->javaBlock=1;
604 yyextra->blockName=DString("end")+&yytext[1];
605 yyextra->inVerbatim=true;
606 yyextra->verbatimLine=yyextra->lineNr;
607 BEGIN(VerbatimCode);
608 }
609<CComment,IncludeFile>"{"[ \t]*"@literal"/[ \t\n] {
610 copyToOutput(yyscanner,"@iliteral");
611 yyextra->lastCommentContext = YY_START;
612 yyextra->javaBlock=1;
613 yyextra->blockName=DString("end")+&yytext[1];
614 yyextra->inVerbatim=true;
615 yyextra->verbatimLine=yyextra->lineNr;
616 BEGIN(VerbatimCode);
617 }
618<CComment,ReadLine,IncludeFile>{CMD}"ilinebr"[ \t]+("```"[`]*|"~~~"[~]*) { /* start of markdown code block */
619 if (!Config_getBool(MARKDOWN_SUPPORT))
620 {
621 REJECT;
622 }
623 copyToOutput(yyscanner,yytext,yyleng);
624 yyextra->lastCommentContext = YY_START;
625 yyextra->javaBlock=0;
626 yyextra->blockName=DString(yytext).stripWhiteSpace().right(3); // take the ``` or ~~~ part
627 yyextra->inVerbatim=true;
628 yyextra->verbatimLine=yyextra->lineNr;
629 BEGIN(VerbatimCode);
630 }
DString right(size_t len) const
Definition dstring.h:311
631<CComment,ReadLine,IncludeFile>^[ \t]*("```"[`]*|"~~~"[~]*) { /* start of markdown code block */
632 if (!Config_getBool(MARKDOWN_SUPPORT))
633 {
634 REJECT;
635 }
636 copyToOutput(yyscanner,yytext,yyleng);
637 yyextra->lastCommentContext = YY_START;
638 yyextra->javaBlock=0;
639 yyextra->blockName=DString(yytext).stripWhiteSpace().left(3); // take the ``` or ~~~ part
640 yyextra->inVerbatim=true;
641 yyextra->verbatimLine=yyextra->lineNr;
642 BEGIN(VerbatimCode);
643 }
DString left(size_t len) const
Definition dstring.h:306
644<CComment,ReadLine,IncludeFile>{CMD}("dot"|"code"|"msc"|"startuml"|"mermaid")/[^a-z_A-Z0-9] { /* start of a verbatim block */
645 copyToOutput(yyscanner,yytext,yyleng);
646 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
647 {
648 yyextra->lastCommentContext = YY_START;
649 yyextra->javaBlock=0;
650 if (dstrcmp(&yytext[1],"startuml")==0)
651 {
652 yyextra->blockName="enduml";
653 }
654 else
655 {
656 yyextra->blockName=DString("end")+&yytext[1];
657 }
658 yyextra->inVerbatim=true;
659 yyextra->verbatimLine=yyextra->lineNr;
660 BEGIN(VerbatimCode);
661 }
662 }
int dstrcmp(const char *str1, const char *str2)
Definition dstring.h:50
663<CComment,ReadLine,IncludeFile>"\\`" {
664 copyToOutput(yyscanner,yytext,yyleng);
665 }
666<CComment,ReadLine,IncludeFile>"```" { // skip ``` if not at the start of the line
667 copyToOutput(yyscanner,yytext,yyleng);
668 }
669<CComment,ReadLine,IncludeFile>"`"{1,2} {
670 if (!Config_getBool(MARKDOWN_SUPPORT))
671 {
672 REJECT;
673 }
674 copyToOutput(yyscanner,yytext,yyleng);
675 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
676 {
677 yyextra->lastCommentContext = YY_START;
678 yyextra->javaBlock=0;
679 yyextra->blockName=yytext;
680 yyextra->inVerbatim=true;
681 yyextra->verbatimLine=yyextra->lineNr;
682 BEGIN(VerbatimCode);
683 }
684 }
685<CComment,ReadLine,IncludeFile>{CMD}("f$"|"f["|"f{"|"f(") {
686 copyToOutput(yyscanner,yytext,yyleng);
687 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
688 {
689 yyextra->blockName=&yytext[1];
690 if (yyextra->blockName.at(1)=='[')
691 {
692 yyextra->blockName.at(1)=']';
693 }
694 else if (yyextra->blockName.at(1)=='{')
695 {
696 yyextra->blockName.at(1)='}';
697 }
698 else if (yyextra->blockName.at(1)=='(')
699 {
700 yyextra->blockName.at(1)=')';
701 }
702 yyextra->lastCommentContext = YY_START;
703 yyextra->inVerbatim=true;
704 yyextra->verbatimLine=yyextra->lineNr;
705 BEGIN(Verbatim);
706 }
707 }
708<CComment,ReadLine,IncludeFile>"<!--!" { /* HTML comment doxygen command*/
709 if (yyextra->inVerbatim) REJECT;
710 //copyToOutput(yyscanner," ",5);
711 yyextra->inHtmlDoxygenCommand=true;
712 }
713<CComment,ReadLine,IncludeFile>"-->" { /* potential end HTML comment doxygen command*/
714 if (yyextra->inHtmlDoxygenCommand)
715 {
716 yyextra->inHtmlDoxygenCommand=false;
717 }
718 else
719 {
720 copyToOutput(yyscanner,yytext,yyleng);
721 }
722 }
723<CComment,ReadLine,IncludeFile>"<!--" { /* HTML comment */
724 copyToOutput(yyscanner,yytext,yyleng);
725 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
726 {
727 yyextra->blockName="-->";
728 yyextra->lastCommentContext = YY_START;
729 yyextra->inVerbatim=true;
730 yyextra->verbatimLine=yyextra->lineNr;
731 BEGIN(Verbatim);
732 }
733 }
734<CComment,ReadLine,IncludeFile>{CMD}("verbatim"|"iliteral"|"latexonly"|"htmlonly"|"xmlonly"|"docbookonly"|"rtfonly"|"manonly")/[^a-z_A-Z0-9] { /* start of a verbatim block */
735 copyToOutput(yyscanner,yytext,yyleng);
736 if (yyextra->inSpecialComment || yyextra->specialComment || yyextra->lang==SrcLangExt::Markdown)
737 {
738 yyextra->blockName=DString("end")+&yytext[1];
739 yyextra->lastCommentContext = YY_START;
740 yyextra->inVerbatim=true;
741 yyextra->verbatimLine=yyextra->lineNr;
742 BEGIN(Verbatim);
743 }
744 }
745<Scan>"\\\"" { /* escaped double quote */
746 copyToOutput(yyscanner,yytext,yyleng);
747 }
748<Scan>"\\\\" { /* escaped backslash */
749 copyToOutput(yyscanner,yytext,yyleng);
750 }
751<Scan>. { /* any other character */
752 copyToOutput(yyscanner,yytext,yyleng);
753 }
754<Verbatim>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
755 copyToOutput(yyscanner,yytext,yyleng);
756 if (&yytext[1]==yyextra->blockName) // end of command or formula
757 {
758 yyextra->inVerbatim=false;
759 BEGIN(yyextra->lastCommentContext);
760 }
761 }
762<Verbatim>"-->" {
763 copyToOutput(yyscanner,yytext,yyleng);
764 if (yytext==yyextra->blockName)
765 {
766 yyextra->inVerbatim=false;
767 BEGIN(yyextra->lastCommentContext);
768 }
769 }
770<VerbatimCode>"{" {
771 if (yyextra->javaBlock==0)
772 {
773 REJECT;
774 }
775 else
776 {
777 yyextra->javaBlock++;
778 copyToOutput(yyscanner,yytext,yyleng);
779 }
780 }
781<VerbatimCode>"}" {
782 if (yyextra->javaBlock==0)
783 {
784 REJECT;
785 }
786 else
787 {
788 yyextra->javaBlock--;
789 if (yyextra->javaBlock==0)
790 {
791 copyToOutput(yyscanner," @endiliteral ");
792 yyextra->inVerbatim=false;
793 BEGIN(yyextra->lastCommentContext);
794 }
795 else
796 {
797 copyToOutput(yyscanner,yytext,yyleng);
798 }
799 }
800 }
801<VerbatimCode>("```"[`]*|"~~~"[~]*) { /* end of markdown code block */
802 if (yytext[0]=='`' && (yyextra->blockName=="`" || yyextra->blockName=="``")) // ``` type block inside single or double backtick "block"
803 {
804 // copy the end block marker
805 copyToOutput(yyscanner,yytext,yyleng);
806 }
807 else
808 {
809 copyToOutput(yyscanner,yytext,yyleng);
810 if (yytext[0]==yyextra->blockName[0])
811 {
812 yyextra->inVerbatim=false;
813 BEGIN(yyextra->lastCommentContext);
814 }
815 }
816 }
817<VerbatimCode>"''" {
818 copyToOutput(yyscanner,yytext,yyleng);
819 if (!Config_getBool(MARKDOWN_STRICT) && yyextra->blockName=="``") // support for ``text''
820 {
821 yyextra->inVerbatim=false;
822 BEGIN(yyextra->lastCommentContext);
823 }
824 }
825<VerbatimCode>"'" {
826 copyToOutput(yyscanner,yytext,yyleng);
827 if (!Config_getBool(MARKDOWN_STRICT) && yyextra->blockName=="`") // support for `text'
828 {
829 yyextra->inVerbatim=false;
830 BEGIN(yyextra->lastCommentContext);
831 }
832 }
833<VerbatimCode>"`"{1,2} {
834 copyToOutput(yyscanner,yytext,yyleng);
835 if (yytext==yyextra->blockName)
836 {
837 yyextra->inVerbatim=false;
838 BEGIN(yyextra->lastCommentContext);
839 }
840 }
841<VerbatimCode>{CMD}("enddot"|"endcode"|"endmsc"|"enduml"|"endmermaid")/("{")? { // end of verbatim block
842 copyToOutput(yyscanner,yytext,yyleng);
843 if (&yytext[1]==yyextra->blockName)
844 {
845 yyextra->inVerbatim=false;
846 BEGIN(yyextra->lastCommentContext);
847 }
848 }
849<VerbatimCode>^[ \t]*{CPPC}[\!\/]? { /* skip leading comments */
850 if (!yyextra->inSpecialComment || yyextra->mlBrief)
851 {
852 copyToOutput(yyscanner,yytext,yyleng);
853 }
854 else
855 {
856 int l=0;
857 while (yytext[l]==' ' || yytext[l]=='\t')
858 {
859 l++;
860 }
861 copyToOutput(yyscanner,yytext,l);
862 if (yyleng-l==3) // ends with //! or ///
863 {
864 copyToOutput(yyscanner," * ");
865 }
866 else // ends with //
867 {
868 copyToOutput(yyscanner,"//");
869 }
870 }
871 }
872<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]* { /* any character not a backslash or new line or } */
873 copyToOutput(yyscanner,yytext,yyleng);
874 }
875<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n{B}*"//" {
876 if (yyextra->lastCommentContext!=ReadLine)
877 {
878 REJECT;
879 }
880 else
881 {
882 copyToOutput(yyscanner,yytext,yyleng);
883 }
884 }
885<Verbatim,VerbatimCode>[^`'~@\/\-\\\n{}]+/\n { /* premature end of comment block */
886 if (yyextra->lastCommentContext==ReadLine)
887 {
888 yyextra->inVerbatim=false;
889 BEGIN(yyextra->lastCommentContext);
890 }
891 copyToOutput(yyscanner,yytext,yyleng);
892 }
893<Verbatim,VerbatimCode>\n { /* new line in verbatim block */
894 copyToOutput(yyscanner,yytext,yyleng);
895 if (yyextra->lastCommentContext == IncludeFile)
896 {
897 insertCommentStart(yyscanner);
898 }
899 }
900<Verbatim>^[ \t]*{CPPC}[/!] {
901 if (yyextra->blockName=="enddot" || yyextra->blockName=="endmsc" || yyextra->blockName=="enduml" || yyextra->blockName.at(0)=='f')
902 {
903 // see bug 487871, strip /// from dot images and formulas.
904 int l=0;
905 while (yytext[l]==' ' || yytext[l]=='\t')
906 {
907 l++;
908 }
909 copyToOutput(yyscanner,yytext,l);
910 copyToOutput(yyscanner," ");
911 }
912 else // even slashes are verbatim (e.g. \verbatim, \code)
913 {
914 REJECT;
915 }
916 }
917<Verbatim,VerbatimCode>. { /* any other character */
918 copyToOutput(yyscanner,yytext,yyleng);
919 }
920<SkipString>\\. { /* escaped character in string */
921 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
922 {
923 unput(yytext[1]);
924 copyToOutput(yyscanner,yytext,1);
925 }
926 else
927 {
928 copyToOutput(yyscanner,yytext,yyleng);
929 }
930 }
931<SkipString>"\"" { /* end of string */
932 copyToOutput(yyscanner,yytext,yyleng);
933 BEGIN(yyextra->stringContext);
934 }
935<SkipString>. { /* any other string character */
936 copyToOutput(yyscanner,yytext,yyleng);
937 }
938<SkipString>\n { /* new line inside string (illegal for some compilers) */
939 copyToOutput(yyscanner,yytext,yyleng);
940 }
941<SkipVerbString>[^"\n]+ {
942 copyToOutput(yyscanner,yytext,yyleng);
943 }
944<SkipVerbString>\"\" { // escaped quote
945 copyToOutput(yyscanner,yytext,yyleng);
946 }
947<SkipVerbString>"\"" { /* end of string */
948 copyToOutput(yyscanner,yytext,yyleng);
949 BEGIN(yyextra->stringContext);
950 }
951<SkipVerbString>. {
952 copyToOutput(yyscanner,yytext,yyleng);
953 }
954<SkipVerbString>\n {
955 copyToOutput(yyscanner,yytext,yyleng);
956 }
957<SkipChar>\\. { /* escaped character */
958 if (yyextra->lang==SrcLangExt::Fortran || yyextra->lang==SrcLangExt::VHDL)
959 {
960 unput(yytext[1]);
961 copyToOutput(yyscanner,yytext,1);
962 }
963 else
964 {
965 copyToOutput(yyscanner,yytext,yyleng);
966 }
967 }
968<SkipChar>' { /* end of character literal */
969 copyToOutput(yyscanner,yytext,yyleng);
970 BEGIN(yyextra->charContext);
971 }
972<SkipChar>. { /* any other string character */
973 copyToOutput(yyscanner,yytext,yyleng);
974 }
975<SkipChar>\n { /* new line character */
976 copyToOutput(yyscanner,yytext,yyleng);
977 }
978
979<CComment,CNComment>[^ `~<\\!@*\n{\"'\/-`]* { /* anything that is not a '*' or command */
980 copyToOutput(yyscanner,yytext,yyleng);
981 }
982<CComment,CNComment>^{B}*"*"+[^*\/<\\@\n{\"`]* { /* stars without slashes */
983 if (yyextra->lang==SrcLangExt::Markdown) REJECT;
984 yyextra->col = computeIndent(yytext);
985 if (yyextra->col>yyextra->blockHeadCol)
986 {
987 //printf("new blockHeadCol=%d\n",yyextra->blockHeadCol);
988 yyextra->blockHeadCol=yyextra->col;
989 }
990 copyToOutput(yyscanner,yytext,yyleng);
991 }
992<CComment>"'''" |
993<CComment>"\"\"\"" { /* end of Python docstring */
994 if (yyextra->lang!=SrcLangExt::Python)
995 {
996 REJECT;
997 }
998 else if (yyextra->pythonDocStringChar != yytext[0])
999 {
1000 copyToOutput(yyscanner,yytext,yyleng);
1001 }
1002 else
1003 {
1004 yyextra->nestingCount--;
1005 yyextra->pythonDocString = false;
1006 yyextra->pythonDocStringChar = '\0';
1007 copyToOutput(yyscanner,yytext,yyleng);
1008 BEGIN(Scan);
1009 }
1010 }
1011<CComment,CNComment>\n { /* new line in comment */
1012 copyToOutput(yyscanner,yytext,yyleng);
1013 /* in case of Fortran always end of comment */
1014 if (yyextra->lang==SrcLangExt::Fortran)
1015 {
1016 BEGIN(Scan);
1017 }
1018 }
1019<CComment,CNComment>"/""/"+/"*/" { /* we are already in C-comment so not a start of a nested comment but
1020 * just the end of the comment (the end part is handled later). */
1021 copyToOutput(yyscanner,yytext,yyleng);
1022 }
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180
1023<CComment,CNComment>"/"+"*" { /* nested C comment */
1024 if (yyextra->lang==SrcLangExt::Python ||
1025 yyextra->lang==SrcLangExt::Markdown)
1026 {
1027 REJECT;
1028 }
1029 yyextra->nestingCount++;
1030 yyextra->commentStack.push(yyextra->lineNr);
1031 copyToOutput(yyscanner,yytext,yyleng);
1032 }
1033<CComment,CNComment>^{B}*"*"+"/" |
1034<CComment,CNComment>"*"+"/" { /* end of C comment */
1035 if (yyextra->lang==SrcLangExt::Python ||
1036 yyextra->lang==SrcLangExt::Markdown)
1037 {
1038 REJECT;
1039 }
1040 else
1041 {
1042 copyToOutput(yyscanner,yytext,yyleng);
1043 yyextra->nestingCount--;
1044 if (yyextra->nestingCount<=0)
1045 {
1046 BEGIN(Scan);
1047 }
1048 else
1049 {
1050 //yyextra->nestingCount--;
1051 yyextra->commentStack.pop();
1052 }
1053 }
1054 }
1055 /* Python an VHDL share CComment,CNComment, so special attention for ending comments is required */
1056<CComment,CNComment>"\n"/[ \t]*"#" {
1057 if (yyextra->lang!=SrcLangExt::VHDL)
1058 {
1059 REJECT;
1060 }
1061 else
1062 {
1063 if (yyextra->vhdl) // inside --! comment
1064 {
1065 yyextra->vhdl = false;
1066 copyToOutput(yyscanner,yytext,yyleng);
1067 BEGIN(Scan);
1068 }
1069 else // C-type comment
1070 {
1071 REJECT;
1072 }
1073 }
1074 }
1075<CComment,CNComment>"\n"/[ \t]*"-" {
1076 if (yyextra->lang!=SrcLangExt::Python || yyextra->pythonDocString)
1077 {
1078 REJECT;
1079 }
1080 else
1081 {
1082 copyToOutput(yyscanner,yytext,yyleng);
1083 BEGIN(Scan);
1084 }
1085 }
1086<CComment,CNComment>"\n"/[ \t]*[^ \t#\-] {
1087 if (yyextra->lang==SrcLangExt::Python)
1088 {
1089 if (yyextra->pythonDocString)
1090 {
1091 REJECT;
1092 }
1093 else
1094 {
1095 copyToOutput(yyscanner,yytext,yyleng);
1096 BEGIN(Scan);
1097 }
1098 }
1099 else if (yyextra->lang==SrcLangExt::VHDL)
1100 {
1101 if (yyextra->vhdl) // inside --! comment
1102 {
1103 yyextra->vhdl = false;
1104 copyToOutput(yyscanner,yytext,yyleng);
1105 BEGIN(Scan);
1106 }
1107 else // C-type comment
1108 {
1109 REJECT;
1110 }
1111 }
1112 else
1113 {
1114 REJECT;
1115 }
1116 }
1117 /* removed for bug 674842 (bug was introduced in rev 768)
1118<CComment,CNComment>"'" {
1119 yyextra->charContext = YY_START;
1120 copyToOutput(yyscanner,yytext,yyleng);
1121 BEGIN(SkipChar);
1122 }
1123<CComment,CNComment>"\"" {
1124 yyextra->stringContext = YY_START;
1125 copyToOutput(yyscanner,yytext,yyleng);
1126 BEGIN(SkipString);
1127 }
1128 */
1129<CComment,CNComment>{CMD}"~"[a-z_A-Z-]* { // language switch command
1130 if (yyextra->lang!=SrcLangExt::Markdown) REJECT;
1131 DString langId = DString(yytext).mid(2);
1132 if (!langId.empty() &&
1133 dstricmp(Config_getEnumAsString(OUTPUT_LANGUAGE),langId)!=0)
1134 { // enable language specific section
1135 if (!Config_isAvailableEnum(OUTPUT_LANGUAGE,langId))
1136 {
1137 warn(yyextra->fileName,yyextra->lineNr,
1138 "non supported language '{}' specified in '{}'",langId,DString(yytext).stripWhiteSpace());
1139 }
1140 BEGIN(SkipLang);
1141 }
1142 }
#define Config_getEnumAsString(name)
Definition config.h:36
#define Config_isAvailableEnum(name, value)
Definition config.h:45
int dstricmp(const char *s1, const char *s2)
Definition dstring.cpp:444
1143<CComment,CNComment>{CMD}{CMD} |
1144<CComment,CNComment>. {
1145 copyToOutput(yyscanner,yytext,yyleng);
1146 }
1147<SkipLang>{CMD}"~"[a-zA-Z-]* { /* language switch */
1148 DString langId(&yytext[2]);
1149 if (!langId.empty() && !Config_isAvailableEnum(OUTPUT_LANGUAGE,langId))
1150 {
1151 warn(yyextra->fileName,yyextra->lineNr,
1152 "non supported language '{}' specified in '{}'",langId,DString(yytext).stripWhiteSpace());
1153 }
1154 else if (langId.empty() ||
1155 dstricmp(Config_getEnumAsString(OUTPUT_LANGUAGE),langId)==0)
1156 { // enable language specific section
1157 BEGIN(CComment);
1158 }
1159 }
1160<SkipLang>[^*@\\\n]* { /* any character not a *, @, backslash or new line */
1161 }
1162<SkipLang>\n { /* new line in language block, needed for keeping track of line numbers */
1163 copyToOutput(yyscanner,yytext,yyleng);
1164 }
1165<SkipLang>. { /* any other character */
1166 }
1167<SComment>^[ \t]*{CPPC}"/"{SLASHopt}/\n {
1168 replaceComment(yyscanner,0);
1169 }
static void replaceComment(yyscan_t yyscanner, int offset)
1170<SComment>\n[ \t]*{CPPC}"/"{SLASHopt}/\n {
1171 replaceComment(yyscanner,1);
1172 }
1173<SComment>^[ \t]*{CPPC}"/"[^\/\n]/.*\n {
1174 replaceComment(yyscanner,0);
1175 yyextra->readLineCtx=YY_START;
1176 YY_CURRENT_BUFFER->yy_at_bol=1;
1177 BEGIN(ReadLine);
1178 }
1179<SComment>\n[ \t]*{CPPC}[\/!]("<")?[ \t]*{CMD}"}".*\n {
1180 /* See Bug 752712: end the multiline comment when finding a @} or \} command */
1181 copyToOutput(yyscanner," */");
1182 copyToOutput(yyscanner,yytext,yyleng);
1183 yyextra->inSpecialComment=false;
1184 yyextra->inRoseComment=false;
1185 BEGIN(Scan);
1186 }
1187<SComment>\n[ \t]*{CPPC}"/"[^\\@\/\n]/.*\n {
1188 replaceComment(yyscanner,1);
1189 yyextra->readLineCtx=YY_START;
1190 YY_CURRENT_BUFFER->yy_at_bol=1;
1191 BEGIN(ReadLine);
1192 }
1193<SComment>^[ \t]*{CPPC}"!" | // just //!
1194<SComment>^[ \t]*{CPPC}"!<"/.*\n | // or //!< something
1195<SComment>^[ \t]*{CPPC}"!"[^<]/.*\n { // or //!something
1196 replaceComment(yyscanner,0);
1197 yyextra->readLineCtx=YY_START;
1198 YY_CURRENT_BUFFER->yy_at_bol=1;
1199 BEGIN(ReadLine);
1200 }
1201<SComment>\n[ \t]*{CPPC}"!" |
1202<SComment>\n[ \t]*{CPPC}"!<"/.*\n |
1203<SComment>\n[ \t]*{CPPC}"!"[^<\n]/.*\n {
1204 replaceComment(yyscanner,1);
1205 yyextra->readLineCtx=YY_START;
1206 YY_CURRENT_BUFFER->yy_at_bol=1;
1207 BEGIN(ReadLine);
1208 }
1209<SComment>^[ \t]*{CPPC}"##"/.*\n {
1210 if (!yyextra->inRoseComment)
1211 {
1212 REJECT;
1213 }
1214 else
1215 {
1216 replaceComment(yyscanner,0);
1217 yyextra->readLineCtx=YY_START;
1218 YY_CURRENT_BUFFER->yy_at_bol=1;
1219 BEGIN(ReadLine);
1220 }
1221 }
1222<SComment>\n[ \t]*{CPPC}"##"/.*\n {
1223 if (!yyextra->inRoseComment)
1224 {
1225 REJECT;
1226 }
1227 else
1228 {
1229 replaceComment(yyscanner,1);
1230 yyextra->readLineCtx=YY_START;
1231 YY_CURRENT_BUFFER->yy_at_bol=1;
1232 BEGIN(ReadLine);
1233 }
1234 }
1235<SComment>\n { /* end of special comment */
1236 copyToOutput(yyscanner," */");
1237 copyToOutput(yyscanner,yytext,yyleng);
1238 yyextra->inSpecialComment=false;
1239 yyextra->inRoseComment=false;
1240 yyextra->insertCppCommentMarker=false;
1241 yyextra->readLineCtx = Scan; // reset, otherwise there will be problems with:
1242 // static void handleCondSectionId
1243 BEGIN(Scan);
1244 }
1245<ReadLine,CopyLine>{CCS}"*" {
1246 copyToOutput(yyscanner,"/&zwj;**");
1247 }
1248<ReadLine,CopyLine>{CCE} {
1249 copyToOutput(yyscanner,"*&zwj;/");
1250 }
1251<ReadLine,CopyLine>"*" {
1252 copyToOutput(yyscanner,yytext,yyleng);
1253 }
1254<ReadLine,CopyLine>{RL} {
1255 copyToOutput(yyscanner,yytext,yyleng);
1256 }
1257<ReadLine,CopyLine>{RL}/{B}{CMD}"ilinebr"{B} {
1258 copyToOutput(yyscanner,yytext,yyleng);
1259 }
1260<ReadLine,CopyLine>{RLopt}/\n {
1261 copyToOutput(yyscanner,yytext,yyleng);
1262 yyextra->insertCppCommentMarker=false;
1263 BEGIN(yyextra->readLineCtx);
1264 }
1265<CComment,CNComment,ReadLine>"\<" { /* escaped html comment */
1266 copyToOutput(yyscanner,yytext,yyleng);
1267 }
1268<CComment,CNComment,ReadLine>{CMD}{CMD}[~a-z_A-Z][a-z_A-Z0-9]*[ \t]* { // escaped command
1269 copyToOutput(yyscanner,yytext,yyleng);
1270 }
1271
1272<CComment,ReadLine,IncludeFile>{CMD}("include"{OPTS}|"includedoc"{OPTS}*) {
1273 if (!parseIncludeOptions(yyscanner,std::string_view{yytext,static_cast<size_t>(yyleng)})) REJECT;
1274 yyextra->includeCtx = YY_START;
1275 yyextra->firstIncludeLine = true;
1276 yyextra->insertCommentCol = yyextra->col;
1277 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1278 {
1279 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1280 }
1281 //printf("blockHeadCol=%d insertCommentCol=%d\n",yyextra->blockHeadCol, yyextra->insertCommentCol);
1282 yyextra->snippetRtn = 0;
1283 BEGIN(IncludeDoc);
1284 }
static bool parseIncludeOptions(yyscan_t yyscanner, std::string_view s)
1285<CComment,ReadLine,IncludeFile>{CMD}("snippet"{OPTS}|"snippetdoc"{OPTS}*) {
1286 if (!parseIncludeOptions(yyscanner,std::string_view{yytext,static_cast<size_t>(yyleng)})) REJECT;
1287 yyextra->includeCtx = YY_START;
1288 yyextra->firstIncludeLine = true;
1289 yyextra->insertCommentCol = yyextra->col;
1290 if (!yyextra->insertCppCommentMarker && (yyextra->includeCtx==ReadLine || yyextra->includeCtx==IncludeFile))
1291 {
1292 yyextra->insertCppCommentMarker = yyextra->mlBrief;
1293 }
1294 //printf("blockHeadCol=%d insertCommentCol=%d\n",yyextra->blockHeadCol, yyextra->insertCommentCol);
1295 yyextra->snippetRtn = 0;
1296 BEGIN(SnippetDoc);
1297 }
1298<IncludeDoc,SnippetDoc>{B}*{CCE} {
1299 warn(yyextra->fileName,yyextra->lineNr,"Found \\{}{{doc}} command without valid file name argument",
1300 YY_START==IncludeDoc? "include" : "snippet"
1301 );
1302 for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1303 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1304 copyToOutput(yyscanner,lineStr.view());
1305 BEGIN(yyextra->includeCtx);
1306 }
1307<IncludeDoc,SnippetDoc>^{B}*"*"+{B}* {
1308 if (!(yyextra->snippetRtn && (yyextra->includeCtx==CComment || yyextra->includeCtx==CNComment))) REJECT;
1309 }
1310<IncludeDoc,SnippetDoc>{B}*
1311<IncludeDoc>{FILEMASK}|"\""[^\n\"]+"\"" {
1312 DString fileName=yytext;
1313 if (yytext[0]=='"')
1314 {
1315 fileName=fileName.mid(1,fileName.length()-2); // strip quotes
1316 }
1317 if (readIncludeFile(yyscanner,fileName,""))
1318 {
1319 BEGIN(IncludeFile);
1320 }
1321 else
1322 {
1323 BEGIN(yyextra->includeCtx);
1324 }
1325 }
static bool readIncludeFile(yyscan_t yyscanner, const DString &inc, const DString &blockId)
1326<SnippetDoc>({FILEMASK}|"\""[^\n\"]+"\"") {
1327 yyextra->snippetFileName=yytext;
1328 yyextra->snippetFileName=yyextra->snippetFileName.stripWhiteSpace();
1329 if (yyextra->snippetFileName == "this") yyextra->snippetFileName=yyextra->fileName;
1330 yyextra->snippetName = "";
1331 yyextra->snippetRtn = 0;
1332 BEGIN(SnippetDocTag);
1333 }
1334<SnippetDocTag>\n{B}*{CPPC}[\/!]{B}*/\n {
1335 if (!yyextra->snippetName.stripWhiteSpace().empty()) REJECT;
1336
1337 warn_doc_error(yyextra->fileName,yyextra->lineNr,"no block identification found in \\snippet{{doc}} command, skipping");
1338 yyextra->lineNr++;
1339 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1340 copyToOutput(yyscanner,lineStr.view());
1341 BEGIN(yyextra->includeCtx);
1342 }
1343<SnippetDocTag>\n{B}*{CPPC}[\/!] {
1344 if (yyextra->snippetName.stripWhiteSpace().empty())
1345 {
1346 if (yyextra->snippetRtn)
1347 {
1348 warn_doc_error(yyextra->fileName,yyextra->lineNr,"no block identification found in \\snippet{{doc}} command, skipping");
1349 yyextra->lineNr++;
1350 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1351 copyToOutput(yyscanner,lineStr.view());
1352 BEGIN(yyextra->includeCtx);
1353 }
1354 else
1355 {
1356 yyextra->lineNr++;
1357 }
1358 }
1359 else
1360 {
1361 REJECT;
1362 }
1363 }
1364<SnippetDocTag>{B}*{CCE} {
1365 if (!yyextra->snippetName.stripWhiteSpace().empty()) REJECT;
1366
1367 warn_doc_error(yyextra->fileName,yyextra->lineNr,"no block identification found in \\snippet{{doc}} command, skipping");
1368 for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1369 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1370 copyToOutput(yyscanner,lineStr.view());
1371 BEGIN(yyextra->includeCtx);
1372 }
1373<SnippetDocTag>^{B}*"*"+{B}* {
1374 if (!(yyextra->snippetRtn && (yyextra->includeCtx==CComment || yyextra->includeCtx==CNComment))) REJECT;
1375 }
1376<SnippetDocTag>[^\\@\n]+ {
1377 yyextra->snippetName += yytext;
1378 }
1379<SnippetDocTag>{CMD} {
1380 yyextra->snippetName += yytext;
1381 }
1382
1383<SnippetDocTag>(\n|{CMD}"ilinebr")/{B}*("*/")? |
1384<SnippetDocTag>(\n|{CMD}"ilinebr"){B}*"*" {
1385 if (!yyextra->snippetName.stripWhiteSpace().empty() || yyextra->snippetRtn)
1386 {
1387 for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1388 yyextra->snippetName = yyextra->snippetName.stripWhiteSpace();
1389 DString blockId = "["+yyextra->snippetName+"]";
1390 if (readIncludeFile(yyscanner,yyextra->snippetFileName,blockId))
1391 {
1392 BEGIN(IncludeFile);
1393 }
1394 else
1395 {
1396 BEGIN(yyextra->includeCtx);
1397 }
1398 }
1399 else if (yyextra->snippetName.stripWhiteSpace().empty() && !yyextra->snippetRtn &&
1400 yyextra->includeCtx == ReadLine)
1401 {
1402 warn_doc_error(yyextra->fileName,yyextra->lineNr,"no block identification found in \\snippet{{doc}} command, skipping");
1403 for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]);
1404 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1405 copyToOutput(yyscanner,lineStr.view());
1406 BEGIN(yyextra->includeCtx);
1407 }
1408 else
1409 {
1410 if (yytext[0] == '\n')
1411 {
1412 yyextra->lineNr++;
1413 yyextra->col=0;
1414 }
1415 else
1416 {
1417 yyextra->col+=8;
1418 }
1419 yyextra->snippetRtn++;
1420 }
1421 }
1422
1423<IncludeDoc,SnippetDoc>\n{B}*{CPPC}[\/!]{B}*/\n {
1424 warn(yyextra->fileName,yyextra->lineNr,"Found \\{}{{doc}} command without valid file name argument",
1425 YY_START==IncludeDoc? "include" : "snippet"
1426 );
1427 yyextra->lineNr++;
1428 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1429 copyToOutput(yyscanner,lineStr.view());
1430 BEGIN(yyextra->includeCtx);
1431 }
1432<IncludeDoc,SnippetDoc>\n{B}*{CPPC}[\/!] {
1433 yyextra->lineNr++;
1434 }
1435<IncludeDoc,SnippetDoc>\n {
1436 if (yyextra->snippetRtn)
1437 {
1438 insertCommentStart(yyscanner);
1439
1440 // missing file name
1441 warn(yyextra->fileName,yyextra->lineNr,"Found \\{}{{doc}} command without valid file name argument",
1442 YY_START==IncludeDoc? "include" : "snippet"
1443 );
1444 copyToOutput(yyscanner,yytext,yyleng);
1445 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1446 copyToOutput(yyscanner,lineStr.view());
1447 BEGIN(yyextra->includeCtx);
1448 }
1449 else if (yyextra->includeCtx == ReadLine)
1450 {
1451 unput('\n');
1452 warn(yyextra->fileName,yyextra->lineNr,"Found \\{}{{doc}} command without valid file name argument",
1453 YY_START==IncludeDoc? "include" : "snippet"
1454 );
1455 BEGIN(yyextra->includeCtx);
1456 }
1457 else
1458 {
1459 yyextra->lineNr++;
1460 yyextra->col=0;
1461 yyextra->snippetRtn++;
1462 }
1463 }
1464<IncludeDoc,SnippetDoc>. { // invalid character
1465 warn(yyextra->fileName,yyextra->lineNr,"Found invalid character for file name of \\{}{{doc}} command",
1466 YY_START==IncludeDoc? "include" : "snippet"
1467 );
1468 DString lineStr= " \\iline "+DString().setNum(yyextra->lineNr)+" ";
1469 copyToOutput(yyscanner,lineStr.view());
1470 copyToOutput(yyscanner,yytext,yyleng);
1471 BEGIN(yyextra->includeCtx);
1472 }
1473<CComment,ReadLine,IncludeFile>{CMD}"cond"/[^a-z_A-Z0-9] { // conditional section
1474 yyextra->condCtx = YY_START;
1475 BEGIN(CondLine);
1476 }
1477<CComment,ReadLine,IncludeFile>{CMD}"endcond"/[^a-z_A-Z0-9] { // end of conditional section
1478 bool oldSkip=yyextra->skip;
1479 endCondSection(yyscanner);
1480 if (YY_START==CComment && oldSkip && !yyextra->skip)
1481 {
1482 //printf("** Adding start of comment!\n");
1483 if (yyextra->lang!=SrcLangExt::Python &&
1484 yyextra->lang!=SrcLangExt::VHDL &&
1485 yyextra->lang!=SrcLangExt::Markdown &&
1486 yyextra->lang!=SrcLangExt::Fortran)
1487 {
1488 yyextra->outBuf+='/';
1489 yyextra->outBuf+='*';
1490 yyextra->col+=2;
1491 if (yyextra->specialComment)
1492 {
1493 yyextra->outBuf+='*';
1494 yyextra->col++;
1495 }
1496 }
1497 }
1498 }
static void endCondSection(yyscan_t yyscanner)
1499<CondLine>{B}*{CMD}doxyconfig{B}+{DOXYCFG} {
1500 handleCondSectionId(yyscanner,yytext);
1501 }
static void handleCondSectionId(yyscan_t yyscanner, const char *expression)
1502<CondLine>([!()&| \ta-z_A-Z0-9.\-]|{CMD}"doxyconfig")+ {
1503 handleCondSectionId(yyscanner,yytext);
1504 }
1505<CComment,ReadLine,IncludeFile>{CMD}"cond"{WSopt}/\n {
1506 yyextra->condCtx=YY_START;
1507 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
1508 }
1509<CondLine>\n |
1510<CondLine>. { // forgot section id?
1511 handleCondSectionId(yyscanner," "); // fake section id causing the section to be hidden unconditionally
1512 if (*yytext=='\n') { copyToOutput(yyscanner,"\n");}
1513 }
1514<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]* { // expand alias without arguments
1515 bool inCppComment = YY_START==ReadLine && yyextra->readLineCtx==SComment;
1516 bool inCComment = YY_START==CComment && yyextra->blockHeadCol>0;
1517 replaceAliases(yyscanner,yytext,inCppComment,inCComment);
1518 }
1519<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{B}?{CMD}"ilinebr"{B}{CMD}"ialias{" { // expand alias with arguments
1520 yyextra->lastBlockContext=YY_START;
1521 yyextra->blockCount=1;
1522 int extraSpace = (yytext[0]==' '? 1:0);
1523 yyextra->aliasString=yytext+9+extraSpace;
1524 yyextra->aliasCmd=yytext+9+extraSpace;
1525 yyextra->lastEscaped=0;
1526 BEGIN( ReadAliasArgs );
1527 }
1528<CComment,ReadLine,IncludeFile,Verbatim,VerbatimCode>{CMD}[a-z_A-Z][a-z_A-Z0-9-]*"{" { // expand alias with arguments
1529 yyextra->lastBlockContext=YY_START;
1530 yyextra->blockCount=1;
1531 yyextra->aliasString=yytext;
1532 yyextra->aliasCmd=yytext;
1533 yyextra->lastEscaped=0;
1534 BEGIN( ReadAliasArgs );
1535 }
1536<ReadAliasArgs>^[ \t]*"*" {
1537 size_t indent=computeIndent(yytext)-1;
1538 if (indent>yyextra->blockHeadCol) // assume part of block marker
1539 {
1540 yyextra->aliasString+=yytext;
1541 }
1542 else
1543 {
1544 // skip leading *
1545 }
1546 }
1547<ReadAliasArgs>^[ \t]*{CPPC}[/!]/[^\n]* { // skip leading special comments (see bug 618079)
1548 }
1549<ReadAliasArgs>[^{}\n\\\*]+ {
1550 yyextra->aliasString+=yytext;
1551 yyextra->lastEscaped=false;
1552 }
1553<ReadAliasArgs>"\\" {
1554 if (yyextra->lastEscaped) yyextra->lastEscaped=false;
1555 else yyextra->lastEscaped=true;
1556 yyextra->aliasString+=yytext;
1557 }
1558<ReadAliasArgs>{CMD}("endverbatim"|"endiliteral"|"endlatexonly"|"endhtmlonly"|"endxmlonly"|"enddocbookonly"|"endrtfonly"|"endmanonly"|"f$"|"f]"|"f}"|"f)") { /* end of verbatim block */
1559 yyextra->aliasString+=yytext;
1560 if (yyextra->inVerbatim && &yytext[1]==yyextra->blockName)
1561 // For verbatim sections we do not support matching end block markers inside
1562 // alias arguments. Instead this will end the verbatim block.
1563 // This is needed to support an alias definition
1564 // like startalign=" \latexonly\noalign{\endlatexonly" were otherwise
1565 // the scanner would try to find a matching closing brace for noalign and then
1566 // skip over the \endlatexonly command.
1567 {
1568 copyToOutput(yyscanner,yyextra->aliasString.view());
1569 yyextra->inVerbatim=false;
1570 BEGIN(yyextra->lastCommentContext);
1571 }
1572 }
1573<ReadAliasArgs>\n {
1574 yyextra->aliasString+=yytext;
1575 yyextra->lastEscaped=false;
1576 if (yyextra->inVerbatim) // for verbatim sections we do not support multi-line
1577 // alias arguments.
1578 {
1579 copyToOutput(yyscanner,yyextra->aliasString.view());
1580 BEGIN( yyextra->lastBlockContext );
1581 }
1582 }
1583<ReadAliasArgs>"{" {
1584 yyextra->aliasString+=yytext;
1585 if (!yyextra->lastEscaped) yyextra->blockCount++;
1586 yyextra->lastEscaped=false;
1587 }
1588<ReadAliasArgs>"}" {
1589 yyextra->aliasString+=yytext;
1590 if (!yyextra->lastEscaped) yyextra->blockCount--;
1591 if (yyextra->blockCount==0)
1592 {
1593 bool inCppComment = yyextra->lastBlockContext==ReadLine && yyextra->readLineCtx==SComment;
1594 bool inCComment = yyextra->lastBlockContext==CComment && yyextra->blockHeadCol>0;
1595 replaceAliases(yyscanner,yyextra->aliasString.view(),inCppComment,inCComment);
1596 BEGIN( yyextra->lastBlockContext );
1597 }
1598 yyextra->lastEscaped=false;
1599 }
1600<ReadAliasArgs>. {
1601 yyextra->aliasString+=yytext;
1602 yyextra->lastEscaped=false;
1603 }
1604<CopyLine>. {
1605 copyToOutput(yyscanner,yytext,yyleng);
1606 }
1607<CopyLine>\n {
1608 copyToOutput(yyscanner,yytext,yyleng);
1609 yyextra->insertCppCommentMarker=false;
1610 BEGIN(yyextra->readLineCtx);
1611 }
1612<ReadLine>{CMD}{CMD} |
1613<ReadLine>. {
1614 copyToOutput(yyscanner,yytext,yyleng);
1615 }
1616<IncludeFile>. {
1617 copyToOutput(yyscanner,yytext,yyleng);
1618 }
1619<IncludeFile>\n {
1620 copyToOutput(yyscanner,yytext,yyleng);
1621 insertCommentStart(yyscanner);
1622 }
1623<*>. {
1624 copyToOutput(yyscanner,yytext,yyleng);
1625 }
1626<<EOF>> {
1627 if (YY_START == ReadAliasArgs)
1628 {
1629 warn(yyextra->fileName,yyextra->lineNr,
1630 "Reached end of file while still searching closing '}}' of an alias argument (probable start: '{}')",
1631 yyextra->aliasCmd);
1632 }
1633 else if (YY_START==Verbatim || YY_START==VerbatimCode)
1634 {
1635 warn(yyextra->fileName,yyextra->lineNr,
1636 "Reached end of file while still searching closing '{}' of a verbatim block starting at line {}",
1637 yyextra->blockName,yyextra->verbatimLine);
1638 }
1639 if (yyextra->includeStack.empty())
1640 {
1641 yyextra->insertCppCommentMarker=false;
1642 yyterminate();
1643 }
1644 else // switch back to parent file
1645 {
1646 std::unique_ptr<commentcnv_FileState> &fs = yyextra->includeStack.back();
1647 YY_BUFFER_STATE oldBuf = YY_CURRENT_BUFFER;
1648 yy_switch_to_buffer(fs->bufState, yyscanner);
1649 yy_delete_buffer(oldBuf, yyscanner);
1650 BEGIN(fs->oldState);
1651 yyextra->fileName = fs->oldFileName;
1652 yyextra->lineNr = fs->oldLineNr;
1653 yyextra->inBuf = fs->oldFileBuf;
1654 yyextra->inBufPos = fs->oldFileBufPos;
1655 yyextra->includeCtx = fs->oldIncludeCtx;
1656 DString lineStr= " \\ifile \""+yyextra->fileName+"\" \\iline "+DString().setNum(yyextra->lineNr)+" ";
1657 if (fs->oldRaiseLvl!=yyextra->raiseLevel)
1658 {
1659 lineStr+="\\iraise " + std::to_string(fs->oldRaiseLvl)+ " ";
1660 }
1661 if (fs->oldRaiseLbl!=yyextra->raiseLabel)
1662 {
1663 lineStr+="\\iprefix \"" + fs->oldRaiseLbl + "\" ";
1664 }
1665 lineStr+="\\ilinebr ";
1666 yyextra->raiseLevel = fs->oldRaiseLvl;
1667 yyextra->raiseLabel = fs->oldRaiseLbl;
1668 copyToOutput(yyscanner,lineStr.view());
1669 yyextra->includeStack.pop_back();
1670 //printf("<<EOF>> switch back to %s line %d inbufPos=%d outbufPos=%d\n",
1671 // qPrint(yyextra->fileName),yyextra->lineNr,yyextra->inBufPos,yyextra->outBuf.curPos());
1672 }
1673 }
1674 /*
#define yyterminate()
1675<*>\n { fprintf(stderr,"Lex scanner %s (%s) default rule newline for state %s.\n", __FILE__, qPrint(yyextra->fileName),stateToString(YY_START));}
1676 */
1677%%

◆ yyread()

int yyread ( yyscan_t yyscanner,
char * buf,
int max_size )
static

Definition at line 2327 of file commentcnv.l.

2328{
2329 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2330 int bytesInBuf = static_cast<int>(yyextra->inBuf->size())-yyextra->inBufPos;
2331 int bytesToCopy = std::min(max_size,bytesInBuf);
2332 memcpy(buf,yyextra->inBuf->data()+yyextra->inBufPos,bytesToCopy);
2333 yyextra->inBufPos+=bytesToCopy;
2334 return bytesToCopy;
2335}

References yyguts_t.