Skip to content

Conversation

@ehuss
Copy link
Contributor

@ehuss ehuss commented Dec 20, 2025

This clarifies the UNICODE_ESCAPE rule that the hex value must be a valid Unicode scalar value. This resolves the problem that a string like "\u{ffffff}" is not a valid token, but the grammar did not reflect that.

I don't see a practical way to define this with character ranges. The resulting expression is huge.

Note that this restriction means that the UNICODE_ESCAPE rule will not match an invalid value, and that all the places where UNICODE_ESCAPE is used, the preceding character must not be \, which forces those rules to fail their match. In turn the only rules that contain UNICODE_ESCAPE have ' or " characters, which won't match any other rule in the grammar, forcing them to fail the parse.

If all those assumptions seem too fragile, then we can consider adding the cut operator just after the \u so that the interpretation is clear that a failure to match the part from the opening brace is an immediate parse failure.

This clarifies the UNICODE_ESCAPE rule that the hex value must be a
valid Unicode scalar value. This resolves the problem that a string like
`"\u{ffffff}"` is not a valid token, but the grammar did not reflect
that.

I don't see a practical way to define this with character ranges. The
resulting expression is huge.

Note that this restriction means that the UNICODE_ESCAPE rule will not
match an invalid value, and that all the places where UNICODE_ESCAPE is
used, the preceding character must *not* be `\`, which forces those
rules to fail their match. In turn the only rules that contain
UNICODE_ESCAPE have `'` or `"` characters, which won't match any other
rule in the grammar, forcing them to fail the parse.

If all those assumptions seem too fragile, then we can consider adding
the [cut operator](rust-lang#2104)
just after the `\u` so that the interpretation is clear that a failure
to match the part from the opening brace is an immediate parse failure.
@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants