LexerCache

Trait LexerCache 

Source
pub trait LexerCache<L: Language> {
    // Required methods
    fn set_lex_output(&mut self, output: LexOutput<L>);
    fn get_token(&self, index: usize) -> Option<Token<L::TokenType>>;
    fn count_tokens(&self) -> usize;
    fn has_tokens(&self) -> bool;

    // Provided method
    fn get_tokens(&self) -> Option<&[Token<L::TokenType>]> { ... }
}
Expand description

Cache trait for lexical results.

This trait defines the interface for caching and accessing lexical analysis results. It provides methods for storing and retrieving token information from previous lexical analysis operations.

Required Methods§

Source

fn set_lex_output(&mut self, output: LexOutput<L>)

Sets the lexed output in the cache.

§Arguments
  • output - The output from lexical analysis, including tokens and diagnostics
Source

fn get_token(&self, index: usize) -> Option<Token<L::TokenType>>

Gets a token from the cache by index.

§Arguments
  • index - The index of the token to retrieve
§Returns

An Option<Token<L::TokenType>> containing the token if it exists, or None if the index is out of bounds or no tokens are cached

Source

fn count_tokens(&self) -> usize

Gets the total number of tokens in the cache.

§Returns

The number of cached tokens, or 0 if no tokens are cached

Source

fn has_tokens(&self) -> bool

Checks if the cache contains any tokens.

§Returns

true if the cache contains tokens, false otherwise

Provided Methods§

Source

fn get_tokens(&self) -> Option<&[Token<L::TokenType>]>

Gets all cached tokens as a slice.

§Returns

An optional slice of tokens if available.

Implementations on Foreign Types§

Source§

impl<'a, L: Language, C: LexerCache<L> + ?Sized> LexerCache<L> for &'a mut C

Source§

fn set_lex_output(&mut self, output: LexOutput<L>)

Source§

fn get_token(&self, index: usize) -> Option<Token<L::TokenType>>

Source§

fn count_tokens(&self) -> usize

Source§

fn has_tokens(&self) -> bool

Source§

fn get_tokens(&self) -> Option<&[Token<L::TokenType>]>

Implementors§

Source§

impl<L: Language + Send + Sync + 'static> LexerCache<L> for ParseSession<L>