Crate pacosso

Crate pacosso 

Source
Expand description

Pacosso is a framework for rapid parser development. It does not aim at building high-performance parsers - other frameworks are much more suitable for that - but rather at easy development for rapid prototyping and projects with moderate performance requirements.

Different from other streaming parser libraries, pacosso manages the incoming stream internally. The feature is intended to make writing parsers as easy as possible. Pacosso is able to handle any reader including in-memory buffers and strings, files, sockets and IO-chains combining such readers.

To see pacosso in action, have a look at Jsosso, a JSON parser that demonstrates the framework. It contains demo programs, benchmarks and more documentation.

Example:

use std::io;
use pacosso::{Stream, ParseResult};
use pacosso::options::Opts;

let parse = |p: &mut Stream<io::Cursor<Vec<u8>>>| -> ParseResult<()> {
    p.string("hello")?;
    p.whitespace()?;
    p.string("world")
};

let mut input = io::Cursor::new("hello world".as_bytes().to_vec());
let mut s = Stream::new(Opts::default().set_buf_size(8), &mut input);

assert!(match s.apply(parse) {
    Ok(()) => true,
    Err(e) => {
       eprintln!("error: {:?}", e);
       false
    },
});

Re-exports§

pub use self::options::Opts;
pub use self::error::*;

Modules§

error
options

Structs§

Cursor
Cursor keeps track of the position in the overall stream, in terms of lines in the stream and within the current line. Note that, for stream, the start position is 0, while, for line and lpos, the start position is 1.
Stream
Stream manages the reader from which to parse. Streams can be built from any reader including in-memory buffers and strings, files, sockets and io::Chains.

Functions§

parse_buffer
Convenience interface for parsing a byte buffer.
parse_file
Convenience interface for parsing from a file.
parse_string
Convenience interface for parsing a string.

Type Aliases§

ParseResult
Parser methods return a Result of a generic type and a ParseError