artichoke_core/
regexp.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! Track `Regexp` global state.

/// Track the state of [`Regexp`] special [global variables] and global
/// interpreter state.
///
/// [`Regexp`]: https://ruby-doc.org/core-3.1.2/Regexp.html
/// [global variables]: https://ruby-doc.org/core-3.1.2/Regexp.html#class-Regexp-label-Special+global+variables
pub trait Regexp {
    /// Concrete error type for errors encountered when manipulating `Regexp`
    /// state.
    type Error;

    /// Retrieve the current number of set `Regexp` capture group global
    /// variables.
    ///
    /// `Regexp` global variables like `$1` and `$7` are defined after certain
    /// `Regexp` matching methods for each capturing group in the regular
    /// expression.
    ///
    /// Per the Ruby documentation:
    ///
    /// > `$1`, `$2` and so on contain text matching first, second, etc capture
    /// > group.
    ///
    /// # Errors
    ///
    /// If the `Regexp` state is inaccessible, an error is returned.
    fn capture_group_globals(&self) -> Result<usize, Self::Error>;

    /// Set the current number of set `Regexp` capture group global variables.
    ///
    /// `Regexp` global variables like `$1` and `$7` are defined after certain
    /// `Regexp` matching methods for each capturing group in the regular
    /// expression.
    ///
    /// Per the Ruby documentation:
    ///
    /// > `$1`, `$2` and so on contain text matching first, second, etc capture
    /// > group.
    ///
    /// # Errors
    ///
    /// If the `Regexp` state is inaccessible, an error is returned.
    fn set_capture_group_globals(&mut self, count: usize) -> Result<(), Self::Error>;

    /// Clear all `Regexp` state.
    ///
    /// # Errors
    ///
    /// If the `Regexp` state is inaccessible, an error is returned.
    fn clear_regexp(&mut self) -> Result<(), Self::Error>;
}