summaryrefslogtreecommitdiff
path: root/examples/help-menu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/help-menu.rs')
-rw-r--r--examples/help-menu.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/examples/help-menu.rs b/examples/help-menu.rs
new file mode 100644
index 0000000..8bafc7a
--- /dev/null
+++ b/examples/help-menu.rs
@@ -0,0 +1,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);
+ });
+}