makepad_live_tokenizer/
char_ext.rs

1/// Extension methods for `char`.
2/// 
3/// These methods assume that all identifiers are ASCII. This is not actually the case for Rust,
4/// which identifiers follow the specification in Unicode Standard Annex #31. We intend to
5/// implement this properly in the future, but doing so requires generating several large Unicode
6/// character tables, which why we've held off from this for now. 
7pub trait CharExt {
8    /// Checks if `char` is the start of an identifier.
9    fn is_identifier_start(&self) -> bool;
10
11    /// Checks if `char` is the continuation of an identifier.
12    /// 
13    /// Note that this method assumes all identifiers are ASCII.
14    fn is_identifier_continue(&self) -> bool;
15}
16
17impl CharExt for char {
18    fn is_identifier_start(&self) -> bool {
19        matches!(*self, 'A'..='Z' | '_' | 'a'..='z')
20    }
21
22    fn is_identifier_continue(&self) -> bool {
23        matches!(*self, '0'..='9' | 'A'..='Z' | '_' | 'a'..='z')
24    }
25}