@@ -951,23 +951,24 @@ static AnyExprV parse_expr75(Lexer& lex) {
951951 return parse_expr80 (lex);
952952}
953953
954- // parse E as / is / !is <type>
954+ // parse E as / is / !is <type> (left-to-right)
955955static AnyExprV parse_expr40 (Lexer& lex) {
956956 AnyExprV lhs = parse_expr75 (lex);
957- if (lex.tok () == tok_as) {
958- SrcLocation loc = lex.cur_location ();
959- lex.next ();
960- AnyTypeV cast_to_type = parse_type_from_tokens (lex);
961- lhs = createV<ast_cast_as_operator>(loc, lhs, cast_to_type);
962- } else if (lex.tok () == tok_is) {
957+ TokenType t = lex.tok ();
958+ while (t == tok_as || t == tok_is) {
963959 SrcLocation loc = lex.cur_location ();
964960 lex.next ();
965961 AnyTypeV rhs_type = parse_type_from_tokens (lex);
966- bool is_negated = lhs->kind == ast_not_null_operator; // `a !is ...`, now lhs = `a!`
967- if (is_negated) {
968- lhs = lhs->as <ast_not_null_operator>()->get_expr ();
962+ if (t == tok_as) {
963+ lhs = createV<ast_cast_as_operator>(loc, lhs, rhs_type);
964+ } else {
965+ bool is_negated = lhs->kind == ast_not_null_operator; // `a !is ...`, now lhs = `a!`
966+ if (is_negated) {
967+ lhs = lhs->as <ast_not_null_operator>()->get_expr ();
968+ }
969+ lhs = createV<ast_is_type_operator>(loc, lhs, rhs_type, is_negated);
969970 }
970- lhs = createV<ast_is_type_operator>(loc, lhs, rhs_type, is_negated );
971+ t = lex. tok ( );
971972 }
972973 return lhs;
973974}
0 commit comments