pub struct Parser<'a> { /* private fields */ }Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub fn new(input: &'a str) -> Self
Sourcepub fn get_errors(&self) -> &[ErrorNode]
pub fn get_errors(&self) -> &[ErrorNode]
Get all errors encountered during parsing
Sourcepub fn parse(&mut self) -> Result<Expr>
pub fn parse(&mut self) -> Result<Expr>
Parse the input into an expression or block of expressions
Parse a complete program or expression
§Examples
use ruchy::Parser;
let mut parser = Parser::new("42");
let ast = parser.parse().expect("Failed to parse");use ruchy::Parser;
let mut parser = Parser::new("let x = 10 in x + 1");
let ast = parser.parse().expect("Failed to parse");§Errors
Returns an error if:
- The input is empty
- Syntax errors are encountered
- Unexpected tokens are found
§Panics
Should not panic in normal operation. Uses expect on verified conditions.
§Errors
Returns an error if the operation fails
Sourcepub fn parse_expr(&mut self) -> Result<Expr>
pub fn parse_expr(&mut self) -> Result<Expr>
Sourcepub fn parse_expr_with_precedence(&mut self, min_prec: i32) -> Result<Expr>
pub fn parse_expr_with_precedence(&mut self, min_prec: i32) -> Result<Expr>
Parse an expression with operator precedence
§Examples
use ruchy::Parser;
let mut parser = Parser::new("1 + 2 * 3");
// Parse with minimum precedence 0 to get all operators
let expr = parser.parse_expr_with_precedence(0).expect("Failed to parse expression");§Errors
Returns an error if the expression cannot be parsed or contains syntax errors
§Errors
Returns an error if the operation fails
Auto Trait Implementations§
impl<'a> !Freeze for Parser<'a>
impl<'a> !RefUnwindSafe for Parser<'a>
impl<'a> !Send for Parser<'a>
impl<'a> !Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> !UnwindSafe for Parser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more