From cb9998216d76ccc62b45fcf01b3a0928a026f7ed Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 9 Feb 2021 15:28:03 +0000 Subject: Fix parse of LoopExpr as part of a normal expression For example this fixes the form of: let x = loop { ... }; Fixes #219 --- gcc/rust/parse/rust-parse-impl.h | 29 ++++++++++++++++++++++++----- gcc/rust/parse/rust-parse.h | 7 +++---- 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 277cd8b..d391304 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7827,14 +7827,30 @@ Parser::parse_if_let_expr ( template std::unique_ptr Parser::parse_loop_expr ( - std::vector outer_attrs, AST::LoopLabel label) + std::vector outer_attrs, AST::LoopLabel label, + bool pratt_parse) { Location locus = Linemap::unknown_location (); - if (label.is_error ()) - locus = lexer.peek_token ()->get_locus (); + if (!pratt_parse) + { + if (label.is_error ()) + locus = lexer.peek_token ()->get_locus (); + else + locus = label.get_locus (); + + if (!skip_token (LOOP)) + { + skip_after_end_block (); + return nullptr; + } + } else - locus = label.get_locus (); - skip_token (LOOP); + { + if (label.is_error ()) + locus = lexer.peek_token ()->get_locus () - 1; + else + locus = label.get_locus (); + } // parse loop body, which is required std::unique_ptr loop_body = parse_block_expr (); @@ -12435,6 +12451,9 @@ Parser::null_denotation ( // if expr return parse_if_expr (std::move (outer_attrs), true); } + case LOOP: + return parse_loop_expr (std::move (outer_attrs), AST::LoopLabel::error (), + true); case MATCH_TOK: // also an expression with block return parse_match_expr (std::move (outer_attrs), true); diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index b811c77..873b55e9 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -500,10 +500,9 @@ private: parse_if_let_expr (std::vector outer_attrs = std::vector (), bool pratt_parse = false); - std::unique_ptr - parse_loop_expr (std::vector outer_attrs - = std::vector (), - AST::LoopLabel label = AST::LoopLabel::error ()); + std::unique_ptr parse_loop_expr ( + std::vector outer_attrs = std::vector (), + AST::LoopLabel label = AST::LoopLabel::error (), bool pratt_parse = false); std::unique_ptr parse_while_loop_expr (std::vector outer_attrs = std::vector (), -- cgit v1.1