| Crates.io | wood_parse |
| lib.rs | wood_parse |
| version | 0.2.0 |
| created_at | 2025-04-07 14:17:06.234136+00 |
| updated_at | 2025-04-07 14:28:01.982345+00 |
| description | A library for lexing |
| homepage | |
| repository | https://github.com/WoodieMaster/wood_parse |
| max_upload_size | |
| id | 1624201 |
| size | 17,480 |
This crate provides some methods for parsing text.
I mostly developed it for a custom language I want to build.
This crate exposes two main structs:
Read trait.To use this package, add the the crate to your Cargo.toml file or run cargo add wood-parse
Then, import into your Rust code:
use wood_parse::{text_parser::TextParser, util::TextParserResult};
This code will remove all whitespace from a file:
let input = "a b c";
let expected = "abc";
// create the parser and get the peeker
let mut parser = TextParser::new(input.as_bytes());
let mut peeker = parser.peeker();
let mut parsed_string = String::new();
// Loop until the end is hit or an error occurs
loop {
// skip whitespace
let _ = peeker.consume_while(|ch: char| ch.is_whitespace());
// get the next character
let (result, _) = peeker.next();
match result {
TextParserResult::Ok(ch) => parsed_string.push(ch),
TextParserResult::End => break,
_ => {}
}
}
//compare results
assert!(
parsed_string == expected,
"Expected {expected}, got {parsed_string}"
);