Enum fancy_regex::Expr

source ·
pub enum Expr {
Show 19 variants Empty, Any { newline: bool, }, StartText, EndText, StartLine, EndLine, Literal { val: String, casei: bool, }, Concat(Vec<Expr>), Alt(Vec<Expr>), Group(Box<Expr>), LookAround(Box<Expr>, LookAround), Repeat { child: Box<Expr>, lo: usize, hi: usize, greedy: bool, }, Delegate { inner: String, size: usize, casei: bool, }, Backref(usize), AtomicGroup(Box<Expr>), KeepOut, ContinueFromPreviousMatchEnd, BackrefExistsCondition(usize), Conditional { condition: Box<Expr>, true_branch: Box<Expr>, false_branch: Box<Expr>, },
}
Expand description

Regular expression AST. This is public for now but may change.

Variants§

§

Empty

An empty expression, e.g. the last branch in (a|b|)

§

Any

Any character, regex .

Fields

§newline: bool

Whether it also matches newlines or not

§

StartText

Start of input text

§

EndText

End of input text

§

StartLine

Start of a line

§

EndLine

End of a line

§

Literal

The string as a literal, e.g. a

Fields

§val: String

The string to match

§casei: bool

Whether match is case-insensitive or not

§

Concat(Vec<Expr>)

Concatenation of multiple expressions, must match in order, e.g. a. is a concatenation of the literal a and . for any character

§

Alt(Vec<Expr>)

Alternative of multiple expressions, one of them must match, e.g. a|b is an alternative where either the literal a or b must match

§

Group(Box<Expr>)

Capturing group of expression, e.g. (a.) matches a and any character and “captures” (remembers) the match

§

LookAround(Box<Expr>, LookAround)

Look-around (e.g. positive/negative look-ahead or look-behind) with an expression, e.g. (?=a) means the next character must be a (but the match is not consumed)

§

Repeat

Repeat of an expression, e.g. a* or a+ or a{1,3}

Fields

§child: Box<Expr>

The expression that is being repeated

§lo: usize

The minimum number of repetitions

§hi: usize

The maximum number of repetitions (or usize::MAX)

§greedy: bool

Greedy means as much as possible is matched, e.g. .*b would match all of abab. Non-greedy means as little as possible, e.g. .*?b would match only ab in abab.

§

Delegate

Delegate a regex to the regex crate. This is used as a simplification so that we don’t have to represent all the expressions in the AST, e.g. character classes.

Fields

§inner: String

The regex

§size: usize

How many characters the regex matches

§casei: bool

Whether the matching is case-insensitive or not

§

Backref(usize)

Back reference to a capture group, e.g. \1 in (abc|def)\1 references the captured group and the whole regex matches either abcabc or defdef.

§

AtomicGroup(Box<Expr>)

Atomic non-capturing group, e.g. (?>ab|a) in text that contains ab will match ab and never backtrack and try a, even if matching fails after the atomic group.

§

KeepOut

Keep matched text so far out of overall match

§

ContinueFromPreviousMatchEnd

Anchor to match at the position where the previous match ended

§

BackrefExistsCondition(usize)

Conditional expression based on whether the numbered capture group matched or not

§

Conditional

If/Then/Else Condition. If there is no Then/Else, these will just be empty expressions.

Fields

§condition: Box<Expr>

The conditional expression to evaluate

§true_branch: Box<Expr>

What to execute if the condition is true

§false_branch: Box<Expr>

What to execute if the condition is false

Implementations§

source§

impl Expr

source

pub fn parse_tree(re: &str) -> Result<ExprTree>

Parse the regex and return an expression (AST) and a bit set with the indexes of groups that are referenced by backrefs.

source

pub fn to_str(&self, buf: &mut String, precedence: u8)

Convert expression to a regex string in the regex crate’s syntax.

§Panics

Panics for expressions that are hard, i.e. can not be handled by the regex crate.

Trait Implementations§

source§

impl Debug for Expr

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Expr

source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Expr

source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.