Enum safe_regex_compiler::parser::FinalNode [−][src]
pub enum FinalNode { Byte(u8), AnyByte, Seq(Vec<FinalNode>), Class(bool, Vec<ClassItem>), Group(Box<FinalNode>), NonCapturingGroup(Box<FinalNode>), Alt(Vec<FinalNode>), Repeat(Box<FinalNode>, usize, Option<usize>), }
Expand description
A completely parsed element of a regular expression abstract syntax tree (AST).
A FinalNode
could represent an entire regular expression (it is the root)
or a small part of one.
Since a regular expression ultimately processes bytes, the leaves of the AST are nodes with bytes:
All other variants are edges of the AST:
Variants
Byte(u8)
Expand description
Byte(u8)
A byte of input. This may be a non-printable byte that was escaped in the source regular expression.
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Byte(b'a')), parse(br"a"), ); assert_eq!( Ok(FinalNode::Byte(b'\n')), parse(br"\n"), ); assert_eq!( Ok(FinalNode::Byte(b'\\')), parse(br"\\"), ); assert_eq!( Ok(FinalNode::Byte(0x12)), parse(br"\x12"), );
Expand description
AnyByte
Matches any byte of input. This is the .
operator.
Example
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::AnyByte), parse(br"."), );
Expand description
Seq(Vec<FinalNode>)
A sequence of nodes.
Example
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Seq(vec![ FinalNode::Byte(b'a'), FinalNode::Byte(b'b')], )), parse(br"ab"), );
Expand description
Class(inclusive: bool, Vec<ClassItem>)
A character class. Matches any byte in the class.
See ClassItem
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; use safe_regex_compiler::parser::ClassItem; assert_eq!( Ok(FinalNode::Class(true, vec![ ClassItem::Byte(b'a'), ClassItem::Byte(b'b'), ])), parse(br"[ab]"), ); assert_eq!( Ok(FinalNode::Class(false, vec![ ClassItem::Byte(b'a'), ClassItem::Byte(b'b'), ])), parse(br"[^ab]"), ); assert_eq!( Ok(FinalNode::Class(true, vec![ ClassItem::ByteRange(b'0', b'9'), ])), parse(br"[0-9]"), );
Expand description
Group(Box<FinalNode>)
A capturing group of nodes. Regular expression authors use it to override operator precedence rules and to capture sub-slices of input.
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Seq(vec![ FinalNode::Byte(b'a'), FinalNode::Group(Box::new( FinalNode::Alt(vec![ FinalNode::Byte(b'b'), FinalNode::Byte(b'c'), ]) )), ])), parse(br"a(b|c)"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Group(Box::new( FinalNode::Seq(vec![ FinalNode::Byte(b'a'), FinalNode::Byte(b'b'), ]) ))), 0, // min None, // max )), parse(br"(ab)*"), );
Expand description
NonCapturingGroup(Box<FinalNode>)
A non-capturing group of nodes. Regular expression authors use it to override operator precedence rules.
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Seq(vec![ FinalNode::Byte(b'a'), FinalNode::NonCapturingGroup(Box::new( FinalNode::Alt(vec![ FinalNode::Byte(b'b'), FinalNode::Byte(b'c'), ]) )), ])), parse(br"a(?:b|c)"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::NonCapturingGroup(Box::new( FinalNode::Seq(vec![ FinalNode::Byte(b'a'), FinalNode::Byte(b'b'), ]) ))), 0, // min None, // max )), parse(br"(?:ab)*"), );
Expand description
Alt(Vec<FinalNode>)
A list of alternate nodes. The input can match any of them.
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Alt(vec![ FinalNode::Byte(b'a'), FinalNode::Byte(b'b'), ])), parse(br"a|b"), ); assert_eq!( Ok(FinalNode::Alt(vec![ FinalNode::Byte(b'a'), FinalNode::Byte(b'b'), FinalNode::Seq(vec![ FinalNode::AnyByte, FinalNode::Byte(b'c'), ]), ])), parse(br"a|b|.c"), );
Expand description
Repeat(Box<FinalNode>, min: usize, max: Option<usize>)
A repetition of a node. It contains the minimum number of repetitions and an optional inclusive maximum number.
Examples
use safe_regex_compiler::parser::parse; use safe_regex_compiler::parser::FinalNode; assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 0, // min Some(1), // max )), parse(br"a?"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 0, // min None, // max )), parse(br"a*"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 1, // min None, // max )), parse(br"a+"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 5, // min Some(5), // max )), parse(br"a{5}"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 5, // min None, // max )), parse(br"a{5,}"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 0, // min Some(7), // max )), parse(br"a{,7}"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 5, // min Some(7), // max )), parse(br"a{5,7}"), ); assert_eq!( Ok(FinalNode::Repeat( Box::new(FinalNode::Byte(b'a')), 0, // min None, // max )), parse(br"a{,}"), );
Implementations
impl FinalNode
[src]
impl FinalNode
[src]pub fn unwrap_alt(self) -> Vec<FinalNode>
[src]
pub fn unwrap_alt(self) -> Vec<FinalNode>
[src]Assumes this is a FinalNode::Alt(_)
and returns its contents.
Panics if this is a different enum variant.
Trait Implementations
impl PartialOrd<FinalNode> for FinalNode
[src]
impl PartialOrd<FinalNode> for FinalNode
[src]fn partial_cmp(&self, other: &FinalNode) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &FinalNode) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl StructuralPartialEq for FinalNode
[src]
Auto Trait Implementations
impl RefUnwindSafe for FinalNode
impl Send for FinalNode
impl Sync for FinalNode
impl Unpin for FinalNode
impl UnwindSafe for FinalNode
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more