aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2022-03-17 22:36:12 -0600
committerTom Tromey <tom@tromey.com>2022-03-28 15:19:47 -0600
commit7685884a38572266216f12069e86f9c7fcdedc14 (patch)
treef1ecea811af8b44d2144325b9d54e2e8267b307a
parenteb3ec1b698275299fe59a9d2268208aaa8277728 (diff)
downloadgdb-7685884a38572266216f12069e86f9c7fcdedc14.zip
gdb-7685884a38572266216f12069e86f9c7fcdedc14.tar.gz
gdb-7685884a38572266216f12069e86f9c7fcdedc14.tar.bz2
Add Rust parser check for end of expression
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.
-rw-r--r--gdb/rust-parse.c6
-rw-r--r--gdb/testsuite/gdb.rust/expr.exp2
2 files changed, 7 insertions, 1 deletions
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 4006df7..7d7d882 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 0c44589..bb0222b 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 ','"