Skip to content

Commit 221b2b5

Browse files
Merge pull request #1053 from akshanshbhatt/pr_1027
2 parents 4df26ca + 86dcf77 commit 221b2b5

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

src/lpython/parser/parser.yy

+1
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ id_list
825825

826826
id_item
827827
: id { $$ = $1; }
828+
| "*" id { $$ = STARRED_ARG_STORE($2, @$); }
828829
| "(" id ")" { $$ = $2; }
829830
| "(" id_list "," ")" { $$ = ID_TUPLE_03($2, @$); }
830831
| "(" id_list "," id_item ")" { $$ = ID_TUPLE_01(TUPLE_($2, $4), @$); }

src/lpython/parser/semantics.h

+2
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,8 @@ ast_t *DICT1(Allocator &al, Location &l, Vec<Key_Val*> dict_list) {
964964
EXPR(SET_EXPR_CTX_01(x, Store)), EXPR(y))
965965
#define STARRED_ARG(e, l) make_Starred_t(p.m_a, l, \
966966
EXPR(e), expr_contextType::Load)
967+
#define STARRED_ARG_STORE(e, l) make_Starred_t(p.m_a, l, \
968+
EXPR(SET_EXPR_CTX_01(e, Store)), expr_contextType::Load)
967969
#define LAMBDA_01(args, e, l) make_Lambda_t(p.m_a, l, args->arguments, EXPR(e))
968970

969971
#endif

tests/parser/comprehension1.py

+2
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@
6161
{x: x**3 for x in range(10) if x**3 % 4 == 0}
6262

6363
square_dict = {num: num*num for num in range(1, 11)}
64+
65+
error_names = [test_full_name.split(" ")[0] for (test_full_name, *_) in errors]

tests/reference/ast_new-comprehension1-69cf2af.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-comprehension1-69cf2af",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/comprehension1.py",
5-
"infile_hash": "b65b175072499f719bf3bcb18630357c2e12082a2244b1ef47486ae1",
5+
"infile_hash": "18bac9bef8299bb9b8a4bd704dd7b125a771a78e82bd5ae6baaa88bd",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-comprehension1-69cf2af.stdout",
9-
"stdout_hash": "deec16e98d396def3c547cf01a7378878ee8a292d540e9cd3a81b8fc",
9+
"stdout_hash": "14b3325a73ee8634ae463512e99d1c164606a14818dd5d4843f44320",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (Assign [(Name items Store)] (ListComp (Name name Load) [((Tuple [(Name name Store) (Name value Store)] Store) (Call (Attribute (Call (Name vars Load) [(Name argparse Load)] []) items Load) [] []) [(UnaryOp Not (BoolOp Or [(Call (Attribute (Name name Load) startswith Load) [(ConstantStr "_" ())] []) (Compare (Name name Load) Eq [(ConstantStr "ngettext" ())])])) (UnaryOp Not (Call (Attribute (Name inspect Load) ismodule Load) [(Name value Load)] []))] 0)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Expr (GeneratorExp (Call (Name sstr Load) [(Name x Load)] []) [((List [(Name x Store)] Store) (Attribute (Attribute (Name self Load) _module Load) gens Load) [] 0)])) (Expr (Call (Name func Load) [(Starred (ListComp (List [(BinOp (Name x Load) Mult (Name y Load))] Load) [((List [(Name x Store)] Store) (Attribute (Attribute (Name self Load) _module Load) gens Load) [] 0) ((List [(Name y Store)] Store) (Attribute (Attribute (Name J Load) _module Load) gens Load) [] 0)]) Load)] [])) (Expr (GeneratorExp (Name x Load) [((List [(Name a Store) (Name b Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [(Name a Store) (Tuple [(Name b Store) (Name c Store)] Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [(Tuple [(Name b Store) (Name c Store)] Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Subscript (Name string Load) (Name i Load) Load) [((Name i Store) (Call (Name range Load) [(BinOp (Call (Name len Load) [(Name string Load)] []) Sub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ()))] []) [] 0)])) (Assign [(Name k Store)] (GeneratorExp (BinOp (Name j Load) Add (Name k Load)) [((Tuple [(Name j Store) (Name k Store)] Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (Name j Load) Gt [(ConstantInt 0 ())])] 0)]) ()) (Expr (GeneratorExp (BinOp (BinOp (Name left Load) Add (Name size Load)) Add (Name right Load)) [((Tuple [(Name size Store) (Tuple [(Name left Store) (Name right Store)] Store)] Store) (Call (Name zip Load) [(Attribute (Name array Load) shape Load) (Name pad_width Load)] []) [] 0)])) (Assign [(Name viter Store)] (GeneratorExp (Tuple [(Name i Load) (Name j Load)] Load) [((Tuple [(Tuple [(Name i Store) (Name _ Store)] Store) (Tuple [(Name j Store) (Name _ Store)] Store)] Store) (Call (Name zip Load) [(Subscript (Name newargs Load) (Slice (ConstantInt 1 ()) () ()) Load) (Subscript (Name args Load) (Slice (ConstantInt 1 ()) () ()) Load)] []) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ())] [])
1+
(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (Assign [(Name items Store)] (ListComp (Name name Load) [((Tuple [(Name name Store) (Name value Store)] Store) (Call (Attribute (Call (Name vars Load) [(Name argparse Load)] []) items Load) [] []) [(UnaryOp Not (BoolOp Or [(Call (Attribute (Name name Load) startswith Load) [(ConstantStr "_" ())] []) (Compare (Name name Load) Eq [(ConstantStr "ngettext" ())])])) (UnaryOp Not (Call (Attribute (Name inspect Load) ismodule Load) [(Name value Load)] []))] 0)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Expr (GeneratorExp (Call (Name sstr Load) [(Name x Load)] []) [((List [(Name x Store)] Store) (Attribute (Attribute (Name self Load) _module Load) gens Load) [] 0)])) (Expr (Call (Name func Load) [(Starred (ListComp (List [(BinOp (Name x Load) Mult (Name y Load))] Load) [((List [(Name x Store)] Store) (Attribute (Attribute (Name self Load) _module Load) gens Load) [] 0) ((List [(Name y Store)] Store) (Attribute (Attribute (Name J Load) _module Load) gens Load) [] 0)]) Load)] [])) (Expr (GeneratorExp (Name x Load) [((List [(Name a Store) (Name b Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [(Name a Store) (Tuple [(Name b Store) (Name c Store)] Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [(Tuple [(Name b Store) (Name c Store)] Store)] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Name x Load) [((List [] Store) (Name y Load) [] 0)])) (Expr (GeneratorExp (Subscript (Name string Load) (Name i Load) Load) [((Name i Store) (Call (Name range Load) [(BinOp (Call (Name len Load) [(Name string Load)] []) Sub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ()))] []) [] 0)])) (Assign [(Name k Store)] (GeneratorExp (BinOp (Name j Load) Add (Name k Load)) [((Tuple [(Name j Store) (Name k Store)] Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (Name j Load) Gt [(ConstantInt 0 ())])] 0)]) ()) (Expr (GeneratorExp (BinOp (BinOp (Name left Load) Add (Name size Load)) Add (Name right Load)) [((Tuple [(Name size Store) (Tuple [(Name left Store) (Name right Store)] Store)] Store) (Call (Name zip Load) [(Attribute (Name array Load) shape Load) (Name pad_width Load)] []) [] 0)])) (Assign [(Name viter Store)] (GeneratorExp (Tuple [(Name i Load) (Name j Load)] Load) [((Tuple [(Tuple [(Name i Store) (Name _ Store)] Store) (Tuple [(Name j Store) (Name _ Store)] Store)] Store) (Call (Name zip Load) [(Subscript (Name newargs Load) (Slice (ConstantInt 1 ()) () ()) Load) (Subscript (Name args Load) (Slice (ConstantInt 1 ()) () ()) Load)] []) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ()) (Assign [(Name error_names Store)] (ListComp (Subscript (Call (Attribute (Name test_full_name Load) split Load) [(ConstantStr " " ())] []) (ConstantInt 0 ()) Load) [((Tuple [(Name test_full_name Store) (Starred (Name _ Store) Store)] Store) (Name errors Load) [] 0)]) ())] [])

0 commit comments

Comments
 (0)