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

Method parse_set_class

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

Parse a standard character class consisting primarily of characters or character ranges, but can also contain nested character classes of any type (sans `.`). This assumes the parser is positioned at the opening `[`. If parsing is successful, then the parser is advanced to the position immediately following the closing `]`.

(&self)

Source from the content-addressed store, hash-verified

1740 /// is successful, then the parser is advanced to the position immediately
1741 /// following the closing `]`.
1742 fn parse_set_class(&self) -> Result<ast::Class> {
1743 assert_eq!(self.char(), '[');
1744
1745 let mut union = ast::ClassSetUnion {
1746 span: self.span(),
1747 items: vec![],
1748 };
1749 loop {
1750 self.bump_space();
1751 if self.is_eof() {
1752 return Err(self.unclosed_class_error());
1753 }
1754 match self.char() {
1755 '[' => {
1756 // If we've already parsed the opening bracket, then
1757 // attempt to treat this as the beginning of an ASCII
1758 // class. If ASCII class parsing fails, then the parser
1759 // backs up to `[`.
1760 if !self.parser().stack_class.borrow().is_empty() {
1761 if let Some(cls) = self.maybe_parse_ascii_class() {
1762 union.push(ast::ClassSetItem::Ascii(cls));
1763 continue;
1764 }
1765 }
1766 union = self.push_class_open(union)?;
1767 }
1768 ']' => {
1769 match self.pop_class(union)? {
1770 Either::Left(nested_union) => { union = nested_union; }
1771 Either::Right(class) => return Ok(class),
1772 }
1773 }
1774 '&' if self.peek() == Some('&') => {
1775 assert!(self.bump_if("&&"));
1776 union = self.push_class_op(
1777 ast::ClassSetBinaryOpKind::Intersection, union);
1778 }
1779 '-' if self.peek() == Some('-') => {
1780 assert!(self.bump_if("--"));
1781 union = self.push_class_op(
1782 ast::ClassSetBinaryOpKind::Difference, union);
1783 }
1784 '~' if self.peek() == Some('~') => {
1785 assert!(self.bump_if("~~"));
1786 union = self.push_class_op(
1787 ast::ClassSetBinaryOpKind::SymmetricDifference, union);
1788 }
1789 _ => {
1790 union.push(self.parse_set_class_range()?);
1791 }
1792 }
1793 }
1794 }
1795
1796 /// Parse a single primitive item in a character class set. The item to
1797 /// be parsed can either be one of a simple literal character, a range

Callers 1

parse_with_commentsMethod · 0.80

Calls 14

bump_spaceMethod · 0.80
unclosed_class_errorMethod · 0.80
parserMethod · 0.80
push_class_openMethod · 0.80
peekMethod · 0.80
push_class_opMethod · 0.80
parse_set_class_rangeMethod · 0.80
spanMethod · 0.45
is_eofMethod · 0.45
charMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected