Rename the unescaping functions.

`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string`
becomes `unescape_mixed`. Because rfc3349 will mean that C string
literals will no longer be the only mixed utf8 literals.
This commit is contained in:
Nicholas Nethercote 2024-01-24 15:24:58 +11:00
parent 5e5aa6d556
commit 86f371ed59
9 changed files with 45 additions and 42 deletions

View file

@ -400,7 +400,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
.with_code(error_code!(E0762))
.emit()
}
self.cook_quoted(token::Char, Mode::Char, start, end, 1, 1) // ' '
self.cook_unicode(token::Char, Mode::Char, start, end, 1, 1) // ' '
}
rustc_lexer::LiteralKind::Byte { terminated } => {
if !terminated {
@ -412,7 +412,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
.with_code(error_code!(E0763))
.emit()
}
self.cook_quoted(token::Byte, Mode::Byte, start, end, 2, 1) // b' '
self.cook_unicode(token::Byte, Mode::Byte, start, end, 2, 1) // b' '
}
rustc_lexer::LiteralKind::Str { terminated } => {
if !terminated {
@ -424,7 +424,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
.with_code(error_code!(E0765))
.emit()
}
self.cook_quoted(token::Str, Mode::Str, start, end, 1, 1) // " "
self.cook_unicode(token::Str, Mode::Str, start, end, 1, 1) // " "
}
rustc_lexer::LiteralKind::ByteStr { terminated } => {
if !terminated {
@ -436,7 +436,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
.with_code(error_code!(E0766))
.emit()
}
self.cook_quoted(token::ByteStr, Mode::ByteStr, start, end, 2, 1) // b" "
self.cook_unicode(token::ByteStr, Mode::ByteStr, start, end, 2, 1) // b" "
}
rustc_lexer::LiteralKind::CStr { terminated } => {
if !terminated {
@ -448,13 +448,13 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
.with_code(error_code!(E0767))
.emit()
}
self.cook_c_string(token::CStr, Mode::CStr, start, end, 2, 1) // c" "
self.cook_mixed(token::CStr, Mode::CStr, start, end, 2, 1) // c" "
}
rustc_lexer::LiteralKind::RawStr { n_hashes } => {
if let Some(n_hashes) = n_hashes {
let n = u32::from(n_hashes);
let kind = token::StrRaw(n_hashes);
self.cook_quoted(kind, Mode::RawStr, start, end, 2 + n, 1 + n) // r##" "##
self.cook_unicode(kind, Mode::RawStr, start, end, 2 + n, 1 + n) // r##" "##
} else {
self.report_raw_str_error(start, 1);
}
@ -463,7 +463,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
if let Some(n_hashes) = n_hashes {
let n = u32::from(n_hashes);
let kind = token::ByteStrRaw(n_hashes);
self.cook_quoted(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n) // br##" "##
self.cook_unicode(kind, Mode::RawByteStr, start, end, 3 + n, 1 + n) // br##" "##
} else {
self.report_raw_str_error(start, 2);
}
@ -472,7 +472,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
if let Some(n_hashes) = n_hashes {
let n = u32::from(n_hashes);
let kind = token::CStrRaw(n_hashes);
self.cook_c_string(kind, Mode::RawCStr, start, end, 3 + n, 1 + n) // cr##" "##
self.cook_mixed(kind, Mode::RawCStr, start, end, 3 + n, 1 + n) // cr##" "##
} else {
self.report_raw_str_error(start, 2);
}
@ -735,7 +735,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
}
}
fn cook_quoted(
fn cook_unicode(
&self,
kind: token::LitKind,
mode: Mode,
@ -745,13 +745,13 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
postfix_len: u32,
) -> (token::LitKind, Symbol) {
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
unescape::unescape_literal(src, mode, &mut |span, result| {
unescape::unescape_unicode(src, mode, &mut |span, result| {
callback(span, result.map(drop))
})
})
}
fn cook_c_string(
fn cook_mixed(
&self,
kind: token::LitKind,
mode: Mode,
@ -761,7 +761,7 @@ impl<'sess, 'src> StringReader<'sess, 'src> {
postfix_len: u32,
) -> (token::LitKind, Symbol) {
self.cook_common(kind, mode, start, end, prefix_len, postfix_len, |src, mode, callback| {
unescape::unescape_c_string(src, mode, &mut |span, result| {
unescape::unescape_mixed(src, mode, &mut |span, result| {
callback(span, result.map(drop))
})
})