Debian Codegraph @

tests/run-pass/pos_neg_assert.rs

raw symbols SCIP
1 extern crate peg;
2
3 peg::parser!( grammar lookahead() for str {
4 pub rule consonants()
5 = (!['a'|'e'|'i'|'o'|'u']['a'..='z'])+
6
7 pub rule neg_lookahead_err() = !(['a']['b']) ['a']['x']
8
9 pub rule lookahead_result() -> &'input str
10 = v:&($(['a'..='c']*)) "abcd" { v }
11 });
12
13 fn main() {
14 // negative lookahead
15 assert!(lookahead::consonants("qwrty").is_ok());
16 assert!(lookahead::consonants("rust").is_err());
17
18 // expected characters in negative lookahead should not be reported in parse error messages
19 let err = lookahead::neg_lookahead_err("ac").err().unwrap();
20 assert_eq!(err.expected.tokens().count(), 1, "expected set includes: {}", err.expected);
21 assert_eq!(err.location.offset, 1);
22
23 // positive lookahead
24 assert_eq!(lookahead::lookahead_result("abcd"), Ok("abc"));
25 assert!(lookahead::lookahead_result("abc").is_err());
26 }