Skip to content

Commit cbc3cde

Browse files
committed
Python,refactor: add a function for parsing class inheritance lists
1 parent 1580ec2 commit cbc3cde

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

parsers/python.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,14 +1039,25 @@ static void deleteTypedParam (struct typedParam *p)
10391039
eFree (p);
10401040
}
10411041

1042-
static void parseArglist (tokenInfo *const token, const int kind,
1042+
static void parseInheritanceList (tokenInfo *const token,
1043+
vString *const inneritanceList)
1044+
{
1045+
do
1046+
{
1047+
readTokenFull (token, true);
1048+
if (token->type != ')')
1049+
reprCat (inneritanceList, token);
1050+
}
1051+
while (token->type != TOKEN_EOF && token->type != ')');
1052+
}
1053+
1054+
static void parseArglist (tokenInfo *const token,
10431055
vString *const arglist, ptrArray *const parameters)
10441056
{
10451057
int prevTokenType = token->type;
10461058
int depth = 1;
10471059

1048-
if (kind != K_CLASS)
1049-
reprCat (arglist, token);
1060+
reprCat (arglist, token);
10501061

10511062
do
10521063
{
@@ -1059,8 +1070,7 @@ static void parseArglist (tokenInfo *const token, const int kind,
10591070
}
10601071

10611072
readTokenFull (token, true);
1062-
if (kind != K_CLASS || token->type != ')' || depth > 1)
1063-
reprCat (arglist, token);
1073+
reprCat (arglist, token);
10641074

10651075
if (token->type == '(' ||
10661076
token->type == '[' ||
@@ -1070,7 +1080,7 @@ static void parseArglist (tokenInfo *const token, const int kind,
10701080
token->type == ']' ||
10711081
token->type == '}')
10721082
depth --;
1073-
else if (kind != K_CLASS && depth == 1 &&
1083+
else if (depth == 1 &&
10741084
token->type == TOKEN_IDENTIFIER &&
10751085
(prevTokenType == '(' || prevTokenType == ',') &&
10761086
PythonKinds[K_PARAMETER].enabled)
@@ -1091,8 +1101,8 @@ static void parseArglist (tokenInfo *const token, const int kind,
10911101
while (token->type != TOKEN_EOF && depth > 0);
10921102
}
10931103

1094-
static void parseCArglist (tokenInfo *const token, const int kind,
1095-
vString *const arglist, ptrArray *const parameters)
1104+
static void parseCArglist (tokenInfo *const token,
1105+
vString *const arglist, ptrArray *const parameters)
10961106
{
10971107
int depth = 1;
10981108
tokenInfo *pname = newToken ();
@@ -1231,12 +1241,14 @@ static bool parseClassOrDef (tokenInfo *const token,
12311241
if (token->type == '(')
12321242
{
12331243
arglist = vStringNew ();
1234-
parameters = ptrArrayNew ((ptrArrayDeleteFunc)deleteTypedParam);
1244+
parameters = (kind == K_CLASS)? NULL: ptrArrayNew ((ptrArrayDeleteFunc)deleteTypedParam);
12351245

1236-
if (isCDef && kind != K_CLASS)
1237-
parseCArglist (token, kind, arglist, parameters);
1246+
if (kind == K_CLASS)
1247+
parseInheritanceList (token, arglist);
1248+
else if (isCDef)
1249+
parseCArglist (token, arglist, parameters);
12381250
else
1239-
parseArglist (token, kind, arglist, parameters);
1251+
parseArglist (token, arglist, parameters);
12401252
}
12411253

12421254
if (kind == K_CLASS)

0 commit comments

Comments
 (0)