Skip to content

Commit 660ed65

Browse files
authored
Merge pull request #84 from JuliaLang/sp/is_identifier_start_char-nothrow
Non-throwing is_identifier_[start_]char
2 parents 70cb057 + 48520d3 commit 660ed65

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/tokenize_utils.jl

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

55
function is_identifier_char(c::Char)
66
c == EOF_CHAR && return false
7+
Base.ismalformed(c) && return false
78
return Base.is_id_char(c)
89
end
910

1011
function is_identifier_start_char(c::Char)
1112
c == EOF_CHAR && return false
13+
Base.ismalformed(c) && return false
1214
return Base.is_id_start_char(c)
1315
end
1416

1517
# Chars that we will never allow to be part of a valid non-operator identifier
1618
function is_never_id_char(ch::Char)
19+
Base.ismalformed(ch) && return true
1720
cat = Unicode.category_code(ch)
1821
c = UInt32(ch)
1922
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)