mistralrs::llguidance::toktrie

Trait Recognizer

pub trait Recognizer {
    // Required methods
    fn pop_bytes(&mut self, num: usize);
    fn collapse(&mut self);
    fn special_allowed(&mut self, tok: SpecialToken) -> bool;
    fn trie_finished(&mut self);
    fn try_push_byte(&mut self, byte: u8) -> bool;

    // Provided methods
    fn byte_allowed(&mut self, byte: u8) -> bool { ... }
    fn trie_started(&mut self) { ... }
    fn get_error(&mut self) -> Option<String> { ... }
}

Required Methods§

fn pop_bytes(&mut self, num: usize)

for _ in 0..num { stack.pop() }

fn collapse(&mut self)

“Collapse” the stack so that it consists only of its former top element. X = stack.top(); stack.empty(); stack.push(X)

fn special_allowed(&mut self, tok: SpecialToken) -> bool

check if stack.top() transitions via tok to a viable state

fn trie_finished(&mut self)

Called when iteration over the trie is finished Stack has exactly one element then, except when iteration started from non-root node. In that case, the stack may have more than one element, and trie_finished() needs to pop the excessive elements.

fn try_push_byte(&mut self, byte: u8) -> bool

This combines push_byte and byte_allowed into one function for performance.

Provided Methods§

fn byte_allowed(&mut self, byte: u8) -> bool

check if stack.top() transitions via byte to a viable state

fn trie_started(&mut self)

Called when iteration over the trie is started

fn get_error(&mut self) -> Option<String>

Check if there are any errors to be reported to the user.

Implementors§

§

impl<'a> Recognizer for ParserRecognizer<'a>

§

impl<S, R> Recognizer for StackRecognizer<S, R>
where S: Copy + Debug, R: FunctionalRecognizer<S>,