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 strThe 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
impl Table
Sourcepub fn find<S: Subject>(
&self,
subject: &S,
term: S::Node,
) -> Option<Match<S::Node>>
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.
Sourcepub fn find_in<S: Subject>(
&self,
subject: &S,
term: S::Node,
left: &mut Vec<S::Node>,
bindings: &mut Vec<S::Node>,
) -> Option<usize>
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.
Sourcepub fn opens(&self, head: Option<(&str, usize)>) -> bool
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.
Sourcepub fn opening<'h>(&self, head: Option<(&'h str, usize)>) -> Option<Opening<'h>>
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.
Sourcepub 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>
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.