Skip to main content

RustLexer

Struct RustLexer 

Source
pub struct RustLexer<'config> { /* private fields */ }
Expand description

A lexer for the Rust programming language.

The RustLexer is responsible for tokenizing Rust source code into a sequence of tokens that can be used by the parser. It handles all Rust syntax including modern features like raw strings, byte strings, lifetimes, and all standard Rust keywords.

§Examples

Basic usage:

use oak_core::{Lexer, LexerState, SourceText};
use oak_rust::{RustLanguage, RustLexer};

let language = RustLanguage::default();
let lexer = RustLexer::new(&language);
let source = SourceText::new("fn main() { println!(\"Hello, world!\"); }");
let mut cache = oak_core::parser::session::ParseSession::<RustLanguage>::default();
let output = lexer.lex(&source, &[], &mut cache);

// The output contains tokens for the entire source code
assert!(output.result.is_ok());

Tokenizing different Rust constructs:

use oak_core::{Lexer, LexerState, SourceText};
use oak_rust::{RustLanguage, RustLexer};

let language = RustLanguage::default();
let lexer = RustLexer::new(&language);

// Tokenize a function with various Rust features
let source = SourceText::new(
    r#"
fn calculate<'a>(x: &'a i32, y: i32) -> i32 {
    let result = x + y;
    println!("Result: {}", result);
    result
}
"#,
);
let mut cache = oak_core::parser::session::ParseSession::<RustLanguage>::default();
let output = lexer.lex(&source, &[], &mut cache);

// Verify that tokens were generated
assert!(output.result.is_ok());

Implementations§

Source§

impl<'config> RustLexer<'config>

Source

pub fn new(config: &'config RustLanguage) -> Self

Creates a new RustLexer with the given language configuration.

§Parameters
  • config - A RustLanguage configuration that controls language-specific parsing behavior.
§Examples

let language = RustLanguage::default();
let lexer = RustLexer::new(&language);

Trait Implementations§

Source§

impl<'config> Clone for RustLexer<'config>

Source§

fn clone(&self) -> RustLexer<'config>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'config> Lexer<RustLanguage> for RustLexer<'config>

Source§

fn lex<'a, S: Source + ?Sized>( &self, source: &'a S, _edits: &[TextEdit], cache: &'a mut impl LexerCache<RustLanguage>, ) -> LexOutput<RustLanguage>

Tokenizes the given source text into a sequence of tokens. Read more

Auto Trait Implementations§

§

impl<'config> Freeze for RustLexer<'config>

§

impl<'config> RefUnwindSafe for RustLexer<'config>

§

impl<'config> Send for RustLexer<'config>

§

impl<'config> Sync for RustLexer<'config>

§

impl<'config> Unpin for RustLexer<'config>

§

impl<'config> UnwindSafe for RustLexer<'config>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.