Crates.io | transduce |
lib.rs | transduce |
version | 0.4.4 |
source | src |
created_at | 2023-06-09 22:17:29.653825 |
updated_at | 2023-06-27 06:34:37.692336 |
description | Zero-copy isomorphic parsing: your code should look like what it parses. |
homepage | |
repository | https://github.com/wrsturgeon/transduce |
max_upload_size | |
id | 886603 |
size | 91,149 |
transduce
: Zero-Copy Isomorphic ParsingSee this example from lib.rs
:
let parser = exact(&b'(') >> verbatim() << exact(&b')');
let input = b"(*)";
assert_eq!(
parser.parse(input),
Ok(&b'*'), // Reference to the region of input inside parentheses
);
// Or, equivalently:
assert_eq!(
parenthesized(verbatim).parse(input),
Ok(&b'*'),
);
This does exactly what it looks like it does.
Equivalently,
assert_eq!(parenthesized(verbatim()).parse(rawstr.chars()), Ok('*'))
The parse
method automatically locates the error (even for user-defined parsers) and prints out gorgeous, colored Rust-style errors:
(exact(b'?') >> exact(b'?')).parse_or_panic(b"???");
...| Error while parsing:
1 | ???
| ^ Unparsed input remains after parsing what should have been everything
(verbatim() & verbatim() & verbatim() & verbatim()).parse_or_panic(b"???");
...| Error while parsing:
1 | ???
| ^ Reached end of input but expected an item
(verbatim() << exact(b'!')).parse_or_panic(b"???")
...| Error while parsing:
1 | ???
| ^ Expected 33 but found 63
no_std
This crate has no dependencies. It's also entirely no_std
; a std
version isn't even necessary.
If (for some reason?) you want to run this on a microcontroller or just without heap allocation, the alloc
feature can be disabled.
The entire core still works, but a few parsers in base
(those involving vectors whose length is unknown at compile time, e.g. comma_separated
) will be unavailable.
Huge shoutout to UPenn's CIS 194 and Haskell's higher-order parsing libraries I learned in 194.