Skip to content

Commit

Permalink
Add parsing support for type-comments in async for-loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshanshbhatt committed Jul 20, 2022
1 parent 42ff302 commit e1d0491
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lpython/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,10 @@ async_for_stmt
$$ = ASYNC_FOR_01($3, $5, $8, @$); }
| KW_ASYNC KW_FOR tuple_item KW_IN expr ":" sep statements KW_ELSE ":" sep
statements { $$ = ASYNC_FOR_02($3, $5, $8, $12, @$); }
| KW_ASYNC KW_FOR tuple_item KW_IN expr ":" TK_TYPE_COMMENT TK_NEWLINE statements {
$$ = ASYNC_FOR_03($3, $5, $9, $7, @$); }
| KW_ASYNC KW_FOR tuple_item KW_IN expr ":" TK_TYPE_COMMENT TK_NEWLINE statements
KW_ELSE ":" sep statements { $$ = ASYNC_FOR_04($3, $5, $9, $13, $7, @$); }
;

async_with_stmt
Expand Down
7 changes: 7 additions & 0 deletions src/lpython/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ static inline Args *FUNC_ARGS(Allocator &al, Location &l,
#define ASYNC_FOR_02(target, iter, stmts, orelse, l) make_AsyncFor_t(p.m_a, l, \
EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \
STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size(), nullptr)
#define ASYNC_FOR_03(target, iter, stmts, type_comment, l) make_AsyncFor_t(p.m_a, l, \
EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \
STMTS(stmts), stmts.size(), nullptr, 0, extract_type_comment(p.m_a, type_comment))
#define ASYNC_FOR_04(target, iter, stmts, orelse, type_comment, l) make_AsyncFor_t(p.m_a, l, \
EXPR(SET_EXPR_CTX_01(SET_STORE_01(target), Store)), EXPR(iter), \
STMTS(stmts), stmts.size(), STMTS(orelse), orelse.size(), \
extract_type_comment(p.m_a, type_comment))

#define ASYNC_WITH(items, body, l) make_AsyncWith_t(p.m_a, l, \
items.p, items.size(), STMTS(body), body.size(), nullptr)
Expand Down

0 comments on commit e1d0491

Please sign in to comment.