authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2024-06-11 22:13:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-12 16:49:00-04:00
log0cef727e59d7b0c34756c09f64cbfe4490dcc3e7
tree4cecb36f3903d8c97a9205dd33e7374cdc9b192f
parent44f4abf3805eb457525a474f243b71373b5c3824

More precise error message for unencodable `\u` escapes

The surrogate code points U+D800 to U+DFFF are valid code points but are not Unicode scalar values. This commit makes the error message more accurately reflect what is actually allowed in `\u` escape sequences. From https://www.unicode.org/versions/Unicode15.0.0/ch03.pdf: > D71 High-surrogate code point: A Unicode code point in the range U+D800 to U+DBFF. > D73 Low-surrogate code point: A Unicode code point in the range U+DC00 to U+DFFF. > > 3.9 Unicode Encoding Forms > D76 Unicode scalar value: Any Unicode code point except high-surrogate and low-surrogate code points. Related: #20270

3 files changed, 4 insertions(+), 4 deletions(-)

doc/langref.html.in+2-2
...@@ -728,12 +728,12 @@...@@ -728,12 +728,12 @@
728 </tr>728 </tr>
729 <tr>729 <tr>
730 <th scope="row"><code>\u{NNNNNN}</code></th>730 <th scope="row"><code>\u{NNNNNN}</code></th>
731 <td>hexadecimal Unicode code point UTF-8 encoded (1 or more digits)</td>731 <td>hexadecimal Unicode scalar value UTF-8 encoded (1 or more digits)</td>
732 </tr>732 </tr>
733 </tbody>733 </tbody>
734 </table>734 </table>
735 </div>735 </div>
736 <p>Note that the maximum valid Unicode point is {#syntax#}0x10ffff{#endsyntax#}.</p>736 <p>Note that the maximum valid Unicode scalar value is {#syntax#}0x10ffff{#endsyntax#}.</p>
737 {#header_close#}737 {#header_close#}
738 {#header_open|Multiline String Literals#}738 {#header_open|Multiline String Literals#}
739 <p>739 <p>
lib/std/zig/AstGen.zig+1-1
...@@ -11306,7 +11306,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token...@@ -11306,7 +11306,7 @@ fn failWithStrLitError(astgen: *AstGen, err: std.zig.string_literal.Error, token
11306 return astgen.failOff(11306 return astgen.failOff(
11307 token,11307 token,
11308 offset + @as(u32, @intCast(bad_index)),11308 offset + @as(u32, @intCast(bad_index)),
11309 "unicode escape does not correspond to a valid codepoint",11309 "unicode escape does not correspond to a valid unicode scalar value",
11310 .{},11310 .{},
11311 );11311 );
11312 },11312 },
src/Package/Manifest.zig+1-1
...@@ -522,7 +522,7 @@ const Parse = struct {...@@ -522,7 +522,7 @@ const Parse = struct {
522 try p.appendErrorOff(522 try p.appendErrorOff(
523 token,523 token,
524 offset + @as(u32, @intCast(bad_index)),524 offset + @as(u32, @intCast(bad_index)),
525 "unicode escape does not correspond to a valid codepoint",525 "unicode escape does not correspond to a valid unicode scalar value",
526 .{},526 .{},
527 );527 );
528 },528 },