use super::*;
pub type Padding<E> = Repeated<Ignored<Filter<fn(&char) -> bool, E>, char>>;
pub type Padded<P, O> = PaddedBy<PaddingFor<Padding<<P as Parser<char, O>>::Error>, P, Vec<()>, O>, Padding<<P as Parser<char, O>>::Error>, O, Vec<()>>;
pub trait TextParser<O>: Parser<char, O> {
fn padded(self) -> Padded<Self, O> where Self: Sized {
whitespace().padding_for(self).padded_by(whitespace())
}
}
impl<O, P: Parser<char, O>> TextParser<O> for P {}
pub fn whitespace<E: Error<char>>() -> Padding<E> {
filter((|c: &char| c.is_whitespace()) as _).ignored().repeated()
}
pub fn newline<E: Error<char>>() -> impl Parser<char, (), Error = E> {
just('\r').or_not().padding_for(just('\n'))
.or(just('\x0B')) .or(just('\x0C')) .or(just('\x0D')) .or(just('\u{0085}')) .or(just('\u{2028}')) .or(just('\u{2029}')) .ignored()
}
pub fn digits<E: Error<char>>() -> Repeated<Filter<fn(&char) -> bool, E>> {
filter(char::is_ascii_digit as _).repeated_at_least(1)
}
pub fn int<E: Error<char>>() -> impl Parser<char, Vec<char>, Error = E> + Copy + Clone {
filter(|c: &char| c.is_ascii_digit() && *c != '0').map(Some)
.chain(filter(char::is_ascii_digit).repeated())
.or(just('0').map(|c| vec![c]))
}
pub fn ident<E: Error<char>>() -> impl Parser<char, Vec<char>, Error = E> + Copy + Clone {
filter(|c: &char| c.is_ascii_alphabetic() || *c == '_').map(Some)
.chain(filter(|c: &char| c.is_ascii_alphanumeric() || *c == '_').repeated())
}