RustParser

Struct RustParser 

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

A parser for the Rust programming language.

The RustParser is responsible for parsing Rust source code and building an Abstract Syntax Tree (AST). It uses a Pratt parser for handling operator precedence in expressions and supports all Rust syntax features.

§Examples

Basic usage:

use oak_core::Parser;
use oak_rust::{RustLanguage, RustParser, SourceText};

let language = RustLanguage::default();
let parser = RustParser::new(&language);
let source = SourceText::new("fn main() { println!(\"Hello, world!\"); }");
let result = parser.parse(source, 0);

// The result contains the parsed AST
assert!(result.is_ok());

Parsing a more complex Rust structure:

use oak_core::Parser;
use oak_rust::{RustLanguage, RustParser, SourceText};

let language = RustLanguage::default();
let parser = RustParser::new(&language);

let source = SourceText::new(
    r#"
struct Point {
    x: f64,
    y: f64,
}

impl Point {
    fn new(x: f64, y: f64) -> Self {
        Point { x, y }
    }
}
"#,
);
let result = parser.parse(source, 0);

// Verify that parsing succeeded
assert!(result.is_ok());

Implementations§

Source§

impl<'config> RustParser<'config>

Source§

impl<'config> RustParser<'config>

Source

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

Creates a new RustParser with the given language configuration.

§Parameters
  • config - A reference to the RustLanguage configuration that controls language-specific parsing behavior.
§Examples
use oak_rust::{RustLanguage, RustParser};

let language = RustLanguage::default();
let parser = RustParser::new(&language);
Source

pub fn operator_rules(&self) -> &PrattParser<RustLanguage>

Returns a reference to the Pratt parser containing operator precedence rules.

The Pratt parser defines the precedence and associativity of all Rust operators, which is used to correctly parse expressions with multiple operators.

Trait Implementations§

Source§

impl<'config> Builder<RustLanguage> for RustParser<'config>

Source§

fn build_incremental( &self, text: impl Source, changed: usize, cache: IncrementalCache<'_, RustLanguage>, ) -> OakDiagnostics<RustRoot>

Builds a kind tree incrementally using an existing cache. Read more
Source§

fn build(&self, text: impl Source) -> OakDiagnostics<<L as Language>::TypedRoot>

Builds a complete kind tree from the given source text. Read more
Source§

impl<'config> Clone for RustParser<'config>

Source§

fn clone(&self) -> RustParser<'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> Parser<RustLanguage> for RustParser<'config>

Source§

fn parse_incremental( &self, text: impl Source, changed: usize, cache: IncrementalCache<'_, RustLanguage>, ) -> OakDiagnostics<Arc<GreenNode<RustSyntaxKind>>>

Parses source text incrementally using an existing cache. Read more
Source§

fn parse( &self, text: impl Source, ) -> OakDiagnostics<Arc<GreenNode<<L as Language>::SyntaxKind>>>

Parses source text into a kind tree. Read more

Auto Trait Implementations§

§

impl<'config> Freeze for RustParser<'config>

§

impl<'config> RefUnwindSafe for RustParser<'config>

§

impl<'config> Send for RustParser<'config>

§

impl<'config> Sync for RustParser<'config>

§

impl<'config> Unpin for RustParser<'config>

§

impl<'config> UnwindSafe for RustParser<'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.
Source§

impl<T> ErasedDestructor for T
where T: 'static,