Skip to content

Commit c808a70

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

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
@@ -75,6 +75,10 @@ end
7575
Diagnostic(6, 9, :error, "invalid octal escape sequence")
7676
@test diagnostic("x = '\\k'") ==
7777
Diagnostic(6, 7, :error, "invalid escape sequence")
78+
@test diagnostic("'\\", allow_multiple=true) == [
79+
Diagnostic(2, 2, :error, "invalid escape sequence"),
80+
Diagnostic(3, 2, :error, "unterminated character literal")
81+
]
7882

7983
# String
8084
@test diagnostic("x = \"abc\\xq\"") ==

test/parser_api.jl

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

162162
@test kind(JuliaSyntax.Token()) == K"None"
163+
164+
@test tokensplit("'\\") == [
165+
K"'" => "'",
166+
K"ErrorInvalidEscapeSequence" => "\\",
167+
K"error" => ""
168+
]
163169
end

0 commit comments

Comments
 (0)