[][src]Struct lexpr::Parser

pub struct Parser<R> { /* fields omitted */ }

Parser for the S-expression text representation.

This type, given a input source, provides the parse method, which can be used to read a single S-expression from the input source.

Methods

impl<'de, R> Parser<R> where
    R: Read<'de>, 
[src]

pub fn new(read: R) -> Self[src]

Create an S-expression parser from one of the possible sexpr input sources.

Typically it is more convenient to use one of these methods instead:

  • Parser::from_str
  • Parser::from_slice
  • Parser::from_reader

pub fn with_options(read: R, options: Options) -> Self[src]

Create a customized S-expression parser parser from one of the possible sexpr input sources.

Typically it is more convenient to use one of these methods instead:

  • Parser::from_str_custom
  • Parser::from_slice_custom
  • Parser::from_reader_custom

impl<R> Parser<IoRead<R>> where
    R: Read
[src]

pub fn from_reader(reader: R) -> Self[src]

Creates an S-expression parser from an io::Read.

pub fn from_reader_custom(reader: R, options: Options) -> Self[src]

Creates an S-expression parser from an io::Read.

impl<'a> Parser<SliceRead<'a>>[src]

pub fn from_slice(bytes: &'a [u8]) -> Self[src]

Creates an S-expression parser from a &[u8].

pub fn from_slice_custom(bytes: &'a [u8], options: Options) -> Self[src]

Creates an S-expression parser from a &[u8].

impl<'a> Parser<StrRead<'a>>[src]

pub fn from_str(s: &'a str) -> Self[src]

Creates a S-expression parser from a &str.

pub fn from_str_custom(s: &'a str, options: Options) -> Self[src]

Creates a S-expression parser from a &str.

impl<'de, R: Read<'de>> Parser<R>[src]

pub fn end(&mut self) -> Result<()>[src]

The Parser::end method should be called after a value has been fully parsed. This allows the Parser to validate that the input stream is at the end or that it only has trailing whitespace.

pub fn parse_value(&mut self) -> Result<Value>[src]

Parse a single S-expression from the input source.

This expects an S-expression value to be actually present, and returns an Err when called at the end of input. Use Parser::parse if you need to handle end of input gracefully.

let mut parser = Parser::from_str(r#"foo ("bar" . 3.14) #:baz (1 2 3)"#);
assert_eq!(parser.parse_value().unwrap(), sexp!(foo));
assert_eq!(parser.parse_value().unwrap(), sexp!(("bar" . 3.14)));
assert_eq!(parser.parse_value().unwrap(), sexp!(#:baz));
assert_eq!(parser.parse_value().unwrap(), sexp!((1 2 3)));
assert!(parser.end().is_ok());

pub fn parse(&mut self) -> Result<Option<Value>>[src]

Parse a single S-expression from the input source.

If the end of input is ecountered, this will return Ok(None), otherwise, if parsing suceeded, Ok(Some(Value)).

let mut parser = Parser::from_str(r#"foo ("bar" . 3.14) #:baz (1 2 3)"#);
assert_eq!(parser.parse().unwrap(), Some(sexp!(foo)));
assert_eq!(parser.parse().unwrap(), Some(sexp!(("bar" . 3.14))));
assert_eq!(parser.parse().unwrap(), Some(sexp!(#:baz)));
assert_eq!(parser.parse().unwrap(), Some(sexp!((1 2 3))));
assert_eq!(parser.parse().unwrap(), None);

Auto Trait Implementations

impl<R> Unpin for Parser<R> where
    R: Unpin

impl<R> Sync for Parser<R> where
    R: Sync

impl<R> Send for Parser<R> where
    R: Send

impl<R> RefUnwindSafe for Parser<R> where
    R: RefUnwindSafe

impl<R> UnwindSafe for Parser<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]