@@ -120,19 +120,57 @@ def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
120
120
def emit_identifier_module (f ):
121
121
f .write ("pub mod identifier {" )
122
122
f .write ("""
123
+
124
+ #[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
125
+ #[allow(non_camel_case_types)]
126
+ /// https://www.unicode.org/reports/tr39/#Identifier_Status_and_Type
127
+ pub enum IdentifierType {
128
+ // Restricted
129
+ Not_Character,
130
+ Deprecated,
131
+ Default_Ignorable,
132
+ Not_NFKC,
133
+ Not_XID,
134
+ Exclusion,
135
+ Obsolete,
136
+ Technical,
137
+ Uncommon_Use,
138
+ Limited_Use,
139
+
140
+ // Allowed
141
+ Inclusion,
142
+ Recommended
143
+ }
123
144
#[inline]
124
145
pub fn identifier_status_allowed(c: char) -> bool {
125
146
// FIXME: do we want to special case ASCII here?
126
147
match c as usize {
127
- _ => super::util::bsearch_range_table(c, identifier_status_table)
148
+ _ => super::util::bsearch_range_table(c, IDENTIFIER_STATUS)
149
+ }
150
+ }
151
+
152
+ #[inline]
153
+ pub fn identifier_type(c: char) -> Option<IdentifierType> {
154
+ // FIXME: do we want to special case ASCII here?
155
+ match c as usize {
156
+ _ => super::util::bsearch_range_value_table(c, IDENTIFIER_TYPE)
128
157
}
129
158
}
130
159
""" )
131
160
132
161
f .write (" // Identifier status table:\n " )
133
162
identifier_status_table = load_properties ("IdentifierStatus.txt" )
134
- emit_table (f , "identifier_status_table " , identifier_status_table ['Allowed' ], "&'static [(char, char)]" , is_pub = False ,
163
+ emit_table (f , "IDENTIFIER_STATUS " , identifier_status_table ['Allowed' ], "&'static [(char, char)]" , is_pub = False ,
135
164
pfun = lambda x : "(%s,%s)" % (escape_char (x [0 ]), escape_char (x [1 ])))
165
+ identifier_type = load_properties ("IdentifierType.txt" )
166
+ type_table = []
167
+ for ty in identifier_type :
168
+ type_table .extend ([(x , y , ty ) for (x , y ) in identifier_type [ty ]])
169
+
170
+ type_table .sort (key = lambda w : w [0 ])
171
+
172
+ emit_table (f , "IDENTIFIER_TYPE" , type_table , "&'static [(char, char, IdentifierType)]" , is_pub = False ,
173
+ pfun = lambda x : "(%s,%s, IdentifierType::%s)" % (escape_char (x [0 ]), escape_char (x [1 ]), x [2 ]))
136
174
f .write ("}\n \n " )
137
175
138
176
def emit_util_mod (f ):
0 commit comments