summaryrefslogtreecommitdiffstats
path: root/vendor/pest_derive/examples/help-menu.rs
blob: 8bafc7a73d26584feee1c985521d9809b4026383 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#[macro_use]
extern crate pest_derive;
extern crate pest;

use pest::Parser;

#[derive(Parser)]
#[grammar = "../examples/help-menu.pest"]
struct HelpMenuGrammar;

const INPUT: &str = r"cli help
cli positional-command <required-single-argument> [optional-single-argument]
cli [choice | of | one | or | none | of | these | options]
cli <choice | of | one | of | these | options>
cli [nesting | <is | ok>]
";

fn main() {
    HelpMenuGrammar::parse(Rule::HelpMenu, INPUT)
        .expect("Error parsing file")
        .next()
        .expect("Infallible")
        .into_inner()
        .filter(|pair| Rule::Command == pair.as_rule())
        .for_each(|pair| {
            println!("{:#?}", pair);
        });
}