File: optional.rs

package info (click to toggle)
rust-peg 0.8.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 756 kB
  • sloc: makefile: 20; sh: 12
file content (16 lines) | stat: -rw-r--r-- 357 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
extern crate peg;

peg::parser!( grammar test_grammar() for str {
    pub rule options() -> Option<()>
        = "abc" v:"def"? {v}

    pub rule option_unused_result() = "a"? / "b"
});

use self::test_grammar::*;

fn main() {
    assert_eq!(options("abc"), Ok(None));
    assert_eq!(options("abcdef"), Ok(Some(())));
    assert!(options("def").is_err());
}