summaryrefslogtreecommitdiffstats
path: root/vendor/pest_derive/examples
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/pest_derive/examples')
-rw-r--r--vendor/pest_derive/examples/calc.rs4
-rw-r--r--vendor/pest_derive/examples/help-menu.pest36
-rw-r--r--vendor/pest_derive/examples/help-menu.rs28
3 files changed, 66 insertions, 2 deletions
diff --git a/vendor/pest_derive/examples/calc.rs b/vendor/pest_derive/examples/calc.rs
index 707162536..61df2527c 100644
--- a/vendor/pest_derive/examples/calc.rs
+++ b/vendor/pest_derive/examples/calc.rs
@@ -72,8 +72,8 @@ fn main() {
.op(Op::infix(Rule::add, Left) | Op::infix(Rule::sub, Left))
.op(Op::infix(Rule::mul, Left) | Op::infix(Rule::div, Left))
.op(Op::infix(Rule::pow, Right))
- .op(Op::postfix(Rule::fac))
- .op(Op::prefix(Rule::neg));
+ .op(Op::prefix(Rule::neg))
+ .op(Op::postfix(Rule::fac));
let stdin = stdin();
let mut stdout = stdout();
diff --git a/vendor/pest_derive/examples/help-menu.pest b/vendor/pest_derive/examples/help-menu.pest
new file mode 100644
index 000000000..f7d398537
--- /dev/null
+++ b/vendor/pest_derive/examples/help-menu.pest
@@ -0,0 +1,36 @@
+WHITESPACE = _{ " " }
+
+Rew = ! { ( ASCII_DIGIT | ASCII_ALPHA_UPPER | "_" | "-" ) + }
+Lit = ! { ( ASCII_ALPHANUMERIC | "_" | "-" ) + }
+Word = _ { Rew | Lit }
+WordGroup = _ { Word ~ ( " " ~ Word ) * }
+
+// Argument groups are nonatomic;
+// "<whitespace |between|the|bar|or|braces |is | OK>"
+
+ArgOptChoiceGroup = { ( "[" ~ Word + ~
+ ( "|" ~ ( Word
+ | ArgChoiceGroup ) + ) * ~
+ "]" ) + }
+ArgReqChoiceGroup = { ( "<" ~ Word + ~
+ ( "|" ~ ( Word
+ | ArgChoiceGroup ) + ) * ~
+ ">" ) + }
+ArgChoiceGroup = _ { ArgOptChoiceGroup
+ | ArgReqChoiceGroup }
+
+Command = {
+ ( WordGroup ) ~
+ ( ArgChoiceGroup ) *
+}
+
+HelpMenu = {
+ SOI ~
+
+ (
+ Command ~
+ NEWLINE
+ ) * ~
+
+ EOI
+}
diff --git a/vendor/pest_derive/examples/help-menu.rs b/vendor/pest_derive/examples/help-menu.rs
new file mode 100644
index 000000000..8bafc7a73
--- /dev/null
+++ b/vendor/pest_derive/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);
+ });
+}