Skip to content

Commit

Permalink
Fix deindentation with triple strings like """\n$x a""" (#179)
Browse files Browse the repository at this point in the history
When an interpolation occurs at the beginning of a line without any
preceding whitespace this counts as zeroing out the common prefix of
indentation.
  • Loading branch information
c42f authored Jan 11, 2023
1 parent 6a113fc commit 45d8431
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3181,6 +3181,11 @@ function parse_string(ps::ParseState, raw::Bool)
k = kind(t)
if k == K"$"
@assert !raw # The lexer detects raw strings separately
if prev_chunk_newline
# """\n$x\n a""" ==> (string-s x "\n" " a")
indent_ref_i = first_byte(t)
indent_ref_len = 0
end
bump(ps, TRIVIA_FLAG)
k = peek(ps)
if k == K"("
Expand Down
1 change: 1 addition & 0 deletions test/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ tests = [
((v=v"1.8",), "[\n ;; \n ]") => "(ncat-2)"
((v=v"1.7",), "[;;]") => "(ncat-2 (error))"
# parse_string
"\"\"\"\n\$x\n a\"\"\"" => "(string-s x \"\\n\" \" a\")"
"\"a \$(x + y) b\"" => "(string \"a \" (call-i x + y) \" b\")"
"\"hi\$(\"ho\")\"" => "(string \"hi\" (string \"ho\"))"
"\"a \$foo b\"" => "(string \"a \" foo \" b\")"
Expand Down

0 comments on commit 45d8431

Please sign in to comment.