From 92898b2903528fc3747d561f26df7f6d70d0a3b3 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 11 Feb 2021 11:01:52 +0000 Subject: Fix bug parsing while loop expressions If a while loop is part of an expression it needs to know it does not need to skip token. --- gcc/rust/parse/rust-parse-impl.h | 39 +++++++++++++++++++++++++++++---------- gcc/rust/parse/rust-parse.h | 7 +++---- 2 files changed, 32 insertions(+), 14 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 437a7b5..bd41ce3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2666,7 +2666,7 @@ Parser::parse_generic_params () } std::unique_ptr param ( - new AST::LifetimeParam (std::move (lifetime), + new AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds), std::move (outer_attr), locus)); generic_params.push_back (std::move (param)); @@ -3167,9 +3167,9 @@ Parser::parse_lifetime_param () // TODO: have end token passed in? } - return AST::LifetimeParam (std::move (lifetime), - std::move (lifetime_bounds), - std::move (outer_attr), lifetime_tok->get_locus ()); + return AST::LifetimeParam (std::move (lifetime), std::move (lifetime_bounds), + std::move (outer_attr), + lifetime_tok->get_locus ()); } // Parses type generic parameters. Will also consume any trailing comma. @@ -3698,7 +3698,7 @@ Parser::parse_trait_bound () * handle this) */ std::vector for_lifetimes; if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); + for_lifetimes = parse_for_lifetimes (); // handle TypePath AST::TypePath type_path = parse_type_path (); @@ -7879,14 +7879,30 @@ Parser::parse_loop_expr ( template std::unique_ptr Parser::parse_while_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 (WHILE)) + { + skip_after_end_block (); + return nullptr; + } + } else - locus = label.get_locus (); - skip_token (WHILE); + { + if (label.is_error ()) + locus = lexer.peek_token ()->get_locus () - 1; + else + locus = label.get_locus (); + } // ensure it isn't a while let loop if (lexer.peek_token ()->get_id () == LET) @@ -12454,6 +12470,9 @@ Parser::null_denotation ( case LOOP: return parse_loop_expr (std::move (outer_attrs), AST::LoopLabel::error (), true); + case WHILE: + return parse_while_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 e691c9e..0708068 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -504,10 +504,9 @@ private: 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 (), - AST::LoopLabel label = AST::LoopLabel::error ()); + std::unique_ptr parse_while_loop_expr ( + std::vector outer_attrs = std::vector (), + AST::LoopLabel label = AST::LoopLabel::error (), bool pratt_parse = false); std::unique_ptr parse_while_let_loop_expr (std::vector outer_attrs = std::vector (), -- cgit v1.1