Skip to main content

Table

Struct Table 

Source
pub struct Table {
    pub source: &'static str,
    pub nodes: &'static [Node],
    pub rules: &'static [Rule],
}
Expand description

A set of rules, as an automaton over their patterns.

Fields§

§source: &'static str

The rule file this was built from, so that anything said about a rule can name a file somebody can open.

§nodes: &'static [Node]

The trie. Node zero is the root.

§rules: &'static [Rule]

The rules, in the order the file writes them.

Implementations§

Source§

impl Table

Source

pub fn find<S: Subject>( &self, subject: &S, term: S::Node, ) -> Option<Match<S::Node>>

The rule that fires on this term, and what it bound.

The term is matched as a whole. Finding the terms in a function worth matching is the caller’s job and not this one’s.

Source

pub fn find_in<S: Subject>( &self, subject: &S, term: S::Node, left: &mut Vec<S::Node>, bindings: &mut Vec<S::Node>, ) -> Option<usize>

Table::find with the two stacks the walk needs handed in, for a caller that asks more than once and would rather not pay for them every time.

Both are emptied before the walk. What bindings holds afterwards is what the pattern bound when a rule fired, and nothing anybody reads when none did.

Source

pub fn opens(&self, head: Option<(&str, usize)>) -> bool

Whether a term with this head could match any rule at all, which is a question about the root of the trie alone.

A walk whose first node has no branch for the head, no constant to compare against, no repeat to look for and no wildcard gives up at that node, so a false here is the answer Table::find would have given without the walk. A caller that matches one term under several ways of showing its operands asks this once, since the head of the term itself does not depend on how its operands are shown.

Source

pub fn opening<'h>(&self, head: Option<(&'h str, usize)>) -> Option<Opening<'h>>

What the root of the trie says about a term with this head, or nothing when that is that no rule matches it, which is Table::opens with the branch it found kept.

A caller that matches one term under several ways of showing its operands hands this to Table::find_opened for each of them. The head of the term is the same under every one, so the root’s branch on it is too, and finding it again for each was a search of the largest node in the trie and a question to the subject for every way tried. tamnd/rucc#3052.

Source

pub fn find_opened<S: Subject>( &self, subject: &S, term: S::Node, opening: Opening<'_>, left: &mut Vec<S::Node>, bindings: &mut Vec<S::Node>, ) -> Option<usize>

Table::find_in for a term whose root Table::opening already looked at.

The opening has to be of this table and of the head this subject gives the term, which is what makes the walk the one Table::find_in would have made.

Source

pub fn rule<N>(&self, found: &Match<N>) -> &Rule

The rule a match found, which is the one thing every caller wants out of it.

Trait Implementations§

Source§

impl Debug for Table

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnsafeUnpin for Table

§

impl UnwindSafe for Table

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.