Skip to content

Commit

Permalink
RFC: strip spaces after backslash-escaped newline
Browse files Browse the repository at this point in the history
This was discussed on Slack with @StefanKarpinski and @BioTurboNick and
the general consensus was that stripping all spaces following a
backslash-escaped newline would make more sense than the current
behavior. One subtle distinction here is whether this stripping should
happen before or after triple-quoted strings. Right now it happens after
detenting so

```julia
"""
  a\
b"""
```

produces `"  ab"`, whereas if it would be the other way around, escaped
newlines would not affect detenting so the spaces preceding the `a`
would be removed.
  • Loading branch information
simeonschaub committed Jun 16, 2021
1 parent c366be5 commit 53ad86c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
if !isempty(st) && peek(st)[2] == '\n'
i = consume_upto!(arg, s, i, j) + 1
_ = popfirst!(st)
while !isempty(st) && peek(st)[2] in (' ', '\t')
i = nextind(str, i)
_ = popfirst!(st)
end
elseif in_double_quotes
isempty(st) && error("unterminated double quote")
k, c′ = peek(st)
Expand Down
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,10 @@
(cond ((eof-object? c))
(preceding-backslash?
(if (not (eqv? c #\newline))
(begin (write-char #\\ out) (write-char c out)))
(begin (write-char #\\ out) (write-char c out))
((define (loop-)
(if (memv (peek-char in) '(#\space #\tab))
(begin (take-char in) (loop-))))))
(loop #f))
((eqv? c #\\) (loop #t))
(else (write-char c out) (loop #f)))))
Expand Down
8 changes: 4 additions & 4 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,7 @@ end
@test "a\
b" == "ab"
@test "a\
b" == "a b"
b" == "ab"
@test raw"a\
b" == "a\\\nb"
@test "a$c\
Expand All @@ -2851,7 +2851,7 @@ b" == "acb"
b""" == "ab"
@test """
a\
b""" == "a b"
b""" == "ab"
@test """
a\
b""" == " ab"
Expand Down Expand Up @@ -2894,7 +2894,7 @@ b" == "acb"
@test `a\
b` == `ab`
@test `a\
b` == `a b`
b` == `ab`
@test `a$c\
b` == `acb`
@test `"a\
Expand All @@ -2910,7 +2910,7 @@ b'` == `$("a\\\nb")`
b``` == `ab`
@test ```
a\
b``` == `a b`
b``` == `ab`
@test ```
a\
b``` == ` ab`
Expand Down

0 comments on commit 53ad86c

Please sign in to comment.