aboutsummaryrefslogtreecommitdiff
path: root/gdb/rust-parse.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-06-11 08:14:09 -0600
committerTom Tromey <tom@tromey.com>2021-06-11 08:14:09 -0600
commit48ec4c05c68bfec4b79e95807bd82e0df4634a6c (patch)
tree27c232057de54ea162dcdbfcf7466063119f19d9 /gdb/rust-parse.c
parent2748c1b17e37c5acfae9d5dbcc627350c3d38167 (diff)
downloadbinutils-48ec4c05c68bfec4b79e95807bd82e0df4634a6c.zip
binutils-48ec4c05c68bfec4b79e95807bd82e0df4634a6c.tar.gz
binutils-48ec4c05c68bfec4b79e95807bd82e0df4634a6c.tar.bz2
Implement Rust raw identifiers
This patch implements Rust raw identifiers in the lexer in gdb. There was an earlier patch to do this, but the contributor didn't reply to my email asking whether he had sorted out his copyright assignment. This is relatively straightforward, but a small test suite addition was needd to ensure that the new test is skipped on older versions of rustc -- ones that predate the introduction of raw identifiers. gdb/ChangeLog 2021-06-11 Tom Tromey <tom@tromey.com> PR rust/23427 * rust-parse.c (rust_parser::lex_identifier): Handle raw identifiers. (rust_lex_tests): Add raw identifier tests. gdb/testsuite/ChangeLog 2021-06-11 Tom Tromey <tom@tromey.com> PR rust/23427 * lib/rust-support.exp (rust_compiler_version): New caching proc. * gdb.rust/rawids.exp: New file. * gdb.rust/rawids.rs: New file.
Diffstat (limited to 'gdb/rust-parse.c')
-rw-r--r--gdb/rust-parse.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 2f2afcf..539e1c8 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -747,12 +747,21 @@ rust_identifier_start_p (char c)
int
rust_parser::lex_identifier ()
{
- const char *start = pstate->lexptr;
unsigned int length;
const struct token_info *token;
int i;
int is_gdb_var = pstate->lexptr[0] == '$';
+ bool is_raw = false;
+ if (pstate->lexptr[0] == 'r'
+ && pstate->lexptr[1] == '#'
+ && rust_identifier_start_p (pstate->lexptr[2]))
+ {
+ is_raw = true;
+ pstate->lexptr += 2;
+ }
+
+ const char *start = pstate->lexptr;
gdb_assert (rust_identifier_start_p (pstate->lexptr[0]));
++pstate->lexptr;
@@ -769,13 +778,16 @@ rust_parser::lex_identifier ()
length = pstate->lexptr - start;
token = NULL;
- for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
+ if (!is_raw)
{
- if (length == strlen (identifier_tokens[i].name)
- && strncmp (identifier_tokens[i].name, start, length) == 0)
+ for (i = 0; i < ARRAY_SIZE (identifier_tokens); ++i)
{
- token = &identifier_tokens[i];
- break;
+ if (length == strlen (identifier_tokens[i].name)
+ && strncmp (identifier_tokens[i].name, start, length) == 0)
+ {
+ token = &identifier_tokens[i];
+ break;
+ }
}
}
@@ -789,6 +801,7 @@ rust_parser::lex_identifier ()
}
}
else if (token == NULL
+ && !is_raw
&& (strncmp (start, "thread", length) == 0
|| strncmp (start, "task", length) == 0)
&& space_then_number (pstate->lexptr))
@@ -2300,6 +2313,13 @@ rust_lex_tests (void)
rust_lex_stringish_test (&parser, "hibob", "hibob", IDENT);
rust_lex_stringish_test (&parser, "hibob__93", "hibob__93", IDENT);
rust_lex_stringish_test (&parser, "thread", "thread", IDENT);
+ rust_lex_stringish_test (&parser, "r#true", "true", IDENT);
+
+ const int expected1[] = { IDENT, DECIMAL_INTEGER, 0 };
+ rust_lex_test_sequence (&parser, "r#thread 23", ARRAY_SIZE (expected1),
+ expected1);
+ const int expected2[] = { IDENT, '#', 0 };
+ rust_lex_test_sequence (&parser, "r#", ARRAY_SIZE (expected2), expected2);
rust_lex_stringish_test (&parser, "\"string\"", "string", STRING);
rust_lex_stringish_test (&parser, "\"str\\ting\"", "str\ting", STRING);