Skip to content

Commit

Permalink
Add support for parsing list inside GenExpr.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshanshbhatt committed Aug 19, 2022
1 parent 39d976d commit 6e82290
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/lpython/parser/parser.yy
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ void yyerror(YYLTYPE *yyloc, LFortran::Parser &p, const std::string &msg)
%type <ast> ternary_if_statement
/* %type <ast> list_comprehension */
%type <vec_ast> id_list
%type <vec_ast> id_list_opt
%type <ast> id_item
%type <ast> subscript
%type <comp> comp_for
Expand Down Expand Up @@ -788,6 +789,11 @@ dict_list
| dict { LIST_NEW($$); LIST_ADD($$, $1); }
;

id_list_opt
: id_list { $$ = $1; }
| %empty { LIST_NEW($$); }
;

id_list
: id_list "," id_item { $$ = $1; LIST_ADD($$, $3); }
| id_item { LIST_NEW($$); LIST_ADD($$, $1); }
Expand All @@ -798,6 +804,8 @@ id_item
| "(" id ")" { $$ = $2; }
| "(" id_list "," ")" { $$ = ID_TUPLE_03($2, @$); }
| "(" id_list "," id_item ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); }
| "[" id_list_opt "]" { $$ = LIST(SET_EXPR_CTX_02($2, Store), @$); }
| "[" id_list "," "]" { $$ = LIST(SET_EXPR_CTX_02($2, Store), @$); }
;

keyword_item
Expand Down
1 change: 1 addition & 0 deletions src/lpython/parser/semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static inline ast_t* SET_EXPR_CTX_01(ast_t* x, expr_contextType ctx) {
SET_EXPR_CTX_(Subscript, ctx)
SET_EXPR_CTX_(Starred, ctx)
SET_EXPR_CTX_(Name, ctx)
SET_EXPR_CTX_(List, ctx)
SET_EXPR_CTX_(Tuple, ctx)
default : { break; }
}
Expand Down

0 comments on commit 6e82290

Please sign in to comment.