File: bytes.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 (13 lines) | stat: -rw-r--r-- 339 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
extern crate peg;
use peg::parser;

parser!{
    grammar byteparser() for [u8] {
        pub rule commands() -> Vec<&'input[u8]> = command()*
        rule command() -> &'input [u8] = ">" val:$([b' ' ..= b'~']+) [0] { val }
    }
}

fn main() {
    assert_eq!(byteparser::commands(b">asdf\0>xyz\0"), Ok(vec![&b"asdf"[..], &b"xyz"[..]]));
}