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
impl HirFrame
sourcefn unwrap_expr(self) -> Hir
fn unwrap_expr(self) -> Hir
Assert that the current stack frame is an Hir expression and return it.
sourcefn unwrap_class_unicode(self) -> ClassUnicode
fn unwrap_class_unicode(self) -> ClassUnicode
Assert that the current stack frame is a Unicode class expression and return it.
sourcefn unwrap_class_bytes(self) -> ClassBytes
fn unwrap_class_bytes(self) -> ClassBytes
Assert that the current stack frame is a byte class expression and return it.
sourcefn unwrap_repetition(self)
fn unwrap_repetition(self)
Assert that the current stack frame is a repetition sentinel. If it isn’t, then panic.
sourcefn unwrap_group(self) -> Flags
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).
sourcefn unwrap_alternation_pipe(self)
fn unwrap_alternation_pipe(self)
Assert that the current stack frame is an alternation pipe sentinel. If it isn’t, then panic.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HirFrame
impl RefUnwindSafe for HirFrame
impl Send for HirFrame
impl Sync for HirFrame
impl Unpin for HirFrame
impl UnwindSafe for HirFrame
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)