https://github.com/jongiddy/hefty
Parser that handles interrupted data streams
https://github.com/jongiddy/hefty
Last synced: 3 months ago
JSON representation
Parser that handles interrupted data streams
- Host: GitHub
- URL: https://github.com/jongiddy/hefty
- Owner: jongiddy
- License: mit
- Created: 2023-11-15T21:15:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-19T21:26:11.000Z (about 1 year ago)
- Last Synced: 2025-02-28T15:32:28.916Z (3 months ago)
- Language: Rust
- Size: 106 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hefty
Parser for streaming data.
```rust
// Build parsers for a URI hostname (https://www.rfc-editor.org/rfc/rfc3986.html#appendix-A)
let unreserved = char::when(|c| c.is_ascii_alphanumeric() || "-._~".contains(c));
let pct_encoded = (
'%',
char::when(|c| c.is_ascii_hexdigit()).times(2).collect(),
)
.seq()
.collect();
let sub_delims = ('!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=').any();let reg_name = (&unreserved, &pct_encoded, &sub_delims)
.any()
.repeated(1..255)
.collect();// Parse a hostname arriving as a stream of data.
let ParseResult::Partial(state) = reg_name.extract(ByteStream::from("www.exa"), None, false)
else {
panic!();
};
let ParseResult::Partial(state) =
reg_name.extract(ByteStream::from("mple.co"), Some(state), false)
else {
panic!();
};
let ParseResult::Match(output, input) =
reg_name.extract(ByteStream::from("m/path"), Some(state), true)
else {
panic!();
};
assert_eq!(output.to_string(), "www.example.com");
assert_eq!(input.to_string(), "/path");
```