Skip to main content

Tokenizer

Struct Tokenizer 

Source
pub struct Tokenizer { /* private fields */ }
Expand description

A stateful tokenizer for one root TextMate grammar.

Implementations§

Source§

impl Tokenizer

Source

pub fn new( registry: &GrammarRegistry, root: GrammarId, options: TokenizerOptions, ) -> Result<Self>

Creates a tokenizer for a root grammar owned by registry.

Source

pub fn for_bundled_language( language: &str, options: TokenizerOptions, ) -> Result<Self>

Available on crate feature bundled-grammars only.

Constructs a tokenizer from the bundled grammar catalog.

Source

pub fn from_prepared( prepared: &PreparedLanguage, options: TokenizerOptions, ) -> Self

Constructs a tokenizer from caller-owned immutable preparation.

Source

pub fn initial_state(&self) -> TokenizerState

Creates initial continuation state owned by this tokenizer.

The returned state is document start: \A may match on the first subsequent line. Later continuation states do not rematch \A.

Source

pub fn tokenize_line( &mut self, line: &str, state: &mut TokenizerState, ) -> Result<TokenizedLine>

Tokenizes one logical line. line must not include a newline terminator.

\A matches only while state is this tokenizer’s initial document-start state, matching Tokenizer::tokenize. After a successful call, state is no longer at document start.

Source

pub fn tokenize_line_into( &mut self, line: &str, state: &mut TokenizerState, tokens: &mut Vec<Token>, ) -> Result<HighlightStatus>

Tokenizes one logical line into a caller-owned reusable buffer.

The buffer is cleared after input validation and retains its capacity for subsequent calls. This is the allocation-conscious counterpart to Tokenizer::tokenize_line.

Source

pub fn tokenize_line_with( &mut self, line: &str, state: &mut TokenizerState, sink: impl FnMut(Token), ) -> Result<HighlightStatus>

Tokenizes one logical line and sends each token to sink in byte order.

The callback receives owned tokens backed by shared immutable scope names, so no output collection is required. It is not called when input validation fails. The returned status covers the complete line.

Source

pub fn tokenize(&mut self, source: &str) -> TokenizedDocument

Tokenizes a complete UTF-8 source document.

Source

pub fn checkpoints(&self, interval: usize) -> CheckpointTable

Creates an owned checkpoint table for viewport tokenization.

Source

pub fn tokenize_viewport( &mut self, source: &str, visible_lines: Range<usize>, checkpoints: &mut CheckpointTable, ) -> Result<TokenizedDocument>

Tokenizes a line viewport while replaying from the nearest checkpoint.

Trait Implementations§

Source§

impl Debug for Tokenizer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.