#![allow(dead_code)]
use loqom::bytes::tag;
use loqom::character::digit1 as digit;
use loqom::combinator::verify;
use loqom::error::{ErrorKind, ParseError};
#[cfg(feature = "alloc")]
use loqom::multi::count;
use loqom::sequence::terminated;
use loqom::{IResult, Parser};
#[derive(Debug)]
pub struct CustomError(String);
impl<'a> From<(&'a str, ErrorKind)> for CustomError {
fn from(error: (&'a str, ErrorKind)) -> Self {
Self(format!("error code was: {error:?}"))
}
}
impl<'a> ParseError<&'a str> for CustomError {
fn from_error_kind(_: &'a str, kind: ErrorKind) -> Self {
Self(format!("error code was: {kind:?}"))
}
fn append(_: &'a str, kind: ErrorKind, other: Self) -> Self {
Self(format!("{other:?}\nerror code was: {kind:?}"))
}
}
fn test1(input: &str) -> IResult<&str, &str, CustomError> {
tag("abcd").parse(input)
}
fn test2(input: &str) -> IResult<&str, &str, CustomError> {
terminated(test1, digit()).parse(input)
}
fn test3(input: &str) -> IResult<&str, &str, CustomError> {
verify(test1, |s: &str| s.starts_with("abcd")).parse(input)
}
#[cfg(feature = "alloc")]
fn test4(input: &str) -> IResult<&str, Vec<&str>, CustomError> {
count(test1, 4).parse(input)
}