From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 84A043858C51; Mon, 28 Mar 2022 21:36:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84A043858C51 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb/gdb-12-branch] Add Rust parser check for end of expression X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/gdb-12-branch X-Git-Oldrev: eb3ec1b698275299fe59a9d2268208aaa8277728 X-Git-Newrev: 7685884a38572266216f12069e86f9c7fcdedc14 Message-Id: <20220328213646.84A043858C51@sourceware.org> Date: Mon, 28 Mar 2022 21:36:46 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Mar 2022 21:36:46 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D7685884a3857= 2266216f12069e86f9c7fcdedc14 commit 7685884a38572266216f12069e86f9c7fcdedc14 Author: Tom Tromey Date: Thu Mar 17 22:36:12 2022 -0600 Add Rust parser check for end of expression =20 I noticed that "print 5," passed in Rust -- the parser wasn't checking that the entire input was used. This patch fixes the problem. This in turn pointed out another bug in the parser, namely that it didn't lex the next token after handling a string token. This is also fixed here. Diff: --- gdb/rust-parse.c | 6 +++++- gdb/testsuite/gdb.rust/expr.exp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c index 4006df7086b..7d7d882872c 100644 --- a/gdb/rust-parse.c +++ b/gdb/rust-parse.c @@ -271,7 +271,10 @@ struct rust_parser operation_up parse_entry_point () { lex (); - return parse_expr (); + operation_up result =3D parse_expr (); + if (current_token !=3D 0) + error (_("Syntax error near '%s'"), pstate->prev_lexptr); + return result; } =20 operation_up parse_tuple (); @@ -2020,6 +2023,7 @@ rust_parser::parse_atom (bool required) =20 case STRING: result =3D parse_string (); + lex (); break; =20 case BYTESTRING: diff --git a/gdb/testsuite/gdb.rust/expr.exp b/gdb/testsuite/gdb.rust/expr.= exp index 0c445897338..bb0222bed4b 100644 --- a/gdb/testsuite/gdb.rust/expr.exp +++ b/gdb/testsuite/gdb.rust/expr.exp @@ -145,3 +145,5 @@ gdb_test "print 0x0 as fn(i64) -> ()" " =3D \\\(\\*mut = fn \\\(i64\\\) -> \\\(\\\)\ gdb_test "print r#" "No symbol 'r' in current context" =20 gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22" + +gdb_test "print 5," "Syntax error near ','"