Correctly update newline and indent state in multiline strings

This commit is contained in:
Joshua Warner 2024-12-14 10:39:33 -08:00
parent a15998872d
commit 2dd4fe03f8
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 70 additions and 1 deletions

View file

@ -324,8 +324,10 @@ pub fn parse_str_like_literal<'a>() -> impl Parser<'a, StrLikeLiteral<'a>, EStri
let without_newline = &state.bytes()[0..(segment_parsed_bytes - 1)];
let with_newline = &state.bytes()[0..segment_parsed_bytes];
state.advance_mut(segment_parsed_bytes);
state.advance_mut(segment_parsed_bytes - 1);
state = state.advance_newline();
state = consume_indent(state, indent)?;
state = state.mark_current_indent();
bytes = state.bytes().iter();
if state.bytes().starts_with(b"\"\"\"") {

View file

@ -0,0 +1,54 @@
@0-21 SpaceAfter(
Str(
Block(
[
[
Interpolated(
@5-9 Apply(
@5-8 Record(
Collection {
items: [],
final_comments: [
Newline,
],
},
),
[
@8-9 Var {
module_name: "",
ident: "i",
},
],
Space,
),
),
Plaintext(
"\n",
),
Interpolated(
@13-17 Apply(
@13-16 Record(
Collection {
items: [],
final_comments: [
Newline,
],
},
),
[
@16-17 Var {
module_name: "",
ident: "i",
},
],
Space,
),
),
],
],
),
),
[
Newline,
],
)

View file

@ -0,0 +1,4 @@
"""$({
}i)
$({
}i)"""

View file

@ -484,6 +484,7 @@ mod test_snapshots {
pass/multiline_str_crazyness.expr,
pass/multiline_str_in_backpassing_pats.expr,
pass/multiline_str_in_pat.expr,
pass/multiline_str_interpolation_records.expr,
pass/multiline_str_opt_field.expr,
pass/multiline_string.expr,
pass/multiline_string_in_apply.expr,