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

Method parse_set_class_open

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

Parses the opening of a character class set. This includes the opening bracket along with `^` if present to indicate negation. This also starts parsing the opening set of unioned items if applicable, since there are special rules applied to certain characters in the opening of a character class. For example, `[^]]` is the class of all characters not equal to `]`. (`]` would need to be escaped in a

(
        &self,
    )

Source from the content-addressed store, hash-verified

1879 ///
1880 /// An error is returned if EOF is found.
1881 fn parse_set_class_open(
1882 &self,
1883 ) -> Result<(ast::ClassBracketed, ast::ClassSetUnion)> {
1884 assert_eq!(self.char(), '[');
1885 let start = self.pos();
1886 if !self.bump_and_bump_space() {
1887 return Err(self.error(
1888 Span::new(start, self.pos()),
1889 ast::ErrorKind::ClassUnclosed,
1890 ));
1891 }
1892
1893 let negated =
1894 if self.char() != '^' {
1895 false
1896 } else {
1897 if !self.bump_and_bump_space() {
1898 return Err(self.error(
1899 Span::new(start, self.pos()),
1900 ast::ErrorKind::ClassUnclosed,
1901 ));
1902 }
1903 true
1904 };
1905 // Accept any number of `-` as literal `-`.
1906 let mut union = ast::ClassSetUnion {
1907 span: self.span(),
1908 items: vec![],
1909 };
1910 while self.char() == '-' {
1911 union.push(ast::ClassSetItem::Literal(ast::Literal {
1912 span: self.span_char(),
1913 kind: ast::LiteralKind::Verbatim,
1914 c: '-',
1915 }));
1916 if !self.bump_and_bump_space() {
1917 return Err(self.error(
1918 Span::new(start, self.pos()),
1919 ast::ErrorKind::ClassUnclosed,
1920 ));
1921 }
1922 }
1923 // If `]` is the *first* char in a set, then interpret it as a literal
1924 // `]`. That is, an empty class is impossible to write.
1925 if union.items.is_empty() && self.char() == ']' {
1926 union.push(ast::ClassSetItem::Literal(ast::Literal {
1927 span: self.span_char(),
1928 kind: ast::LiteralKind::Verbatim,
1929 c: ']',
1930 }));
1931 if !self.bump_and_bump_space() {
1932 return Err(self.error(
1933 Span::new(start, self.pos()),
1934 ast::ErrorKind::ClassUnclosed,
1935 ));
1936 }
1937 }
1938 let set = ast::ClassBracketed {

Callers 1

push_class_openMethod · 0.80

Calls 10

unionFunction · 0.85
bump_and_bump_spaceMethod · 0.80
span_charMethod · 0.80
LiteralClass · 0.70
posMethod · 0.45
errorMethod · 0.45
charMethod · 0.45
spanMethod · 0.45
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected