Doxygen
Loading...
Searching...
No Matches
pyscanner.l File Reference
#include <stdint.h>
#include "pyscanner.h"
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "arguments.h"
#include "commentscan.h"
#include "config.h"
#include "debug.h"
#include "defargs.h"
#include "entry.h"
#include "fileinfo.h"
#include "markdown.h"
#include "message.h"
#include "stringutil.h"
#include "util.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 yyguts_t   pyscannerYYguts_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 newTypeAlias (yyscan_t yyscanner)
static void addVariable (yyscan_t yyscanner)
static void newFunction (yyscan_t yyscanner)
static DString findPackageScopeFromPath (yyscan_t yyscanner, const DString &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 DString &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 void searchFoundTypeAlias (yyscan_t yyscanner)
static DString findPackageScope (yyscan_t yyscanner, const DString &fileName)
static void setProtection (yyscan_t yyscanner)
static void handleParamComment (yyscan_t yyscanner, const DString &doc)
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 DString &fileName, const char *fileBuf, const std::shared_ptr< Entry > &rt)
static void parsePrototype (yyscan_t yyscanner, const DString &text)

Macro Definition Documentation

◆ DBG_CTX

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

Definition at line 61 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 66 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 pyscanner.l:1845

Definition at line 163 of file pyscanner.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 63 of file pyscanner.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 64 of file pyscanner.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 29 of file pyscanner.l.

◆ yyguts_t

#define yyguts_t   pyscannerYYguts_t

Definition at line 30 of file pyscanner.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 32 of file pyscanner.l.

Function Documentation

◆ addEntry()

void addEntry ( yyscan_t yyscanner)
static

Definition at line 1928 of file pyscanner.l.

1929{
1930 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
#define yyguts_t
Definition code.l:23
1931
1932 auto doc = yyextra->current->doc;
1933 auto docLine = yyextra->current->docLine;
1934 auto docFile = yyextra->current->docFile;
1935 auto brief = yyextra->current->brief;
1936 auto briefLine = yyextra->current->briefLine;
1937 auto briefFile = yyextra->current->briefFile;
1938
1939 yyextra->previous = yyextra->current;
1940 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
1941 initEntry(yyscanner);
static void initEntry(yyscan_t yyscanner)
Definition pyscanner.l:1866
1942
1943 yyextra->current->doc = doc;
1944 yyextra->current->docLine = docLine;
1945 yyextra->current->docFile = docFile;
1946 yyextra->current->brief = brief;
1947 yyextra->current->briefLine = briefLine;
1948 yyextra->current->briefFile = briefFile;
1949}

References initEntry(), and yyguts_t.

Referenced by addVariable().

◆ addFrom()

void addFrom ( yyscan_t yyscanner,
bool all )
static

Definition at line 2073 of file pyscanner.l.

2074{
2075 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2076 DString item=all ? yyextra->packageName : yyextra->packageName+"."+yytext;
2077 yyextra->current->name=removeRedundantWhiteSpace(substitute(item,".","::"));
2078 yyextra->current->fileName = yyextra->fileName;
2079 //printf("Adding using declaration: found:%s:%d name=%s\n",qPrint(yyextra->fileName),yyextra->yyLineNr,qPrint(yyextra->current->name));
2080 yyextra->current->section=all ? EntryType::makeUsingDir() : EntryType::makeUsingDecl();
2081 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
2082 initEntry(yyscanner);
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
Wrapper class for the Entry type.
Definition types.h:860
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
2083}

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

◆ addToString()

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

Definition at line 2187 of file pyscanner.l.

2188{
2189 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2190 if (yyextra->copyString) (*yyextra->copyString) << s;
2191}

References yyguts_t.

◆ addVariable()

void addVariable ( yyscan_t yyscanner)
static

Definition at line 1998 of file pyscanner.l.

1999{
2000 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2001 setProtection(yyscanner);
2002 if (yyextra->current_root->section.isCompound()) // mark as class variable
2003 {
2004 yyextra->current->isStatic = true;
2005 }
2006 addEntry(yyscanner);
static void setProtection(yyscan_t yyscanner)
Definition pyscanner.l:1951
static void addEntry(yyscan_t yyscanner)
Definition pyscanner.l:1928
2007}

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

◆ computeIndent()

int computeIndent ( const char * s)
inlinestatic

Definition at line 2024 of file pyscanner.l.

2025{
2026 int col=0;
2027 int tabSize=Config_getInt(TAB_SIZE);
2028 const char *p=s;
2029 char c;
2030 while ((c=*p++))
2031 {
2032 if (c==' ') col++;
2033 else if (c=='\t') col+=tabSize-(col%tabSize);
2034 else break;
2035 }
2036 return col;
#define Config_getInt(name)
Definition config.h:34
2037}

References Config_getInt.

Referenced by handleParamComment().

◆ docVariable()

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

Definition at line 1967 of file pyscanner.l.

1968{
1969 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1970 yyextra->current->name = name;
1971 yyextra->current->section=EntryType::makeVariable();
1972 yyextra->current->fileName = yyextra->fileName;
1973 yyextra->current->startLine = yyextra->yyLineNr;
1974 yyextra->current->bodyLine = yyextra->yyLineNr;
1975 yyextra->current->type.clear();
1976 setProtection(yyscanner);
1977 yyextra->checkDupEntry = true;
const char * name(int level)
Definition latexgen.h:368
1978}

References setProtection(), and yyguts_t.

◆ endOfDef()

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

Definition at line 2174 of file pyscanner.l.

2175{
2176 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2177 //printf("endOfDef at=%d\n",yyextra->yyLineNr);
2178 if (yyextra->bodyEntry)
2179 {
2180 yyextra->bodyEntry->endBodyLine = yyextra->yyLineNr-correction;
2181 yyextra->bodyEntry = 0;
2182 }
2183 newEntry(yyscanner);
2184 //yyextra->insideConstructor = false;
static void newEntry(yyscan_t yyscanner)
Definition pyscanner.l:1882
2185}

References newEntry(), and yyguts_t.

◆ findPackageScope()

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

Definition at line 2066 of file pyscanner.l.

2067{
2068 if (fileName.empty()) return fileName;
2069 FileInfo fi(fileName.str());
2070 return findPackageScopeFromPath(yyscanner,fi.dirPath(true));
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
const std::string & str() const
Definition dstring.h:645
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
static DString findPackageScopeFromPath(yyscan_t yyscanner, const DString &path)
Definition pyscanner.l:2039
2071}

References FileInfo::dirPath(), DString::empty(), findPackageScopeFromPath(), and DString::str().

Referenced by parseMain().

◆ findPackageScopeFromPath()

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

Definition at line 2039 of file pyscanner.l.

2040{
2041 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2042 auto it = yyextra->packageNameCache.find(path.str());
2043 if (it!=yyextra->packageNameCache.end())
2044 {
2045 return it->second;
2046 }
2047 FileInfo pf(path.str()+"/__init__.py"); // found package initialization file
2048 if (pf.exists())
2049 {
2050 size_t i=path.rfind('/');
2051 if (i!=DString::npos)
2052 {
2053 DString scope = findPackageScopeFromPath(yyscanner,path.left(i));
2054 if (!scope.empty())
2055 {
2056 scope+="::";
2057 }
2058 scope+=path.mid(i+1);
2059 yyextra->packageNameCache.emplace(path.str(),scope.str());
2060 return scope;
2061 }
2062 }
2063 return "";
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
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
DString left(size_t len) const
Definition dstring.h:306
2064}

References DString::empty(), FileInfo::exists(), findPackageScopeFromPath(), DString::left(), DString::mid(), DString::npos, DString::rfind(), DString::str(), and yyguts_t.

Referenced by findPackageScope(), and findPackageScopeFromPath().

◆ getLexerFILE()

const char * getLexerFILE ( )
inlinestatic

Definition at line 166 of file pyscanner.l.

166{return __FILE__;}

◆ handleCommentBlock()

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

Definition at line 2119 of file pyscanner.l.

2120{
2121 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2122 //printf("handleCommentBlock(doc=[%s] brief=%d yyextra->docBlockInBody=%d yyextra->docBlockJavaStyle=%d\n",
2123 // qPrint(doc),brief,yyextra->docBlockInBody,yyextra->docBlockJavaStyle);
2124
2125 // TODO: Fix me
2126 yyextra->docBlockInBody=false;
2127
2128 if (!yyextra->current->doc.empty())
2129 {
2130 yyextra->current->doc=yyextra->current->doc.stripWhiteSpace()+"\n\n";
2131 }
2132 if (yyextra->docBlockInBody && yyextra->previous && !yyextra->previous->doc.empty())
2133 {
2134 yyextra->previous->doc=yyextra->previous->doc.stripWhiteSpace()+"\n\n";
2135 }
2136
2137 int position = 0;
2138 bool needsEntry = false;
2139 int lineNr = brief ? yyextra->current->briefLine : yyextra->current->docLine;
2140 Markdown markdown(yyextra->fileName,lineNr);
2141 GuardedSectionStack guards;
2142 DString strippedDoc = stripIndentation(doc,true);
2143 //printf("stippedDoc=[%s]\n",qPrint(strippedDoc));
2144 DString processedDoc = Config_getBool(MARKDOWN_SUPPORT) ? markdown.process(strippedDoc,lineNr) : strippedDoc;
2145 while (yyextra->commentScanner.parseCommentBlock(
2146 yyextra->thisParser,
2147 (yyextra->docBlockInBody && yyextra->previous) ? yyextra->previous.get() : yyextra->current.get(),
2148 processedDoc, // text
2149 yyextra->fileName, // file
2150 lineNr,
2151 yyextra->docBlockInBody ? false : brief,
2152 yyextra->docBlockJavaStyle, // javadoc style // or false,
2153 yyextra->docBlockInBody,
2154 yyextra->protection,
2155 position,
2156 needsEntry,
2157 Config_getBool(MARKDOWN_SUPPORT),
2158 &guards
2159 )
2160 ) // need to start a new entry
2161 {
2162 if (needsEntry)
2163 {
2164 newEntry(yyscanner);
2165 }
2166 }
2167 if (needsEntry)
2168 {
2169 newEntry(yyscanner);
2170 }
Helper class to process markdown formatted text.
Definition markdown.h:33
std::stack< GuardedSection > GuardedSectionStack
Definition commentscan.h:48
#define Config_getBool(name)
Definition config.h:33
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4819
2171
2172}

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

◆ handleParamComment()

void handleParamComment ( yyscan_t yyscanner,
const DString & doc )
static

Definition at line 2276 of file pyscanner.l.

2277{
2278 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2279 yyextra->curIndent=computeIndent(yytext);
2280 initSpecialBlock(yyscanner);
2281 if (!yyextra->current->argList.empty())
2282 {
2283 yyextra->docBlock += "@param ";
2284 yyextra->docBlock += yyextra->current->argList.back().name;
2285 yyextra->docBlock += " ";
2286 }
2287 yyextra->docBlockContext = YY_START;
static void initSpecialBlock(yyscan_t yyscanner)
Definition pyscanner.l:2219
static int computeIndent(const char *s)
Definition pyscanner.l:2024
2288}

References computeIndent(), initSpecialBlock(), and yyguts_t.

◆ incLineNr()

void incLineNr ( yyscan_t yyscanner)
static

Definition at line 2096 of file pyscanner.l.

2097{
2098 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2099 DBG_CTX((stderr,"yyextra->yyLineNr=%d\n",yyextra->yyLineNr));
2100 yyextra->yyLineNr++;
#define DBG_CTX(x)
Definition pyscanner.l:61
2101}

References DBG_CTX, and yyguts_t.

◆ initEntry()

void initEntry ( yyscan_t yyscanner)
static

Definition at line 1866 of file pyscanner.l.

1867{
1868 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1869 //yyextra->current->python = true;
1870 yyextra->current->protection = yyextra->protection ;
1871 yyextra->current->mtype = yyextra->mtype;
1872 yyextra->current->virt = yyextra->virt;
1873 yyextra->current->isStatic = yyextra->isStatic;
1874 yyextra->current->lang = SrcLangExt::Python;
1875 yyextra->current->type.clear();
1876 yyextra->current->name.clear();
1877 yyextra->current->initializer.clear();
1878 yyextra->commentScanner.initGroupInfo(yyextra->current.get());
1879 yyextra->isStatic = false;
1880}

References yyguts_t.

Referenced by addEntry(), addFrom(), newEntry(), parseCompounds(), and parseMain().

◆ initParser()

void initParser ( yyscan_t yyscanner)
static

Definition at line 1855 of file pyscanner.l.

1856{
1857 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1858 yyextra->protection = Protection::Public;
1859 yyextra->mtype = MethodTypes::Method;
1860 yyextra->isStatic = false;
1861 yyextra->virt = Specifier::Normal;
1862 yyextra->previous = 0;
1863 yyextra->packageCommentAllowed = true;
1864}

References yyguts_t.

Referenced by parseMain().

◆ initSpecialBlock()

void initSpecialBlock ( yyscan_t yyscanner)
static

Definition at line 2219 of file pyscanner.l.

2220{
2221 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2222 yyextra->docBlockContext = YY_START;
2223 yyextra->docBlockInBody = false;
2224 yyextra->docBlockJavaStyle = true;
2225 yyextra->docBrief = true;
2226 yyextra->docBlock.clear();
2227 yyextra->commentIndent = yyextra->curIndent;
2228 startCommentBlock(yyscanner,false);
static void startCommentBlock(yyscan_t yyscanner, bool brief)
Definition pyscanner.l:2104
2229}

References startCommentBlock(), and yyguts_t.

Referenced by handleParamComment().

◆ initTriDoubleQuoteBlock()

void initTriDoubleQuoteBlock ( yyscan_t yyscanner)
static

Definition at line 2193 of file pyscanner.l.

2194{
2195 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2196 yyextra->docBlockContext = YY_START;
2197 yyextra->docBlockInBody = false;
2198 yyextra->docBlockJavaStyle = true;
2199 yyextra->docBlockSpecial = yytext[strlen(yytext) - 1]=='!' || !Config_getBool(PYTHON_DOCSTRING);
2200 yyextra->docBlock.clear();
2201 yyextra->commentIndent = yyextra->curIndent;
2202 yyextra->doubleQuote = true;
2203 startCommentBlock(yyscanner,false);
2204}

References Config_getBool, startCommentBlock(), and yyguts_t.

◆ initTriSingleQuoteBlock()

void initTriSingleQuoteBlock ( yyscan_t yyscanner)
static

Definition at line 2206 of file pyscanner.l.

2207{
2208 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2209 yyextra->docBlockContext = YY_START;
2210 yyextra->docBlockInBody = false;
2211 yyextra->docBlockJavaStyle = true;
2212 yyextra->docBlockSpecial = yytext[strlen(yytext) - 1]=='!' || !Config_getBool(PYTHON_DOCSTRING);
2213 yyextra->docBlock.clear();
2214 yyextra->commentIndent = yyextra->curIndent;
2215 yyextra->doubleQuote = false;
2216 startCommentBlock(yyscanner,false);
2217}

References Config_getBool, startCommentBlock(), and yyguts_t.

◆ lineCount()

void lineCount ( yyscan_t yyscanner)
static

Definition at line 2086 of file pyscanner.l.

2087{
2088 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2089 DBG_CTX((stderr,"yyextra->yyLineNr=%d\n",yyextra->yyLineNr));
2090 for (const char *p = yytext; *p; ++p)
2091 {
2092 yyextra->yyLineNr += (*p == '\n') ;
2093 }
2094}

References DBG_CTX, and yyguts_t.

◆ newEntry()

void newEntry ( yyscan_t yyscanner)
static

Definition at line 1882 of file pyscanner.l.

1883{
1884 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1885 if (yyextra->current->name.empty())
1886 {
1887 initEntry(yyscanner);
1888 return;
1889 }
1890 bool found = false;
1891 if (yyextra->checkDupEntry)
1892 {
1893 for (auto &v : yyextra->current_root->children())
1894 {
1895 //printf("candidate %s<->%s section=%s!\n",qPrint(v->name),qPrint(yyextra->current->name), qPrint(v->section.to_string()));
1896 if (v->name==yyextra->current->name && v->section==yyextra->current->section) // name is already added, don't add it again
1897 {
1898 if (v->doc.empty() && !yyextra->current->doc.empty())
1899 {
1900 v->doc = yyextra->current->doc;
1901 v->docLine = yyextra->current->docLine;
1902 v->docFile = yyextra->current->docFile;
1903 }
1904 if (v->brief.empty() && !yyextra->current->brief.empty())
1905 {
1906 v->brief = yyextra->current->brief;
1907 v->briefLine = yyextra->current->briefLine;
1908 v->briefFile = yyextra->current->briefFile;
1909 }
1910 if (v->type.empty() && !yyextra->current->type.empty())
1911 {
1912 //printf("copying type '%s' from '%s' to '%s'\n",qPrint(yyextra->current->type),qPrint(yyextra->current->name),qPrint(v->name));
1913 v->type = yyextra->current->type;
1914 }
1915 found=true;
1916 break;
1917 }
1918 }
1919 }
1920 if (!found)
1921 {
1922 yyextra->previous = yyextra->current;
1923 yyextra->current_root->moveToSubEntryAndRefresh(yyextra->current);
1924 }
1925 initEntry(yyscanner);
1926}

References initEntry(), and yyguts_t.

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

◆ newFunction()

void newFunction ( yyscan_t yyscanner)
static

Definition at line 2009 of file pyscanner.l.

2010{
2011 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2012 if (yyextra->current->name.startsWith("__") && yyextra->current->name.endsWith("__"))
2013 {
2014 // special method name, see
2015 // http://docs.python.org/ref/specialnames.html
2016 yyextra->current->protection=Protection::Public;
2017 }
2018 else
2019 {
2020 setProtection(yyscanner);
2021 }
2022}

References setProtection(), and yyguts_t.

◆ newTypeAlias()

void newTypeAlias ( yyscan_t yyscanner)
static

Definition at line 1991 of file pyscanner.l.

1992{
1993 //struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1994 //printf("*** newTypeAlias %s\n",qPrint(yyextra->current->name));
1995 newEntry(yyscanner);
1996}

References newEntry().

◆ newVariable()

void newVariable ( yyscan_t yyscanner)
static

Definition at line 1980 of file pyscanner.l.

1981{
1982 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1983 setProtection(yyscanner);
1984 if (yyextra->current_root->section.isCompound()) // mark as class variable
1985 {
1986 yyextra->current->isStatic = true;
1987 }
1988 newEntry(yyscanner);
1989}

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

◆ parseCompounds()

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

Definition at line 2292 of file pyscanner.l.

2293{
2294 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2295 //printf("parseCompounds(%s)\n",qPrint(rt->name));
2296 for (size_t i=0; i<rt->children().size(); ++i)
2297 {
2298 std::shared_ptr<Entry> ce = rt->children()[i];
2299 if (!ce->program.empty())
2300 {
2301 //fprintf(stderr,"parseCompounds: -- %s (line %d) ---------\n%s\n---------------\n",
2302 // qPrint(ce->name), ce->bodyLine, qPrint(ce->program));
2303 // init scanner state
2304 yyextra->programStr = ce->program.str();
2305 yyextra->inputString = yyextra->programStr.data();
2306 yyextra->inputPosition = 0;
2307 yyextra->firstPass = false;
2308 pyscannerYYrestart( nullptr, yyscanner );
2309 if (ce->section.isCompound())
2310 {
2311 yyextra->specialBlock = false;
2312 yyextra->current_root = ce;
2313 BEGIN( Search );
2314 }
2315 else if (ce->parent())
2316 {
2317 yyextra->current_root = rt;
2318 //printf("Searching for member variables in %s parent=%s\n",
2319 // qPrint(ce->name),qPrint(ce->parent->name));
2320 BEGIN( SearchMemVars );
2321 }
2322 yyextra->fileName = ce->fileName;
2323 yyextra->yyLineNr = ce->bodyLine ;
2324 yyextra->current = std::make_shared<Entry>();
2325 initEntry(yyscanner);
2326
2327 yyextra->checkDupEntry = false;
2328
2329 DString name = ce->name;
2330 yyextra->commentScanner.enterCompound(yyextra->fileName,yyextra->yyLineNr,name);
2331
2332 pyscannerYYlex(yyscanner) ;
2333 yyextra->lexInit=true;
2334
2335 yyextra->programStr.clear();
2336 ce->program.str(std::string());
2337
2338 yyextra->commentScanner.leaveCompound(yyextra->fileName,yyextra->yyLineNr,name);
2339
2340 }
2341 parseCompounds(yyscanner,ce);
2342 }
static void parseCompounds(yyscan_t yyscanner, std::shared_ptr< Entry > rt)
Definition pyscanner.l:2292
2343}

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

Referenced by parseCompounds(), and parseMain().

◆ parseMain()

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

Definition at line 2348 of file pyscanner.l.

2349{
2350 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2351 initParser(yyscanner);
static void initParser(yyscan_t yyscanner)
Definition pyscanner.l:1855
2352
2353 if (fileBuf==nullptr || fileBuf[0]=='\0') return;
2354
2355 yyextra->inputString = fileBuf;
2356 yyextra->inputPosition = 0;
2357
2358 yyextra->protection = Protection::Public;
2359 yyextra->mtype = MethodTypes::Method;
2360 yyextra->isStatic = false;
2361 yyextra->virt = Specifier::Normal;
2362 yyextra->current_root = rt;
2363 yyextra->specialBlock = false;
2364
2365 yyextra->yyLineNr = 1 ;
2366 yyextra->fileName = fileName;
2367 yyextra->checkDupEntry = false;
2368 yyextra->firstPass = true;
2369 //setContext();
2370 msg("Parsing file {}...\n",yyextra->fileName);
#define msg(fmt,...)
Definition message.h:94
2371
2372 FileInfo fi(fileName.str());
2373 yyextra->moduleScope = findPackageScope(yyscanner,fileName);
2374 DString baseName=fi.baseName();
2375 if (baseName!="__init__") // package initializer file is not a package itself
2376 {
2377 if (!yyextra->moduleScope.empty())
2378 {
2379 yyextra->moduleScope+="::";
2380 }
2381 yyextra->moduleScope+=baseName;
2382 }
static DString findPackageScope(yyscan_t yyscanner, const DString &fileName)
Definition pyscanner.l:2066
2383
2384 // add namespaces for each scope
2385 DString scope = yyextra->moduleScope;
2386 size_t startPos = 0;
2387 size_t pos = 0;
2388 do
2389 {
2390 pos = scope.find("::",startPos);
2391 if (pos==DString::npos)
2392 {
2393 startPos = pos = scope.length();
2394 }
2395 else
2396 {
2397 startPos = pos+2;
2398 }
2399 yyextra->current = std::make_shared<Entry>();
2400 initEntry(yyscanner);
2401 yyextra->current->name = scope.left(pos);
2402 yyextra->current->section = EntryType::makeNamespace();
2403 yyextra->current->type = "namespace";
2404 yyextra->current->fileName = yyextra->fileName;
2405 yyextra->current->startLine = yyextra->yyLineNr;
2406 yyextra->current->bodyLine = yyextra->yyLineNr;
2407 yyextra->current_root = yyextra->current;
2408 rt->moveToSubEntryAndRefresh(yyextra->current);
2409 } while (pos<scope.length());
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
2410
2411 initParser(yyscanner);
2412
2413 yyextra->commentScanner.enterFile(yyextra->fileName,yyextra->yyLineNr);
2414
2415 yyextra->current->reset();
2416 initEntry(yyscanner);
2417 pyscannerYYrestart(nullptr,yyscanner);
2418 BEGIN( Search );
2419 pyscannerYYlex(yyscanner);
2420 yyextra->lexInit=true;
2421
2422 yyextra->commentScanner.leaveFile(yyextra->fileName,yyextra->yyLineNr);
2423
2424 yyextra->programStr.clear();
2425 yyextra->current_root->program.str(std::string());
2426
2427 parseCompounds(yyscanner, yyextra->current_root);
2428}

References FileInfo::baseName(), DString::find(), findPackageScope(), initEntry(), initParser(), DString::left(), DString::length(), msg, DString::npos, parseCompounds(), Search, DString::str(), and yyguts_t.

Referenced by PythonOutlineParser::parseInput().

◆ parsePrototype()

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

Definition at line 2432 of file pyscanner.l.

2433{
2434 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2435 //printf("**** parsePrototype(%s) begin\n",qPrint(text));
2436 if (text.empty())
2437 {
2438 warn(yyextra->fileName,yyextra->yyLineNr,"Empty prototype found!");
2439 return;
2440 }
#define warn(file, line, fmt,...)
Definition message.h:97
2441
2442 yyextra->specialBlock = false;
2443 yyextra->packageCommentAllowed = false;
2444
2445 // save scanner state
2446 YY_BUFFER_STATE orgState = YY_CURRENT_BUFFER;
2447 yy_switch_to_buffer(yy_create_buffer(nullptr, YY_BUF_SIZE, yyscanner), yyscanner);
2448 const char *orgInputString = yyextra->inputString;
2449 int orgInputPosition = yyextra->inputPosition;
#define YY_BUF_SIZE
Definition commentcnv.l:19
2450
2451 // set new string
2452 yyextra->inputString = text.data();
2453 yyextra->inputPosition = 0;
2454 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 dstring.h:157
2455
2456 BEGIN( FunctionDec );
2457
2458 pyscannerYYlex(yyscanner);
2459 yyextra->lexInit=true;
2460
2461 yyextra->current->name = yyextra->current->name.stripWhiteSpace();
2462 if (yyextra->current->section.isMemberDoc() && yyextra->current->args.empty())
2463 {
2464 yyextra->current->section = EntryType::makeVariableDoc();
2465 }
2466
2467 // restore original scanner state
2468
2469 yy_delete_buffer(YY_CURRENT_BUFFER, yyscanner);
2470 yy_switch_to_buffer(orgState, yyscanner);
2471
2472 yyextra->inputString = orgInputString;
2473 yyextra->inputPosition = orgInputPosition;
2474
2475 //printf("**** parsePrototype end\n");
2476}

References DString::data(), DString::empty(), warn, YY_BUF_SIZE, and yyguts_t.

◆ searchFoundClass()

void searchFoundClass ( yyscan_t yyscanner)
static

Definition at line 2251 of file pyscanner.l.

2252{
2253 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2254 yyextra->current->section = EntryType::makeClass();
2255 yyextra->current->argList.clear();
2256 yyextra->current->type += "class" ;
2257 yyextra->current->fileName = yyextra->fileName;
2258 yyextra->current->startLine = yyextra->yyLineNr;
2259 yyextra->current->bodyLine = yyextra->yyLineNr;
2260 yyextra->packageCommentAllowed = false;
2261}

References yyguts_t.

◆ searchFoundDef()

void searchFoundDef ( yyscan_t yyscanner)
static

Definition at line 2231 of file pyscanner.l.

2232{
2233 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2234 yyextra->current->fileName = yyextra->fileName;
2235 yyextra->current->startLine = yyextra->yyLineNr;
2236 yyextra->current->bodyLine = yyextra->yyLineNr;
2237 yyextra->current->section = EntryType::makeFunction();
2238 yyextra->current->lang = SrcLangExt::Python;
2239 yyextra->current->virt = Specifier::Normal;
2240 yyextra->current->isStatic = yyextra->isStatic;
2241 yyextra->current->mtype = yyextra->mtype = MethodTypes::Method;
2242 yyextra->current->type.clear();
2243 yyextra->current->name.clear();
2244 yyextra->current->args.clear();
2245 yyextra->current->argList.clear();
2246 yyextra->packageCommentAllowed = false;
2247 yyextra->isStatic=false;
2248 //printf("searchFoundDef at=%d\n",yyextra->yyLineNr);
2249}

References yyguts_t.

◆ searchFoundTypeAlias()

void searchFoundTypeAlias ( yyscan_t yyscanner)
static

Definition at line 2263 of file pyscanner.l.

2264{
2265 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2266 yyextra->current->section = EntryType::makeVariable();
2267 yyextra->current->argList.clear();
2268 yyextra->current->type = "typedef " ;
2269 yyextra->current->spec.setAlias(true);
2270 yyextra->current->fileName = yyextra->fileName;
2271 yyextra->current->startLine = yyextra->yyLineNr;
2272 yyextra->current->bodyLine = yyextra->yyLineNr;
2273 yyextra->packageCommentAllowed = false;
2274}

References yyguts_t.

◆ setProtection()

void setProtection ( yyscan_t yyscanner)
static

Definition at line 1951 of file pyscanner.l.

1952{
1953 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1954 if (!yyextra->current->name.empty() && yyextra->current->name.at(0)=='_')
1955 {
1956 if (yyextra->current->name.at(1)=='_') // mark as private
1957 {
1958 yyextra->current->protection=Protection::Private;
1959 }
1960 else // mark as protected
1961 {
1962 yyextra->current->protection=Protection::Protected;
1963 }
1964 }
1965}

References yyguts_t.

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

◆ startCommentBlock()

void startCommentBlock ( yyscan_t yyscanner,
bool brief )
static

Definition at line 2104 of file pyscanner.l.

2105{
2106 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
2107 if (brief)
2108 {
2109 yyextra->current->briefFile = yyextra->fileName;
2110 yyextra->current->briefLine = yyextra->yyLineNr;
2111 }
2112 else
2113 {
2114 yyextra->current->docFile = yyextra->fileName;
2115 yyextra->current->docLine = yyextra->yyLineNr;
2116 }
2117}

References yyguts_t.

Referenced by initSpecialBlock(), initTriDoubleQuoteBlock(), and initTriSingleQuoteBlock().

◆ stateToString()

const char * stateToString ( int state)
static

◆ yylex()

int yylex ( yyscan_t yyscanner)

Definition at line 280 of file pyscanner.l.

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

◆ yyread()

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

Definition at line 1845 of file pyscanner.l.

1846{
1847 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1848 int c=0;
1849 const char *p = yyextra->inputString + yyextra->inputPosition;
1850 while ( c < max_size && *p ) { *buf++ = *p++; c++; }
1851 yyextra->inputPosition+=c;
1852 return c;
1853}

References yyguts_t.