@@ -66,14 +66,15 @@ func applyTrailers(expr ast.Expr, trailers []ast.Expr) ast.Expr {
66
66
identifiers []ast.Identifier
67
67
ifstmt *ast.If
68
68
lastif *ast.If
69
+ exchandlers []*ast.ExceptHandler
69
70
}
70
71
71
72
%type <obj> strings
72
73
%type <mod> inputs file_input single_input eval_input
73
74
%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
75
76
%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
77
78
%type <exprs> exprlist testlistraw comp_if comp_iter expr_or_star_exprs test_or_star_exprs tests test_colon_tests trailers
78
79
%type <cmpop> comp_op
79
80
%type <comma> optional_comma
@@ -86,6 +87,7 @@ func applyTrailers(expr ast.Expr, trailers []ast.Expr) ast.Expr {
86
87
%type <alias> dotted_as_name import_as_name
87
88
%type <aliases> dotted_as_names import_as_names import_from_arg
88
89
%type <ifstmt> elifs
90
+ %type <exchandlers> except_clauses
89
91
90
92
%token NEWLINE
91
93
%token ENDMARKER
@@ -833,8 +835,7 @@ import_as_name:
833
835
}
834
836
| NAME AS NAME
835
837
{
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 )}
838
839
}
839
840
840
841
dotted_as_name :
@@ -844,8 +845,7 @@ dotted_as_name:
844
845
}
845
846
| dotted_name AS NAME
846
847
{
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 )}
849
849
}
850
850
851
851
import_as_names :
@@ -927,23 +927,23 @@ assert_stmt:
927
927
compound_stmt :
928
928
if_stmt
929
929
{
930
- // FIXME
930
+ $$ = $1
931
931
}
932
932
| while_stmt
933
933
{
934
934
$$ = $1
935
935
}
936
936
| for_stmt
937
937
{
938
- // FIXME
938
+ $$ = $1
939
939
}
940
940
| try_stmt
941
941
{
942
- // FIXME
942
+ $$ = $1
943
943
}
944
944
| with_stmt
945
945
{
946
- // FIXME
946
+ $$ = $1
947
947
}
948
948
| funcdef
949
949
{
@@ -1021,29 +1021,30 @@ for_stmt:
1021
1021
1022
1022
except_clauses :
1023
1023
{
1024
- // FIXME
1024
+ $$ = nil
1025
1025
}
1026
1026
| except_clauses except_clause ' :' suite
1027
1027
{
1028
- // FIXME
1028
+ exc := &ast.ExceptHandler{Pos: $<pos>$, ExprType: $2 , Name: ast.Identifier($<str>2 ), Body: $4 }
1029
+ $$ = append($$ , exc)
1029
1030
}
1030
1031
1031
1032
try_stmt :
1032
1033
TRY ' :' suite except_clauses
1033
1034
{
1034
- // FIXME
1035
+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 }
1035
1036
}
1036
1037
| TRY ' :' suite except_clauses ELSE ' :' suite
1037
1038
{
1038
- // FIXME
1039
+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Orelse: $7 }
1039
1040
}
1040
1041
| TRY ' :' suite except_clauses FINALLY ' :' suite
1041
1042
{
1042
- // FIXME
1043
+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Finalbody: $7 }
1043
1044
}
1044
1045
| TRY ' :' suite except_clauses ELSE ' :' suite FINALLY ' :' suite
1045
1046
{
1046
- // FIXME
1047
+ $$ = &ast.Try{StmtBase: ast.StmtBase{$<pos>$}, Body: $3 , Handlers: $4 , Orelse: $7 , Finalbody: $10 }
1047
1048
}
1048
1049
1049
1050
with_items :
@@ -1076,15 +1077,18 @@ with_item:
1076
1077
except_clause :
1077
1078
EXCEPT
1078
1079
{
1079
- // FIXME
1080
+ $$ = nil
1081
+ $<str>$ = " "
1080
1082
}
1081
1083
| EXCEPT test
1082
1084
{
1083
- // FIXME
1085
+ $$ = $2
1086
+ $<str>$ = " "
1084
1087
}
1085
1088
| EXCEPT test AS NAME
1086
1089
{
1087
- // FIXME
1090
+ $$ = $2
1091
+ $<str>$ = $4
1088
1092
}
1089
1093
1090
1094
stmts :
0 commit comments