Skip to content

Commit bf6d797

Browse files
Kristoffer Carlssonc42f
andcommitted
fix parsing '\\ to not error in the validate token step (#233)
Co-authored-by: c42f <[email protected]>
1 parent fb06a26 commit bf6d797

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/literal_parsing.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ function unescape_julia_string(io::IO, str::AbstractString,
243243
escstart = i
244244
i += 1
245245
if i >= endind
246+
emit_diagnostic(diagnostics, escstart:endind-1,
247+
error="invalid escape sequence")
248+
had_error = true
246249
break
247250
end
248251
c = str[i]

test/diagnostics.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ end
3939
Diagnostic(6, 9, :error, "invalid octal escape sequence")
4040
@test diagnostic("x = '\\k'") ==
4141
Diagnostic(6, 7, :error, "invalid escape sequence")
42+
@test diagnostic("'\\", allow_multiple=true) == [
43+
Diagnostic(2, 2, :error, "invalid escape sequence"),
44+
Diagnostic(3, 2, :error, "unterminated character literal")
45+
]
4246

4347
# String
4448
@test diagnostic("x = \"abc\\xq\"") ==

test/parser_api.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,10 @@ tokensplit(str) = [kind(tok) => untokenize(tok, str) for tok in tokenize(str)]
138138
]
139139

140140
@test kind(JuliaSyntax.Token()) == K"None"
141+
142+
@test tokensplit("'\\") == [
143+
K"'" => "'",
144+
K"ErrorInvalidEscapeSequence" => "\\",
145+
K"error" => ""
146+
]
141147
end

0 commit comments

Comments
 (0)