(&mut self)
| 204 | } |
| 205 | |
| 206 | fn parse_unicode_name(&mut self) -> Result<char, LexicalError> { |
| 207 | let start_pos = self.position(); |
| 208 | let Some('{') = self.next_char() else { |
| 209 | return Err(LexicalError::new( |
| 210 | LexicalErrorType::MissingUnicodeLbrace, |
| 211 | TextRange::empty(start_pos), |
| 212 | )); |
| 213 | }; |
| 214 | |
| 215 | let start_pos = self.position(); |
| 216 | let Some(close_idx) = self.source[self.cursor..].find('}') else { |
| 217 | return Err(LexicalError::new( |
| 218 | LexicalErrorType::MissingUnicodeRbrace, |
| 219 | TextRange::empty(self.compute_position(self.source.len())), |
| 220 | )); |
| 221 | }; |
| 222 | |
| 223 | let name_and_ending = self.skip_bytes(close_idx + 1); |
| 224 | let name = &name_and_ending[..name_and_ending.len() - 1]; |
| 225 | |
| 226 | unicode_names2::character(name).ok_or_else(|| { |
| 227 | LexicalError::new( |
| 228 | LexicalErrorType::UnicodeError, |
| 229 | // The cursor is right after the `}` character, so we subtract 1 to get the correct |
| 230 | // range of the unicode name. |
| 231 | TextRange::new( |
| 232 | start_pos, |
| 233 | self.compute_position(self.cursor - '}'.len_utf8()), |
| 234 | ), |
| 235 | ) |
| 236 | }) |
| 237 | } |
| 238 | |
| 239 | /// Parse an escaped character, returning the new character. |
| 240 | fn parse_escaped_char(&mut self) -> Result<Option<EscapedChar>, LexicalError> { |
no test coverage detected