Enum safe_regex_compiler::parser::FinalNode[][src]

pub enum FinalNode {
    Byte(u8),
    AnyByte,
    Seq(Vec<FinalNode>),
    Class(boolVec<ClassItem>),
    Group(Box<FinalNode>),
    NonCapturingGroup(Box<FinalNode>),
    Alt(Vec<FinalNode>),
    Repeat(Box<FinalNode>, usizeOption<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"),
);
AnyByte
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"),
);
Class(boolVec<ClassItem>)
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]"),
);
Group(Box<FinalNode>)
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)*"),
);
NonCapturingGroup(Box<FinalNode>)
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]

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 Clone for FinalNode[src]

fn clone(&self) -> FinalNode[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for FinalNode[src]

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

Formats the value using the given formatter. Read more

impl PartialEq<FinalNode> for FinalNode[src]

fn eq(&self, other: &FinalNode) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &FinalNode) -> bool[src]

This method tests for !=.

impl PartialOrd<FinalNode> for FinalNode[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]

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]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl StructuralPartialEq for FinalNode[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.