aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse/rust-parse-impl.h
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/rust/parse/rust-parse-impl.h
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/rust/parse/rust-parse-impl.h')
-rw-r--r--gcc/rust/parse/rust-parse-impl.h29
1 files changed, 24 insertions, 5 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);