diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-14 14:29:58 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-14 16:34:50 +0100 |
commit | 313e9890d85b688f538fed52d158b4b4f4aea9dc (patch) | |
tree | 1e6b8e44c8c9970894be9ff8b1dde0f727443a3d /gcc/rust/expand | |
parent | 41f402f0b19c7e4f19f8d4d65d15223d2752f302 (diff) | |
download | gcc-313e9890d85b688f538fed52d158b4b4f4aea9dc.zip gcc-313e9890d85b688f538fed52d158b4b4f4aea9dc.tar.gz gcc-313e9890d85b688f538fed52d158b4b4f4aea9dc.tar.bz2 |
parser: Allow parsing stmts without closing semicolon
In certain cases such as macro matching or macro expansion, it is
important to allow the parser to return a valid statement even if no
closing semicolon is given. This commit adds an optional parameter to
the concerned functions to allow a lack of semicolon those special cases
Diffstat (limited to 'gcc/rust/expand')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 22ba1d8a..f131372 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -479,7 +479,7 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser, break; case AST::MacroFragSpec::STMT: - parser.parse_stmt (); + parser.parse_stmt (/* allow_no_semi */ true); break; case AST::MacroFragSpec::LIFETIME: @@ -506,6 +506,9 @@ MacroExpander::match_fragment (Parser<MacroInvocLexer> &parser, return false; } + for (const auto &error : parser.get_errors ()) + error.emit_error (); + // it matches if the parser did not produce errors trying to parse that type // of item return !parser.has_errors (); @@ -825,7 +828,7 @@ transcribe_many_stmts (Parser<MacroInvocLexer> &parser, TokenId &delimiter) // transcriber is an expression, but since the macro call is followed by // a semicolon, it's a valid ExprStmt return parse_many (parser, delimiter, [&parser] () { - auto stmt = parser.parse_stmt (); + auto stmt = parser.parse_stmt (/* allow_no_semi */ true); return AST::SingleASTNode (std::move (stmt)); }); } |