| Crates.io | incpa |
| lib.rs | incpa |
| version | 0.0.3 |
| created_at | 2025-04-19 14:00:57.307133+00 |
| updated_at | 2025-04-20 13:39:11.782527+00 |
| description | An INCremental PArser composition crate. |
| homepage | https://github.com/nejucomo/incpa |
| repository | https://github.com/nejucomo/incpa |
| max_upload_size | |
| id | 1640678 |
| size | 41,884 |
incpa is an incremental parser composition crate.
Incremental parsers process a chunk of input, then either produce an error, a parsed output, or an updated parser state ready for future input. This primitive, codified by ParserState::feed, allows the same parser definition to support parsing streaming input from async or sync sources, as well as other "incremental" use cases such as interactive REPL loop parsing.
The term "parser composition" emphasizes how sophisticated parsers can be defined by composing simpler parsers.
The incpa project functionality is separated into multiple distinct crates:
incpa-byte crate provides byte-wise input functionality, such as UTF8 decoding (so that any string parser can read byte-oriented sources).async input streams is provided in the downstream incpa-tokio crate.use incpa::BaseParserError;
use incpa::primitive::remaining;
use incpa::Parser;
fn main() -> Result<(), BaseParserError> {
let parser = define_my_parser();
let output = parser.parse_all("Hello World!")?;
assert_eq!(output, ("Hello", " World!".to_string()));
Ok(())
}
fn define_my_parser() -> impl Parser<str, Output=(&'static str, String), Error=BaseParserError> {
"Hello".then(remaining())
}
There is a fundamental trade-off between streaming parsers, like incpa-based parsers, versus "zero-copy" parsers which parse values which refer back to the original input buffer.
Zero-copy parsers reduce the memory footprint and amount of copying at the cost of requiring all input to be held in memory, whereas streaming parsers can parse very large inputs at the cost of internally copying input where necessary.
This crate is inspired by chumsky which is an excellent and mature parser composition crate. Another inspiration is parsec in haskell-land.
This crate is in the version 0.0.x phase of early proof of concept with unstable APIs.
incpa-byte crate.This release just fixed some missing Cargo.toml metadata: homepage and repository.
Basic core structure with:
incpa_byte::ByteParser, hardcoded incpa_byte::BufferManager strategy (later moved to separate incpa_byte crate.