Doxygen
Loading...
Searching...
No Matches
pycode.l File Reference
#include <stdint.h>
#include <vector>
#include <unordered_map>
#include <string>
#include <stack>
#include <stdio.h>
#include "pycode.h"
#include "message.h"
#include "scanner.h"
#include "entry.h"
#include "doxygen.h"
#include "outputlist.h"
#include "util.h"
#include "membername.h"
#include "searchindex.h"
#include "config.h"
#include "groupdef.h"
#include "classlist.h"
#include "filedef.h"
#include "namespacedef.h"
#include "tooltip.h"
#include "scopedtypevariant.h"
#include "symbolresolver.h"
#include "debug.h"
#include "doxygen_lex.h"
#include "pycode.l.h"
Include dependency graph for pycode.l:

Go to the source code of this file.

Classes

struct  pycodeYY_state
struct  PythonCodeParser::Private

Macros

#define YY_TYPEDEF_YY_SCANNER_T
#define DBG_CTX(x)
#define YY_NO_INPUT   1
#define YY_NO_UNISTD_H   1
#define YY_INPUT(buf, result, max_size)

Typedefs

typedef yyguts_t * yyscan_t

Functions

static const char * stateToString (int state)
static void startCodeLine (yyscan_t yyscanner)
static int countLines (yyscan_t yyscanner)
static void setCurrentDoc (yyscan_t yyscanner, const QCString &anchor)
static void addToSearchIndex (yyscan_t yyscanner, const QCString &text)
static const ClassDefstripClassName (yyscan_t yyscanner, const QCString &s, Definition *d)
static void codify (yyscan_t yyscanner, const QCString &text)
static void endCodeLine (yyscan_t yyscanner)
static void nextCodeLine (yyscan_t yyscanner)
static void writeMultiLineCodeLink (yyscan_t yyscanner, OutputCodeList &ol, const Definition *d, const QCString &text)
static void startFontClass (yyscan_t yyscanner, const char *s, bool specialComment=false)
static void endFontClass (yyscan_t yyscanner, bool specialComment=false)
static void codifyLines (yyscan_t yyscanner, const QCString &text)
static bool getLinkInScope (yyscan_t yyscanner, const QCString &c, const QCString &m, const QCString &memberText, OutputCodeList &ol, const QCString &text)
static bool getLink (yyscan_t yyscanner, const QCString &className, const QCString &memberName, OutputCodeList &ol, const QCString &text=QCString())
static void generateClassOrGlobalLink (yyscan_t yyscanner, OutputCodeList &ol, const QCString &clName, bool typeOnly=FALSE)
static void generateFunctionLink (yyscan_t yyscanner, OutputCodeList &ol, const QCString &funcName)
static bool findMemberLink (yyscan_t yyscanner, OutputCodeList &ol, const Definition *sym, const QCString &symName)
static void findMemberLink (yyscan_t yyscanner, OutputCodeList &ol, const QCString &symName)
static void incrementFlowKeyWordCount (yyscan_t yyscanner)
static void adjustScopesAndSuites (yyscan_t yyscanner, unsigned indentLength)
static int yyread (yyscan_t yyscanner, char *buf, int max_size)
static void pop_state (yyscan_t yyscanner)
static const char * getLexerFILE ()
int yylex (yyscan_t yyscanner)
static void codeFolding (yyscan_t yyscanner, const Definition *d)

Macro Definition Documentation

◆ DBG_CTX

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

Definition at line 65 of file pycode.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:3982

Definition at line 161 of file pycode.l.

◆ YY_NO_INPUT

#define YY_NO_INPUT   1

Definition at line 67 of file pycode.l.

◆ YY_NO_UNISTD_H

#define YY_NO_UNISTD_H   1

Definition at line 68 of file pycode.l.

◆ YY_TYPEDEF_YY_SCANNER_T

#define YY_TYPEDEF_YY_SCANNER_T

Definition at line 30 of file pycode.l.

Typedef Documentation

◆ yyscan_t

typedef yyguts_t* yyscan_t

Definition at line 32 of file pycode.l.

Function Documentation

◆ addToSearchIndex()

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

Definition at line 863 of file pycode.l.

864{
865 if (Doxygen::searchIndex.enabled())
866 {
867 Doxygen::searchIndex.addWord(text,FALSE);
868 }
static SearchIndexIntf searchIndex
Definition doxygen.h:123
#define FALSE
Definition qcstring.h:34
869}

References FALSE, and Doxygen::searchIndex.

◆ adjustScopesAndSuites()

void adjustScopesAndSuites ( yyscan_t yyscanner,
unsigned indentLength )
static

Examines current stack of white-space indentations; re-syncs the parser with the correct scope.

Definition at line 793 of file pycode.l.

794{
795 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
796 // States to pop
797 if (!yyextra->indents.empty() && indentLength < yyextra->indents.top())
798 {
799 while (!yyextra->indents.empty() && indentLength < yyextra->indents.top())
800 {
801 // printf("Exited scope indent of [%d]\n", yyextra->indents.top());
802 yyextra->indents.pop(); // Pop the old suite's indentation
803
804 yyextra->currentMemberDef=nullptr;
805 if (yyextra->currentDefinition)
806 yyextra->currentDefinition=yyextra->currentDefinition->getOuterScope();
807 }
808 }
809
810 // Are there any remaining indentation levels for suites?
811 if (!yyextra->indents.empty())
812 {
813 BEGIN( Suite );
814 }
815 else
816 {
817 BEGIN( Body );
818 }
819}

◆ codeFolding()

void codeFolding ( yyscan_t yyscanner,
const Definition * d )
static

Definition at line 902 of file pycode.l.

903{
904 if (Config_getBool(HTML_CODE_FOLDING))
905 {
906 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
907 while (!yyextra->foldStack.empty())
908 {
909 const Definition *dd = yyextra->foldStack.back();
910 if (dd->getEndBodyLine()+1==yyextra->yyLineNr) // +1 to close the section after the end of the body
911 {
912 yyextra->code->endFold();
913 //printf("%d: end codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(dd->name()),dd->getStartDefLine(),dd->getEndBodyLine());
914 yyextra->foldStack.pop_back();
915 }
916 else
917 {
918 break;
919 }
920 }
921 if (d)
922 {
923 int startLine = d->getStartDefLine();
924 int endLine = d->getEndBodyLine();
925 if (endLine!=-1 && startLine!=endLine &&
926 // since the end of a section is closed after the last line, we need to avoid starting a
927 // new section if the previous section ends at the same line, i.e. something like
928 // struct X {
929 // ...
930 // }; struct S { <- start of S and end of X at the same line
931 // ...
932 // };
933 (yyextra->foldStack.empty() || yyextra->foldStack.back()->getEndBodyLine()!=startLine))
934 {
935 //printf("%d: start codeFolding for %s [%d..%d]\n",yyextra->yyLineNr,qPrint(d->name()),d->getStartDefLine(),d->getEndBodyLine());
936 yyextra->code->startFold(yyextra->yyLineNr,"", "");
937 yyextra->foldStack.push_back(d);
938 }
939 }
940 }
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual int getEndBodyLine() const =0
virtual int getStartDefLine() const =0
#define Config_getBool(name)
Definition config.h:33
941}

References Definition::getEndBodyLine(), and Definition::getStartDefLine().

◆ codify()

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

Definition at line 1017 of file pycode.l.

1018{
1019 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1020 yyextra->code->codify(text);
1021}

Referenced by findMemberLink().

◆ codifyLines()

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

Definition at line 1134 of file pycode.l.

1135{
1136 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1137 if (text.isEmpty()) return;
1138 //printf("codifyLines(%d,\"%s\")\n",yyextra->yyLineNr,text);
1139 const char *p=text.data(),*sp=p;
1140 char c=0;
1141 bool done=FALSE;
1142 while (!done)
1143 {
1144 sp=p;
1145 while ((c=*p++) && c!='\n') { }
1146 if (c=='\n')
1147 {
1148 yyextra->yyLineNr++;
1149 size_t l = static_cast<size_t>(p-sp-1);
1150 yyextra->code->codify(QCString(sp,l));
1151 nextCodeLine(yyscanner);
1152 }
1153 else
1154 {
1155 yyextra->code->codify(sp);
1156 done=TRUE;
1157 }
1158 }
This is an alternative implementation of QCString.
Definition qcstring.h:101
bool isEmpty() const
Returns TRUE iff the string is empty.
Definition qcstring.h:163
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:172
static void nextCodeLine(yyscan_t yyscanner)
Definition pycode.l:1035
#define TRUE
Definition qcstring.h:37
1159}

References FALSE, nextCodeLine(), and TRUE.

◆ countLines()

int countLines ( yyscan_t yyscanner)
static

counts the number of lines in the input

Definition at line 824 of file pycode.l.

825{
826 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
827 const char *p=yyextra->inputString;
828 char c=0;
829 int count=1;
830 while ((c=*p))
831 {
832 p++;
833 if (c=='\n') count++;
834 }
835 if (p>yyextra->inputString && *(p-1)!='\n')
836 { // last line does not end with a \n, so we add an extra
837 // line and explicitly terminate the line after parsing.
838 count++;
839 }
840 return count;
841}

◆ endCodeLine()

void endCodeLine ( yyscan_t yyscanner)
static

Definition at line 1025 of file pycode.l.

1026{
1027 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1028 endFontClass(yyscanner);
1029 yyextra->code->endCodeLine();
1030 yyextra->insideCodeLine=false;
static void endFontClass(yyscan_t yyscanner, bool specialComment=false)
Definition pycode.l:1117
1031}

◆ endFontClass()

void endFontClass ( yyscan_t yyscanner,
bool specialComment = false )
static

Definition at line 1117 of file pycode.l.

1118{
1119 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1120 if (yyextra->currentFontClass)
1121 {
1122 yyextra->code->endFontClass();
1123 yyextra->currentFontClass=nullptr;
1124 }
1125 if (specialComment && yyextra->insideSpecialComment)
1126 {
1127 yyextra->code->endSpecialComment();
1128 yyextra->insideSpecialComment=false;
1129 }
1130}

◆ findMemberLink() [1/2]

bool findMemberLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const Definition * sym,
const QCString & symName )
static

Definition at line 1417 of file pycode.l.

1421{
1422 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1423 //printf("sym %s outerScope=%s equal=%d\n",
1424 // qPrint(sym->name()),qPrint(sym->getOuterScope()->name()),
1425 // sym->getOuterScope()==yyextra->currentDefinition);
1426
1427 if (sym->getOuterScope() &&
1429 yyextra->currentDefinition->definitionType()==Definition::TypeClass)
1430 {
1431 const ClassDef *cd = toClassDef(sym->getOuterScope());
1432 const ClassDef *thisCd = toClassDef(yyextra->currentDefinition);
1434 {
1435 if (yyextra->currentMemberDef && yyextra->collectXRefs)
1436 {
1437 addDocCrossReference(yyextra->currentMemberDef,toMemberDef(sym));
1438 }
1439 }
1440 DBG_CTX((stderr,"cd=%s thisCd=%s\n",cd?qPrint(cd->name()):"<none>",thisCd?qPrint(thisCd->name()):"<none>"));
A abstract class representing of a compound symbol.
Definition classdef.h:104
virtual DefType definitionType() const =0
virtual Definition * getOuterScope() const =0
virtual const QCString & name() const =0
ClassDef * toClassDef(Definition *d)
void addDocCrossReference(const MemberDef *s, const MemberDef *d)
MemberDef * toMemberDef(Definition *d)
#define DBG_CTX(x)
Definition pycode.l:65
const char * qPrint(const char *s)
Definition qcstring.h:687
1441
1442 // TODO: find the nearest base class in case cd is a base class of
1443 // thisCd
1444 if (cd==thisCd || (thisCd && thisCd->isBaseClass(cd,TRUE)))
1445 {
1446 writeMultiLineCodeLink(yyscanner,ol,sym,symName);
1447 return TRUE;
1448 }
1449 }
1450 return FALSE;
virtual int isBaseClass(const ClassDef *bcd, bool followInstances, const QCString &templSpec=QCString()) const =0
Returns TRUE iff bcd is a direct or indirect base class of this class.
static void writeMultiLineCodeLink(yyscan_t yyscanner, OutputCodeList &ol, const Definition *d, const QCString &text)
Definition pycode.l:1056
1451}

References addDocCrossReference(), DBG_CTX, Definition::definitionType(), FALSE, Definition::getOuterScope(), ClassDef::isBaseClass(), Definition::name(), qPrint(), toClassDef(), toMemberDef(), TRUE, Definition::TypeClass, Definition::TypeMember, and writeMultiLineCodeLink().

Referenced by findMemberLink().

◆ findMemberLink() [2/2]

void findMemberLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const QCString & symName )
static

Definition at line 1455 of file pycode.l.

1458{
1459 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1460 //printf("Member reference: %s scope=%s member=%s\n",
1461 // yytext,
1462 // yyextra->currentDefinition?qPrint(yyextra->currentDefinition->name()):"<none>",
1463 // yyextra->currentMemberDef?qPrint(yyextra->currentMemberDef->name()):"<none>"
1464 // );
1465 if (yyextra->currentDefinition)
1466 {
1467 const auto &v = Doxygen::symbolMap->find(symName);
1468 for (const auto &p : v)
1469 {
1470 if (findMemberLink(yyscanner,ol,p,symName)) return;
1471 }
1472 }
1473 //printf("sym %s not found\n",&yytext[5]);
1474 codify(yyscanner,symName);
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:124
static void codify(yyscan_t yyscanner, const QCString &text)
Definition pycode.l:1017
static bool findMemberLink(yyscan_t yyscanner, OutputCodeList &ol, const Definition *sym, const QCString &symName)
Definition pycode.l:1417
1475}

References codify(), findMemberLink(), and Doxygen::symbolMap.

◆ generateClassOrGlobalLink()

void generateClassOrGlobalLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const QCString & clName,
bool typeOnly = FALSE )
static

Definition at line 1233 of file pycode.l.

1237{
1238 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1239 QCString className=clName;
1240
1241 // Don't do anything for empty text
1242 if (className.isEmpty()) return;
1243
1244 DBG_CTX((stderr,"generateClassOrGlobalLink(className=%s)\n",qPrint(className)));
1245
1246 const ScopedTypeVariant *lcd = nullptr;
1247 const ClassDef *cd=nullptr; // Class def that we may find
1248 const MemberDef *md=nullptr; // Member def that we may find
1249 //bool isLocal=FALSE;
A model of a class/file/namespace member symbol.
Definition memberdef.h:48
1250
1251 if ((lcd=yyextra->theVarContext.findVariable(className))==nullptr) // not a local variable
1252 {
1253 const Definition *d = yyextra->currentDefinition;
1254 QCString scope = substitute(className,".","::");
QCString substitute(const QCString &s, const QCString &src, const QCString &dst)
substitute all occurrences of src in s by dst
Definition qcstring.cpp:571
1255
1256 cd = yyextra->symbolResolver.resolveClass(d,substitute(className,".","::"),true);
1257 md = yyextra->symbolResolver.getTypedef();
1258
1259 DBG_CTX((stderr,"d=%s yyextra->sourceFileDef=%s\n",
1260 d?qPrint(d->displayName()):"<null>",
1261 yyextra->currentDefinition?qPrint(yyextra->currentDefinition->displayName()):"<null>"));
1262 DBG_CTX((stderr,"is found as a type %s\n",cd?qPrint(cd->name()):"<null>"));
virtual QCString displayName(bool includeScope=TRUE) const =0
1263
1264 if (cd==nullptr && md==nullptr) // also see if it is variable or enum or enum value
1265 {
1266 const NamespaceDef *nd = getResolvedNamespace(scope);
1267 if (nd)
1268 {
1269 writeMultiLineCodeLink(yyscanner,ol,nd,clName);
1270 addToSearchIndex(yyscanner,className);
1271 return;
1272 }
1273 else if (getLink(yyscanner,yyextra->classScope,clName,ol,clName))
1274 {
1275 return;
1276 }
1277 }
1278 }
1279 else
1280 {
1281 if (!lcd->isDummy())
1282 {
1283 yyextra->theCallContext.setScope(*lcd);
1284 }
1285 //isLocal=TRUE;
1286 DBG_CTX((stderr,"is a local variable cd=%p!\n",cd));
1287 }
An abstract interface of a namespace symbol.
NamespaceDef * getResolvedNamespace(const QCString &name)
static void addToSearchIndex(yyscan_t yyscanner, const QCString &text)
Definition pycode.l:863
static bool getLink(yyscan_t yyscanner, const QCString &className, const QCString &memberName, OutputCodeList &ol, const QCString &text=QCString())
Definition pycode.l:1205
1288
1289 if (cd && cd->isLinkable()) // is it a linkable class
1290 {
1291 writeMultiLineCodeLink(yyscanner,ol,cd,clName);
1292 addToSearchIndex(yyscanner,className);
1293 if (md)
1294 {
1296 md->getBodyDef() : md->getOuterScope();
1297 if (md->getGroupDef()) d = md->getGroupDef();
1298 if (d && d->isLinkable() && md->isLinkable() &&
1299 yyextra->currentMemberDef && yyextra->collectXRefs && yyextra->insideBody)
1300 {
1301 addDocCrossReference(yyextra->currentMemberDef,md);
1302 }
1303 }
1304 }
1305 else // not a class, maybe a global member
1306 {
1307 int scopeEnd = className.findRev(".");
1308 if (scopeEnd!=-1 && !typeOnly) // name with explicit scope
1309 {
1310 QCString scope = substitute(className.left(scopeEnd),".","::");
1311 QCString locName = className.right(className.length()-scopeEnd-1);
1312 ClassDef *mcd = getClass(scope);
1313 DBG_CTX((stderr,"scope=%s locName=%s mcd=%p\n",qPrint(scope),qPrint(locName),mcd));
1314 if (mcd)
1315 {
1316 const MemberDef *mmd = mcd->getMemberByName(locName);
1317 if (mmd)
1318 {
1319 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,mmd->typeString(),mmd->getOuterScope())));
1320 writeMultiLineCodeLink(yyscanner,ol,mmd,clName);
1321 addToSearchIndex(yyscanner,className);
1322 const Definition *d = mmd->getOuterScope()==Doxygen::globalScope ?
1323 mmd->getBodyDef() : mmd->getOuterScope();
1324 if (mmd->getGroupDef()) d = mmd->getGroupDef();
1325 if (d && d->isLinkable() && mmd->isLinkable() &&
1326 yyextra->currentMemberDef && yyextra->collectXRefs && yyextra->insideBody)
1327 {
1328 addDocCrossReference(yyextra->currentMemberDef,mmd);
1329 }
1330 return;
1331 }
1332 }
1333 else // check namespace as well
1334 {
1335 const NamespaceDef *mnd = getResolvedNamespace(scope);
1336 if (mnd)
1337 {
1338 const MemberDef *mmd=mnd->getMemberByName(locName);
1339 if (mmd)
1340 {
1341 //printf("name=%s scope=%s\n",qPrint(locName),qPrint(scope));
1342 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,mmd->typeString(),mmd->getOuterScope())));
1343 writeMultiLineCodeLink(yyscanner,ol,mmd,clName);
1344 addToSearchIndex(yyscanner,className);
1345 const Definition *d = mmd->getOuterScope()==Doxygen::globalScope ?
1346 mmd->getBodyDef() : mmd->getOuterScope();
1347 if (mmd->getGroupDef()) d = mmd->getGroupDef();
1348 if (d && d->isLinkable() && mmd->isLinkable() &&
1349 yyextra->currentMemberDef && yyextra->collectXRefs && yyextra->insideBody)
1350 {
1351 addDocCrossReference(yyextra->currentMemberDef,mmd);
1352 }
1353 return;
1354 }
1355 }
1356 }
1357 }
virtual const MemberDef * getMemberByName(const QCString &) const =0
Returns the member with the given name.
virtual bool isLinkable() const =0
virtual const FileDef * getBodyDef() const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:120
virtual QCString typeString() const =0
virtual GroupDef * getGroupDef()=0
virtual const MemberDef * getMemberByName(const QCString &) const =0
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition qcstring.h:166
QCString right(size_t len) const
Definition qcstring.h:234
int findRev(char c, int index=-1, bool cs=TRUE) const
Definition qcstring.cpp:96
QCString left(size_t len) const
Definition qcstring.h:229
ClassDef * getClass(const QCString &n)
static const ClassDef * stripClassName(yyscan_t yyscanner, const QCString &s, Definition *d)
Definition pycode.l:873
1358
1359 // nothing found, just write out the word
1360 codifyLines(yyscanner,clName);
1361 addToSearchIndex(yyscanner,clName);
1362 }
static void codifyLines(yyscan_t yyscanner, const QCString &text)
Definition pycode.l:1134
1363}

References addDocCrossReference(), addToSearchIndex(), codifyLines(), DBG_CTX, Definition::displayName(), QCString::findRev(), Definition::getBodyDef(), getClass(), MemberDef::getGroupDef(), getLink(), ClassDef::getMemberByName(), NamespaceDef::getMemberByName(), Definition::getOuterScope(), getResolvedNamespace(), Doxygen::globalScope, ScopedTypeVariant::isDummy(), QCString::isEmpty(), Definition::isLinkable(), QCString::left(), QCString::length(), Definition::name(), qPrint(), QCString::right(), stripClassName(), substitute(), MemberDef::typeString(), and writeMultiLineCodeLink().

◆ generateFunctionLink()

void generateFunctionLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const QCString & funcName )
static

Definition at line 1374 of file pycode.l.

1377{
1378 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1379 QCString locScope=yyextra->classScope;
1380 QCString locFunc=removeRedundantWhiteSpace(funcName);
1381 DBG_CTX((stdout,"*** locScope=%s locFunc=%s\n",qPrint(locScope),qPrint(locFunc)));
1382 int i=locFunc.findRev("::");
1383 if (i>0)
1384 {
1385 locScope=locFunc.left(i);
1386 locFunc=locFunc.right(locFunc.length()-i-2).stripWhiteSpace();
1387 }
1388 //printf("generateFunctionLink(%s) classScope='%s'\n",qPrint(locFunc),qPrint(locScope));
1389 if (!locScope.isEmpty())
1390 {
1391 auto it = yyextra->codeClassMap.find(locScope.str());
1392 if (it!=yyextra->codeClassMap.end())
1393 {
1394 ScopedTypeVariant ccd = it->second;
1395 //printf("using classScope %s\n",qPrint(yyextra->classScope));
1396 if (ccd.localDef() && !ccd.localDef()->baseClasses().empty())
1397 {
1398 for (const auto &bcName : ccd.localDef()->baseClasses())
1399 {
1400 if (getLink(yyscanner,bcName,locFunc,ol,funcName))
1401 {
1402 return;
1403 }
1404 }
1405 }
1406 }
1407 }
1408 if (!getLink(yyscanner,locScope,locFunc,ol,funcName))
1409 {
1410 generateClassOrGlobalLink(yyscanner,ol,funcName);
1411 }
1412 return;
std::vector< QCString > baseClasses() const
QCString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition qcstring.h:260
const std::string & str() const
Definition qcstring.h:552
static void generateClassOrGlobalLink(yyscan_t yyscanner, OutputCodeList &ol, const QCString &clName, bool typeOnly=FALSE)
Definition pycode.l:1233
QCString removeRedundantWhiteSpace(const QCString &s)
Definition util.cpp:567
1413}

References LocalDef::baseClasses(), DBG_CTX, QCString::findRev(), generateClassOrGlobalLink(), getLink(), QCString::isEmpty(), QCString::left(), QCString::length(), ScopedTypeVariant::localDef(), qPrint(), removeRedundantWhiteSpace(), QCString::right(), QCString::str(), and QCString::stripWhiteSpace().

◆ getLexerFILE()

const char * getLexerFILE ( )
inlinestatic

Definition at line 164 of file pycode.l.

164{return __FILE__;}

◆ getLink()

bool getLink ( yyscan_t yyscanner,
const QCString & className,
const QCString & memberName,
OutputCodeList & ol,
const QCString & text = QCString() )
static

Definition at line 1205 of file pycode.l.

1210{
1211 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1212 QCString m=removeRedundantWhiteSpace(memberName);
1213 QCString c=className;
1214 if (!getLinkInScope(yyscanner,c,m,memberName,ol,text))
1215 {
1216 if (!yyextra->curClassName.isEmpty())
1217 {
1218 if (!c.isEmpty()) c.prepend("::");
1219 c.prepend(yyextra->curClassName);
1220 return getLinkInScope(yyscanner,c,m,memberName,ol,text);
1221 }
1222 return FALSE;
1223 }
1224 return TRUE;
QCString & prepend(const char *s)
Definition qcstring.h:422
static bool getLinkInScope(yyscan_t yyscanner, const QCString &c, const QCString &m, const QCString &memberText, OutputCodeList &ol, const QCString &text)
Definition pycode.l:1163
1225}

References FALSE, getLinkInScope(), QCString::isEmpty(), QCString::prepend(), removeRedundantWhiteSpace(), and TRUE.

◆ getLinkInScope()

bool getLinkInScope ( yyscan_t yyscanner,
const QCString & c,
const QCString & m,
const QCString & memberText,
OutputCodeList & ol,
const QCString & text )
static

Definition at line 1163 of file pycode.l.

1170{
1171 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1172 GetDefInput input(c,m,"()");
1173 input.currentFile = yyextra->sourceFileDef;
1174 input.insideCode = true;
1175 GetDefResult result = getDefs(input);
1176 //printf("Trying '%s'::'%s'\n",qPrint(c),qPrint(m));
1177 if (result.found && result.md && result.md->isLinkable())
1178 {
1179 const Definition *d = result.md->getOuterScope()==Doxygen::globalScope ?
1180 result.md->getBodyDef() : result.md->getOuterScope();
1181 //printf("Found! d=%s\n",d?qPrint(d->name()):"<none>");
1182 if (result.md->getGroupDef()) d = result.md->getGroupDef();
1183 if (d && d->isLinkable())
1184 {
1185 yyextra->theCallContext.setScope(ScopedTypeVariant(stripClassName(yyscanner,result.md->typeString(),result.md->getOuterScope())));
1186 //printf("yyextra->currentDefinition=%p yyextra->currentMemberDef=%p\n",
1187 // yyextra->currentDefinition,yyextra->currentMemberDef);
const MemberDef * md
Definition util.h:125
bool found
Definition util.h:124
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:2277
1188
1189 if (yyextra->currentDefinition && yyextra->currentMemberDef && yyextra->collectXRefs && yyextra->insideBody)
1190 {
1191 addDocCrossReference(yyextra->currentMemberDef,result.md);
1192 }
1193 //printf("d->getReference()='%s' d->getOutputBase()='%s' name='%s' member name='%s'\n",qPrint(d->getReference()),qPrint(d->getOutputFileBase()),qPrint(d->name()),qPrint(md->name()));
1194
1195 writeMultiLineCodeLink(yyscanner,ol,result.md, !text.isEmpty() ? text : memberText);
1196 addToSearchIndex(yyscanner,!text.isEmpty() ? text : memberText);
1197 return TRUE;
1198 }
1199 }
1200 return FALSE;
1201}

References addDocCrossReference(), addToSearchIndex(), GetDefInput::currentFile, FALSE, GetDefResult::found, Definition::getBodyDef(), getDefs(), MemberDef::getGroupDef(), Definition::getOuterScope(), Doxygen::globalScope, GetDefInput::insideCode, QCString::isEmpty(), Definition::isLinkable(), GetDefResult::md, stripClassName(), TRUE, MemberDef::typeString(), and writeMultiLineCodeLink().

◆ incrementFlowKeyWordCount()

void incrementFlowKeyWordCount ( yyscan_t yyscanner)
static

Definition at line 1477 of file pycode.l.

1478{
1479 std::lock_guard<std::mutex> lock(Doxygen::countFlowKeywordsMutex);
1480 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1481 if (yyextra->currentMemberDef && yyextra->currentMemberDef->isFunction())
1482 {
1483 MemberDefMutable *md = toMemberDefMutable(const_cast<MemberDef*>(yyextra->currentMemberDef));
1484 if (md)
1485 {
1487 }
1488 }
static std::mutex countFlowKeywordsMutex
Definition doxygen.h:140
virtual void incrementFlowKeyWordCount()=0
MemberDefMutable * toMemberDefMutable(Definition *d)
1489}

References Doxygen::countFlowKeywordsMutex.

◆ nextCodeLine()

void nextCodeLine ( yyscan_t yyscanner)
static

Definition at line 1035 of file pycode.l.

1036{
1037 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1038 const char *fc = yyextra->currentFontClass;
1039 if (yyextra->insideCodeLine)
1040 {
1041 endCodeLine(yyscanner);
1042 }
1043 if (yyextra->yyLineNr<yyextra->inputLines)
1044 {
1045 yyextra->currentFontClass = fc;
1046 startCodeLine(yyscanner);
1047 }
static void endCodeLine(yyscan_t yyscanner)
Definition pycode.l:1025
static void startCodeLine(yyscan_t yyscanner)
Definition pycode.l:949
1048}

References endCodeLine().

◆ pop_state()

void pop_state ( yyscan_t yyscanner)
inlinestatic

Definition at line 1606 of file pycode.l.

1607{
1608 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1609 if ( yyg->yy_start_stack_ptr <= 0 )
1610 warn(yyextra->fileName,yyextra->yyLineNr,"Unexpected statement '{}'",yytext );
1611 else
1612 yy_pop_state(yyscanner);
#define warn(file, line, fmt,...)
Definition message.h:97
1613}

◆ setCurrentDoc()

void setCurrentDoc ( yyscan_t yyscanner,
const QCString & anchor )
static

Definition at line 845 of file pycode.l.

846{
847 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
848 if (Doxygen::searchIndex.enabled())
849 {
850 if (yyextra->searchCtx)
851 {
852 Doxygen::searchIndex.setCurrentDoc(yyextra->searchCtx,yyextra->searchCtx->anchor(),FALSE);
853 }
854 else
855 {
856 Doxygen::searchIndex.setCurrentDoc(yyextra->sourceFileDef,anchor,TRUE);
857 }
858 }
859}

References FALSE, Doxygen::searchIndex, and TRUE.

◆ startCodeLine()

void startCodeLine ( yyscan_t yyscanner)
static

start a new line of code, inserting a line number if yyextra->sourceFileDef is TRUE. If a definition starts at the current line, then the line number is linked to the documentation of that definition.

Definition at line 949 of file pycode.l.

950{
951 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
952 //if (yyextra->currentFontClass) { yyextra->code->endFontClass(yyscanner); }
953 if (yyextra->sourceFileDef && yyextra->lineNumbers)
954 {
955 //QCString lineNumber,lineAnchor;
956 //lineNumber.sprintf("%05d",yyextra->yyLineNr);
957 //lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
958
959 const Definition *d = yyextra->sourceFileDef->getSourceDefinition(yyextra->yyLineNr);
960 //printf("startCodeLine %d d=%p\n",yyextra->yyLineNr,d);
961 //yyextra->code->startLineNumber();
962
963 if (!yyextra->includeCodeFragment && d && d->isLinkableInProject())
964 {
965 yyextra->currentDefinition = d;
966 yyextra->currentMemberDef = yyextra->sourceFileDef->getSourceMember(yyextra->yyLineNr);
967 yyextra->insideBody = false;
968 yyextra->endComment = FALSE;
969 yyextra->searchingForBody = TRUE;
970 yyextra->realScope = d->name();
971 yyextra->classScope = d->name();
972 //printf("Real scope: '%s'\n",qPrint(yyextra->realScope));
973 yyextra->bodyCurlyCount = 0;
974 QCString lineAnchor;
975 lineAnchor.sprintf("l%05d",yyextra->yyLineNr);
976 if (yyextra->currentMemberDef)
977 {
978 codeFolding(yyscanner,yyextra->currentMemberDef);
979 yyextra->code->writeLineNumber(yyextra->currentMemberDef->getReference(),
980 yyextra->currentMemberDef->getOutputFileBase(),
981 yyextra->currentMemberDef->anchor(),yyextra->yyLineNr,
982 !yyextra->includeCodeFragment);
983 setCurrentDoc(yyscanner,lineAnchor);
984 }
985 else if (d->isLinkableInProject())
986 {
987 codeFolding(yyscanner,d);
988 yyextra->code->writeLineNumber(d->getReference(),
990 QCString(),yyextra->yyLineNr,
991 !yyextra->includeCodeFragment);
992 setCurrentDoc(yyscanner,lineAnchor);
993 }
994 else
995 {
996 codeFolding(yyscanner,nullptr);
997 }
998 }
999 else
1000 {
1001 codeFolding(yyscanner,nullptr);
1002 yyextra->code->writeLineNumber(QCString(),QCString(),QCString(),yyextra->yyLineNr,
1003 !yyextra->includeCodeFragment);
1004 }
1005 }
1006 yyextra->code->startCodeLine(yyextra->yyLineNr);
1007 yyextra->insideCodeLine=true;
virtual bool isLinkableInProject() const =0
virtual QCString getReference() const =0
virtual QCString getOutputFileBase() const =0
QCString & sprintf(const char *format,...)
Definition qcstring.cpp:29
static void setCurrentDoc(yyscan_t yyscanner, const QCString &anchor)
Definition pycode.l:845
static void codeFolding(yyscan_t yyscanner, const Definition *d)
Definition pycode.l:902
1008
1009 if (yyextra->currentFontClass)
1010 {
1011 yyextra->code->startFontClass(yyextra->currentFontClass);
1012 }
1013}

References codeFolding(), FALSE, Definition::getOutputFileBase(), Definition::getReference(), Definition::isLinkableInProject(), Definition::name(), setCurrentDoc(), QCString::sprintf(), and TRUE.

◆ startFontClass()

void startFontClass ( yyscan_t yyscanner,
const char * s,
bool specialComment = false )
static

Definition at line 1098 of file pycode.l.

1099{
1100 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1101 if (specialComment)
1102 {
1103 yyextra->code->startSpecialComment();
1104 yyextra->insideSpecialComment = true;
1105 }
1106 // if font class is already set don't stop and start it.
1107 if (qstrcmp(yyextra->currentFontClass,s)!=0)
1108 {
1109 endFontClass(yyscanner);
1110 yyextra->code->startFontClass(s);
1111 yyextra->currentFontClass=s;
1112 }
int qstrcmp(const char *str1, const char *str2)
Definition qcstring.h:69
1113}

◆ stateToString()

const char * stateToString ( int state)
static

References FALSE.

◆ stripClassName()

const ClassDef * stripClassName ( yyscan_t yyscanner,
const QCString & s,
Definition * d )
static

Definition at line 873 of file pycode.l.

874{
875 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
876 int pos=0;
877 QCString type = s;
878 QCString className;
879 QCString templSpec;
880 while (extractClassNameFromType(type,pos,className,templSpec)!=-1)
881 {
882 QCString clName=className+templSpec;
883 const ClassDef *cd=nullptr;
884 if (!yyextra->classScope.isEmpty())
885 {
886 cd=yyextra->symbolResolver.resolveClass(d,yyextra->classScope+"::"+clName,true);
887 }
888 if (cd==nullptr)
889 {
890 cd=yyextra->symbolResolver.resolveClass(d,clName,true);
891 }
892 if (cd)
893 {
894 return cd;
895 }
896 }
int extractClassNameFromType(const QCString &type, int &pos, QCString &name, QCString &templSpec, SrcLangExt lang)
Definition util.cpp:4198
897
898 return nullptr;
899}

◆ writeMultiLineCodeLink()

void writeMultiLineCodeLink ( yyscan_t yyscanner,
OutputCodeList & ol,
const Definition * d,
const QCString & text )
static

writes a link to a fragment text that may span multiple lines, inserting line numbers for each line. If text contains newlines, the link will be split into multiple links with the same destination, one for each line.

Definition at line 1056 of file pycode.l.

1060{
1061 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
1062 if (text.isEmpty()) return;
1063 bool sourceTooltips = Config_getBool(SOURCE_TOOLTIPS);
1064 yyextra->tooltipManager.addTooltip(d);
1065 QCString ref = d->getReference();
1066 QCString file = d->getOutputFileBase();
1067 QCString anchor = d->anchor();
1068 QCString tooltip;
1069 if (!sourceTooltips) // fall back to simple "title" tooltips
1070 {
1071 tooltip = d->briefDescriptionAsTooltip();
1072 }
1073 bool done=FALSE;
1074 const char *p=text.data();
1075 while (!done)
1076 {
1077 const char *sp=p;
1078 char c=0;
1079 while ((c=*p++) && c!='\n') { }
1080 if (c=='\n')
1081 {
1082 yyextra->yyLineNr++;
1083 //printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
1084 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,QCString(sp,p-sp-1),tooltip);
1085 nextCodeLine(yyscanner);
1086 }
1087 else
1088 {
1089 //printf("writeCodeLink(%s,%s,%s,%s)\n",ref,file,anchor,sp);
1090 ol.writeCodeLink(d->codeSymbolType(),ref,file,anchor,sp,tooltip);
1091 done=TRUE;
1092 }
1093 }
virtual QCString anchor() const =0
virtual QCString briefDescriptionAsTooltip() const =0
virtual CodeSymbolType codeSymbolType() const =0
void writeCodeLink(CodeSymbolType type, const QCString &ref, const QCString &file, const QCString &anchor, const QCString &name, const QCString &tooltip)
Definition outputlist.h:250
1094}

References Definition::anchor(), Definition::briefDescriptionAsTooltip(), Definition::codeSymbolType(), Config_getBool, QCString::data(), FALSE, Definition::getOutputFileBase(), Definition::getReference(), QCString::isEmpty(), nextCodeLine(), TRUE, and OutputCodeList::writeCodeLink().

◆ yylex()

int yylex ( yyscan_t yyscanner)

Definition at line 218 of file pycode.l.

220 {
221 "def"{BB} {
222 startFontClass(yyscanner,"keyword");
223 codify(yyscanner,yytext);
224 endFontClass(yyscanner);
225 BEGIN( FunctionDec );
226 }
227 "async"{BB}"def"{BB} {
228 startFontClass(yyscanner,"keyword");
229 codify(yyscanner,yytext);
230 endFontClass(yyscanner);
231 BEGIN( FunctionDec );
232 }
static void startFontClass(yyscan_t yyscanner, const char *s, bool specialComment=false)
Definition pycode.l:1098
233
234 "class"{BB} {
235 startFontClass(yyscanner,"keyword");
236 codify(yyscanner,yytext);
237 endFontClass(yyscanner);
238 BEGIN( ClassDec );
239 }
240 "None" {
241 startFontClass(yyscanner,"keywordtype");
242 codify(yyscanner,yytext);
243 endFontClass(yyscanner);
244 }
245 "self."{IDENTIFIER}/"."({IDENTIFIER}".")*{IDENTIFIER}"(" {
246 codify(yyscanner,"self.");
247 findMemberLink(yyscanner,*yyextra->code,&yytext[5]);
248 }
249 "self."{IDENTIFIER}/"(" {
250 codify(yyscanner,"self.");
251 findMemberLink(yyscanner,*yyextra->code,&yytext[5]);
252 }
253 "self."{IDENTIFIER}/"."({IDENTIFIER}".")*{IDENTIFIER} {
254 codify(yyscanner,"self.");
255 findMemberLink(yyscanner,*yyextra->code,&yytext[5]);
256 }
257 "self."{IDENTIFIER} {
258 codify(yyscanner,"self.");
259 findMemberLink(yyscanner,*yyextra->code,&yytext[5]);
260 }
261 "cls."{IDENTIFIER}/"."({IDENTIFIER}".")*{IDENTIFIER}"(" {
262 codify(yyscanner,"cls.");
263 findMemberLink(yyscanner,*yyextra->code,&yytext[4]);
264 }
265 "cls."{IDENTIFIER}/"(" {
266 codify(yyscanner,"cls.");
267 findMemberLink(yyscanner,*yyextra->code,&yytext[4]);
268 }
269 "cls."{IDENTIFIER}/"."({IDENTIFIER}".")*{IDENTIFIER} {
270 codify(yyscanner,"cls.");
271 findMemberLink(yyscanner,*yyextra->code,&yytext[4]);
272 }
273 "cls."{IDENTIFIER} {
274 codify(yyscanner,"cls.");
275 findMemberLink(yyscanner,*yyextra->code,&yytext[4]);
276 }
277 "@"{SCOPE}{CALLANY}? { // decorator
278 startFontClass(yyscanner,"preprocessor");
279 codify(yyscanner,yytext);
280 endFontClass(yyscanner);
281 }
282}
283
284<ClassDec>{IDENTIFIER} {
285 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
286 // codify(yyscanner,yytext);
287 yyextra->curClassName = yytext;
288 yyextra->curClassBases.clear();
289 BEGIN( ClassInheritance );
290 }
291
292<ClassInheritance>{
293 ({BB}|[(,)]) {
294 codify(yyscanner,yytext);
295 }
296
297 ({IDENTIFIER}".")*{IDENTIFIER} {
298 // The parser
299 // is assuming
300 // that ALL identifiers
301 // in this state
302 // are base classes;
303 // it doesn't check to see
304 // that the first parenthesis
305 // has been seen.
306
307 // This is bad - it should
308 // probably be more strict
309 // about what to accept.
310
311 yyextra->curClassBases.emplace_back(yytext);
312 yyextra->insideBody = true;
313 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
314 yyextra->insideBody = false;
315 // codify(yyscanner,yytext);
316 }
317
318 ":" {
319 codify(yyscanner,yytext);
320
321 // Assume this will
322 // be a one-line suite;
323 // found counter-example
324 // in SuiteStart.
325
326 // Push a class scope
327 ScopedTypeVariant var(yyextra->curClassName);
328 for (const auto &s : yyextra->curClassBases)
329 {
330 const ClassDef *baseDefToAdd = nullptr;
331 // find class in the local scope
332 auto it = yyextra->codeClassMap.find(s);
333 if (it != yyextra->codeClassMap.end())
334 {
335 baseDefToAdd = toClassDef(it->second.globalDef());
336 }
337 // Try to find class in global scope
338 if (baseDefToAdd==nullptr)
339 {
340 baseDefToAdd=yyextra->symbolResolver.resolveClass(yyextra->currentDefinition,s,true);
341 }
342
343 if (baseDefToAdd && baseDefToAdd->name()!=yyextra->curClassName)
344 {
345 var.localDef()->insertBaseClass(baseDefToAdd->name());
346 }
347 }
348 yyextra->codeClassMap.emplace(yyextra->curClassName.str(),std::move(var));
349
350 // Reset class-parsing variables.
351 yyextra->curClassName.clear();
352 yyextra->curClassBases.clear();
353
354 yyextra->noSuiteFound = TRUE;
355 BEGIN( SuiteStart );
356 }
357}
358
359
360<FunctionDec>{
361 {IDENTIFIER} {
362 generateFunctionLink(yyscanner,*yyextra->code,yytext);
363 }
static void generateFunctionLink(yyscan_t yyscanner, OutputCodeList &ol, const QCString &funcName)
Definition pycode.l:1374
364
365 {B}"(" {
366 codify(yyscanner,yytext);
367 BEGIN( FunctionParams );
368 }
369}
370
371<FunctionParams>{
372 ({BB}|",") {
373 // Parses delimiters
374 codify(yyscanner,yytext);
375 }
376
377 ({IDENTIFIER}|{PARAMNONEMPTY}+) {
378 codify(yyscanner,yytext);
379 }
380
381 ")" {
382 codify(yyscanner,yytext);
383 }
384
385 "\n" {
386 codifyLines(yyscanner,yytext);
387 }
388
389 ":" {
390 codify(yyscanner,yytext);
391
392 // Assume this will
393 // be a one-line suite;
394 // found counter-example
395 // in SuiteStart.
396 yyextra->noSuiteFound = TRUE;
397 BEGIN( SuiteStart );
398 }
399}
400
401<Body,Suite>{
402
403 {KEYWORD} {
404 // Position-sensitive rules!
405 // Must come AFTER keyword-triggered rules
406 // Must come BEFORE identifier NONEMPTY-like rules
407 // to syntax highlight.
408
409 startFontClass(yyscanner,"keyword");
410 codify(yyscanner,yytext);
411 endFontClass(yyscanner);
412 }
413
414 {FLOWKW} {
415 incrementFlowKeyWordCount(yyscanner);
416 startFontClass(yyscanner,"keywordflow");
417 codify(yyscanner,yytext);
418 endFontClass(yyscanner);
419 }
420 ({IDENTIFIER}".")*{IDENTIFIER}/"(" {
421 yyextra->insideBody = true;
422 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext);
423 yyextra->insideBody = false;
424 }
425 ({IDENTIFIER}".")+{IDENTIFIER} {
426 yyextra->insideBody = true;
427 generateClassOrGlobalLink(yyscanner,*yyextra->code,yytext,TRUE);
428 yyextra->insideBody = false;
429 }
430 {IDENTIFIER} { codify(yyscanner,yytext); }
static void incrementFlowKeyWordCount(yyscan_t yyscanner)
Definition pycode.l:1477
431
432}
433
434
435
436<SuiteStart>{
437
438 {BB} {
439 codify(yyscanner,yytext);
440 }
441 "pass" {
442 startFontClass(yyscanner,"keyword");
443 codifyLines(yyscanner,yytext);
444 endFontClass(yyscanner);
445 BEGIN(Body);
446 }
447 {KEYWORD} {
448 startFontClass(yyscanner,"keyword");
449 codifyLines(yyscanner,yytext);
450 endFontClass(yyscanner);
451
452 // No indentation necessary
453 yyextra->noSuiteFound = FALSE;
454 }
455
456 {FLOWKW} {
457 incrementFlowKeyWordCount(yyscanner);
458 startFontClass(yyscanner,"keywordflow");
459 codifyLines(yyscanner,yytext);
460 endFontClass(yyscanner);
461
462 // No indentation necessary
463 yyextra->noSuiteFound = FALSE;
464 }
465 {IDENTIFIER} {
466 codify(yyscanner,yytext);
467 }
468
469
470 {POUNDCOMMENT} {
471 if (YY_START==SingleQuoteString ||
472 YY_START==DoubleQuoteString ||
473 YY_START==TripleString
474 )
475 {
476 REJECT;
477 }
478 yy_push_state(YY_START,yyscanner);
479 BEGIN(DocBlock);
480 yyextra->docBlock=yytext;
481 }
482
483 {NEWLINE} {
484 codifyLines(yyscanner,yytext);
485 if ( yyextra->noSuiteFound )
486 {
487 // printf("New suite to capture! [%d]\n", yyextra->yyLineNr);
488 BEGIN ( SuiteCaptureIndent );
489 }
490 }
491}
492
493<SuiteCaptureIndent>{
494 "\n"|({BB}"\n") {
495 // Blankline - ignore, keep looking for indentation.
496 codifyLines(yyscanner,yytext);
497 }
498
499 {BB} {
500 // This state lasts momentarily,
501 // to check the indentation
502 // level that is about to be
503 // used.
504 codifyLines(yyscanner,yytext);
505 yyextra->indents.push(yyleng);
506 // printf("Captured indent of %d [line %d]\n", yyleng, yyextra->yyLineNr);
507 BEGIN( Suite );
508 }
509}
510
511<SuiteMaintain>{
512
513 {BB}/({NONEMPTY}|{EXPCHAR}) {
514 // This implements poor
515 // indentation-tracking;
516 // should be improved.
517 // (translate tabs to space, etc)
518 codifyLines(yyscanner,yytext);
519 adjustScopesAndSuites(yyscanner,static_cast<int>(yyleng));
520 }
static void adjustScopesAndSuites(yyscan_t yyscanner, unsigned indentLength)
Definition pycode.l:793
521
522 "\n"|({BB}"\n") {
523 // If this ever succeeds,
524 // it means that this is
525 // a blank line, and
526 // can be ignored.
527 codifyLines(yyscanner,yytext);
528 }
529
530 ""/({NONEMPTY}|{EXPCHAR}) {
531 // Default rule; matches
532 // the empty string, assuming
533 // real text starts here.
534 // Just go straight to Body.
535 adjustScopesAndSuites(yyscanner,0);
536 }
537}
538
539
540<Suite>{NEWLINE} {
541 codifyLines(yyscanner,yytext);
542 BEGIN( SuiteMaintain );
543 }
544<Body>{IDENTIFIER} {
545 codify(yyscanner,yytext);
546 }
547<Body>{NEWLINE} {
548 codifyLines(yyscanner,yytext);
549 }
550
551<SingleQuoteString>{ // Single quoted string like 'That\'s a """nice""" string!'
552 \\{B}\n { // line continuation
553 codifyLines(yyscanner,yytext);
554 }
555 \\. { // escaped char
556 codify(yyscanner,yytext);
557 }
558 {STRINGPREFIX}?{TRIDOUBLEQUOTE} { // triple double quotes
559 codify(yyscanner,yytext);
560 }
561 "'" { // end of the string
562 codify(yyscanner,yytext);
563 endFontClass(yyscanner);
564 BEGIN(yyextra->stringContext);
565 }
566 [^"'\n\\]+ { // normal chars
567 codify(yyscanner,yytext);
568 }
569 . { // normal char
570 codify(yyscanner,yytext);
571 }
572}
573
574<DoubleQuoteString>{ // Double quoted string like "That's \"a '''nice'''\" string!"
575 \\{B}\n { // line continuation
576 codifyLines(yyscanner,yytext);
577 }
578 \\. { // escaped char
579 codify(yyscanner,yytext);
580 }
581 {STRINGPREFIX}?{TRISINGLEQUOTE} { // triple single quotes
582 codify(yyscanner,yytext);
583 }
584 "\"" { // end of the string
585 codify(yyscanner,yytext);
586 endFontClass(yyscanner);
587 BEGIN(yyextra->stringContext);
588 }
589 [^"'\n\\]+ { // normal chars
590 codify(yyscanner,yytext);
591 }
592 . { // normal char
593 codify(yyscanner,yytext);
594 }
595}
596
597<TripleString>{
598 {TRIDOUBLEQUOTE} |
599 {TRISINGLEQUOTE} {
600 codify(yyscanner,yytext);
601 if (yyextra->doubleQuote==(yytext[0]=='"'))
602 {
603 endFontClass(yyscanner);
604 BEGIN(yyextra->stringContext);
605 }
606 }
607 {LONGSTRINGBLOCK} {
608 codifyLines(yyscanner,yytext);
609 }
610 \n {
611 codifyLines(yyscanner,yytext);
612 }
613 [ \t]+ {
614 codify(yyscanner,yytext);
615 }
616 . {
617 codify(yyscanner,yytext);
618 }
619}
620
621
622<*>{STRINGPREFIX}?{TRISINGLEQUOTE} {
623 if (YY_START==SingleQuoteString) REJECT;
624 startFontClass(yyscanner,"stringliteral");
625 yyextra->stringContext=YY_START;
626 yyextra->doubleQuote=yytext[yyleng-1]=='"';
627 codify(yyscanner,yytext);
628 BEGIN(TripleString);
629 }
630<*>{STRINGPREFIX}?{TRIDOUBLEQUOTE} {
631 if (YY_START==DoubleQuoteString) REJECT;
632 startFontClass(yyscanner,"stringliteral");
633 yyextra->stringContext=YY_START;
634 yyextra->doubleQuote=yytext[yyleng-1]=='"';
635 codify(yyscanner,yytext);
636 BEGIN(TripleString);
637 }
638<*>{STRINGPREFIX}?"'" { // single quoted string
639 if (YY_START==SingleQuoteString ||
640 YY_START==DoubleQuoteString ||
641 YY_START==TripleString)
642 {
643 REJECT;
644 }
645 startFontClass(yyscanner,"stringliteral");
646 yyextra->stringContext=YY_START;
647 codify(yyscanner,yytext);
648 BEGIN(SingleQuoteString);
649 }
650<*>{STRINGPREFIX}?"\"" { // double quoted string
651 if (YY_START==SingleQuoteString ||
652 YY_START==DoubleQuoteString ||
653 YY_START==TripleString)
654 {
655 REJECT;
656 }
657 startFontClass(yyscanner,"stringliteral");
658 yyextra->stringContext=YY_START;
659 codify(yyscanner,yytext);
660 BEGIN(DoubleQuoteString);
661 }
662<DocBlock>.* { // contents of current comment line
663 yyextra->docBlock+=yytext;
664 }
665<DocBlock>"\n"{B}("#") { // comment block (next line is also comment line)
666 yyextra->docBlock+=yytext;
667 }
668<DocBlock>{NEWLINE} { // comment block ends at the end of this line
669 // remove special comment (default config)
670 startFontClass(yyscanner,"comment",true);
671 codifyLines(yyscanner,yyextra->docBlock);
672 endFontClass(yyscanner,true);
673 unput(*yytext);
674 pop_state(yyscanner);
675 }
static void pop_state(yyscan_t yyscanner)
Definition pycode.l:1606
676<*>{POUNDCOMMENT}.* {
677 if (YY_START==SingleQuoteString ||
678 YY_START==DoubleQuoteString ||
679 YY_START==TripleString)
680 {
681 REJECT;
682 }
683 yy_push_state(YY_START,yyscanner);
684 BEGIN(DocBlock);
685 yyextra->docBlock=yytext;
686 }
687<*>"#".* { // normal comment
688 if (YY_START==SingleQuoteString ||
689 YY_START==DoubleQuoteString ||
690 YY_START==TripleString)
691 {
692 REJECT;
693 }
694 startFontClass(yyscanner,"comment");
695 codifyLines(yyscanner,yytext);
696 endFontClass(yyscanner);
697 }
698<*>{NEWLINE} {
699 if (yyextra->endComment)
700 {
701 yyextra->endComment=FALSE;
702 }
703 else
704 {
705 codifyLines(yyscanner,yytext);
706 }
707 //printf("[pycode] %d NEWLINE [line %d] no match\n",
708 // YY_START, yyextra->yyLineNr);
709
710 BEGIN(Body);
711 }
712
713<*>[ \t]+ {
714 codify(yyscanner,yytext);
715 BEGIN(Body);
716 }
717<*>. {
718 codify(yyscanner,yytext);
719 // printf("[pycode] '%s' [ state %d ] [line %d] no match\n",
720 // yytext, YY_START, yyextra->yyLineNr);
721
722 BEGIN(Body);
723 }
724
725<*><<EOF>> {
726 if (YY_START==DocBlock)
727 {
728 startFontClass(yyscanner,"comment",true);
729 codifyLines(yyscanner,yyextra->docBlock);
730 endFontClass(yyscanner,true);
731 }
732 yyterminate();
733 }
#define yyterminate()
734%%

◆ yyread()

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

Definition at line 772 of file pycode.l.

773{
774 struct yyguts_t *yyg = (struct yyguts_t*)yyscanner;
775 int inputPosition = yyextra->inputPosition;
776 const char *s = yyextra->inputString + inputPosition;
777 int c=0;
778 while( c < max_size && *s )
779 {
780 *buf++ = *s++;
781 c++;
782 }
783 yyextra->inputPosition += c;
784 return c;
785}