diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-02-10 11:03:29 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-02-10 18:10:57 +0000 |
commit | a3a343c8853cb0967b21e8da23a829665208b25d (patch) | |
tree | f7b1c76a4f7c2fd230b731c7cef8ecffd18beb0f /gcc | |
parent | 1a2c0911f0e818328a8909b1f5ba0685b6eca351 (diff) | |
download | gcc-a3a343c8853cb0967b21e8da23a829665208b25d.zip gcc-a3a343c8853cb0967b21e8da23a829665208b25d.tar.gz gcc-a3a343c8853cb0967b21e8da23a829665208b25d.tar.bz2 |
Give ParseRestriction option to allow for null parse_expr.
The null_denotion function expects to find the beginning of an expression
but breaks can be empty and the parser will fail with unexpected ';'.
Fixes #225
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 12 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse.h | 1 |
2 files changed, 9 insertions, 4 deletions
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index d391304..18e6983 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7437,7 +7437,10 @@ Parser<ManagedTokenSource>::parse_break_expr ( } // parse break return expression if it exists - std::unique_ptr<AST::Expr> return_expr = parse_expr (); + ParseRestrictions restrictions; + restrictions.expr_can_be_null = true; + std::unique_ptr<AST::Expr> return_expr + = parse_expr (std::vector<AST::Attribute> (), restrictions); return std::unique_ptr<AST::BreakExpr> ( new AST::BreakExpr (locus, std::move (label), std::move (return_expr), @@ -12461,9 +12464,10 @@ Parser<ManagedTokenSource>::null_denotation ( // array definition expr (not indexing) return parse_array_expr (std::move (outer_attrs), true); default: - rust_error_at (tok->get_locus (), - "found unexpected token %qs in null denotation", - tok->get_token_description ()); + if (!restrictions.expr_can_be_null) + rust_error_at (tok->get_locus (), + "found unexpected token %qs in null denotation", + tok->get_token_description ()); return nullptr; } } diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 873b55e9..e691c9e 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -82,6 +82,7 @@ struct ParseRestrictions /* Whether the expression was entered from a unary expression - prevents stuff * like struct exprs being parsed from a dereference. */ bool entered_from_unary = false; + bool expr_can_be_null = false; }; // Parser implementation for gccrs. |