J-F-Liu / pom

PEG parser combinators using operator overloading without macros.
MIT License
500 stars 31 forks source link

Is it possible to match a case insensitive seq? #20

Closed real-felix closed 6 years ago

real-felix commented 6 years ago
use pom::{
    combinator::{Combinator, seq},
    Parser,
};

enum Operation {
    Data,
}

fn operation<'a>() -> Combinator<impl Parser<'a, u8, Output=Operation>> {
    seq(b"DAT").map(|_| Operation::Data)
}

#[test]
fn operation_is_ok() {
    assert_eq!(
        super::operation().parse(b"DAT"),
        Ok(Operation::Data)
    );
    assert_eq!(
        super::operation().parse(b"Dat"),
        Ok(Operation::Data)
    );
    assert_eq!(
        super::operation().parse(b"dat"),
        Ok(Operation::Data)
    );

    assert!(super::operation().parse(b"whatever").is_err());
}

How to make the test ok?

J-F-Liu commented 6 years ago

Maybe create a new combinator, change this line to match case insensitively.

real-felix commented 6 years ago

It worked, thanks! I used the 1.* version, tho