1 #![allow(dead_code)]
2 #![cfg_attr(feature = "cargo-clippy", allow(block_in_if_condition_stmt))]
3 
4 #[macro_use]
5 extern crate nom;
6 
7 use nom::IResult;
8 use nom::error::{ErrorKind,ParseError};
9 use nom::character::streaming::digit1 as digit;
10 
11 use std::convert::From;
12 
13 #[derive(Debug)]
14 pub struct CustomError(String);
15 
16 impl<'a> From<(&'a str, ErrorKind)> for CustomError {
from(error: (&'a str, ErrorKind)) -> Self17   fn from(error: (&'a str, ErrorKind)) -> Self {
18     CustomError(format!("error code was: {:?}", error))
19   }
20 }
21 
22 impl<'a> ParseError<&'a str> for CustomError {
from_error_kind(_: &'a str, kind: ErrorKind) -> Self23   fn from_error_kind(_: &'a str, kind: ErrorKind) -> Self {
24     CustomError(format!("error code was: {:?}", kind))
25   }
26 
append(_: &'a str, kind: ErrorKind, other: CustomError) -> Self27   fn append(_: &'a str, kind: ErrorKind, other: CustomError) -> Self {
28     CustomError(format!("{:?}\nerror code was: {:?}", other, kind))
29 
30   }
31 
32 }
33 
test1(input: &str) -> IResult<&str, &str, CustomError>34 fn test1(input: &str) -> IResult<&str, &str, CustomError> {
35   //fix_error!(input, CustomError, tag!("abcd"))
36   tag!(input, "abcd")
37 }
38 
test2(input: &str) -> IResult<&str, &str, CustomError>39 fn test2(input: &str) -> IResult<&str, &str, CustomError> {
40   //terminated!(input, test1, fix_error!(CustomError, digit))
41   terminated!(input, test1, digit)
42 }
43 
test3(input: &str) -> IResult<&str, &str, CustomError>44 fn test3(input: &str) -> IResult<&str, &str, CustomError> {
45   verify!(input, test1, |s: &str| {
46     s.starts_with("abcd")
47   })
48 }
49 
50 #[cfg(feature = "alloc")]
test4(input: &str) -> IResult<&str, Vec<&str>, CustomError>51 fn test4(input: &str) -> IResult<&str, Vec<&str>, CustomError> {
52   count!(input, test1, 4)
53 }
54