Skip to main content

Ast

Enum Ast 

Source
pub enum Ast {
Show 19 variants Empty, Literal { text: String, fuzziness: Fuzziness, }, Char(char), CharClass(CharClass), Concat(Vec<Ast>), Alternation(Vec<Ast>), Quantified { expr: Box<Ast>, quantifier: Quantifier, greedy: bool, }, Group { index: usize, name: Option<String>, expr: Box<Ast>, }, NonCapturingGroup { expr: Box<Ast>, fuzziness: Fuzziness, }, Anchor(Anchor), Lookahead { positive: bool, expr: Box<Ast>, }, Lookbehind { positive: bool, expr: Box<Ast>, }, Backreference { group: usize, fuzziness: Fuzziness, }, NamedList { name: String, }, ResetMatchStart, AtomicGroup { expr: Box<Ast>, }, RecursivePattern, RecursiveGroup { group: usize, }, RecursiveNamedGroup { name: String, },
}
Expand description

AST node representing a parsed regex pattern.

Variants§

§

Empty

Empty pattern.

§

Literal

Literal string with optional fuzziness: hello, hello~2.

Fields

§text: String

The literal text to match.

§fuzziness: Fuzziness

Fuzziness specification for approximate matching.

§

Char(char)

Single character (from escape or plain char outside literals).

§

CharClass(CharClass)

Character class: [a-z], [^abc], \d, \w, \s, .

§

Concat(Vec<Ast>)

Concatenation of patterns.

§

Alternation(Vec<Ast>)

Alternation: a|b|c.

§

Quantified

Quantified expression: a*, a+, a?, a{n,m}.

Fields

§expr: Box<Ast>

The expression being quantified.

§quantifier: Quantifier

The quantifier specifying repetition bounds.

§greedy: bool

Whether the quantifier is greedy (matches as much as possible).

§

Group

Capture group: (expr).

Fields

§index: usize

The capture group index (1-based for user-facing, 0-based internally).

§name: Option<String>

Optional name for named capture groups like (?P<name>...).

§expr: Box<Ast>

The expression contained in the group.

§

NonCapturingGroup

Non-capturing group: (?:expr).

Fields

§expr: Box<Ast>

The expression contained in the group.

§fuzziness: Fuzziness

Fuzziness specification applied to this group.

§

Anchor(Anchor)

Anchor: ^, $.

§

Lookahead

Lookahead: (?=...), (?!...).

Fields

§positive: bool

True for positive lookahead (?=...), false for negative (?!...).

§expr: Box<Ast>

The expression to match in the lookahead.

§

Lookbehind

Lookbehind: (?<=...), (?<!...).

Fields

§positive: bool

True for positive lookbehind (?<=...), false for negative (?<!...).

§expr: Box<Ast>

The expression to match in the lookbehind.

§

Backreference

Backreference: \1, \2, optionally with fuzziness \1{e<=1}.

Fields

§group: usize

The capture group number being referenced.

§fuzziness: Fuzziness

Fuzziness specification for approximate backreference matching.

§

NamedList

Named list reference: \L<name>.

Fields

§name: String

The name of the list.

§

ResetMatchStart

Reset match start: \K Resets the starting point of the match. Everything before \K is matched but not included in the final match result.

§

AtomicGroup

Atomic group: (?>...) Once the group matches, backtracking is disabled within the group.

Fields

§expr: Box<Ast>

The expression contained in the atomic group.

§

RecursivePattern

Recursive entire pattern: (?R) Recursively matches the entire pattern.

§

RecursiveGroup

Recursive numbered group: (?1), (?2), etc. Recursively matches a specific capture group.

Fields

§group: usize

The capture group number to recurse into.

§

RecursiveNamedGroup

Recursive named group: (?&name) or (?P>name) Recursively matches a named capture group.

Fields

§name: String

The name of the capture group to recurse into.

Implementations§

Source§

impl Ast

Source

pub fn literal(text: impl Into<String>) -> Self

Create a literal AST node with inherited fuzziness.

Source

pub fn literal_fuzzy(text: impl Into<String>, fuzziness: Fuzziness) -> Self

Create a literal AST node with specific fuzziness.

Source

pub fn quantified(expr: Ast, quantifier: Quantifier, greedy: bool) -> Self

Create a quantified AST node.

Source

pub fn group(index: usize, expr: Ast) -> Self

Create a capture group.

Source

pub fn named_group(index: usize, name: impl Into<String>, expr: Ast) -> Self

Create a named capture group.

Source

pub fn is_empty(&self) -> bool

Check if this AST is empty.

Trait Implementations§

Source§

impl Clone for Ast

Source§

fn clone(&self) -> Ast

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 Ast

Source§

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

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

impl PartialEq for Ast

Source§

fn eq(&self, other: &Ast) -> 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 StructuralPartialEq for Ast

Auto Trait Implementations§

§

impl Freeze for Ast

§

impl RefUnwindSafe for Ast

§

impl Send for Ast

§

impl Sync for Ast

§

impl Unpin for Ast

§

impl UnsafeUnpin for Ast

§

impl UnwindSafe for Ast

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.