MCPcopy Create free account
hub / github.com/davidblewett/rure-python / parse_set_class_range

Method parse_set_class_range

regex/regex-syntax/src/ast/parse.rs:1804–1839  ·  view source on GitHub ↗

Parse a single primitive item in a character class set. The item to be parsed can either be one of a simple literal character, a range between two simple literal characters or a "primitive" character class like \w or \p{Greek}. If an invalid escape is found, or if a character class is found where a simple literal is expected (e.g., in a range), then an error is returned.

(&self)

Source from the content-addressed store, hash-verified

1802 /// a simple literal is expected (e.g., in a range), then an error is
1803 /// returned.
1804 fn parse_set_class_range(&self) -> Result<ast::ClassSetItem> {
1805 let prim1 = self.parse_set_class_item()?;
1806 self.bump_space();
1807 if self.is_eof() {
1808 return Err(self.unclosed_class_error());
1809 }
1810 // If the next char isn't a `-`, then we don't have a range.
1811 // There are two exceptions. If the char after a `-` is a `]`, then
1812 // `-` is interpreted as a literal `-`. Alternatively, if the char
1813 // after a `-` is a `-`, then `--` corresponds to a "difference"
1814 // operation.
1815 if self.char() != '-'
1816 || self.peek_space() == Some(']')
1817 || self.peek_space() == Some('-')
1818 {
1819 return prim1.into_class_set_item(self);
1820 }
1821 // OK, now we're parsing a range, so bump past the `-` and parse the
1822 // second half of the range.
1823 if !self.bump_and_bump_space() {
1824 return Err(self.unclosed_class_error());
1825 }
1826 let prim2 = self.parse_set_class_item()?;
1827 let range = ast::ClassSetRange {
1828 span: Span::new(prim1.span().start, prim2.span().end),
1829 start: prim1.into_class_literal(self)?,
1830 end: prim2.into_class_literal(self)?,
1831 };
1832 if !range.is_valid() {
1833 return Err(self.error(
1834 range.span,
1835 ast::ErrorKind::ClassRangeInvalid,
1836 ));
1837 }
1838 Ok(ast::ClassSetItem::Range(range))
1839 }
1840
1841 /// Parse a single item in a character class as a primitive, where the
1842 /// primitive either consists of a verbatim literal or a single escape

Callers 1

parse_set_classMethod · 0.80

Calls 12

parse_set_class_itemMethod · 0.80
bump_spaceMethod · 0.80
unclosed_class_errorMethod · 0.80
peek_spaceMethod · 0.80
into_class_set_itemMethod · 0.80
bump_and_bump_spaceMethod · 0.80
into_class_literalMethod · 0.80
is_validMethod · 0.80
is_eofMethod · 0.45
charMethod · 0.45
spanMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected