Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tokenize_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ const EOF_CHAR = typemax(Char)

function is_identifier_char(c::Char)
c == EOF_CHAR && return false
Base.ismalformed(c) && return false
return Base.is_id_char(c)
end

function is_identifier_start_char(c::Char)
c == EOF_CHAR && return false
Base.ismalformed(c) && return false
return Base.is_id_start_char(c)
end

# Chars that we will never allow to be part of a valid non-operator identifier
function is_never_id_char(ch::Char)
Base.ismalformed(ch) && return true
cat = Unicode.category_code(ch)
c = UInt32(ch)
return (
Expand Down
7 changes: 7 additions & 0 deletions test/tokenize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -909,4 +909,11 @@ end
@test strtok("a .&&₁ b") == ["a", " ", ".&&", "₁", " ", "b", ""]
end

@testset "is_identifier[_start]_char" begin
malformed = first("\xe2")
@test Tokenize.is_identifier_char(malformed) == false
@test Tokenize.is_identifier_start_char(malformed) == false
@test Tokenize.is_never_id_char(malformed) == true
end

end