Skip to content

Commit

Permalink
Add support for parsing more cases of class def.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshanshbhatt committed Jul 22, 2022
1 parent e2f98b7 commit b54150a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lpython/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,16 @@ function_def
;

class_def
: decorators_opt KW_CLASS id ":" sep statements { $$ = CLASS_01($1, $3, $6, @$); }
: decorators_opt KW_CLASS id ":" sep statements {
$$ = CLASS_01($1, $3, $6, @$); }
| decorators_opt KW_CLASS id "(" expr_list_opt ")" ":" sep statements {
$$ = CLASS_02($1, $3, $5, $9, @$); }
| decorators_opt KW_CLASS id "(" expr_list "," keyword_items ")"
":" sep statements { $$ = CLASS_03($1, $3, $5, $7, $11, @$); }
| decorators_opt KW_CLASS id "(" keyword_items "," expr_list ")"
":" sep statements { $$ = CLASS_03($1, $3, $7, $5, $11, @$); }
| decorators_opt KW_CLASS id "(" keyword_items ")" ":" sep statements {
$$ = CLASS_04($1, $3, $5, $9, @$); }
;

async_func_def
Expand Down
8 changes: 8 additions & 0 deletions src/lpython/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ static inline Args *FUNC_ARGS(Allocator &al, Location &l,
name2char(id), EXPRS(args), args.size(), nullptr, 0, \
STMTS(stmts), stmts.size(), \
EXPRS(decorator), decorator.size())
#define CLASS_03(decorator, id, args, keywords, stmts, l) \
make_ClassDef_t(p.m_a, l, name2char(id), EXPRS(args), args.size(), \
keywords.p, keywords.n, STMTS(stmts), stmts.size(), \
EXPRS(decorator), decorator.size())
#define CLASS_04(decorator, id, keywords, stmts, l) make_ClassDef_t(p.m_a, l, \
name2char(id), nullptr, 0, keywords.p, keywords.n, \
STMTS(stmts), stmts.size(), \
EXPRS(decorator), decorator.size())

#define ASYNC_FUNCTION_01(decorator, id, args, stmts, l) \
make_AsyncFunctionDef_t(p.m_a, l, name2char(id), args->arguments, \
Expand Down

0 comments on commit b54150a

Please sign in to comment.