[][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 expect_end(&mut self) -> Result<()>[src]

Expect the end of input.

The Parser::expect_end method should be called after the last S-expression has been consumed. This allows the parser` to validate that the input stream is at the end or that it only has trailing whitespace.

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

Deprecated since 0.2.5:

Please use the expect_end method instead

Expect the end of input.

pub fn value_iter(&mut self) -> ValueIter<R>[src]

Obtain an iterator over the values produced by the parser.

let mut parser = Parser::from_str(r#"foo ("bar" . 3.14) #:baz (1 2 3)"#);
for value in parser.value_iter() {
    println!("parsed value: {}", value.expect("parse error"));
}

pub fn datum_iter(&mut self) -> DatumIter<R>[src]

Obtain an iterator over the values produced by the parser, including location information.

use lexpr::Parser;

let mut parser = Parser::from_str(r#"foo ("bar" . 3.14) #:baz (1 2 3)"#); for datum in parser.datum_iter() { let datum = datum.expect("parse error"); let span = datum.span(); let start = span.start(); let end = span.end(); println!("parsed datum at {}:{}--{}:{}: {}", start.line(), start.column(), end.start(), end.column(), datum.value()); }

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

Deprecated since 0.2.5:

Please use the expect_value method instead

Parse a single S-expression from the input source.

pub fn expect_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::value_iter() 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.expect_value().unwrap(), sexp!(foo));
assert_eq!(parser.expect_value().unwrap(), sexp!(("bar" . 3.14)));
assert_eq!(parser.expect_value().unwrap(), sexp!(#:baz));
assert_eq!(parser.expect_value().unwrap(), sexp!((1 2 3)));
assert!(parser.expect_end().is_ok());

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

Parse an S-expression, returning None on end-of-input.

For consuming the entire sequence of parsed S-expression values, the value_iter method may be more convenient than calling this method in a loop.

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

Deprecated since 0.2.5:

Please use the next_value method instead

Parse a single S-expression from the input source.

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

Parse a single S-expression including location information, returning an error on end-of-input.

pub fn next_datum(&mut self) -> Result<Option<Datum>>[src]

Parse a single S-expression including location information.

When end of input is reached, None is returned.

For consuming the entire sequence of parsed S-expression datums, the datum_iter method may be more convenient than calling this method in a loop.

Trait Implementations

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

type Item = Result<Value>

The type of the elements being iterated over.

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

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

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

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

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

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.