1#![allow(dead_code)] 2// #![allow(unused_variables)] 3 4use std::str; 5 6use nom::bytes::complete::is_not; 7use nom::character::complete::char; 8use nom::combinator::{map, map_res}; 9use nom::multi::fold_many0; 10use nom::sequence::delimited; 11use nom::IResult; 12 13fn 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? 23fn 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} 32