Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 23 variants Empty, Any { newline: bool, crlf: bool, }, Assertion(Assertion), GeneralNewline { unicode: bool, }, Literal { val: String, casei: bool, }, Concat(Vec<Expr>), Alt(Vec<Expr>), Group(Arc<Expr>), LookAround(Box<Expr>, LookAround), Repeat { child: Box<Expr>, lo: usize, hi: usize, greedy: bool, }, Delegate { inner: String, casei: bool, }, Backref { group: usize, casei: bool, }, BackrefWithRelativeRecursionLevel { group: usize, relative_level: isize, casei: bool, }, AtomicGroup(Box<Expr>), KeepOut, ContinueFromPreviousMatchEnd, BackrefExistsCondition { group: usize, relative_recursion_level: Option<isize>, }, Conditional { condition: Box<Expr>, true_branch: Box<Expr>, false_branch: Box<Expr>, }, SubroutineCall(usize), BacktrackingControlVerb(BacktrackingControlVerb), Absent(Absent), DefineGroup { definitions: Box<Expr>, }, AstNode(AstNode, usize),
}
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

§crlf: bool

Whether CRLF mode is enabled (\r also counts as a newline, so dot excludes both \r and \n)

§

Assertion(Assertion)

An assertion

§

GeneralNewline

General newline sequence, \R Matches \r\n or any single newline character (\n, \v, \f, \r) In Unicode mode, also matches U+0085, U+2028, U+2029

Fields

§unicode: bool

Whether Unicode mode is enabled

§

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(Arc<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.

Constraint: All Delegate expressions must match exactly 1 character. This ensures consistent analysis and compilation behavior. For zero-width or multi-character patterns, use the appropriate Expr variants instead (e.g., Assertion, Repeat, Concat).

Fields

§inner: String

The regex

§casei: bool

Whether the matching is case-insensitive or not

§

Backref

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.

Fields

§group: usize

The capture group number being referenced

§casei: bool

Whether the matching is case-insensitive or not

§

BackrefWithRelativeRecursionLevel

Back reference to a capture group at the given specified relative recursion level.

Fields

§group: usize

The capture group number being referenced

§relative_level: isize

Relative recursion level

§casei: bool

Whether the matching is case-insensitive or not

§

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

Conditional expression based on whether the numbered capture group matched or not. The optional relative_recursion_level qualifies which recursion level’s capture is tested (Oniguruma (?(name+N)...) syntax).

Fields

§group: usize

The resolved capture group number

§relative_recursion_level: Option<isize>

Optional relative recursion level (e.g. +0, -1)

§

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

§

SubroutineCall(usize)

Subroutine call to the specified group number

§

BacktrackingControlVerb(BacktrackingControlVerb)

Backtracking control verb

§

Absent(Absent)

Match while the given expression is absent from the haystack

§

DefineGroup

DEFINE group - defines capture groups for subroutines without matching anything The expressions inside are parsed and assigned group numbers, but no VM instructions are generated for the DEFINE block itself.

Fields

§definitions: Box<Expr>

The expressions/groups being defined

§

AstNode(AstNode, usize)

Abstract Syntax Tree node - will be resolved into an Expr before analysis. Contains the position in the pattern where the node was parsed from

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 parse_tree_with_flags(re: &str, flags: u32) -> Result<ExprTree>

Parse the regex and return an expression (AST) Flags should be bit based based on flags

Source

pub fn is_leaf_node(&self) -> bool

Returns true if this expression is a leaf node (has no children).

Leaf nodes include literals, assertions, backreferences, and other atomic expressions. Non-leaf nodes include groups, concatenations, alternations, and repetitions.

Source

pub fn has_descendant(&self, predicate: impl Fn(&Expr) -> bool) -> bool

Returns true if any descendant of this expression (not including itself) satisfies the given predicate.

This performs an iterative depth-first search using children_iter.

Source

pub fn children_iter(&self) -> ExprChildrenIter<'_>

Returns an iterator over the immediate children of this expression.

For leaf nodes, this returns an empty iterator. For non-leaf nodes, it returns references to their immediate children (non-recursive).

Source

pub fn children_iter_mut(&mut self) -> ExprChildrenIterMut<'_>

Returns an iterator over the immediate children of this expression for mutable access.

For leaf nodes, this returns an empty iterator. For non-leaf nodes, it returns mutable references to their immediate children (non-recursive).

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 Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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 UnsafeUnpin 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.