Skip to content

Commit 19ee614

Browse files
committed
Python class vaiables type and initial value
With non static class variables some parts are missing: - initial value - implicit type though with class static variables these items are present, synchronizing.
1 parent e9ec8d2 commit 19ee614

File tree

1 file changed

+111
-123
lines changed

1 file changed

+111
-123
lines changed

src/pyscanner.l

Lines changed: 111 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ struct pyscannerYY_state
105105
char atomStart = 0;
106106
char atomEnd = 0;
107107
int atomCount = 0;
108+
int atomContext = 0;
108109
QCString moduleScope;
109110
QCString packageName;
110111
TextStream defVal;
@@ -551,7 +552,7 @@ ID [a-z_A-Z%]+{IDSYM}*
551552
const char *s = strchr(yytext,'.'); s++;
552553
DBG_CTX((stderr,"Found instance method variable %s in %s at %d\n",s,qPrint(yyextra->current_root->name.data(),yyextra->yyLineNr)));
553554
docVariable(yyscanner,s);
554-
newEntry(yyscanner);
555+
BEGIN( SearchSkipValue );
555556
}
556557
("cls"|"self")"."{IDENTIFIER}/{B}":" { // type hint
557558
const char *s = strchr(yytext,'.'); s++;
@@ -589,6 +590,7 @@ ID [a-z_A-Z%]+{IDSYM}*
589590
"=" {
590591
yyextra->current->doc.clear();
591592
yyextra->current->brief.clear();
593+
unput(*yytext);
592594
BEGIN( SearchSkipValue );
593595
}
594596
{IDENTIFIER} // identifiers
@@ -622,7 +624,7 @@ ID [a-z_A-Z%]+{IDSYM}*
622624
if (yyextra->braceCount==0)
623625
{ // end of the type hint
624626
yyextra->current->type = yyextra->current->type.stripWhiteSpace();
625-
newEntry(yyscanner);
627+
unput(*yytext);
626628
BEGIN(SearchSkipValue);
627629
}
628630
else
@@ -645,37 +647,126 @@ ID [a-z_A-Z%]+{IDSYM}*
645647
}
646648
}
647649

648-
<SearchSkipValue>{
649-
{TRIDOUBLEQUOTE} { // start of a comment block
650-
initTriDoubleQuoteBlock(yyscanner);
651-
BEGIN(TripleComment);
650+
<SearchSkipValue,VariableDec>{
651+
"=" { // the assignment operator
652+
//printf("====== VariableDec at line %d\n",yyextra->yyLineNr);
653+
yyextra->startInit = TRUE;
654+
yyextra->current->initializer.str(yytext);
655+
yyextra->current->initializer << " ";
656+
}
657+
{B} { // spaces
658+
yyextra->current->initializer << yytext;
652659
}
653660

654-
{TRISINGLEQUOTE} { // start of a comment block
655-
initTriSingleQuoteBlock(yyscanner);
656-
BEGIN(TripleComment);
661+
{INTNUMBER} { // integer value
662+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "int";
663+
yyextra->current->initializer << yytext;
657664
}
658-
{STARTDOCSYMS}/[^#] { // start of a special comment
659-
initSpecialBlock(yyscanner);
660-
BEGIN(SpecialComment);
665+
{FLOATNUMBER} { // floating point value
666+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "float";
667+
yyextra->current->initializer << yytext;
661668
}
662-
{POUNDCOMMENT} { // #
669+
{BOOL} { // boolean value
670+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "bool";
671+
yyextra->current->initializer << yytext;
663672
}
664-
"'" { // start of a single quoted string
673+
{STRINGPREFIX}?"'" { // string
674+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
675+
yyextra->current->initializer << yytext;
676+
yyextra->copyString=&yyextra->current->initializer;
665677
yyextra->stringContext=YY_START;
666-
yyextra->copyString=nullptr;
667678
BEGIN( SingleQuoteString );
668679
}
669-
"\"" { // start of a double quoted string
680+
{STRINGPREFIX}?"\"" { // string
681+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
682+
yyextra->current->initializer << yytext;
683+
yyextra->copyString=&yyextra->current->initializer;
670684
yyextra->stringContext=YY_START;
671-
yyextra->copyString=nullptr;
672685
BEGIN( DoubleQuoteString );
673686
}
687+
{TRIDOUBLEQUOTE} { // start of a comment block
688+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
689+
yyextra->current->initializer << yytext;
690+
yyextra->doubleQuote=TRUE;
691+
yyextra->copyString=&yyextra->current->initializer;
692+
yyextra->stringContext=YY_START;
693+
BEGIN(TripleString);
694+
}
695+
696+
{TRISINGLEQUOTE} { // start of a comment block
697+
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
698+
yyextra->current->initializer << yytext;
699+
yyextra->doubleQuote=FALSE;
700+
yyextra->copyString=&yyextra->current->initializer;
701+
yyextra->stringContext=YY_START;
702+
BEGIN(TripleString);
703+
}
704+
"(" { // tuple, only when direct after =
705+
if (yyextra->current->mtype!=MethodTypes::Property && yyextra->startInit)
706+
{
707+
yyextra->current->type = "tuple";
708+
}
709+
yyextra->current->initializer << *yytext;
710+
yyextra->atomStart='(';
711+
yyextra->atomEnd=')';
712+
yyextra->atomCount=1;
713+
yyextra->atomContext=YY_START;
714+
BEGIN( VariableAtom );
715+
}
716+
"[" { // list
717+
if (yyextra->startInit) yyextra->current->type = "list";
718+
yyextra->current->initializer << *yytext;
719+
yyextra->atomStart='[';
720+
yyextra->atomEnd=']';
721+
yyextra->atomCount=1;
722+
yyextra->atomContext=YY_START;
723+
BEGIN( VariableAtom );
724+
}
725+
"{" { // dictionary
726+
if (yyextra->startInit) yyextra->current->type = "dict";
727+
yyextra->current->initializer << *yytext;
728+
yyextra->atomStart='{';
729+
yyextra->atomEnd='}';
730+
yyextra->atomCount=1;
731+
yyextra->atomContext=YY_START;
732+
BEGIN( VariableAtom );
733+
}
734+
"\\\n" {
735+
yyextra->current->initializer << yytext;
736+
incLineNr(yyscanner);
737+
}
738+
{IDENTIFIER} {
739+
// do something based on the type of the IDENTIFIER
740+
if (yyextra->current->type.isEmpty())
741+
{
742+
for (const auto &child : yyextra->current_root->children())
743+
{
744+
if (child->name == QCString(yytext))
745+
{
746+
yyextra->current->type = child->type;
747+
break;
748+
}
749+
}
750+
}
751+
yyextra->startInit = FALSE;
752+
yyextra->current->initializer << yytext;
753+
}
754+
. {
755+
yyextra->startInit = FALSE;
756+
yyextra->current->initializer << *yytext;
757+
}
758+
}
759+
<SearchSkipValue>{
760+
{STARTDOCSYMS}/[^#] { // start of a special comment
761+
initSpecialBlock(yyscanner);
762+
BEGIN(SpecialComment);
763+
}
764+
{POUNDCOMMENT} { // #
765+
}
674766
\n { incLineNr(yyscanner);
767+
newEntry(yyscanner);
675768
BEGIN(SearchMemVars);
676769
}
677-
{IDENTIFIER} // identifiers
678-
. // anything else
679770
}
680771

681772
<FunctionBody>{
@@ -1232,89 +1323,10 @@ ID [a-z_A-Z%]+{IDSYM}*
12321323

12331324

12341325
<VariableDec>{
1235-
"=" { // the assignment operator
1236-
//printf("====== VariableDec at line %d\n",yyextra->yyLineNr);
1237-
yyextra->startInit = TRUE;
1238-
yyextra->current->initializer.str(yytext);
1239-
yyextra->current->initializer << " ";
1240-
}
12411326
":"{B}{IDENTIFIER} { //typing
12421327
yyextra->startInit = FALSE;
12431328
yyextra->current->type = substitute(yytext,":","");
12441329
}
1245-
{B} { // spaces
1246-
yyextra->current->initializer << yytext;
1247-
}
1248-
{INTNUMBER} { // integer value
1249-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "int";
1250-
yyextra->current->initializer << yytext;
1251-
}
1252-
{FLOATNUMBER} { // floating point value
1253-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "float";
1254-
yyextra->current->initializer << yytext;
1255-
}
1256-
{BOOL} { // boolean value
1257-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "bool";
1258-
yyextra->current->initializer << yytext;
1259-
}
1260-
{STRINGPREFIX}?"'" { // string
1261-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
1262-
yyextra->current->initializer << yytext;
1263-
yyextra->copyString=&yyextra->current->initializer;
1264-
yyextra->stringContext=VariableDec;
1265-
BEGIN( SingleQuoteString );
1266-
}
1267-
{STRINGPREFIX}?"\"" { // string
1268-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
1269-
yyextra->current->initializer << yytext;
1270-
yyextra->copyString=&yyextra->current->initializer;
1271-
yyextra->stringContext=VariableDec;
1272-
BEGIN( DoubleQuoteString );
1273-
}
1274-
{TRIDOUBLEQUOTE} { // start of a comment block
1275-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
1276-
yyextra->current->initializer << yytext;
1277-
yyextra->doubleQuote=TRUE;
1278-
yyextra->copyString=&yyextra->current->initializer;
1279-
yyextra->stringContext=VariableDec;
1280-
BEGIN(TripleString);
1281-
}
1282-
1283-
{TRISINGLEQUOTE} { // start of a comment block
1284-
if (yyextra->current->type.isEmpty()) yyextra->current->type = "str";
1285-
yyextra->current->initializer << yytext;
1286-
yyextra->doubleQuote=FALSE;
1287-
yyextra->copyString=&yyextra->current->initializer;
1288-
yyextra->stringContext=VariableDec;
1289-
BEGIN(TripleString);
1290-
}
1291-
"(" { // tuple, only when direct after =
1292-
if (yyextra->current->mtype!=MethodTypes::Property && yyextra->startInit)
1293-
{
1294-
yyextra->current->type = "tuple";
1295-
}
1296-
yyextra->current->initializer << *yytext;
1297-
yyextra->atomStart='(';
1298-
yyextra->atomEnd=')';
1299-
yyextra->atomCount=1;
1300-
BEGIN( VariableAtom );
1301-
}
1302-
"[" { // list
1303-
if (yyextra->startInit) yyextra->current->type = "list";
1304-
yyextra->current->initializer << *yytext;
1305-
yyextra->atomStart='[';
1306-
yyextra->atomEnd=']';
1307-
yyextra->atomCount=1;
1308-
BEGIN( VariableAtom );
1309-
}
1310-
"{" { // dictionary
1311-
if (yyextra->startInit) yyextra->current->type = "dict";
1312-
yyextra->current->initializer << *yytext;
1313-
yyextra->atomStart='{';
1314-
yyextra->atomEnd='}';
1315-
yyextra->atomCount=1;
1316-
BEGIN( VariableAtom );
1317-
}
13181330
{STARTDOCSYMS}"<"/.* { // start of a special comment
13191331
yyextra->curIndent=computeIndent(yytext);
13201332
yyextra->packageCommentAllowed = FALSE;
@@ -1325,30 +1337,6 @@ ID [a-z_A-Z%]+{IDSYM}*
13251337
"#".* { // comment
13261338
BEGIN( VariableEnd );
13271339
}
1328-
{IDENTIFIER} {
1329-
// do something based on the type of the IDENTIFIER
1330-
if (yyextra->current->type.isEmpty())
1331-
{
1332-
for (const auto &child : yyextra->current_root->children())
1333-
{
1334-
if (child->name == QCString(yytext))
1335-
{
1336-
yyextra->current->type = child->type;
1337-
break;
1338-
}
1339-
}
1340-
}
1341-
yyextra->startInit = FALSE;
1342-
yyextra->current->initializer << yytext;
1343-
}
1344-
"\\\n" {
1345-
yyextra->current->initializer << yytext;
1346-
incLineNr(yyscanner);
1347-
}
1348-
. {
1349-
yyextra->startInit = FALSE;
1350-
yyextra->current->initializer << *yytext;
1351-
}
13521340
\n {
13531341
unput('\n');
13541342
BEGIN( VariableEnd );
@@ -1372,7 +1360,7 @@ ID [a-z_A-Z%]+{IDSYM}*
13721360
if (yyextra->atomCount==0)
13731361
{
13741362
yyextra->startInit = FALSE;
1375-
BEGIN(VariableDec);
1363+
BEGIN(yyextra->atomContext);
13761364
}
13771365
}
13781366
{TRIDOUBLEQUOTE} { // start of a comment block

0 commit comments

Comments
 (0)