| 1 |
#![allow(dead_code)] |
| 2 |
// #![allow(unused_variables)] |
| 3 |
|
| 4 |
use std::str; |
| 5 |
|
| 6 |
use nom::bytes::complete::is_not; |
| 7 |
use nom::character::complete::char; |
| 8 |
use nom::combinator::{map, map_res}; |
| 9 |
use nom::multi::fold_many0; |
| 10 |
use nom::sequence::delimited; |
| 11 |
use nom::IResult; |
| 12 |
|
| 13 |
fn atom<'a>(_tomb: &'a mut ()) -> impl FnMut(&'a [u8]) -> IResult<&'a [u8], String> { |
| 14 |
move |input| { |
| 15 |
map( |
| 16 |
map_res(is_not(" \t\r\n"), str::from_utf8), |
| 17 |
ToString::to_string, |
| 18 |
)(input) |
| 19 |
} |
| 20 |
} |
| 21 |
|
| 22 |
// FIXME: should we support the use case of borrowing data mutably in a parser? |
| 23 |
fn list<'a>(i: &'a [u8], tomb: &'a mut ()) -> IResult<&'a [u8], String> { |
| 24 |
delimited( |
| 25 |
char('('), |
| 26 |
fold_many0(atom(tomb), String::new, |acc: String, next: String| { |
| 27 |
acc + next.as_str() |
| 28 |
}), |
| 29 |
char(')'), |
| 30 |
)(i) |
| 31 |
} |