Skip to content

Commit a9963f0

Browse files
committed
Python,refactor: add a function for parsing class inheritance lists
1 parent 740360d commit a9963f0

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
@@ -1041,14 +1041,25 @@ static void deleteTypedParam (struct typedParam *p)
10411041
eFree (p);
10421042
}
10431043

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

1050-
if (kind != K_CLASS)
1051-
reprCat (arglist, token);
1062+
reprCat (arglist, token);
10521063

10531064
do
10541065
{
@@ -1061,8 +1072,7 @@ static void parseArglist (tokenInfo *const token, const int kind,
10611072
}
10621073

10631074
readTokenFull (token, true);
1064-
if (kind != K_CLASS || token->type != ')' || depth > 1)
1065-
reprCat (arglist, token);
1075+
reprCat (arglist, token);
10661076

10671077
if (token->type == '(' ||
10681078
token->type == '[' ||
@@ -1072,7 +1082,7 @@ static void parseArglist (tokenInfo *const token, const int kind,
10721082
token->type == ']' ||
10731083
token->type == '}')
10741084
depth --;
1075-
else if (kind != K_CLASS && depth == 1 &&
1085+
else if (depth == 1 &&
10761086
token->type == TOKEN_IDENTIFIER &&
10771087
(prevTokenType == '(' || prevTokenType == ',') &&
10781088
PythonKinds[K_PARAMETER].enabled)
@@ -1093,8 +1103,8 @@ static void parseArglist (tokenInfo *const token, const int kind,
10931103
while (token->type != TOKEN_EOF && depth > 0);
10941104
}
10951105

1096-
static void parseCArglist (tokenInfo *const token, const int kind,
1097-
vString *const arglist, ptrArray *const parameters)
1106+
static void parseCArglist (tokenInfo *const token,
1107+
vString *const arglist, ptrArray *const parameters)
10981108
{
10991109
int depth = 1;
11001110
tokenInfo *pname = newToken ();
@@ -1233,12 +1243,14 @@ static bool parseClassOrDef (tokenInfo *const token,
12331243
if (token->type == '(')
12341244
{
12351245
arglist = vStringNew ();
1236-
parameters = ptrArrayNew ((ptrArrayDeleteFunc)deleteTypedParam);
1246+
parameters = (kind == K_CLASS)? NULL: ptrArrayNew ((ptrArrayDeleteFunc)deleteTypedParam);
12371247

1238-
if (isCDef && kind != K_CLASS)
1239-
parseCArglist (token, kind, arglist, parameters);
1248+
if (kind == K_CLASS)
1249+
parseInheritanceList (token, arglist);
1250+
else if (isCDef)
1251+
parseCArglist (token, arglist, parameters);
12401252
else
1241-
parseArglist (token, kind, arglist, parameters);
1253+
parseArglist (token, arglist, parameters);
12421254
}
12431255

12441256
if (kind == K_CLASS)

0 commit comments

Comments
 (0)