Enum regex_syntax::hir::translate::HirFrame

source ·
enum HirFrame {
    Expr(Hir),
    Literal(Vec<u8>),
    ClassUnicode(ClassUnicode),
    ClassBytes(ClassBytes),
    Repetition,
    Group {
        old_flags: Flags,
    },
    Concat,
    Alternation,
    AlternationBranch,
}
Expand description

An HirFrame is a single stack frame, represented explicitly, which is created for each item in the Ast that we traverse.

Note that technically, this type doesn’t represent our entire stack frame. In particular, the Ast visitor represents any state associated with traversing the Ast itself.

Variants§

§

Expr(Hir)

An arbitrary HIR expression. These get pushed whenever we hit a base case in the Ast. They get popped after an inductive (i.e., recursive) step is complete.

§

Literal(Vec<u8>)

A literal that is being constructed, character by character, from the AST. We need this because the AST gives each individual character its own node. So as we see characters, we peek at the top-most HirFrame. If it’s a literal, then we add to it. Otherwise, we push a new literal. When it comes time to pop it, we convert it to an Hir via Hir::literal.

§

ClassUnicode(ClassUnicode)

A Unicode character class. This frame is mutated as we descend into the Ast of a character class (which is itself its own mini recursive structure).

§

ClassBytes(ClassBytes)

A byte-oriented character class. This frame is mutated as we descend into the Ast of a character class (which is itself its own mini recursive structure).

Byte character classes are created when Unicode mode (u) is disabled. If utf8 is enabled (the default), then a byte character is only permitted to match ASCII text.

§

Repetition

This is pushed whenever a repetition is observed. After visiting every sub-expression in the repetition, the translator’s stack is expected to have this sentinel at the top.

This sentinel only exists to stop other things (like flattening literals) from reaching across repetition operators.

§

Group

This is pushed on to the stack upon first seeing any kind of capture, indicated by parentheses (including non-capturing groups). It is popped upon leaving a group.

Fields

§old_flags: Flags

The old active flags when this group was opened.

If this group sets flags, then the new active flags are set to the result of merging the old flags with the flags introduced by this group. If the group doesn’t set any flags, then this is simply equivalent to whatever flags were set when the group was opened.

When this group is popped, the active flags should be restored to the flags set here.

The “active” flags correspond to whatever flags are set in the Translator.

§

Concat

This is pushed whenever a concatenation is observed. After visiting every sub-expression in the concatenation, the translator’s stack is popped until it sees a Concat frame.

§

Alternation

This is pushed whenever an alternation is observed. After visiting every sub-expression in the alternation, the translator’s stack is popped until it sees an Alternation frame.

§

AlternationBranch

This is pushed immediately before each sub-expression in an alternation. This separates the branches of an alternation on the stack and prevents literal flattening from reaching across alternation branches.

It is popped after each expression in a branch until an ‘Alternation’ frame is observed when doing a post visit on an alternation.

Implementations§

source§

impl HirFrame

source

fn unwrap_expr(self) -> Hir

Assert that the current stack frame is an Hir expression and return it.

source

fn unwrap_class_unicode(self) -> ClassUnicode

Assert that the current stack frame is a Unicode class expression and return it.

source

fn unwrap_class_bytes(self) -> ClassBytes

Assert that the current stack frame is a byte class expression and return it.

source

fn unwrap_repetition(self)

Assert that the current stack frame is a repetition sentinel. If it isn’t, then panic.

source

fn unwrap_group(self) -> Flags

Assert that the current stack frame is a group indicator and return its corresponding flags (the flags that were active at the time the group was entered).

source

fn unwrap_alternation_pipe(self)

Assert that the current stack frame is an alternation pipe sentinel. If it isn’t, then panic.

Trait Implementations§

source§

impl Clone for HirFrame

source§

fn clone(&self) -> HirFrame

Returns a copy 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 HirFrame

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

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

§

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.