Skip to content

Commit 48520d3

Browse files
committed
Check Base.ismalformed instead
and add a test
1 parent 614bfaf commit 48520d3

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/tokenize_utils.jl

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,19 @@ const EOF_CHAR = typemax(Char)
44

55
function is_identifier_char(c::Char)
66
c == EOF_CHAR && return false
7-
return try
8-
Base.is_id_char(c)
9-
catch
10-
false
11-
end
12-
7+
Base.ismalformed(c) && return false
8+
return Base.is_id_char(c)
139
end
1410

1511
function is_identifier_start_char(c::Char)
1612
c == EOF_CHAR && return false
17-
return try
18-
Base.is_id_start_char(c)
19-
catch
20-
false
21-
end
13+
Base.ismalformed(c) && return false
14+
return Base.is_id_start_char(c)
2215
end
2316

2417
# Chars that we will never allow to be part of a valid non-operator identifier
2518
function is_never_id_char(ch::Char)
19+
Base.ismalformed(ch) && return true
2620
cat = Unicode.category_code(ch)
2721
c = UInt32(ch)
2822
return (

test/tokenize.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,4 +909,11 @@ end
909909
@test strtok("a .&&₁ b") == ["a", " ", ".&&", "", " ", "b", ""]
910910
end
911911

912+
@testset "is_identifier[_start]_char" begin
913+
malformed = first("\xe2")
914+
@test Tokenize.is_identifier_char(malformed) == false
915+
@test Tokenize.is_identifier_start_char(malformed) == false
916+
@test Tokenize.is_never_id_char(malformed) == true
917+
end
918+
912919
end

0 commit comments

Comments
 (0)