Doxygen
Loading...
Searching...
No Matches
pyscanner.l File Reference
#include <stdint.h>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <string.h>
#include "pyscanner.h"
#include "entry.h"
#include "message.h"
#include "config.h"
#include "doxygen.h"
#include "util.h"
#include "defargs.h"
#include "language.h"
#include "commentscan.h"
#include "arguments.h"
#include "markdown.h"
#include "fileinfo.h"
#include "debug.h"
#include "stringutil.h"
#include "doxygen_lex.h"
#include "pyscanner.l.h"
+ Include dependency graph for pyscanner.l:

Go to the source code of this file.

Classes

struct  pyscannerYY_state
 
struct  PythonOutlineParser::Private
 

Macros

#define YY_TYPEDEF_YY_SCANNER_T
 
#define DBG_CTX(x)
 
#define YY_NO_INPUT   1
 
#define YY_NO_UNISTD_H   1
 
#define unput_string(yytext, yyleng)
 
#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 initParser (yyscan_t yyscanner)
 
static void initEntry (yyscan_t yyscanner)
 
static void newEntry (yyscan_t yyscanner)
 
static void addEntry (yyscan_t yyscanner)
 
static void docVariable (yyscan_t yyscanner, const char *s)
 
static void newVariable (yyscan_t yyscanner)
 
static void addVariable (yyscan_t yyscanner)
 
static void newFunction (yyscan_t yyscanner)
 
static QCString findPackageScopeFromPath (yyscan_t yyscanner, const QCString &path)
 
static void addFrom (yyscan_t yyscanner, bool all)
 
static void lineCount (yyscan_t yyscanner)
 
static void incLineNr (yyscan_t yyscanner)
 
static void startCommentBlock (yyscan_t yyscanner, bool brief)
 
static void handleCommentBlock (yyscan_t yyscanner, const QCString &doc, bool brief)
 
static void endOfDef (yyscan_t yyscanner, int correction=0)
 
static void addToString (yyscan_t yyscanner, const char *s)
 
static void initTriDoubleQuoteBlock (yyscan_t yyscanner)
 
static void initTriSingleQuoteBlock (yyscan_t yyscanner)
 
static void initSpecialBlock (yyscan_t yyscanner)
 
static void searchFoundDef (yyscan_t yyscanner)
 
static void searchFoundClass (yyscan_t yyscanner)
 
static QCString findPackageScope (yyscan_t yyscanner, const QCString &fileName)
 
static void setProtection (yyscan_t yyscanner)
 
static int yyread (yyscan_t yyscanner, char *buf, int max_size)
 
static const char * getLexerFILE ()
 
int yylex (yyscan_t yyscanner)
 
static void parseCompounds (yyscan_t yyscanner, std::shared_ptr< Entry > rt)
 
static void parseMain (yyscan_t yyscanner, const QCString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &rt)
 
static void parsePrototype (yyscan_t yyscanner, const QCString &text)
 

Macro Definition Documentation

◆ DBG_CTX

#define DBG_CTX ( x)
Value:
do { } while(0)

Definition at line 65 of file pyscanner.l.

◆ unput_string

#define unput_string ( yytext,
yyleng )
Value:
do { for (int i=(int)yyleng-1;i>=0;i--) unput(yytext[i]); } while(0)

Definition at line 70 of file pyscanner.l.

◆ 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 code.l:3989

Definition at line 161 of file pyscanner.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 67 of file pyscanner.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 68 of file pyscanner.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 29 of file pyscanner.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 31 of file pyscanner.l.

Function Documentation

◆ addEntry()

static void addEntry ( yyscan_t yyscanner)
static

Definition at line 1819 of file pyscanner.l.

1820{
1821 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1822
1823 auto doc = yyextra->current->doc;
1824 auto docLine = yyextra->current->docLine;
1825 auto docFile = yyextra->current->docFile;
1826 auto brief = yyextra->current->brief;
1827 auto briefLine = yyextra->current->briefLine;
1828 auto briefFile = yyextra->current->briefFile;
1829
1830 yyextra->previous = yyextra->current;
1831 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
1832 initEntry(yyscanner);
static void initEntry(yyscan_t yyscanner)
Definition pyscanner.l:1763
1833
1834 yyextra->current->doc = doc;
1835 yyextra->current->docLine = docLine;
1836 yyextra->current->docFile = docFile;
1837 yyextra->current->brief = brief;
1838 yyextra->current->briefLine = briefLine;
1839 yyextra->current->briefFile = briefFile;
1840}

References initEntry().

Referenced by addVariable().

◆ addFrom()

static void addFrom ( yyscan_t yyscanner,
bool all )
static

Definition at line 1957 of file pyscanner.l.

1958{
1959 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1960 QCString item=all ? yyextra->packageName : yyextra->packageName+"."+yytext;
1961 yyextra->current->name=removeRedundantWhiteSpace(substitute(item,".","::"));
1962 yyextra->current->fileName = yyextra->fileName;
1963 //printf("Adding using declaration: found:%s:%d name=%s\n",qPrint(yyextra->fileName),yyextra->yyLineNr,qPrint(yyextra->current->name));
1964 yyextra->current->section=all ? EntryType::makeUsingDir() : EntryType::makeUsingDecl();
1965 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
1966 initEntry(yyscanner);
Wrapper class for the Entry type.
Definition types.h:631
This is an alternative implementation of QCString.
Definition qcstring.h:101
static void initEntry(yyscan_t yyscanner)
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:477
QCString removeRedundantWhiteSpace(const QCString &s)
Definition util.cpp:578
1967}

References initEntry(), removeRedundantWhiteSpace(), and substitute().

◆ addToString()

static void addToString ( yyscan_t yyscanner,
const char * s )
inlinestatic

Definition at line 2071 of file pyscanner.l.

2072{
2073 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2074 if (yyextra->copyString) (*yyextra->copyString) << s;
2075}

◆ addVariable()

static void addVariable ( yyscan_t yyscanner)
static

Definition at line 1882 of file pyscanner.l.

1883{
1884 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1885 setProtection(yyscanner);
1886 if (yyextra->current_root->section.isCompound()) // mark as class variable
1887 {
1888 yyextra->current->isStatic = TRUE;
1889 }
1890 addEntry(yyscanner);
static void setProtection(yyscan_t yyscanner)
Definition pyscanner.l:1842
static void addEntry(yyscan_t yyscanner)
Definition pyscanner.l:1819
#define TRUE
Definition qcstring.h:37
1891}

References addEntry(), setProtection(), and TRUE.

◆ computeIndent()

static int computeIndent ( const char * s)
inlinestatic

Definition at line 1908 of file pyscanner.l.

1909{
1910 int col=0;
1911 int tabSize=Config_getInt(TAB_SIZE);
1912 const char *p=s;
1913 char c;
1914 while ((c=*p++))
1915 {
1916 if (c==' ') col++;
1917 else if (c=='\t') col+=tabSize-(col%tabSize);
1918 else break;
1919 }
1920 return col;
#define Config_getInt(name)
Definition config.h:34
1921}

References Config_getInt.

◆ docVariable()

static void docVariable ( yyscan_t yyscanner,
const char * s )
static

Definition at line 1858 of file pyscanner.l.

1859{
1860 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1861 yyextra->current->name = name;
1862 yyextra->current->section=EntryType::makeVariable();
1863 yyextra->current->fileName = yyextra->fileName;
1864 yyextra->current->startLine = yyextra->yyLineNr;
1865 yyextra->current->bodyLine = yyextra->yyLineNr;
1866 yyextra->current->type.clear();
1867 setProtection(yyscanner);
1868 yyextra->checkDupEntry = true;
1869}

References setProtection().

◆ endOfDef()

static void endOfDef ( yyscan_t yyscanner,
int correction = 0 )
static

Definition at line 2058 of file pyscanner.l.

2059{
2060 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2061 //printf("endOfDef at=%d\n",yyextra->yyLineNr);
2062 if (yyextra->bodyEntry)
2063 {
2064 yyextra->bodyEntry->endBodyLine = yyextra->yyLineNr-correction;
2065 yyextra->bodyEntry = 0;
2066 }
2067 newEntry(yyscanner);
2068 //yyextra->insideConstructor = FALSE;
static void newEntry(yyscan_t yyscanner)
Definition pyscanner.l:1778
2069}

References newEntry().

◆ findPackageScope()

static QCString findPackageScope ( yyscan_t yyscanner,
const QCString & fileName )
static

Definition at line 1950 of file pyscanner.l.

1951{
1952 if (fileName.isEmpty()) return fileName;
1953 FileInfo fi(fileName.str());
1954 return findPackageScopeFromPath(yyscanner,fi.dirPath(true).c_str());
Minimal replacement for QFileInfo.
Definition fileinfo.h:23
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:150
const std::string & str() const
Definition qcstring.h:537
static QCString findPackageScopeFromPath(yyscan_t yyscanner, const QCString &path)
Definition pyscanner.l:1923
1955}

References FileInfo::dirPath(), findPackageScopeFromPath(), QCString::isEmpty(), and QCString::str().

Referenced by parseMain().

◆ findPackageScopeFromPath()

static QCString findPackageScopeFromPath ( yyscan_t yyscanner,
const QCString & path )
static

Definition at line 1923 of file pyscanner.l.

1924{
1925 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1926 auto it = yyextra->packageNameCache.find(path.str());
1927 if (it!=yyextra->packageNameCache.end())
1928 {
1929 return QCString(it->second);
1930 }
1931 FileInfo pf(path.str()+"/__init__.py"); // found package initialization file
1932 if (pf.exists())
1933 {
1934 int i=path.findRev('/');
1935 if (i!=-1)
1936 {
1937 QCString scope = findPackageScopeFromPath(yyscanner,path.left(i));
1938 if (!scope.isEmpty())
1939 {
1940 scope+="::";
1941 }
1942 scope+=path.mid(i+1);
1943 yyextra->packageNameCache.emplace(path.str(),scope.str());
1944 return scope;
1945 }
1946 }
1947 return "";
QCString mid(size_t index, size_t len=static_cast< size_t >(-1)) const
Definition qcstring.h:226
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:91
QCString left(size_t len) const
Definition qcstring.h:214
1948}

References FileInfo::exists(), QCString::find(), findPackageScopeFromPath(), QCString::findRev(), QCString::isEmpty(), QCString::left(), QCString::mid(), and QCString::str().

Referenced by findPackageScope(), and findPackageScopeFromPath().

◆ getLexerFILE()

static const char * getLexerFILE ( )
inlinestatic

Definition at line 164 of file pyscanner.l.

164{return __FILE__;}

◆ handleCommentBlock()

static void handleCommentBlock ( yyscan_t yyscanner,
const QCString & doc,
bool brief )
static

Definition at line 2003 of file pyscanner.l.

2004{
2005 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2006 //printf("handleCommentBlock(doc=[%s] brief=%d yyextra->docBlockInBody=%d yyextra->docBlockJavaStyle=%d\n",
2007 // qPrint(doc),brief,yyextra->docBlockInBody,yyextra->docBlockJavaStyle);
2008
2009 // TODO: Fix me
2010 yyextra->docBlockInBody=FALSE;
#define FALSE
Definition qcstring.h:34
2011
2012 if (!yyextra->current->doc.isEmpty())
2013 {
2014 yyextra->current->doc=yyextra->current->doc.stripWhiteSpace()+"\n\n";
2015 }
2016 if (yyextra->docBlockInBody && yyextra->previous && !yyextra->previous->doc.isEmpty())
2017 {
2018 yyextra->previous->doc=yyextra->previous->doc.stripWhiteSpace()+"\n\n";
2019 }
2020
2021 int position = 0;
2022 bool needsEntry = false;
2023 int lineNr = brief ? yyextra->current->briefLine : yyextra->current->docLine;
2024 Markdown markdown(yyextra->fileName,lineNr);
2025 GuardedSectionStack guards;
2026 QCString strippedDoc = stripIndentation(doc,true);
2027 //printf("stippedDoc=[%s]\n",qPrint(strippedDoc));
2028 QCString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(strippedDoc,lineNr) : strippedDoc;
2029 while (yyextra->commentScanner.parseCommentBlock(
2030 yyextra->thisParser,
2031 (yyextra->docBlockInBody && yyextra->previous) ? yyextra->previous.get() : yyextra->current.get(),
2032 processedDoc, // text
2033 yyextra->fileName, // file
2034 lineNr,
2035 yyextra->docBlockInBody ? FALSE : brief,
2036 yyextra->docBlockJavaStyle, // javadoc style // or FALSE,
2037 yyextra->docBlockInBody,
2038 yyextra->protection,
2039 position,
2040 needsEntry,
2041 Config_getBool(MARKDOWN_SUPPORT),
2042 &guards
2043 )
2044 ) // need to start a new entry
2045 {
2046 if (needsEntry)
2047 {
2048 newEntry(yyscanner);
2049 }
2050 }
2051 if (needsEntry)
2052 {
2053 newEntry(yyscanner);
2054 }
Helper class to process markdown formatted text.
Definition markdown.h:32
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
#define Config_getBool(name)
Definition config.h:33
QCString stripIndentation(const QCString &s, bool skipFirstLine)
Definition util.cpp:6438
2055
2056}

References Config_getBool, FALSE, newEntry(), Markdown::process(), and stripIndentation().

◆ incLineNr()

static void incLineNr ( yyscan_t yyscanner)
static

Definition at line 1980 of file pyscanner.l.

1981{
1982 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1983 DBG_CTX((stderr,"yyextra->yyLineNr=%d\n",yyextra->yyLineNr));
1984 yyextra->yyLineNr++;
#define DBG_CTX(x)
Definition pyscanner.l:65
1985}

References DBG_CTX.

◆ initEntry()

static void initEntry ( yyscan_t yyscanner)
static

Definition at line 1763 of file pyscanner.l.

1764{
1765 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1766 //yyextra->current->python = TRUE;
1767 yyextra->current->protection = yyextra->protection ;
1768 yyextra->current->mtype = yyextra->mtype;
1769 yyextra->current->virt = yyextra->virt;
1770 yyextra->current->isStatic = yyextra->isStatic;
1771 yyextra->current->lang = SrcLangExt::Python;
1772 yyextra->current->type.clear();
1773 yyextra->current->name.clear();
1774 yyextra->commentScanner.initGroupInfo(yyextra->current.get());
1775 yyextra->isStatic = FALSE;
@ Python
Definition types.h:52
1776}

References FALSE, and Python.

◆ initParser()

static void initParser ( yyscan_t yyscanner)
static

Definition at line 1752 of file pyscanner.l.

1753{
1754 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1755 yyextra->protection = Protection::Public;
1756 yyextra->mtype = MethodTypes::Method;
1757 yyextra->isStatic = FALSE;
1758 yyextra->virt = Specifier::Normal;
1759 yyextra->previous = 0;
1760 yyextra->packageCommentAllowed = TRUE;
@ Public
Definition types.h:26
@ Normal
Definition types.h:29
1761}

References FALSE, Method, Normal, Public, and TRUE.

◆ initSpecialBlock()

static void initSpecialBlock ( yyscan_t yyscanner)
static

Definition at line 2103 of file pyscanner.l.

2104{
2105 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2106 yyextra->docBlockContext = YY_START;
2107 yyextra->docBlockInBody = FALSE;
2108 yyextra->docBlockJavaStyle = TRUE;
2109 yyextra->docBrief = TRUE;
2110 yyextra->docBlock.clear();
2111 yyextra->commentIndent = yyextra->curIndent;
2112 startCommentBlock(yyscanner,FALSE);
static void startCommentBlock(yyscan_t yyscanner, bool brief)
Definition pyscanner.l:1988
2113}

References FALSE, startCommentBlock(), and TRUE.

◆ initTriDoubleQuoteBlock()

static void initTriDoubleQuoteBlock ( yyscan_t yyscanner)
static

Definition at line 2077 of file pyscanner.l.

2078{
2079 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2080 yyextra->docBlockContext = YY_START;
2081 yyextra->docBlockInBody = FALSE;
2082 yyextra->docBlockJavaStyle = TRUE;
2083 yyextra->docBlockSpecial = yytext[strlen(yytext) - 1]=='!' || !Config_getBool(PYTHON_DOCSTRING);
2084 yyextra->docBlock.clear();
2085 yyextra->commentIndent = yyextra->curIndent;
2086 yyextra->doubleQuote = TRUE;
2087 startCommentBlock(yyscanner,FALSE);
2088}

References Config_getBool, FALSE, startCommentBlock(), and TRUE.

◆ initTriSingleQuoteBlock()

static void initTriSingleQuoteBlock ( yyscan_t yyscanner)
static

Definition at line 2090 of file pyscanner.l.

2091{
2092 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2093 yyextra->docBlockContext = YY_START;
2094 yyextra->docBlockInBody = FALSE;
2095 yyextra->docBlockJavaStyle = TRUE;
2096 yyextra->docBlockSpecial = yytext[strlen(yytext) - 1]=='!' || !Config_getBool(PYTHON_DOCSTRING);
2097 yyextra->docBlock.clear();
2098 yyextra->commentIndent = yyextra->curIndent;
2099 yyextra->doubleQuote = FALSE;
2100 startCommentBlock(yyscanner,FALSE);
2101}

References Config_getBool, FALSE, startCommentBlock(), and TRUE.

◆ lineCount()

static void lineCount ( yyscan_t yyscanner)
static

Definition at line 1970 of file pyscanner.l.

1971{
1972 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1973 DBG_CTX((stderr,"yyextra->yyLineNr=%d\n",yyextra->yyLineNr));
1974 for (const char *p = yytext; *p; ++p)
1975 {
1976 yyextra->yyLineNr += (*p == '\n') ;
1977 }
1978}

References DBG_CTX.

◆ newEntry()

static void newEntry ( yyscan_t yyscanner)
static

Definition at line 1778 of file pyscanner.l.

1779{
1780 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1781 bool found = false;
1782 if (yyextra->checkDupEntry)
1783 {
1784 for (auto &v : yyextra->current_root->children())
1785 {
1786 //printf("candidate %s<->%s section=%s!\n",qPrint(v->name),qPrint(yyextra->current->name), v->section.to_string().c_str());
1787 if (v->name==yyextra->current->name && v->section==yyextra->current->section) // name is already added, don't add it again
1788 {
1789 if (v->doc.isEmpty() && !yyextra->current->doc.isEmpty())
1790 {
1791 v->doc = yyextra->current->doc;
1792 v->docLine = yyextra->current->docLine;
1793 v->docFile = yyextra->current->docFile;
1794 }
1795 if (v->brief.isEmpty() && !yyextra->current->brief.isEmpty())
1796 {
1797 v->brief = yyextra->current->brief;
1798 v->briefLine = yyextra->current->briefLine;
1799 v->briefFile = yyextra->current->briefFile;
1800 }
1801 if (v->type.isEmpty() && !yyextra->current->type.isEmpty())
1802 {
1803 //printf("copying type '%s' from '%s' to '%s'\n",qPrint(yyextra->current->type),qPrint(yyextra->current->name),qPrint(v->name));
1804 v->type = yyextra->current->type;
1805 }
1806 found=true;
1807 break;
1808 }
1809 }
1810 }
1811 if (!found)
1812 {
1813 yyextra->previous = yyextra->current;
1814 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
1815 }
1816 initEntry(yyscanner);
bool found
Definition util.cpp:984
1817}

References found, and initEntry().

Referenced by endOfDef(), handleCommentBlock(), handleCommentBlock(), handleParametersCommentBlocks(), and newVariable().

◆ newFunction()

static void newFunction ( yyscan_t yyscanner)
static

Definition at line 1893 of file pyscanner.l.

1894{
1895 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1896 if (yyextra->current->name.startsWith("__") && yyextra->current->name.endsWith("__"))
1897 {
1898 // special method name, see
1899 // http://docs.python.org/ref/specialnames.html
1900 yyextra->current->protection=Protection::Public;
1901 }
1902 else
1903 {
1904 setProtection(yyscanner);
1905 }
1906}

References Public, and setProtection().

◆ newVariable()

static void newVariable ( yyscan_t yyscanner)
static

Definition at line 1871 of file pyscanner.l.

1872{
1873 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1874 setProtection(yyscanner);
1875 if (yyextra->current_root->section.isCompound()) // mark as class variable
1876 {
1877 yyextra->current->isStatic = TRUE;
1878 }
1879 newEntry(yyscanner);
1880}

References newEntry(), setProtection(), and TRUE.

◆ parseCompounds()

static void parseCompounds ( yyscan_t yyscanner,
std::shared_ptr< Entry > rt )
static

Definition at line 2149 of file pyscanner.l.

2150{
2151 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2152 //printf("parseCompounds(%s)\n",qPrint(rt->name));
2153 for (size_t i=0; i<rt->children().size(); ++i)
2154 {
2155 std::shared_ptr<Entry> ce = rt->children()[i];
2156 if (!ce->program.empty())
2157 {
2158 //fprintf(stderr,"parseCompounds: -- %s (line %d) ---------\n%s\n---------------\n",
2159 // qPrint(ce->name), ce->bodyLine, qPrint(ce->program));
2160 // init scanner state
2161 yyextra->programStr = ce->program.str();
2162 yyextra->inputString = yyextra->programStr.data();
2163 yyextra->inputPosition = 0;
2164 yyextra->firstPass = false;
2165 pyscannerYYrestart( nullptr, yyscanner );
2166 if (ce->section.isCompound())
2167 {
2168 yyextra->specialBlock = false;
2169 yyextra->current_root = ce;
2170 BEGIN( Search );
2171 }
2172 else if (ce->parent())
2173 {
2174 yyextra->current_root = rt;
2175 //printf("Searching for member variables in %s parent=%s\n",
2176 // qPrint(ce->name),qPrint(ce->parent->name));
2177 BEGIN( SearchMemVars );
2178 }
2179 yyextra->fileName = ce->fileName;
2180 yyextra->yyLineNr = ce->bodyLine ;
2181 yyextra->current = std::make_shared<Entry>();
2182 initEntry(yyscanner);
2183
2184 yyextra->checkDupEntry = false;
2185
2186 QCString name = ce->name;
2187 yyextra->commentScanner.enterCompound(yyextra->fileName,yyextra->yyLineNr,name);
2188
2189 pyscannerYYlex(yyscanner) ;
2190 yyextra->lexInit=TRUE;
2191
2192 yyextra->programStr.clear();
2193 ce->program.str(std::string());
2194
2195 yyextra->commentScanner.leaveCompound(yyextra->fileName,yyextra->yyLineNr,name);
2196
2197 }
2198 parseCompounds(yyscanner,ce);
2199 }
static void parseCompounds(yyscan_t yyscanner, std::shared_ptr< Entry > rt)
Definition pyscanner.l:2149
2200}

References initEntry(), parseCompounds(), Search, and TRUE.

Referenced by parseCompounds(), parseCompounds(), parseMain(), and parseMain().

◆ parseMain()

static void parseMain ( yyscan_t yyscanner,
const QCString & fileName,
const char * fileBuf,
const std::shared_ptr< Entry > & rt )
static

Definition at line 2205 of file pyscanner.l.

2206{
2207 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2208 initParser(yyscanner);
static void initParser(yyscan_t yyscanner)
Definition pyscanner.l:1752
2209
2210 if (fileBuf==nullptr || fileBuf[0]=='\0') return;
2211
2212 yyextra->inputString = fileBuf;
2213 yyextra->inputPosition = 0;
2214
2215 yyextra->protection = Protection::Public;
2216 yyextra->mtype = MethodTypes::Method;
2217 yyextra->isStatic = false;
2218 yyextra->virt = Specifier::Normal;
2219 yyextra->current_root = rt;
2220 yyextra->specialBlock = false;
2221
2222 yyextra->yyLineNr = 1 ;
2223 yyextra->fileName = fileName;
2224 yyextra->checkDupEntry = false;
2225 yyextra->firstPass = true;
2226 //setContext();
2227 msg("Parsing file {}...\n",yyextra->fileName);
#define msg(fmt,...)
Definition message.h:94
2228
2229 FileInfo fi(fileName.str());
2230 yyextra->moduleScope = findPackageScope(yyscanner,fileName);
2231 QCString baseName=fi.baseName();
2232 if (baseName!="__init__") // package initializer file is not a package itself
2233 {
2234 if (!yyextra->moduleScope.isEmpty())
2235 {
2236 yyextra->moduleScope+="::";
2237 }
2238 yyextra->moduleScope+=baseName;
2239 }
static QCString findPackageScope(yyscan_t yyscanner, const QCString &fileName)
Definition pyscanner.l:1950
2240
2241 // add namespaces for each scope
2242 QCString scope = yyextra->moduleScope;
2243 int startPos = 0;
2244 int pos = 0;
2245 do
2246 {
2247 pos = scope.find("::",startPos);
2248 startPos=pos+2;
2249 if (pos==-1) pos=(int)scope.length();
2250 yyextra->current = std::make_shared<Entry>();
2251 initEntry(yyscanner);
2252 yyextra->current->name = scope.left(pos);
2253 yyextra->current->section = EntryType::makeNamespace();
2254 yyextra->current->type = "namespace";
2255 yyextra->current->fileName = yyextra->fileName;
2256 yyextra->current->startLine = yyextra->yyLineNr;
2257 yyextra->current->bodyLine = yyextra->yyLineNr;
2258 yyextra->current_root = yyextra->current;
2259 rt->moveToSubEntryAndRefresh(yyextra->current);
2260 } while (pos<(int)scope.length());
int find(char c, int index=0, bool cs=TRUE) const
Definition qcstring.cpp:43
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:153
2261
2262 initParser(yyscanner);
2263
2264 yyextra->commentScanner.enterFile(yyextra->fileName,yyextra->yyLineNr);
2265
2266 yyextra->current->reset();
2267 initEntry(yyscanner);
2268 pyscannerYYrestart(nullptr,yyscanner);
2269 BEGIN( Search );
2270 pyscannerYYlex(yyscanner);
2271 yyextra->lexInit=TRUE;
2272
2273 yyextra->commentScanner.leaveFile(yyextra->fileName,yyextra->yyLineNr);
2274
2275 yyextra->programStr.clear();
2276 yyextra->current_root->program.str(std::string());
2277
2278 parseCompounds(yyscanner, yyextra->current_root);
2279}

References FileInfo::baseName(), QCString::find(), findPackageScope(), initEntry(), initParser(), QCString::left(), QCString::length(), Method, msg, Normal, parseCompounds(), Public, Search, QCString::str(), and TRUE.

◆ parsePrototype()

static void parsePrototype ( yyscan_t yyscanner,
const QCString & text )
static

Definition at line 2283 of file pyscanner.l.

2284{
2285 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2286 //printf("**** parsePrototype(%s) begin\n",qPrint(text));
2287 if (text.isEmpty())
2288 {
2289 warn(yyextra->fileName,yyextra->yyLineNr,"Empty prototype found!");
2290 return;
2291 }
#define warn(file, line, fmt,...)
Definition message.h:97
2292
2293 yyextra->specialBlock = FALSE;
2294 yyextra->packageCommentAllowed = FALSE;
2295
2296 // save scanner state
2297 YY_BUFFER_STATE orgState = YY_CURRENT_BUFFER;
2298 yy_switch_to_buffer(yy_create_buffer(nullptr, YY_BUF_SIZE, yyscanner), yyscanner);
2299 const char *orgInputString = yyextra->inputString;
2300 int orgInputPosition = yyextra->inputPosition;
#define YY_BUF_SIZE
Definition commentcnv.l:19
2301
2302 // set new string
2303 yyextra->inputString = text.data();
2304 yyextra->inputPosition = 0;
2305 pyscannerYYrestart( nullptr, yyscanner );
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition qcstring.h:159
2306
2307 BEGIN( FunctionDec );
2308
2309 pyscannerYYlex(yyscanner);
2310 yyextra->lexInit=TRUE;
2311
2312 yyextra->current->name = yyextra->current->name.stripWhiteSpace();
2313 if (yyextra->current->section.isMemberDoc() && yyextra->current->args.isEmpty())
2314 {
2315 yyextra->current->section = EntryType::makeVariableDoc();
2316 }
2317
2318 // restore original scanner state
2319
2320 yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner);
2321 yy_switch_to_buffer(orgState, yyscanner);
2322
2323 yyextra->inputString = orgInputString;
2324 yyextra->inputPosition = orgInputPosition;
2325
2326 //printf("**** parsePrototype end\n");
2327}

References QCString::data(), FALSE, QCString::isEmpty(), TRUE, warn, and YY_BUF_SIZE.

◆ searchFoundClass()

static void searchFoundClass ( yyscan_t yyscanner)
static

Definition at line 2135 of file pyscanner.l.

2136{
2137 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2138 yyextra->current->section = EntryType::makeClass();
2139 yyextra->current->argList.clear();
2140 yyextra->current->type += "class" ;
2141 yyextra->current->fileName = yyextra->fileName;
2142 yyextra->current->startLine = yyextra->yyLineNr;
2143 yyextra->current->bodyLine = yyextra->yyLineNr;
2144 yyextra->packageCommentAllowed = FALSE;
2145}

References FALSE.

◆ searchFoundDef()

static void searchFoundDef ( yyscan_t yyscanner)
static

Definition at line 2115 of file pyscanner.l.

2116{
2117 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2118 yyextra->current->fileName = yyextra->fileName;
2119 yyextra->current->startLine = yyextra->yyLineNr;
2120 yyextra->current->bodyLine = yyextra->yyLineNr;
2121 yyextra->current->section = EntryType::makeFunction();
2122 yyextra->current->lang = SrcLangExt::Python;
2123 yyextra->current->virt = Specifier::Normal;
2124 yyextra->current->isStatic = yyextra->isStatic;
2125 yyextra->current->mtype = yyextra->mtype = MethodTypes::Method;
2126 yyextra->current->type.clear();
2127 yyextra->current->name.clear();
2128 yyextra->current->args.clear();
2129 yyextra->current->argList.clear();
2130 yyextra->packageCommentAllowed = FALSE;
2131 yyextra->isStatic=FALSE;
2132 //printf("searchFoundDef at=%d\n",yyextra->yyLineNr);
2133}

References FALSE, Method, Normal, and Python.

◆ setProtection()

static void setProtection ( yyscan_t yyscanner)
static

Definition at line 1842 of file pyscanner.l.

1843{
1844 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1845 if (!yyextra->current->name.isEmpty() && yyextra->current->name.at(0)=='_')
1846 {
1847 if (yyextra->current->name.at(1)=='_') // mark as private
1848 {
1849 yyextra->current->protection=Protection::Private;
1850 }
1851 else // mark as protected
1852 {
1853 yyextra->current->protection=Protection::Protected;
1854 }
1855 }
@ Private
Definition types.h:26
@ Protected
Definition types.h:26
1856}

References Private, and Protected.

Referenced by addVariable(), docVariable(), newFunction(), and newVariable().

◆ startCommentBlock()

static void startCommentBlock ( yyscan_t yyscanner,
bool brief )
static

Definition at line 1988 of file pyscanner.l.

1989{
1990 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1991 if (brief)
1992 {
1993 yyextra->current->briefFile = yyextra->fileName;
1994 yyextra->current->briefLine = yyextra->yyLineNr;
1995 }
1996 else
1997 {
1998 yyextra->current->docFile = yyextra->fileName;
1999 yyextra->current->docLine = yyextra->yyLineNr;
2000 }
2001}

◆ stateToString()

static const char * stateToString ( int state)
static

◆ yylex()

int yylex ( yyscan_t yyscanner)

Definition at line 273 of file pyscanner.l.

277 {
278
279 ^{B}"def"{BB} { // start of a function/method definition with indent
280 DBG_CTX((stderr,"Found def at %d\n",yyextra->yyLineNr));
281 yyextra->indent=computeIndent(yytext);
282 searchFoundDef(yyscanner);
283 BEGIN( FunctionDec );
284 }
285 ^{B}"async"{BB}"def"{BB} { // start of an async function/method definition with indent
286 DBG_CTX((stderr,"Found async def at %d\n",yyextra->yyLineNr));
287 yyextra->indent=computeIndent(yytext);
288 searchFoundDef(yyscanner);
289 BEGIN( FunctionDec );
290 }
291 "def"{BB} { // start of a function/method definition
292 searchFoundDef(yyscanner);
293 BEGIN( FunctionDec );
294 }
295 "async"{BB}"def"{BB} { // start of a function/method definition
296 searchFoundDef(yyscanner);
297 BEGIN( FunctionDec );
298 }
static int computeIndent(const char *s)
Definition pyscanner.l:1908
static void searchFoundDef(yyscan_t yyscanner)
Definition pyscanner.l:2115
299
300 ^{B}"class"{BB} { // start of a class definition with indent
301 DBG_CTX((stderr,"Found class at %d\n",yyextra->yyLineNr));
302 yyextra->indent=computeIndent(yytext);
303 searchFoundClass(yyscanner);
304 BEGIN( ClassDec ) ;
305 }
306 "class"{BB} { // start of a class definition
307 searchFoundClass(yyscanner);
308 BEGIN( ClassDec ) ;
309 }
310 ^{B}"from"{BB} |
311 "from"{BB} { // start of an from import
312 yyextra->packageCommentAllowed = FALSE;
313 BEGIN( FromMod );
314 }
static void searchFoundClass(yyscan_t yyscanner)
Definition pyscanner.l:2135
315
316 ^{B}"import"{BB} |
317 "import"{BB} { // start of an import statement
318 yyextra->packageCommentAllowed = FALSE;
319 BEGIN( Import );
320 }
321 ^{B}{IDENTIFIER}/{B}"="{B}"property" { // property
322 yyextra->current->section = EntryType::makeVariable();
323 yyextra->current->mtype = MethodTypes::Property;
324 yyextra->current->name = QCString(yytext).stripWhiteSpace();
325 yyextra->current->fileName = yyextra->fileName;
326 yyextra->current->startLine = yyextra->yyLineNr;
327 yyextra->current->bodyLine = yyextra->yyLineNr;
328 yyextra->packageCommentAllowed = FALSE;
329 BEGIN(VariableDec);
330 }
331 ^{B}{IDENTIFIER}/{B}"="[^=] { // variable
332 if (yyextra->searchCount>0) REJECT;
333 yyextra->indent=computeIndent(yytext);
334 yyextra->current->section = EntryType::makeVariable();
335 yyextra->current->name = QCString(yytext).stripWhiteSpace();
336 yyextra->current->fileName = yyextra->fileName;
337 yyextra->current->startLine = yyextra->yyLineNr;
338 yyextra->current->bodyLine = yyextra->yyLineNr;
339 yyextra->packageCommentAllowed = FALSE;
340 BEGIN(VariableDec);
341 }
342 ^{B}{IDENTIFIER}/{B}":" { // variable
343 if (yyextra->searchCount>0) REJECT;
344 QCString id = QCString(yytext).stripWhiteSpace();
345 if (id =="try" || id == "else" || id == "except" || id == "finally") REJECT;
346 yyextra->indent=computeIndent(yytext);
347 yyextra->current->section = EntryType::makeVariable();
348 yyextra->current->name = id;
349 yyextra->current->fileName = yyextra->fileName;
350 yyextra->current->startLine = yyextra->yyLineNr;
351 yyextra->current->bodyLine = yyextra->yyLineNr;
352 yyextra->packageCommentAllowed = FALSE;
353 BEGIN(VariableDec);
354 }
355 {B}{IDENTIFIER}/({B},{B}{IDENTIFIER})*{B}")"*{B}"="[^=] { // list of variables, we cannot place the default value
356 // so we will skip it later on in a general rule
357 // Also note ")" this is to catch also (a,b). the "("
358 // is caught in the rule: [(], the ")" will be handled in [)]
359 if (yyextra->searchCount>1) REJECT;
360 yyextra->indent=computeIndent(yytext);
361 yyextra->current->section = EntryType::makeVariable();
362 yyextra->current->name = QCString(yytext).stripWhiteSpace();
363 yyextra->current->fileName = yyextra->fileName;
364 yyextra->current->startLine = yyextra->yyLineNr;
365 yyextra->current->bodyLine = yyextra->yyLineNr;
366 yyextra->packageCommentAllowed = FALSE;
367 addVariable(yyscanner);
368 }
369 "'" { // start of a single quoted string
370 yyextra->stringContext=YY_START;
371 yyextra->copyString=nullptr;
372 yyextra->packageCommentAllowed = FALSE;
373 BEGIN( SingleQuoteString );
374 }
375 "\"" { // start of a double quoted string
376 yyextra->stringContext=YY_START;
377 yyextra->copyString=nullptr;
378 yyextra->packageCommentAllowed = FALSE;
379 BEGIN( DoubleQuoteString );
380 }
381 "@staticmethod" {
382 yyextra->isStatic=TRUE;
383 }
384 "@"{SCOPE}"(" { // decorator
385 lineCount(yyscanner);
386 yyextra->decoratorRound = 1;
387 yyextra->copyString=nullptr;
388 BEGIN( Decorator );
389 }
390 "@"{SCOPE} { // decorator
391 lineCount(yyscanner);
392 }
393 {SCRIPTCOMMENT} { // Unix type script comment
394 if (yyextra->yyLineNr != 1) REJECT;
395 }
396 {POUNDCOMMENT} { // normal comment
397 // issue 9672
398 //yyextra->packageCommentAllowed = FALSE;
399 }
400 {IDENTIFIER} { // some other identifier
401 yyextra->packageCommentAllowed = FALSE;
402 }
403 ^{BB} {
404 yyextra->curIndent=computeIndent(yytext);
405 }
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:245
#define lineCount(s, len)
static void addVariable(yyscan_t yyscanner)
Definition pyscanner.l:1882
@ Property
Definition types.h:32
406
407 {NEWLINE}+ { // new line
408 lineCount(yyscanner);
409 }
410
411 {TRIDOUBLEQUOTE} { // start of a comment block
412 initTriDoubleQuoteBlock(yyscanner);
413 BEGIN(TripleComment);
414 }
static void initTriDoubleQuoteBlock(yyscan_t yyscanner)
Definition pyscanner.l:2077
415
416 {TRISINGLEQUOTE} { // start of a comment block
417 initTriSingleQuoteBlock(yyscanner);
418 BEGIN(TripleComment);
419 }
static void initTriSingleQuoteBlock(yyscan_t yyscanner)
Definition pyscanner.l:2090
420
421 {B}{STARTDOCSYMS}/[^#] { // start of a special comment
422 yyextra->curIndent=computeIndent(yytext);
423 yyextra->packageCommentAllowed = FALSE;
424 initSpecialBlock(yyscanner);
425 BEGIN(SpecialComment);
426 }
427 [(] { // we have to do something with (
428 yyextra->searchCount++;
429 }
430 [)] { // we have to do something with )
431 if (yyextra->searchCount>0)
432 {
433 yyextra->searchCount--;
434 }
435 }
436 "=" {
437 yyextra->current->doc.clear();
438 yyextra->current->brief.clear();
439 }
440 {IDENTIFIER} {
441 }
442 [^\n] { // any other character...
443 // This is the major default
444 // that should catch everything
445 // else in Body.
446 }
static void initSpecialBlock(yyscan_t yyscanner)
Definition pyscanner.l:2103
447}
448
449<FromMod>{
450 "." { // python3 style imports
451 }
452 {IDENTIFIER}({B}"."{B}{IDENTIFIER})* { // from package import
453 yyextra->packageName=yytext;
454 }
455 "import"{B} {
456 BEGIN(FromModItem);
457 }
458 \n {
459 incLineNr(yyscanner);
460 BEGIN(Search);
461 }
462 {B} {
463 }
464 . {
465 unput(*yytext);
466 BEGIN(Search);
467 }
static void incLineNr(yyscan_t yyscanner)
Definition pyscanner.l:1980
468}
469
470<FromModItem>{
471 "*" { // import all
472 addFrom(yyscanner,TRUE);
473 BEGIN(Search);
474 }
475 {IDENTIFIER}/{B}","{B} {
476 addFrom(yyscanner,FALSE);
477 }
478 {IDENTIFIER}/{B}")" {
479 addFrom(yyscanner,FALSE);
480 }
481 {IDENTIFIER} {
482 addFrom(yyscanner,FALSE);
483 if (!yyextra->importTuple)
484 {
485 BEGIN(Search);
486 }
487 }
488 \n {
489 incLineNr(yyscanner);
490 if (!yyextra->importTuple)
491 {
492 BEGIN(Search);
493 }
494 }
495 {B} {
496 }
497 "(" {
498 yyextra->importTuple=TRUE;
499 }
500 ")" {
501 yyextra->importTuple=FALSE;
502 BEGIN(Search);
503 }
504 "," {
505 }
506 "\\"{B}\n { // line continuation
507 incLineNr(yyscanner);
508 }
509 . {
510 unput(*yytext);
511 BEGIN(Search);
512 }
static void addFrom(yyscan_t yyscanner, bool all)
Definition pyscanner.l:1957
513}
514
515<Import>{
516 {IDENTIFIER}({B}"."{B}{IDENTIFIER})* {
517 yyextra->current->name=removeRedundantWhiteSpace(substitute(yytext,".","::"));
518 yyextra->current->fileName = yyextra->fileName;
519 //printf("Adding using declaration: found:%s:%d name=%s\n",qPrint(yyextra->fileName),yyextra->yyLineNr,qPrint(yyextra->current->name));
520 yyextra->current->section=EntryType::makeUsingDecl();
521 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
522 initEntry(yyscanner);
523 BEGIN(Search);
524 }
525 \n {
526 incLineNr(yyscanner);
527 BEGIN(Search);
528 }
529 {B} {
530 }
531 . {
532 unput(*yytext);
533 BEGIN(Search);
534 }
535}
536
537<SearchMemVars>{
538 ("cls"|"self")"."{IDENTIFIER}/{B}[,)] {
539 const char *s = strchr(yytext,'.'); s++;
540 DBG_CTX((stderr,"Found instance method variable %s in %s at %d\n",s,qPrint(yyextra->current_root->name.data(),yyextra->yyLineNr)));
541 docVariable(yyscanner,s);
542 addEntry(yyscanner);
543 }
544 ("cls"|"self")"."{IDENTIFIER}/{B}"=" {
545 const char *s = strchr(yytext,'.'); s++;
546 DBG_CTX((stderr,"Found instance method variable %s in %s at %d\n",s,qPrint(yyextra->current_root->name.data(),yyextra->yyLineNr)));
547 docVariable(yyscanner,s);
548 BEGIN( SearchSkipValue );
549 }
550 ("cls"|"self")"."{IDENTIFIER}/{B}":" { // type hint
551 const char *s = strchr(yytext,'.'); s++;
552 DBG_CTX((stderr,"Found instance method variable %s in %s at %d\n",s,qPrint(yyextra->current_root->name.data(),yyextra->yyLineNr)));
553 docVariable(yyscanner,s);
554 BEGIN(TypeHint);
555 }
556 {TRIDOUBLEQUOTE} { // start of a comment block
557 initTriDoubleQuoteBlock(yyscanner);
558 BEGIN(TripleComment);
559 }
static void docVariable(yyscan_t yyscanner, const char *s)
Definition pyscanner.l:1858
const char * qPrint(const char *s)
Definition qcstring.h:672
560
561 {TRISINGLEQUOTE} { // start of a comment block
562 initTriSingleQuoteBlock(yyscanner);
563 BEGIN(TripleComment);
564 }
565
566 {STARTDOCSYMS}/[^#] { // start of a special comment
567 initSpecialBlock(yyscanner);
568 BEGIN(SpecialComment);
569 }
570 {POUNDCOMMENT} { // #
571 }
572 "'" { // start of a single quoted string
573 yyextra->stringContext=YY_START;
574 yyextra->copyString=nullptr;
575 BEGIN( SingleQuoteString );
576 }
577 "\"" { // start of a double quoted string
578 yyextra->stringContext=YY_START;
579 yyextra->copyString=nullptr;
580 BEGIN( DoubleQuoteString );
581 }
582 \n { incLineNr(yyscanner); }
583 "=" {
584 yyextra->current->doc.clear();
585 yyextra->current->brief.clear();
586 unput(*yytext);
587 BEGIN( SearchSkipValue );
588 }
589 {IDENTIFIER} // identifiers
590 [^'"\.#a-z_A-Z=\n]+ // other uninteresting stuff
591 . // anything else
592}
593
594<TypeHint>{
595 ":" { // skip over start of type hint
596 yyextra->braceCount=0;
597 }
598 "("|"["|"{" {
599 yyextra->current->type+=*yytext;
600 yyextra->braceCount++;
601 }
602 ")"|"]"|"}" {
603 yyextra->current->type+=*yytext;
604 yyextra->braceCount--;
605 }
606 "'" { // start of a single quoted string
607 yyextra->stringContext=YY_START;
608 yyextra->copyString=nullptr;
609 BEGIN( SingleQuoteString );
610 }
611 "\"" { // start of a double quoted string
612 yyextra->stringContext=YY_START;
613 yyextra->copyString=nullptr;
614 BEGIN( DoubleQuoteString );
615 }
616 "=" {
617 if (yyextra->braceCount==0)
618 { // end of the type hint
619 yyextra->current->type = yyextra->current->type.stripWhiteSpace();
620 unput(*yytext);
621 BEGIN(SearchSkipValue);
622 }
623 else
624 {
625 yyextra->current->type+=*yytext;
626 }
627 }
628 \n { // end of the type hint
629 yyextra->current->type = yyextra->current->type.stripWhiteSpace();
630 incLineNr(yyscanner);
631 newEntry(yyscanner);
632 BEGIN(SearchMemVars);
633 }
634 "\\\n" {
635 yyextra->current->type+=' ';
636 incLineNr(yyscanner);
637 }
638 . {
639 yyextra->current->type+=*yytext;
640 }
641}
642
643<SearchSkipValue,VariableDec>{
644 "=" { // the assignment operator
645 //printf("====== VariableDec at line %d\n",yyextra->yyLineNr);
646 yyextra->startInit = TRUE;
647 yyextra->current->initializer.str(yytext);
648 yyextra->current->initializer << " ";
649 }
650 {B} { // spaces
651 yyextra->current->initializer << yytext;
652 }
653
654 {INTNUMBER} { // integer value
655 if (yyextra->current->type.isEmpty()) yyextra->current->type = "int";
656 yyextra->current->initializer << yytext;
657 }
658 {FLOATNUMBER} { // floating point value
659 if (yyextra->current->type.isEmpty()) yyextra->current->type = "float";
660 yyextra->current->initializer << yytext;
661 }
662 {BOOL} { // boolean value
663 if (yyextra->current->type.isEmpty()) yyextra->current->type = "bool";
664 yyextra->current->initializer << yytext;
665 }
666 {STRINGPREFIX}?"'" { // string
667 if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
668 yyextra->current->initializer << yytext;
669 yyextra->copyString=&yyextra->current->initializer;
670 yyextra->stringContext=YY_START;
671 BEGIN( SingleQuoteString );
672 }
673 {STRINGPREFIX}?"\"" { // string
674 if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
675 yyextra->current->initializer << yytext;
676 yyextra->copyString=&yyextra->current->initializer;
677 yyextra->stringContext=YY_START;
678 BEGIN( DoubleQuoteString );
679 }
680 {TRIDOUBLEQUOTE} { // start of a comment block
681 if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
682 yyextra->current->initializer << yytext;
683 yyextra->doubleQuote=TRUE;
684 yyextra->copyString=&yyextra->current->initializer;
685 yyextra->stringContext=YY_START;
686 BEGIN(TripleString);
687 }
688
689 {TRISINGLEQUOTE} { // start of a comment block
690 if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
691 yyextra->current->initializer << yytext;
692 yyextra->doubleQuote=FALSE;
693 yyextra->copyString=&yyextra->current->initializer;
694 yyextra->stringContext=YY_START;
695 BEGIN(TripleString);
696 }
697 "(" { // tuple, only when direct after =
698 if (yyextra->current->mtype!=MethodTypes::Property && yyextra->startInit)
699 {
700 yyextra->current->type = "tuple";
701 }
702 yyextra->current->initializer << *yytext;
703 yyextra->atomStart='(';
704 yyextra->atomEnd=')';
705 yyextra->atomCount=1;
706 yyextra->atomContext=YY_START;
707 BEGIN( VariableAtom );
708 }
709 "[" { // list
710 if (yyextra->startInit) yyextra->current->type = "list";
711 yyextra->current->initializer << *yytext;
712 yyextra->atomStart='[';
713 yyextra->atomEnd=']';
714 yyextra->atomCount=1;
715 yyextra->atomContext=YY_START;
716 BEGIN( VariableAtom );
717 }
718 "{" { // dictionary
719 if (yyextra->startInit) yyextra->current->type = "dict";
720 yyextra->current->initializer << *yytext;
721 yyextra->atomStart='{';
722 yyextra->atomEnd='}';
723 yyextra->atomCount=1;
724 yyextra->atomContext=YY_START;
725 BEGIN( VariableAtom );
726 }
727 "\\\n" {
728 yyextra->current->initializer << yytext;
729 incLineNr(yyscanner);
730 }
731 {IDENTIFIER} {
732 // do something based on the type of the IDENTIFIER
733 if (yyextra->current->type.isEmpty())
734 {
735 for (const auto &child : yyextra->current_root->children())
736 {
737 if (child->name == QCString(yytext))
738 {
739 yyextra->current->type = child->type;
740 break;
741 }
742 }
743 }
744 yyextra->startInit = FALSE;
745 yyextra->current->initializer << yytext;
746 }
747 . {
748 yyextra->startInit = FALSE;
749 yyextra->current->initializer << *yytext;
750 }
751}
752<SearchSkipValue>{
753 {STARTDOCSYMS}/[^#] { // start of a special comment
754 initSpecialBlock(yyscanner);
755 BEGIN(SpecialComment);
756 }
757 {POUNDCOMMENT} { // #
758 }
759 \n { incLineNr(yyscanner);
760 newEntry(yyscanner);
761 BEGIN(SearchMemVars);
762 }
763 <<EOF>> { incLineNr(yyscanner);
764 newEntry(yyscanner);
765 BEGIN(SearchMemVars);
766 }
767}
768
769<FunctionBody>{
770 \n{B}/{IDENTIFIER}[^{LETTER}{DIGIT}_] {
771 DBG_CTX((stderr,"indent %d<=%d\n",computeIndent(&yytext[1]),yyextra->indent));
772 if (computeIndent(&yytext[1])<=yyextra->indent)
773 {
774 unput_string(yytext,yyleng);
775 endOfDef(yyscanner);
776 //YY_CURRENT_BUFFER->yy_at_bol=TRUE;
777 BEGIN(Search);
778 }
779 else
780 {
781 incLineNr(yyscanner);
782 yyextra->current->program << yytext;
783 }
784 }
785 \n{B}/"##" {
786 if (computeIndent(&yytext[1])<=yyextra->indent)
787 {
788 unput_string(yytext,yyleng);
789 endOfDef(yyscanner);
790 //YY_CURRENT_BUFFER->yy_at_bol=TRUE;
791 BEGIN(Search);
792 }
793 else
794 {
795 incLineNr(yyscanner);
796 yyextra->current->program << yytext;
797 }
798 }
799 <<EOF>> {
800 endOfDef(yyscanner);
801 yyterminate();
802 }
803 ^{BB}/\n { // skip empty line
804 yyextra->current->program << yytext;
805 }
806 ^{BB} { // something at indent >0
807 yyextra->curIndent = computeIndent(yytext);
808 if (yyextra->curIndent<=yyextra->indent)
809 // jumped out of the function
810 {
811 endOfDef(yyscanner,1);
812 BEGIN(Search);
813 }
814 else
815 {
816 yyextra->current->program << yytext;
817 }
818 }
819 "'" { // start of a single quoted string
820 yyextra->current->program << yytext;
821 yyextra->stringContext=YY_START;
822 yyextra->specialBlock = FALSE;
823 yyextra->copyString=&yyextra->current->program;
824 BEGIN( SingleQuoteString );
825 }
826 "\"" { // start of a double quoted string
827 yyextra->current->program << yytext;
828 yyextra->stringContext=YY_START;
829 yyextra->specialBlock = FALSE;
830 yyextra->copyString=&yyextra->current->program;
831 BEGIN( DoubleQuoteString );
832 }
833 [^ \t\n#'".]+ { // non-special stuff
834 yyextra->current->program << yytext;
835 yyextra->specialBlock = FALSE;
836 }
837 ^{POUNDCOMMENT} { // normal comment
838 yyextra->current->program << yytext;
839 }
840 "#".* { // comment half way
841 yyextra->current->program << yytext;
842 }
843 {NEWLINE} {
844 incLineNr(yyscanner);
845 yyextra->current->program << yytext;
846 }
847 . { // any character
848 yyextra->current->program << *yytext;
849 yyextra->specialBlock = FALSE;
850 }
#define yyterminate()
const int DIGIT
RegularExpression Id.
const int LETTER
RegularExpression Id.
static void endOfDef(yyscan_t yyscanner, int correction=0)
Definition pyscanner.l:2058
#define unput_string(yytext, yyleng)
Definition pyscanner.l:70
851
852 {TRIDOUBLEQUOTE} { // start of a comment block
853 yyextra->current->program << yytext;
854 initTriDoubleQuoteBlock(yyscanner);
855 BEGIN(TripleComment);
856 }
857
858 {TRISINGLEQUOTE} { // start of a comment block
859 yyextra->current->program << yytext;
860 initTriSingleQuoteBlock(yyscanner);
861 BEGIN(TripleComment);
862 }
863
864}
865
866<FunctionDec>{
867 {IDENTIFIER} {
868 //found function name
869 yyextra->current->name = yytext;
870 yyextra->current->name = yyextra->current->name.stripWhiteSpace();
871 newFunction(yyscanner);
872 }
873 {B}":"{B} { // function without arguments
874 yyextra->specialBlock = TRUE; // expecting a docstring
875 yyextra->bodyEntry = yyextra->current;
876 yyextra->current->bodyLine = yyextra->yyLineNr;
877 BEGIN(FunctionBody);
878 }
static void newFunction(yyscan_t yyscanner)
Definition pyscanner.l:1893
879
880 "->" {
881 yyextra->defVal.str(std::string());
882 yyextra->braceCount = 0;
883 BEGIN(FunctionTypeAnnotation);
884 }
885 {B}"(" {
886 yyextra->funcParamsEnd = FALSE;
887 yyextra->current->bodyLine = yyextra->yyLineNr;
888 BEGIN(FunctionParams);
889 }
890 ")" { // end of parameter list
891 if (yyextra->current->argList.empty())
892 {
893 yyextra->current->argList.setNoParameters(TRUE);
894 }
895 yyextra->current->args = argListToString(yyextra->current->argList);
896 yyextra->funcParamsEnd = TRUE;
897 }
QCString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:1201
898}
899
900<FunctionParams>{
901 {BB} {
902 }
903
904 "," {
905 if (!yyextra->argType.isEmpty())
906 {
907 Argument a;
908 a.name = "";
909 a.type = yyextra->argType;
910 yyextra->current->argList.push_back(a);
911 yyextra->argType = "";
912 }
913 }
This class contains the information about the argument of a function or template.
Definition arguments.h:27
QCString type
Definition arguments.h:42
QCString name
Definition arguments.h:44
914
915 [\*]+ {
916 yyextra->argType = yytext;
917 }
918 {IDENTIFIER} { // Name of parameter
919 lineCount(yyscanner);
920 Argument a;
921 a.name = QCString(yytext).stripWhiteSpace();
922 a.type = yyextra->argType;
923 yyextra->current->argList.push_back(a);
924 yyextra->argType = "";
925 }
926 "=" { // default value
927 // TODO: this rule is too simple, need to be able to
928 // match things like =")" as well!
929 yyextra->defVal.str(std::string());
930 yyextra->braceCount = 0;
931 BEGIN(FunctionParamDefVal);
932 }
933 ")" {
934 if (!yyextra->argType.isEmpty())
935 {
936 Argument a;
937 a.name = "";
938 a.type = yyextra->argType;
939 yyextra->current->argList.push_back(a);
940 yyextra->argType = "";
941 }
942 unput(*yytext);
943 BEGIN(FunctionDec);
944 }
945 ":"{B} {
946 yyextra->defVal.str(std::string());
947 yyextra->braceCount = 0;
948 BEGIN(FunctionAnnotation);
949 }
950 {POUNDCOMMENT} { // a comment
951 }
952 {PARAMNONEMPTY} { // Default rule inside arguments.
953 }
954
955}
956
957<FunctionTypeAnnotation>{
958 "{" |
959 "[" |
960 "(" {
961 ++yyextra->braceCount;
962 yyextra->defVal << *yytext;
963 }
964 "}" |
965 "]" |
966 ")" {
967 --yyextra->braceCount;
968 yyextra->defVal << *yytext;
969 }
970 ":" {
971 if (yyextra->braceCount == 0)
972 {
973 yyextra->current->type = yyextra->defVal.str();
974 unput(*yytext);
975 BEGIN(FunctionDec);
976 }
977 else
978 yyextra->defVal << *yytext;
979 }
980 "'" {
981 yyextra->defVal << *yytext;
982 yyextra->copyString=&yyextra->defVal;
983 yyextra->stringContext=FunctionTypeAnnotation;
984 BEGIN(SingleQuoteString);
985 }
986 "\"" {
987 yyextra->defVal << *yytext;
988 yyextra->copyString=&yyextra->defVal;
989 yyextra->stringContext=FunctionTypeAnnotation;
990 BEGIN(DoubleQuoteString);
991 }
992 \n {
993 yyextra->defVal << *yytext;
994 incLineNr(yyscanner);
995 }
996 . {
997 yyextra->defVal << *yytext;
998 }
999}
1000
1001<FunctionAnnotation>{
1002 "{" |
1003 "[" |
1004 "(" {
1005 ++yyextra->braceCount;
1006 yyextra->defVal << *yytext;
1007 }
1008 "}" |
1009 "]" {
1010 --yyextra->braceCount;
1011 yyextra->defVal << *yytext;
1012 }
1013 ")" |
1014 "=" |
1015 "," {
1016 if (yyextra->braceCount == 0)
1017 {
1018 if (!yyextra->current->argList.empty())
1019 yyextra->current->argList.back().type += yyextra->defVal.str();
1020 if (*yytext != ',')
1021 unput(*yytext);
1022 BEGIN(FunctionParams);
1023 }
1024 else
1025 {
1026 if (*yytext == ')')
1027 --yyextra->braceCount;
1028 yyextra->defVal << *yytext;
1029 }
1030 }
1031 "'" {
1032 yyextra->defVal << *yytext;
1033 yyextra->copyString=&yyextra->defVal;
1034 yyextra->stringContext=FunctionAnnotation;
1035 BEGIN(SingleQuoteString);
1036 }
1037 "\"" {
1038 yyextra->defVal << *yytext;
1039 yyextra->copyString=&yyextra->defVal;
1040 yyextra->stringContext=FunctionAnnotation;
1041 BEGIN(DoubleQuoteString);
1042 }
1043 \n {
1044 yyextra->defVal << *yytext;
1045 incLineNr(yyscanner);
1046 }
1047 . {
1048 yyextra->defVal << *yytext;
1049 }
1050}
1051
1052<FunctionParamDefVal>{
1053 "{" |
1054 "[" |
1055 "(" { // internal opening brace, assumption is that we have correct code so braces do match
1056 ++yyextra->braceCount;
1057 yyextra->defVal << *yytext;
1058 }
1059 "}" |
1060 "]" {
1061 --yyextra->braceCount;
1062 yyextra->defVal << *yytext;
1063 }
1064 ")" |
1065 "," {
1066 if (yyextra->braceCount == 0)
1067 {
1068 if (!yyextra->current->argList.empty())
1069 yyextra->current->argList.back().defval=QCString(yyextra->defVal.str()).stripWhiteSpace();
1070 if (*yytext == ')')
1071 unput(*yytext);
1072 BEGIN(FunctionParams);
1073 }
1074 else
1075 {
1076 if (*yytext == ')')
1077 --yyextra->braceCount;
1078 yyextra->defVal << *yytext;
1079 }
1080 }
1081
1082 "'" {
1083 yyextra->defVal << *yytext;
1084 yyextra->copyString=&yyextra->defVal;
1085 yyextra->stringContext=FunctionParamDefVal;
1086 BEGIN( SingleQuoteString );
1087 }
1088 "\"" {
1089 yyextra->defVal << *yytext;
1090 yyextra->copyString=&yyextra->defVal;
1091 yyextra->stringContext=FunctionParamDefVal;
1092 BEGIN( DoubleQuoteString );
1093 }
1094 \n {
1095 yyextra->defVal << *yytext;
1096 incLineNr(yyscanner);
1097 }
1098 . {
1099 yyextra->defVal << *yytext;
1100 }
1101}
1102
1103
1104<ClassBody>{
1105 \n/{IDENTIFIER}{BB} { // new def at indent 0
1106 if (computeIndent(&yytext[1])<=yyextra->indent)
1107 {
1108 int i;
1109 for (i=(int)yyleng-1;i>=0;i--)
1110 {
1111 unput(yytext[i]);
1112 }
1113 endOfDef(yyscanner);
1114 //YY_CURRENT_BUFFER->yy_at_bol=TRUE;
1115 BEGIN(Search);
1116 }
1117 else
1118 {
1119 incLineNr(yyscanner);
1120 yyextra->current->program << yytext;
1121 }
1122 }
1123 \n/"##"[^#] { // start of a special comment at indent 0
1124 if (computeIndent(&yytext[1])<=yyextra->indent)
1125 {
1126 int i;
1127 for (i=(int)yyleng-1;i>=0;i--)
1128 {
1129 unput(yytext[i]);
1130 }
1131 endOfDef(yyscanner);
1132 //YY_CURRENT_BUFFER->yy_at_bol=TRUE;
1133 BEGIN(Search);
1134 }
1135 else
1136 {
1137 incLineNr(yyscanner);
1138 yyextra->current->program << yytext;
1139 }
1140 }
1141 ^{BB}/\n { // skip empty line
1142 yyextra->current->program << yytext;
1143 }
1144 <<EOF>> {
1145 endOfDef(yyscanner);
1146 yyterminate();
1147 }
1148 ^{BB} { // something at indent >0
1149 yyextra->curIndent=computeIndent(yytext);
1150 DBG_CTX((stderr,"yyextra->curIndent=%d yyextra->indent=%d\n",yyextra->curIndent,yyextra->indent));
1151 if (yyextra->curIndent<=yyextra->indent)
1152 // jumped out of the class/method
1153 {
1154 endOfDef(yyscanner,1);
1155 yyextra->indent=yyextra->curIndent;
1156 // make sure the next rule matches ^...
1157 //YY_CURRENT_BUFFER->yy_at_bol=TRUE;
1158 //yyextra->hideClassDocs = FALSE;
1159 BEGIN(Search);
1160 }
1161 else
1162 {
1163 yyextra->current->program << yytext;
1164 }
1165 }
1166 "'" { // start of a single quoted string
1167 yyextra->current->program << *yytext;
1168 yyextra->stringContext=YY_START;
1169 yyextra->specialBlock = FALSE;
1170 yyextra->copyString=&yyextra->current->program;
1171 BEGIN( SingleQuoteString );
1172 }
1173 "\"" { // start of a double quoted string
1174 yyextra->current->program << *yytext;
1175 yyextra->stringContext=YY_START;
1176 yyextra->specialBlock = FALSE;
1177 yyextra->copyString=&yyextra->current->program;
1178 BEGIN( DoubleQuoteString );
1179 }
1180 [^ \t\n#'"]+ { // non-special stuff
1181 yyextra->current->program << yytext;
1182 yyextra->specialBlock = FALSE;
1183 //yyextra->hideClassDocs = FALSE;
1184 }
1185 {NEWLINE} {
1186 yyextra->current->program << *yytext;
1187 incLineNr(yyscanner);
1188 }
1189 {POUNDCOMMENT} { // normal comment
1190 yyextra->current->program << yytext;
1191 }
1192 . { // any character
1193 yyextra->specialBlock = FALSE;
1194 yyextra->current->program << *yytext;
1195 }
1196 {TRIDOUBLEQUOTE} { // start of a comment block
1197 //if (!yyextra->hideClassDocs)
1198 yyextra->current->program << yytext;
1199 initTriDoubleQuoteBlock(yyscanner);
1200 BEGIN(TripleComment);
1201 }
1202
1203 {TRISINGLEQUOTE} { // start of a comment block
1204 //if (!yyextra->hideClassDocs)
1205 yyextra->current->program << yytext;
1206 initTriSingleQuoteBlock(yyscanner);
1207 BEGIN(TripleComment);
1208 }
1209}
1210
1211<ClassDec>{IDENTIFIER} {
1212 if (yyextra->current->type.isEmpty())
1213 {
1214 yyextra->current->type = "class";
1215 }
1216
1217 yyextra->current->section = EntryType::makeClass();
1218 yyextra->current->name = yytext;
1219 // we need to set the protectiion based on the "local" class name
1220 setProtection(yyscanner);
1221
1222 // prepend scope in case of nested classes
1223 if (yyextra->current_root->section.isScope())
1224 {
1225 //printf("*** Prepending scope %s to class %s\n",qPrint(yyextra->current_root->name),qPrint(yyextra->current->name));
1226 yyextra->current->name.prepend(yyextra->current_root->name+"::");
1227 }
1228
1229 yyextra->current->name = yyextra->current->name.stripWhiteSpace();
1230 yyextra->current->fileName = yyextra->fileName;
1231 yyextra->docBlockContext = YY_START;
1232 yyextra->docBlockInBody = FALSE;
1233 yyextra->docBlockJavaStyle = FALSE;
1234 yyextra->docBlock.clear();
1235
1236 BEGIN(ClassInheritance);
1237 }
1238
1239<ClassInheritance>{
1240 ({BB}|[\‍(,\‍)]) { // syntactic sugar for the list
1241 }
1242
1243 ":" { // begin of the class definition
1244 yyextra->specialBlock = TRUE; // expecting a docstring
1245 yyextra->current->bodyLine = yyextra->yyLineNr;
1246 yyextra->current->program.str(std::string());
1247 BEGIN(ClassCaptureIndent);
1248 }
1249
1250 {SCOPE} {
1251 yyextra->current->extends.emplace_back(
1253 );
1254 //Has base class-do stuff
1255 }
1256 "'" { // start of a single quoted string
1257 yyextra->stringContext=YY_START;
1258 BEGIN( SingleQuoteStringIgnore );
1259 }
1260 "\"" { // start of a double quoted string
1261 yyextra->stringContext=YY_START;
1262 BEGIN( DoubleQuoteStringIgnore );
1263 }
1264}
1265
1266<SingleQuoteStringIgnore>{
1267 "'" { // end of a single quoted string
1268 BEGIN(yyextra->stringContext);
1269 }
1270 . { }
1271}
1272<DoubleQuoteStringIgnore>{
1273 "\"" { // end of a double quoted string
1274 BEGIN(yyextra->stringContext);
1275 }
1276 . { }
1277}
1278
1279<ClassCaptureIndent>{
1280 "\n"|({BB}"\n") {
1281 // Blankline - ignore, keep looking for indentation.
1282 lineCount(yyscanner);
1283 yyextra->current->program << yytext;
1284 }
1285
1286 {TRIDOUBLEQUOTE} { // start of a comment block
1287 initTriDoubleQuoteBlock(yyscanner);
1288 yyextra->current->program << yytext;
1289 BEGIN(TripleComment);
1290 }
1291 {TRISINGLEQUOTE} { // start of a comment block
1292 initTriSingleQuoteBlock(yyscanner);
1293 yyextra->current->program << yytext;
1294 BEGIN(TripleComment);
1295 }
1296 {STARTDOCSYMS}[#]* { // start of a special comment
1297 initSpecialBlock(yyscanner);
1298 BEGIN(SpecialComment);
1299 }
1300 {POUNDCOMMENT} { // ignore comment with just one #
1301 }
1302 ^{BB} {
1303 yyextra->current->program << yytext;
1304 //yyextra->current->startLine = yyextra->yyLineNr;
1305 yyextra->curIndent=computeIndent(yytext);
1306 yyextra->bodyEntry = yyextra->current;
1307 DBG_CTX((stderr,"setting indent %d\n",yyextra->curIndent));
1308 //printf("yyextra->current->program=[%s]\n",qPrint(yyextra->current->program));
1309 //yyextra->hideClassDocs = TRUE;
1310 BEGIN(ClassBody);
1311 }
1312
1313 ""/({NONEMPTY}|{EXPCHAR}) {
1314 // Just pushback an empty class, and
1315 // resume parsing the body.
1316 newEntry(yyscanner);
1317 yyextra->current->program << yytext;
1318
1319 // printf("Failed to find indent - skipping!");
1320 BEGIN( Search );
1321 }
1322}
1323
1324
1325<VariableDec>{
1326 ":"{B}{IDENTIFIER} { //typing
1327 yyextra->startInit = FALSE;
1328 yyextra->current->type = substitute(yytext,":","");
1329 }
1330 {STARTDOCSYMS}"<"/.* { // start of a special comment
1331 yyextra->curIndent=computeIndent(yytext);
1332 yyextra->packageCommentAllowed = FALSE;
1333 initSpecialBlock(yyscanner);
1334 yyextra->docBlockContext = VariableEnd;
1335 BEGIN(SpecialComment);
1336 }
1337 "#".* { // comment
1338 BEGIN( VariableEnd );
1339 }
1340 \n {
1341 unput('\n');
1342 BEGIN( VariableEnd );
1343 }
1344}
1345
1346<VariableAtom>{
1347 [\‍(\[\{] {
1348 yyextra->current->initializer << *yytext;
1349 if (yyextra->atomStart==*yytext)
1350 {
1351 yyextra->atomCount++;
1352 }
1353 }
1354 [\‍)\]\}] {
1355 yyextra->current->initializer << *yytext;
1356 if (yyextra->atomEnd==*yytext)
1357 {
1358 yyextra->atomCount--;
1359 }
1360 if (yyextra->atomCount==0)
1361 {
1362 yyextra->startInit = FALSE;
1363 BEGIN(yyextra->atomContext);
1364 }
1365 }
1366 {TRIDOUBLEQUOTE} { // start of a comment block
1367 yyextra->specialBlock = FALSE;
1368 yyextra->current->program << yytext;
1369 initTriDoubleQuoteBlock(yyscanner);
1370 BEGIN(TripleComment);
1371 }
1372
1373 {TRISINGLEQUOTE} { // start of a comment block
1374 yyextra->specialBlock = FALSE;
1375 yyextra->current->program << yytext;
1376 initTriSingleQuoteBlock(yyscanner);
1377 BEGIN(TripleComment);
1378 }
1379 "'" {
1380 yyextra->stringContext=YY_START;
1381 yyextra->current->initializer << "'";
1382 yyextra->copyString=&yyextra->current->initializer;
1383 BEGIN( SingleQuoteString );
1384 }
1385 "\"" {
1386 yyextra->stringContext=YY_START;
1387 yyextra->current->initializer << "\"";
1388 yyextra->copyString=&yyextra->current->initializer;
1389 BEGIN( DoubleQuoteString );
1390 }
1391 {IDENTIFIER} {
1392 yyextra->current->initializer << yytext;
1393 }
1394 . {
1395 yyextra->current->initializer << *yytext;
1396 }
1397 \n {
1398 yyextra->current->initializer << *yytext;
1399 incLineNr(yyscanner);
1400 }
1401
1402}
1403
1404<VariableEnd>{
1405 \n {
1406 incLineNr(yyscanner);
1407 if (!stripWhiteSpace(yyextra->current->initializer.str()).empty())
1408 {
1409 newVariable(yyscanner);
1410 }
1411 BEGIN(Search);
1412 }
1413 . {
1414 unput(*yytext);
1415 newVariable(yyscanner);
1416 BEGIN(Search);
1417 }
1418 <<EOF>> { yyterminate();
1419 }
static void newVariable(yyscan_t yyscanner)
Definition pyscanner.l:1871
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:72
1420}
1421
1422<TripleComment>{
1423 {ENDTRIDOUBLEQUOTE} |
1424 {ENDTRISINGLEQUOTE} {
1425 // printf("Expected module block %d special=%d\n",yyextra->expectModuleDocs,yyextra->specialBlock);
1426 if (yyextra->doubleQuote==(yytext[0]=='"'))
1427 {
1428 if (yyextra->specialBlock) // expecting a docstring
1429 {
1430 QCString actualDoc=yyextra->docBlock;
1431 if (!yyextra->docBlockSpecial) // legacy unformatted docstring
1432 {
1433 if (!actualDoc.isEmpty())
1434 {
1435 stripIndentationVerbatim(actualDoc,yyextra->commentIndent);
1436 actualDoc.prepend("@iverbatim\n");
1437 actualDoc.append("@endiverbatim ");
1438 }
1439 }
1440 //printf("-------> yyextra->current=%p yyextra->bodyEntry=%p\n",yyextra->current,yyextra->bodyEntry);
1441 handleCommentBlock(yyscanner, actualDoc, FALSE);
1442 }
1443 else if (yyextra->packageCommentAllowed) // expecting module docs
1444 {
1445 QCString actualDoc=yyextra->docBlock;
1446 if (!yyextra->docBlockSpecial) // legacy unformatted docstring
1447 {
1448 if (!actualDoc.isEmpty())
1449 {
1450 stripIndentationVerbatim(actualDoc,yyextra->commentIndent);
1451 actualDoc.prepend("@iverbatim\n");
1452 actualDoc.append("@endiverbatim ");
1453 }
1454 }
1455 if (yyextra->moduleScope.startsWith("__") && yyextra->moduleScope.endsWith("__"))
1456 {
1457 actualDoc.prepend("\\namespace \\"+yyextra->moduleScope+" ");
1458 }
1459 else
1460 {
1461 actualDoc.prepend("\\namespace "+yyextra->moduleScope+" ");
1462 }
1463 handleCommentBlock(yyscanner, actualDoc, FALSE);
1464 }
1465 if ((yyextra->docBlockContext==ClassBody /*&& !yyextra->hideClassDocs*/) ||
1466 yyextra->docBlockContext==FunctionBody)
1467 {
1468 yyextra->current->program << yyextra->docBlock;
1469 yyextra->current->program << yytext;
1470 }
1471 //if (yyextra->hideClassDocs)
1472 //{
1473 // yyextra->current->startLine = yyextra->yyLineNr;
1474 //}
1475 //yyextra->hideClassDocs=FALSE;
1476 BEGIN(yyextra->docBlockContext);
1477 }
1478 else
1479 {
1480 yyextra->docBlock += yytext;
1481 }
1482 yyextra->packageCommentAllowed = FALSE;
1483 }
QCString & prepend(const char *s)
Definition qcstring.h:407
QCString & append(char c)
Definition qcstring.h:381
static void handleCommentBlock(yyscan_t yyscanner, const QCString &doc, bool brief)
Definition pyscanner.l:2003
void stripIndentationVerbatim(QCString &doc, const int indentationLevel)
Definition util.cpp:6526
1484
1485
1486 ^{BB} { // leading whitespace, compensate for """! / '''!
1487 if (yyextra->firstPass && yyextra->docBlockSpecial && yyleng >= yyextra->curIndent)
1488 yyextra->docBlock += yytext + yyextra->curIndent;
1489 else
1490 yyextra->docBlock += yytext;
1491 }
1492 [^"'\n \t\\@]+ {
1493 yyextra->docBlock += yytext;
1494 }
1495 \n {
1496 incLineNr(yyscanner);
1497 yyextra->docBlock += yytext;
1498 }
1499 {CMD}"ifile"{B}+"\""[^\n\"]+"\"" {
1500 yyextra->fileName = &yytext[6];
1501 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1502 yyextra->fileName = yyextra->fileName.mid(1,yyextra->fileName.length()-2);
1503 yyextra->docBlock+=yytext;
1504 }
1505 {CMD}"ifile"{B}+{FILEMASK} {
1506 yyextra->fileName = &yytext[6];
1507 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1508 yyextra->docBlock+=yytext;
1509 }
1510 {CMD}"iline"{LINENR}/[\n\.] |
1511 {CMD}"iline"{LINENR}{B} {
1512 bool ok = false;
1513 int nr = QCString(&yytext[6]).toInt(&ok);
1514 if (!ok)
1515 {
1516 warn(yyextra->fileName,yyextra->yyLineNr,"Invalid line number '{}' for iline command",yytext);
1517 }
1518 else
1519 {
1520 yyextra->yyLineNr = nr;
1521 }
1522 yyextra->docBlock+=yytext;
1523 }
1524 ({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command
1525 yyextra->docBlock+=yytext;
1526 }
1527 \\. { // escaped char TO be extended
1528 yyextra->docBlock += yytext;
1529 }
1530 . {
1531 yyextra->docBlock += yytext;
1532 }
int toInt(bool *ok=nullptr, int base=10) const
Definition qcstring.cpp:249
1533}
1534
1535<SpecialComment>{
1536 ^{B}"#"("#")* { // skip leading hashes
1537 }
1538 \n/{B}"#" { // continuation of the comment on the next line
1539 yyextra->docBlock+='\n';
1540 yyextra->docBrief = FALSE;
1541 incLineNr(yyscanner);
1542 }
1543 {CMD}"ifile"{B}+"\""[^\n\"]+"\"" {
1544 yyextra->fileName = &yytext[6];
1545 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1546 yyextra->fileName = yyextra->fileName.mid(1,yyextra->fileName.length()-2);
1547 yyextra->docBlock+=yytext;
1548 }
1549 {CMD}"ifile"{B}+{FILEMASK} {
1550 yyextra->fileName = &yytext[6];
1551 yyextra->fileName = yyextra->fileName.stripWhiteSpace();
1552 yyextra->docBlock+=yytext;
1553 }
1554 {CMD}"iline"{LINENR}/[\n\.] |
1555 {CMD}"iline"{LINENR}{B} {
1556 bool ok = false;
1557 int nr = QCString(&yytext[6]).toInt(&ok);
1558 if (!ok)
1559 {
1560 warn(yyextra->fileName,yyextra->yyLineNr,"Invalid line number '{}' for iline command",yytext);
1561 }
1562 else
1563 {
1564 yyextra->yyLineNr = nr;
1565 }
1566 yyextra->docBlock+=yytext;
1567 }
1568 ({CMD}{CMD}){ID}/[^a-z_A-Z0-9] { // escaped command
1569 yyextra->docBlock+=yytext;
1570 }
1571 "\\ilinebr "{B}* {
1572 QCString indent;
1573 int extraSpaces = std::max(0,static_cast<int>(yyleng-9-yyextra->curIndent-2));
1574 indent.fill(' ',extraSpaces);
1575 //printf("extraSpaces=%d\n",extraSpaces);
1576 yyextra->docBlock += "\\ilinebr ";
1577 yyextra->docBlock += indent;
1578 }
1579 [^#\\@\n]+ { // any other stuff
1580 yyextra->docBlock+=yytext;
1581 }
1582 \n { // new line that ends the comment
1583 handleCommentBlock(yyscanner, yyextra->docBlock, yyextra->docBrief);
1584 if (yyextra->docBlockContext == VariableEnd)
1585 {
1586 unput(*yytext);
1587 }
1588 else
1589 {
1590 incLineNr(yyscanner);
1591 }
1592 BEGIN(yyextra->docBlockContext);
1593 }
1594 . { // anything we missed
1595 yyextra->docBlock+=*yytext;
1596 }
void fill(char c, int len=-1)
Fills a string with a predefined character.
Definition qcstring.h:180
1597}
1598
1599<SingleQuoteString>{
1600 \\{B}\n { // line continuation
1601 addToString(yyscanner,yytext);
1602 incLineNr(yyscanner);
1603 }
1604 \\. { // escaped char
1605 addToString(yyscanner,yytext);
1606 }
1607 "\"\"\"" { // triple double quotes
1608 addToString(yyscanner,yytext);
1609 }
1610 "'" { // end of the string
1611 addToString(yyscanner,yytext);
1612 BEGIN(yyextra->stringContext);
1613 }
1614 [^"'\n\\]+ { // normal chars
1615 addToString(yyscanner,yytext);
1616 }
1617 . { // normal char
1618 addToString(yyscanner,yytext);
1619 }
static void addToString(yyscan_t yyscanner, const char *s)
Definition pyscanner.l:2071
1620}
1621
1622<DoubleQuoteString>{
1623 \\{B}\n { // line continuation
1624 addToString(yyscanner,yytext);
1625 incLineNr(yyscanner);
1626 }
1627 \\. { // escaped char
1628 addToString(yyscanner,yytext);
1629 }
1630 "'''" { // triple single quotes
1631 addToString(yyscanner,yytext);
1632 }
1633 "\"" { // end of the string
1634 addToString(yyscanner,yytext);
1635 BEGIN(yyextra->stringContext);
1636 }
1637 [^"'\n\\]+ { // normal chars
1638 addToString(yyscanner,yytext);
1639 }
1640 . { // normal char
1641 addToString(yyscanner,yytext);
1642 }
1643}
1644
1645<TripleString>{
1646 {ENDTRIDOUBLEQUOTE} |
1647 {ENDTRISINGLEQUOTE} {
1648 *yyextra->copyString << yytext;
1649 if (yyextra->doubleQuote==(yytext[0]=='"'))
1650 {
1651 BEGIN(yyextra->stringContext);
1652 }
1653 }
1654
1655
1656 ({LONGSTRINGBLOCK}) {
1657 lineCount(yyscanner);
1658 *yyextra->copyString << yytext;
1659 }
1660 \n {
1661 incLineNr(yyscanner);
1662 *yyextra->copyString << yytext;
1663 }
1664 . {
1665 *yyextra->copyString << *yytext;
1666 }
1667}
1668
1669<Decorator>{
1670 {TRIDOUBLEQUOTE} { // start of a comment block
1671 yyextra->doubleQuote=TRUE;
1672 yyextra->decoratorCommentStr.str(std::string());
1673 yyextra->copyString=&yyextra->decoratorCommentStr;
1674 yyextra->stringContext=YY_START;
1675 BEGIN(TripleString);
1676 }
1677
1678 {TRISINGLEQUOTE} { // start of a comment block
1679 yyextra->doubleQuote=FALSE;
1680 yyextra->decoratorCommentStr.str(std::string());
1681 yyextra->copyString=&yyextra->decoratorCommentStr;
1682 yyextra->stringContext=YY_START;
1683 BEGIN(TripleString);
1684 }
1685 "'" {
1686 yyextra->stringContext=YY_START;
1687 yyextra->decoratorCommentStr.str(std::string());
1688 yyextra->copyString=&yyextra->decoratorCommentStr;
1689 BEGIN( SingleQuoteString );
1690 }
1691 "\"" {
1692 yyextra->stringContext=YY_START;
1693 yyextra->decoratorCommentStr.str(std::string());
1694 yyextra->copyString=&yyextra->decoratorCommentStr;
1695 BEGIN( DoubleQuoteString );
1696 }
1697 "(" {
1698 yyextra->decoratorRound++;
1699 }
1700 ")" {
1701 yyextra->decoratorRound--;
1702 if (!yyextra->decoratorRound) BEGIN( Search );
1703 }
1704 \n {
1705 incLineNr(yyscanner);
1706 }
1707 . { }
1708}
1709
1710 /* ------------ End rules -------------- */
1711
1712 /*
1713<*>({NONEMPTY}|{EXPCHAR}|{BB}) { // This should go one character at a time.
1714 // printf("[pyscanner] '%s' [ state %d ] [line %d] no match\n",
1715 // yytext, YY_START, yyextra->yyLineNr);
1716
1717 }
1718 */
1719
1720<*>{NEWLINE} {
1721 //printf("[pyscanner] %d NEWLINE [line %d] no match\n",
1722 // YY_START, yyextra->yyLineNr);
1723
1724 lineCount(yyscanner);
1725 }
1726
1727<*>"'" {
1728 //fprintf(stderr,"Quote: %d\n",YY_START);
1729 }
1730
1731<*>. {
1732 //printf("[pyscanner] '%s' [ state %d ] [line %d] no match\n",
1733 // yytext, YY_START, yyextra->yyLineNr);
1734
1735 }
1736
1737
1738%%

◆ yyread()

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

Definition at line 1742 of file pyscanner.l.

1743{
1744 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1745 int c=0;
1746 const char *p = yyextra->inputString + yyextra->inputPosition;
1747 while ( c < max_size && *p ) { *buf++ = *p++; c++; }
1748 yyextra->inputPosition+=c;
1749 return c;
1750}