Debian Codegraph @

tests/run-pass/rule_where_clause.rs

raw symbols SCIP
1 extern crate peg;
2 use std::{
3 str::FromStr,
4 fmt::Debug,
5 };
6
7 peg::parser!(
8 grammar parser() for str {
9 use std::cell::Cell;
10 pub rule nums<C, T>() -> C
11 where C: Default + Extend<T>,
12 T: FromStr,
13 <T as FromStr>::Err: Debug,
14 = c:({ Cell::new(C::default()) })
15 (ch:$(['0'..='9']) {
16 let mut mutc = c.take();
17 mutc.extend(Some(ch.parse::<T>().unwrap()));
18 c.set(mutc);
19 })+
20 { c.take() }
21 }
22 );
23
24 fn main() {
25 assert_eq!(parser::nums::<Vec<u8>, u8>("3729"), Ok(vec![3, 7, 2, 9]));
26 }
27