Skip to content

Commit 45d8431

Browse files
authored
Fix deindentation with triple strings like """\n$x a""" (#179)
When an interpolation occurs at the beginning of a line without any preceding whitespace this counts as zeroing out the common prefix of indentation.
1 parent 6a113fc commit 45d8431

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/parser.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,11 @@ function parse_string(ps::ParseState, raw::Bool)
31813181
k = kind(t)
31823182
if k == K"$"
31833183
@assert !raw # The lexer detects raw strings separately
3184+
if prev_chunk_newline
3185+
# """\n$x\n a""" ==> (string-s x "\n" " a")
3186+
indent_ref_i = first_byte(t)
3187+
indent_ref_len = 0
3188+
end
31843189
bump(ps, TRIVIA_FLAG)
31853190
k = peek(ps)
31863191
if k == K"("

test/parser.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,7 @@ tests = [
816816
((v=v"1.8",), "[\n ;; \n ]") => "(ncat-2)"
817817
((v=v"1.7",), "[;;]") => "(ncat-2 (error))"
818818
# parse_string
819+
"\"\"\"\n\$x\n a\"\"\"" => "(string-s x \"\\n\" \" a\")"
819820
"\"a \$(x + y) b\"" => "(string \"a \" (call-i x + y) \" b\")"
820821
"\"hi\$(\"ho\")\"" => "(string \"hi\" (string \"ho\"))"
821822
"\"a \$foo b\"" => "(string \"a \" foo \" b\")"

0 commit comments

Comments
 (0)