Struct inator::Parser

source ·
pub struct Parser<I: Clone + Ord> { /* private fields */ }
Expand description

Nondeterministic finite automata with epsilon transitions.

Implementations§

source§

impl<I: Clone + Ord> Parser<I>

source

pub fn reverse(&self) -> Self

Reverse all transitions and swap initial with accepting states.

Panics

TODO

source

pub fn compile(&self) -> Dfa<I>

Brzozowski’s algorithm for minimizing automata.

source§

impl<I: Clone + Ord> Graph<I>

source

pub fn void() -> Self

NFA with zero states.

source

pub fn empty() -> Self

NFA accepting only the empty string.

source

pub fn unit(singleton: I, fn_name: Option<&'static str>) -> Self

NFA accepting this exact token and only this exact token, only once.

source

pub fn take_all_epsilon_transitions(&self, queue: Vec<usize>) -> BTreeSet<usize>

Take every transition that doesn’t require input.

source

pub fn step(&self) -> Stepper<'_, I>

Step through each input token one at a time.

source

pub fn accept<Iter: IntoIterator>(&self, iter: Iter) -> boolwhere Iter::Item: Borrow<I>,

Decide whether an input belongs to the regular langage this NFA accepts.

source

pub fn reject<Iter: IntoIterator<Item = I>>(&self, iter: Iter) -> bool

Decide whether an input belongs to the regular langage this NFA accepts.

source

pub fn size(&self) -> usize

Number of states.

source

pub fn fuzz(&self) -> Result<Fuzzer<I>, NeverAccepts>

Randomly generate inputs that are all guaranteed to be accepted. NOTE: returns an infinite iterator! for input in automaton.fuzz()? will loop forever . . .

Errors

If this automaton never accepts any input.

source

pub fn would_ever_accept(&self) -> bool

Check if there exists a string this DFA will accept.

source

pub fn repeat(self) -> Self

Match at least one time, then as many times as we want. Note that if ANY number of times leads to an accepting state, we take it!

source

pub fn optional(self) -> Self

Match at most one time (i.e. ignore if not present).

source

pub fn star(self) -> Self

Match zero or more times (a.k.a. Kleene star).

Trait Implementations§

source§

impl Add for Parser<char>

§

type Output = Graph<char>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<I: Clone + Ord> BitOr for Parser<I>

§

type Output = Graph<I>

The resulting type after applying the | operator.
source§

fn bitor(self, rhs: Self) -> Self::Output

Performs the | operation. Read more
source§

impl<I: Clone + Clone + Ord> Clone for Graph<I>

source§

fn clone(&self) -> Graph<I>

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<I: Debug + Clone + Ord> Debug for Graph<I>

source§

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

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

impl<I: Clone + Ord> Default for Graph<I>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<I: Clone + Ord + Expression> Display for Graph<I>

source§

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

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

impl<I: Hash + Clone + Ord> Hash for Graph<I>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'a, I: Clone + Ord> IntoIterator for &'a Graph<I>

§

type Item = &'a State<I>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, State<I>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<I: Clone + Ord> IntoIterator for Graph<I>

§

type Item = State<I>

The type of the elements being iterated over.
§

type IntoIter = IntoIter<State<I>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<I: Ord + Clone + Ord> Ord for Graph<I>

source§

fn cmp(&self, other: &Graph<I>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<I: PartialEq + Clone + Ord> PartialEq for Graph<I>

source§

fn eq(&self, other: &Graph<I>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: PartialOrd + Clone + Ord> PartialOrd for Graph<I>

source§

fn partial_cmp(&self, other: &Graph<I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

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

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl<I: Clone + Ord> Shr<(I, Option<&'static str>, Graph<I>)> for Parser<I>

§

type Output = Graph<I>

The resulting type after applying the >> operator.
source§

fn shr( self, (token, fn_name, rhs): (I, Option<&'static str>, Nfa<I>) ) -> Self::Output

Performs the >> operation. Read more
source§

impl<I: Clone + Ord> Shr for Parser<I>

§

type Output = Graph<I>

The resulting type after applying the >> operator.
source§

fn shr(self, rhs: Self) -> Self::Output

Performs the >> operation. Read more
source§

impl<I: Eq + Clone + Ord> Eq for Graph<I>

source§

impl<I: Clone + Ord> StructuralEq for Graph<I>

source§

impl<I: Clone + Ord> StructuralPartialEq for Graph<I>

Auto Trait Implementations§

§

impl<I> RefUnwindSafe for Graph<I>where I: RefUnwindSafe,

§

impl<I> Send for Graph<I>where I: Send,

§

impl<I> Sync for Graph<I>where I: Sync,

§

impl<I> Unpin for Graph<I>

§

impl<I> UnwindSafe for Graph<I>where I: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V