@@ -66,14 +66,15 @@ func applyTrailers(expr ast.Expr, trailers []ast.Expr) ast.Expr {
6666 identifiers []ast.Identifier
6767 ifstmt *ast.If
6868 lastif *ast.If
69+ exchandlers []*ast.ExceptHandler
6970}
7071
7172%type <obj> strings
7273%type <mod> inputs file_input single_input eval_input
7374%type <stmts> simple_stmt stmt nl_or_stmt small_stmts stmts suite optional_else
74- %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 import_name import_from while_stmt if_stmt for_stmt
75+ %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 import_name import_from while_stmt if_stmt for_stmt try_stmt with_stmt
7576%type <op> augassign
76- %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 sliceop arglist
77+ %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 sliceop arglist except_clause
7778%type <exprs> exprlist testlistraw comp_if comp_iter expr_or_star_exprs test_or_star_exprs tests test_colon_tests trailers
7879%type <cmpop> comp_op
7980%type <comma> optional_comma
@@ -86,6 +87,7 @@ func applyTrailers(expr ast.Expr, trailers []ast.Expr) ast.Expr {
8687%type <alias> dotted_as_name import_as_name
8788%type <aliases> dotted_as_names import_as_names import_from_arg
8889%type <ifstmt> elifs
90+ %type <exchandlers> except_clauses
8991
9092%token NEWLINE
9193%token ENDMARKER
@@ -833,8 +835,7 @@ import_as_name:
833835 }
834836| NAME AS NAME
835837 {
836- as := ast.Identifier($3 )
837- $$ = &ast.Alias{Pos: $<pos>$, Name: ast.Identifier($1 ), AsName: &as}
838+ $$ = &ast.Alias{Pos: $<pos>$, Name: ast.Identifier($1 ), AsName: ast.Identifier($3 )}
838839 }
839840
840841dotted_as_name :
@@ -844,8 +845,7 @@ dotted_as_name:
844845 }
845846| dotted_name AS NAME
846847 {
847- as := ast.Identifier($3 )
848- $$ = &ast.Alias{Pos: $<pos>$, Name: ast.Identifier($1 ), AsName: &as}
848+ $$ = &ast.Alias{Pos: $<pos>$, Name: ast.Identifier($1 ), AsName: ast.Identifier($3 )}
849849 }
850850
851851import_as_names :
@@ -927,23 +927,23 @@ assert_stmt:
927927compound_stmt :
928928 if_stmt
929929 {
930- // FIXME
930+ $$ = $1
931931 }
932932| while_stmt
933933 {
934934 $$ = $1
935935 }
936936| for_stmt
937937 {
938- // FIXME
938+ $$ = $1
939939 }
940940| try_stmt
941941 {
942- // FIXME
942+ $$ = $1
943943 }
944944| with_stmt
945945 {
946- // FIXME
946+ $$ = $1
947947 }
948948| funcdef
949949 {
@@ -1021,29 +1021,30 @@ for_stmt:
10211021
10221022except_clauses :
10231023 {
1024- // FIXME
1024+ $$ = nil
10251025 }
10261026| except_clauses except_clause ' :' suite
10271027 {
1028- // FIXME
1028+ exc := &ast.ExceptHandler{Pos: $<pos>$, ExprType: $2 , Name: ast.Identifier($<str>2 ), Body: $4 }
1029+ $$ = append($$ , exc)
10291030 }
10301031
10311032try_stmt :
10321033 TRY ' :' suite except_clauses
10331034 {
1034- // FIXME
1035+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 }
10351036 }
10361037| TRY ' :' suite except_clauses ELSE ' :' suite
10371038 {
1038- // FIXME
1039+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Orelse: $7 }
10391040 }
10401041| TRY ' :' suite except_clauses FINALLY ' :' suite
10411042 {
1042- // FIXME
1043+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Finalbody: $7 }
10431044 }
10441045| TRY ' :' suite except_clauses ELSE ' :' suite FINALLY ' :' suite
10451046 {
1046- // FIXME
1047+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Orelse: $7 , Finalbody: $10 }
10471048 }
10481049
10491050with_items :
@@ -1076,15 +1077,18 @@ with_item:
10761077except_clause :
10771078 EXCEPT
10781079 {
1079- // FIXME
1080+ $$ = nil
1081+ $<str>$ = " "
10801082 }
10811083| EXCEPT test
10821084 {
1083- // FIXME
1085+ $$ = $2
1086+ $<str>$ = " "
10841087 }
10851088| EXCEPT test AS NAME
10861089 {
1087- // FIXME
1090+ $$ = $2
1091+ $<str>$ = $4
10881092 }
10891093
10901094stmts :
0 commit comments