@@ -83,6 +83,8 @@ func (es *stmtsStack) Add(stmt ...ast.Stmt) {
8383 exprsStack exprsStack
8484 trailers []ast.Expr // list of trailer expressions
8585 comma bool
86+ comprehension ast.Comprehension
87+ comprehensions []ast.Comprehension
8688}
8789
8890%type <obj> strings
@@ -91,12 +93,13 @@ func (es *stmtsStack) Add(stmt ...ast.Stmt) {
9193%type <stmtsStack> nl_or_stmt small_stmts stmts
9294%type <stmt> compound_stmt small_stmt expr_stmt del_stmt pass_stmt flow_stmt import_stmt global_stmt nonlocal_stmt assert_stmt break_stmt continue_stmt return_stmt raise_stmt yield_stmt
9395%type <op> augassign
94- %type <expr> expr_or_star_expr expr star_expr xor_expr and_expr shift_expr arith_expr term factor power trailer atom test_or_star_expr test not_test lambdef test_nocond lambdef_nocond or_test and_test comparison testlist testlist_star_expr yield_expr_or_testlist yield_expr yield_expr_or_testlist_star_expr
96+ %type <expr> expr_or_star_expr expr star_expr xor_expr and_expr shift_expr arith_expr term factor power trailer atom test_or_star_expr test not_test lambdef test_nocond lambdef_nocond or_test and_test comparison testlist testlist_star_expr yield_expr_or_testlist yield_expr yield_expr_or_testlist_star_expr dictorsetmaker
9597%type <exprs> exprlist
96- %type <exprsStack> expr_or_star_exprs test_or_star_exprs tests
98+ %type <exprsStack> expr_or_star_exprs test_or_star_exprs tests test_colon_tests
9799%type <trailers> trailers
98100%type <cmpop> comp_op
99101%type <comma> optional_comma
102+ %type <comprehensions> comp_for
100103
101104%token NEWLINE
102105%token ENDMARKER
@@ -1108,8 +1111,7 @@ atom:
11081111 }
11091112| ' {' dictorsetmaker ' }'
11101113 {
1111- // FIXME
1112- $$ = nil
1114+ $$ = $2
11131115 }
11141116| NAME
11151117 {
@@ -1242,13 +1244,46 @@ testlist:
12421244// (',' test ':' test)*
12431245test_colon_tests:
12441246 test ' :' test
1247+ {
1248+ $$ .Push()
1249+ $$ .Add($1 , $3 ) // key, value order
1250+ }
12451251| test_colon_tests ' ,' test ' :' test
1252+ {
1253+ $$ .Add($3 , $5 )
1254+ }
12461255
12471256dictorsetmaker:
12481257 test_colon_tests optional_comma
1258+ {
1259+ keyValues := $1 .Pop()
1260+ d := &ast.Dict{ExprBase: ast.ExprBase{$<pos>$}, Keys: nil, Values: nil}
1261+ for i := 0 ; i < len(keyValues)-1 ; i += 2 {
1262+ d.Keys = append(d.Keys, keyValues[i])
1263+ d.Values = append(d.Values, keyValues[i+1 ])
1264+ }
1265+ $$ = d
1266+ }
12491267| test ' :' test comp_for
1268+ {
1269+ // FIXME DictComp
1270+ $$ = &ast.DictComp{ExprBase: ast.ExprBase{$<pos>$}, Key: $1 , Value: $3 , Generators: $4 }
1271+ }
12501272| testlist
1273+ {
1274+ var elts []ast.Expr
1275+ if x, ok := $1 .(*ast.Tuple); ok {
1276+ elts = x.Elts
1277+ } else {
1278+ elts = []ast.Expr{$1 }
1279+ }
1280+ $$ = &ast.Set{ExprBase: ast.ExprBase{$<pos>$}, Elts: elts}
1281+ }
12511282| test comp_for
1283+ {
1284+ // FIXME SetComp
1285+ $$ = &ast.SetComp{ExprBase: ast.ExprBase{$<pos>$}, Elt: $1 , Generators: $2 }
1286+ }
12521287
12531288classdef:
12541289 CLASS NAME optional_arglist_call ' :' suite
@@ -1282,7 +1317,15 @@ comp_iter:
12821317
12831318comp_for:
12841319 FOR exprlist IN or_test
1320+ {
1321+ // FIXME
1322+ $$ = nil
1323+ }
12851324| FOR exprlist IN or_test comp_iter
1325+ {
1326+ // FIXME
1327+ $$ = nil
1328+ }
12861329
12871330comp_if:
12881331 IF test_nocond
0 commit comments