File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -1687,6 +1687,7 @@ mod tests {
1687
1687
parse_as_expression ( & [ "foo_bar" ] , identifier ! ( "foo_bar" ) ) ;
1688
1688
parse_as_expression ( & [ "MeineSchöneVariable" ] , identifier ! ( "MeineSchöneVariable" ) ) ;
1689
1689
parse_as_expression ( & [ "°" ] , identifier ! ( "°" ) ) ;
1690
+ parse_as_expression ( & [ "Mass_H₂O" ] , identifier ! ( "Mass_H₂O" ) ) ;
1690
1691
}
1691
1692
1692
1693
#[ test]
Original file line number Diff line number Diff line change @@ -171,6 +171,13 @@ fn is_other_allowed_identifier_char(c: char) -> bool {
171
171
c == '%'
172
172
}
173
173
174
+ fn is_subscript_char ( c : char ) -> bool {
175
+ let c_u32 = c as u32 ;
176
+
177
+ // See https://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts#Superscripts_and_subscripts_block
178
+ ( 0x2080 ..=0x209CF ) . contains ( & c_u32)
179
+ }
180
+
174
181
fn is_identifier_start ( c : char ) -> bool {
175
182
unicode_ident:: is_xid_start ( c)
176
183
|| is_numerical_fraction_char ( c)
@@ -182,6 +189,7 @@ fn is_identifier_start(c: char) -> bool {
182
189
183
190
fn is_identifier_continue ( c : char ) -> bool {
184
191
( unicode_ident:: is_xid_continue ( c)
192
+ || is_subscript_char ( c)
185
193
|| is_currency_char ( c)
186
194
|| is_other_allowed_identifier_char ( c) )
187
195
&& !is_exponent_char ( c)
@@ -1049,3 +1057,12 @@ fn test_is_currency_char() {
1049
1057
1050
1058
assert ! ( !is_currency_char( 'E' ) ) ;
1051
1059
}
1060
+
1061
+ #[ test]
1062
+ fn test_is_subscript_char ( ) {
1063
+ assert ! ( is_subscript_char( '₅' ) ) ;
1064
+ assert ! ( is_subscript_char( '₁' ) ) ;
1065
+ assert ! ( is_subscript_char( 'ₓ' ) ) ;
1066
+ assert ! ( is_subscript_char( 'ₘ' ) ) ;
1067
+ assert ! ( is_subscript_char( '₎' ) ) ;
1068
+ }
You can’t perform that action at this time.
0 commit comments