aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-09 15:28:03 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-10 18:10:57 +0000
commitcb9998216d76ccc62b45fcf01b3a0928a026f7ed (patch)
tree6a2531a63f9b768273d137b5e309a406b59565e5 /gcc
parent9355fb29fc756807a775f9e8f71124071676c8e4 (diff)
downloadgcc-cb9998216d76ccc62b45fcf01b3a0928a026f7ed.zip
gcc-cb9998216d76ccc62b45fcf01b3a0928a026f7ed.tar.gz
gcc-cb9998216d76ccc62b45fcf01b3a0928a026f7ed.tar.bz2
Fix parse of LoopExpr as part of a normal expression
For example this fixes the form of: let x = loop { ... }; Fixes #219
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h29
-rw-r--r--gcc/rust/parse/rust-parse.h7
2 files changed, 27 insertions, 9 deletions
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<ManagedTokenSource>::parse_if_let_expr (
template <typename ManagedTokenSource>
std::unique_ptr<AST::LoopExpr>
Parser<ManagedTokenSource>::parse_loop_expr (
- std::vector<AST::Attribute> outer_attrs, AST::LoopLabel label)
+ std::vector<AST::Attribute> 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<AST::BlockExpr> loop_body = parse_block_expr ();
@@ -12435,6 +12451,9 @@ Parser<ManagedTokenSource>::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<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> (),
bool pratt_parse = false);
- std::unique_ptr<AST::LoopExpr>
- parse_loop_expr (std::vector<AST::Attribute> outer_attrs
- = std::vector<AST::Attribute> (),
- AST::LoopLabel label = AST::LoopLabel::error ());
+ std::unique_ptr<AST::LoopExpr> parse_loop_expr (
+ std::vector<AST::Attribute> outer_attrs = std::vector<AST::Attribute> (),
+ AST::LoopLabel label = AST::LoopLabel::error (), bool pratt_parse = false);
std::unique_ptr<AST::WhileLoopExpr>
parse_while_loop_expr (std::vector<AST::Attribute> outer_attrs
= std::vector<AST::Attribute> (),