[−][src]Struct lexpr::Parser
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][−]
R: Read<'de>,
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][−]
R: Read,
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][−]
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][−]
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][−]
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
Auto Trait Implementations
impl<R> RefUnwindSafe for Parser<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> Send for Parser<R> where
R: Send,
R: Send,
impl<R> Sync for Parser<R> where
R: Sync,
R: Sync,
impl<R> Unpin for Parser<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for Parser<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src][+]
I: Iterator,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,