pub struct BeancountParser<'s, 't> { /* private fields */ }
Expand description

The Beancount parser itself, which tokenizes and parses the source files contained in BeancountSources.

§Examples


use beancount_parser_lima::{BeancountParser, BeancountSources, ParseError, ParseSuccess};

fn main() {
    let sources = BeancountSources::from(PathBuf::from("examples/data/full.beancount"));
    let parser = BeancountParser::new(&sources);

    parse(&sources, &parser, &io::stderr());
}

fn parse<W>(sources: &BeancountSources, parser: &BeancountParser, error_w: W)
where
    W: Write + Copy,
{
    match parser.parse() {
        Ok(ParseSuccess {
            directives,
            options: _,
            plugins: _,
            warnings,
        }) => {
            for directive in directives {
                println!("{}\n", &directive);
            }
    
            sources.write(error_w, warnings).unwrap();
        }
        Err(ParseError { errors, warnings }) => {
            sources.write(error_w, errors).unwrap();
            sources.write(error_w, warnings).unwrap();
        }
    }
}

Implementations§

source§

impl<'s, 't> BeancountParser<'s, 't>
where 's: 't,

source

pub fn new(sources: &'s BeancountSources) -> Self

Create a BeancountParser from BeancountSources read from all input files.

source

pub fn parse(&'t self) -> Result<ParseSuccess<'t>, ParseError>
where 's: 't,

Parse the sources, returning date-sorted directives and options, or errors, along with warnings in both cases.

Auto Trait Implementations§

§

impl<'s, 't> RefUnwindSafe for BeancountParser<'s, 't>

§

impl<'s, 't> Send for BeancountParser<'s, 't>

§

impl<'s, 't> Sync for BeancountParser<'s, 't>

§

impl<'s, 't> Unpin for BeancountParser<'s, 't>

§

impl<'s, 't> UnwindSafe for BeancountParser<'s, 't>

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>,

§

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>,

§

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> MaybeSync for T