Skip to content

Commit 88f445a

Browse files
authored
fix JuliaLang#38501, wrap interpolated literal strings in :string exprs (JuliaLang#38692)
1 parent b78e505 commit 88f445a

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

src/julia-parser.scm

+4-1
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,10 @@
22632263
(loop (read-char p) b e 0))))
22642264

22652265
((and (eqv? c #\$) (not raw))
2266-
(let ((ex (parse-interpolate s)))
2266+
(let* ((ex (parse-interpolate s))
2267+
;; wrap interpolated literal strings in (string ) so we can
2268+
;; distinguish them from the surrounding text (issue #38501)
2269+
(ex (if (string? ex) `(string ,ex) ex)))
22672270
(loop (read-char p)
22682271
(open-output-string)
22692272
(list* ex (io.tostring! b) e)

src/julia-syntax.scm

+7-1
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,13 @@
23082308
'bracescat (lambda (e) (error "{ } matrix syntax is discontinued"))
23092309

23102310
'string
2311-
(lambda (e) (expand-forms `(call (top string) ,@(cdr e))))
2311+
(lambda (e)
2312+
(expand-forms
2313+
`(call (top string) ,@(map (lambda (s)
2314+
(if (and (pair? s) (eq? (car s) 'string))
2315+
(cadr s)
2316+
s))
2317+
(cdr e)))))
23122318

23132319
'|::|
23142320
(lambda (e)

test/show.jl

+2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ end
152152
@test_repr ":(:(:(x)))"
153153
@test_repr "-\"\""
154154
@test_repr "-(<=)"
155+
@test_repr "\$x"
156+
@test_repr "\$(\"x\")"
155157

156158
# order of operations
157159
@test_repr "x + y * z"

test/syntax.jl

+3
Original file line numberDiff line numberDiff line change
@@ -2642,3 +2642,6 @@ end
26422642
@test ncalls_in_lowered(quote a, _... = b, c end, GlobalRef(Base, :rest)) == 0
26432643
@test ncalls_in_lowered(quote a, _... = (b...,) end, GlobalRef(Base, :rest)) == 0
26442644
end
2645+
2646+
# issue #38501
2647+
@test :"a $b $("str") c" == Expr(:string, "a ", :b, " ", Expr(:string, "str"), " c")

0 commit comments

Comments
 (0)