artichoke_core/regexp.rs
1//! Track `Regexp` global state.
2
3/// Track the state of [`Regexp`] special [global variables] and global
4/// interpreter state.
5///
6/// [`Regexp`]: https://ruby-doc.org/core-3.1.2/Regexp.html
7/// [global variables]: https://ruby-doc.org/core-3.1.2/Regexp.html#class-Regexp-label-Special+global+variables
8pub trait Regexp {
9 /// Concrete error type for errors encountered when manipulating `Regexp`
10 /// state.
11 type Error;
12
13 /// Retrieve the current number of set `Regexp` capture group global
14 /// variables.
15 ///
16 /// `Regexp` global variables like `$1` and `$7` are defined after certain
17 /// `Regexp` matching methods for each capturing group in the regular
18 /// expression.
19 ///
20 /// Per the Ruby documentation:
21 ///
22 /// > `$1`, `$2` and so on contain text matching first, second, etc capture
23 /// > group.
24 ///
25 /// # Errors
26 ///
27 /// If the `Regexp` state is inaccessible, an error is returned.
28 fn capture_group_globals(&self) -> Result<usize, Self::Error>;
29
30 /// Set the current number of set `Regexp` capture group global variables.
31 ///
32 /// `Regexp` global variables like `$1` and `$7` are defined after certain
33 /// `Regexp` matching methods for each capturing group in the regular
34 /// expression.
35 ///
36 /// Per the Ruby documentation:
37 ///
38 /// > `$1`, `$2` and so on contain text matching first, second, etc capture
39 /// > group.
40 ///
41 /// # Errors
42 ///
43 /// If the `Regexp` state is inaccessible, an error is returned.
44 fn set_capture_group_globals(&mut self, count: usize) -> Result<(), Self::Error>;
45
46 /// Clear all `Regexp` state.
47 ///
48 /// # Errors
49 ///
50 /// If the `Regexp` state is inaccessible, an error is returned.
51 fn clear_regexp(&mut self) -> Result<(), Self::Error>;
52}