From: Pedro Alves <pedro@palves.net>
To: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Add Rust parser check for end of expression
Date: Fri, 18 Mar 2022 16:00:31 +0000 [thread overview]
Message-ID: <1cd1981e-658e-dd2f-1ab7-e696dd7ef2ff@palves.net> (raw)
In-Reply-To: <20220318044450.221851-1-tom@tromey.com>
On 2022-03-18 04:44, Tom Tromey wrote:
> 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.
OOC, is the lex-next-token bug something that is also covered by
the added test? It doesn't seem to use strings.
Pedro Alves
> ---
> 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 = parse_expr ();
> + if (current_token != 0)
> + error (_("Syntax error near '%s'"), pstate->prev_lexptr);
> + return result;
> }
>
> operation_up parse_tuple ();
> @@ -2020,6 +2023,7 @@ rust_parser::parse_atom (bool required)
>
> case STRING:
> result = parse_string ();
> + lex ();
> break;
>
> 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) -> ()" " = \\\(\\*mut fn \\\(i64\\\) -> \\\(\\\)\
> gdb_test "print r#" "No symbol 'r' in current context"
>
> gdb_test "printf \"%d %d\\n\", 23+1, 23-1" "24 22"
> +
> +gdb_test "print 5," "Syntax error near ','"
next prev parent reply other threads:[~2022-03-18 16:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-18 4:44 Tom Tromey
2022-03-18 16:00 ` Pedro Alves [this message]
2022-03-18 16:58 ` Tom Tromey
2022-03-28 21:16 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1cd1981e-658e-dd2f-1ab7-e696dd7ef2ff@palves.net \
--to=pedro@palves.net \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).