aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/lex/rust-lex.cc
diff options
context:
space:
mode:
authorliushuyu <liushuyu011@gmail.com>2022-06-07 00:57:43 -0600
committerliushuyu <liushuyu011@gmail.com>2022-06-07 01:17:37 -0600
commit46e248fb7fe7af696f5bd331f1b981cfe2ffca76 (patch)
tree87ae2e67d3bd298ebc13055ededa390734baa68b /gcc/rust/lex/rust-lex.cc
parent957914b4284213b1d72c9c4210892367acaf1419 (diff)
downloadgcc-46e248fb7fe7af696f5bd331f1b981cfe2ffca76.zip
gcc-46e248fb7fe7af696f5bd331f1b981cfe2ffca76.tar.gz
gcc-46e248fb7fe7af696f5bd331f1b981cfe2ffca76.tar.bz2
rust/lex: skip broken string expression ...
... when the matching quote is not found on the same line this could unstuck the string parser when the parser could not advance the parsing position
Diffstat (limited to 'gcc/rust/lex/rust-lex.cc')
-rw-r--r--gcc/rust/lex/rust-lex.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc
index ea09ac2..023b676 100644
--- a/gcc/rust/lex/rust-lex.cc
+++ b/gcc/rust/lex/rust-lex.cc
@@ -1856,6 +1856,35 @@ Lexer::parse_raw_identifier (Location loc)
}
}
+// skip broken string input (unterminated strings)
+void
+Lexer::skip_broken_string_input (int current_char)
+{
+ while (current_char != '"' && current_char != EOF)
+ {
+ if (current_char == '\n')
+ {
+ current_line++;
+ current_column = 1;
+ }
+ else
+ {
+ current_column++;
+ }
+ skip_input ();
+ current_char = peek_input ();
+ }
+ if (current_char == '"')
+ {
+ current_column++;
+
+ skip_input ();
+ current_char = peek_input ();
+ }
+ rust_debug ("skipped to %d:%d due to bad quotes", current_line,
+ current_column);
+}
+
// Parses a unicode string.
TokenPtr
Lexer::parse_string (Location loc)
@@ -1903,6 +1932,9 @@ Lexer::parse_string (Location loc)
if (current_char32.value == '\n')
{
rust_error_at (get_current_location (), "unended string literal");
+ // by this point, the parser will stuck at this position due to
+ // undetermined string termination. we now need to unstuck the parser
+ skip_broken_string_input (current_char32.value);
}
else if (current_char32.value == '"')
{