@@ -1088,53 +1088,49 @@ static VALUE parse_simple(parserstate *state) {
1088
1088
| {} <optional>
1089
1089
*/
1090
1090
static VALUE parse_intersection (parserstate * state ) {
1091
- range rg ;
1092
- rg .start = state -> next_token .range .start ;
1093
-
1091
+ position start = state -> next_token .range .start ;
1094
1092
VALUE type = parse_optional (state );
1095
- VALUE intersection_types = rb_ary_new ();
1093
+ if (state -> next_token .type != pAMP ) {
1094
+ return type ;
1095
+ }
1096
1096
1097
+ VALUE intersection_types = rb_ary_new ();
1097
1098
rb_ary_push (intersection_types , type );
1098
1099
while (state -> next_token .type == pAMP ) {
1099
1100
parser_advance (state );
1100
1101
rb_ary_push (intersection_types , parse_optional (state ));
1101
1102
}
1102
-
1103
- rg .end = state -> current_token .range .end ;
1104
-
1105
- if (rb_array_len (intersection_types ) > 1 ) {
1106
- VALUE location = rbs_new_location (state -> buffer , rg );
1107
- type = rbs_intersection (intersection_types , location );
1108
- }
1109
-
1110
- return type ;
1103
+ range rg = (range ) {
1104
+ .start = start ,
1105
+ .end = state -> current_token .range .end ,
1106
+ };
1107
+ VALUE location = rbs_new_location (state -> buffer , rg );
1108
+ return rbs_intersection (intersection_types , location );
1111
1109
}
1112
1110
1113
1111
/*
1114
1112
union ::= {} intersection '|' ... '|' <intersection>
1115
1113
| {} <intersection>
1116
1114
*/
1117
1115
VALUE parse_type (parserstate * state ) {
1118
- range rg ;
1119
- rg .start = state -> next_token .range .start ;
1120
-
1116
+ position start = state -> next_token .range .start ;
1121
1117
VALUE type = parse_intersection (state );
1122
- VALUE union_types = rb_ary_new ();
1118
+ if (state -> next_token .type != pBAR ) {
1119
+ return type ;
1120
+ }
1123
1121
1122
+ VALUE union_types = rb_ary_new ();
1124
1123
rb_ary_push (union_types , type );
1125
1124
while (state -> next_token .type == pBAR ) {
1126
1125
parser_advance (state );
1127
1126
rb_ary_push (union_types , parse_intersection (state ));
1128
1127
}
1129
-
1130
- rg .end = state -> current_token .range .end ;
1131
-
1132
- if (rb_array_len (union_types ) > 1 ) {
1133
- VALUE location = rbs_new_location (state -> buffer , rg );
1134
- type = rbs_union (union_types , location );
1135
- }
1136
-
1137
- return type ;
1128
+ range rg = (range ) {
1129
+ .start = start ,
1130
+ .end = state -> current_token .range .end ,
1131
+ };
1132
+ VALUE location = rbs_new_location (state -> buffer , rg );
1133
+ return rbs_union (union_types , location );
1138
1134
}
1139
1135
1140
1136
/*
0 commit comments