summaryrefslogtreecommitdiff
path: root/support/pkgcheck/src/gparser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/pkgcheck/src/gparser.rs')
-rw-r--r--support/pkgcheck/src/gparser.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/support/pkgcheck/src/gparser.rs b/support/pkgcheck/src/gparser.rs
new file mode 100644
index 0000000000..6f9d7f393a
--- /dev/null
+++ b/support/pkgcheck/src/gparser.rs
@@ -0,0 +1,46 @@
+use pest::Parser;
+
+#[cfg(debug_assertions)]
+const _GRAMMAR: &'static str = include_str!("generate.pest");
+
+#[derive(Parser)]
+#[grammar = "generate.pest"]
+pub struct GenerateParser;
+
+pub fn parse_generate(s: &str) -> Option<Vec<String>> {
+ let pairs = GenerateParser::parse(Rule::file, s);
+
+ if pairs.is_err() {
+ return None;
+ }
+
+ let mut found = Vec::new();
+
+ for pair in pairs.unwrap() {
+ // A pair is a combination of the rule which matched and a span of input
+
+ // A pair can be converted to an iterator of the tokens which make it up:
+ for inner_pair in pair.into_inner() {
+ let inner_span = inner_pair.clone().as_span();
+ match inner_pair.as_rule() {
+ Rule::filename => {
+ //println!("fname: {}", inner_span.as_str());
+ // https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#clone_double_ref
+ let s: String = inner_span.as_str().to_string();
+ //println!("filename: {}", s);
+ found.push(s);
+ }
+ Rule::EOI => (),
+ e => {
+ println!("unreachable: {:?}", e);
+ unreachable!()
+ }
+ };
+ }
+ }
+ if found.is_empty() {
+ None
+ } else {
+ Some(found)
+ }
+}