support {{ }} brace escaping in string literals#198
Merged
Conversation
literal braces previously required chr(123)/chr(125) because { always
opened interpolation. adopt the universal doubling convention: {{ -> {
and }} -> }, while a single {expr} still interpolates.
the lexer now skips {{ pairs when deciding whether a string interpolates,
and the ir consumer collapses {{/}} to single braces in the string table
(the same choke point that decodes \n, \t, etc).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
literal braces in string literals previously required
chr(123)/chr(125),because a
{always opened interpolation. this adds the universal doublingconvention:
{{emits a literal{and}}emits a literal}, while asingle
{expr}still interpolates as before.two coordinated changes:
{{pairs when scanning a string literal to decide whetherit interpolates (and inside trailing segments of an interpolated string)
{{/}}to single braces in the string table —the same decode pass that already handles
\n,\t,\\, etc.a single
{still means interpolation, so existing code is unaffected(a lone literal
{never worked before anyway).the regenerated
self-host/ir_driveris included so the change takes effecton the native build path, matching how prior frontend changes are committed.
what was tested
tests/cases/test_brace_escaping.pithcovering plain{{}},interpolation, mixed literal+interp, lone
}}, json-ish, and empty{}design notes
}}needs no lexer change: a single}is already literal everywhere outsidean interpolation expression, so doubled close braces survive into the string
table and are collapsed there alongside
{{.