Skip to content

Commit 4a7a5e8

Browse files
committed
test(pratt): migrate parser example
A new feature 'unstable' publishes module internals for tests and examples only. This isn't a general-purpose winnow crate, so keep it private by default. Refs: winnow-rs/winnow#622
1 parent 8920503 commit 4a7a5e8

4 files changed

Lines changed: 676 additions & 0 deletions

File tree

‎crates/dice_parse/Cargo.toml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ edition = "2024"
66
[dependencies]
77
bumpalo = { version = "3.17.0", features = ["std"] }
88
winnow = { version = "0.7.10", features = ["std"] }
9+
10+
[features]
11+
unstable = []
12+
13+
[dev-dependencies]
14+
15+
[[example]]
16+
name = "pratt"
17+
test = true
18+
required-features = ["unstable"]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::io::BufRead;
2+
3+
use winnow::prelude::*;
4+
5+
mod parser;
6+
7+
fn main() {
8+
let stdin = std::io::stdin();
9+
let mut handle = stdin.lock();
10+
let mut buffer = String::new();
11+
12+
loop {
13+
buffer.clear();
14+
match handle.read_line(&mut buffer) {
15+
Ok(0) => break, // eof
16+
Ok(_) => parse(&buffer),
17+
Err(why) => eprintln!("failed to read line: `{why}`"),
18+
}
19+
}
20+
}
21+
22+
fn parse(input: &str) {
23+
match parser::pratt_parser.parse(input) {
24+
Ok(result) => {
25+
println!("{result}");
26+
}
27+
Err(err) => {
28+
eprintln!("FAILED");
29+
eprintln!("{err}");
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)