]> git.proxmox.com Git - proxmox-backup.git/commitdiff
move tools::nom to pbs-tools
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Jul 2021 08:08:26 +0000 (10:08 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Jul 2021 08:08:26 +0000 (10:08 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
pbs-tools/src/lib.rs
pbs-tools/src/nom.rs [new file with mode: 0644]
src/tools/mod.rs
src/tools/nom.rs [deleted file]

index 9bf1368c30021c782bb28a4a23011898b2774d1d..3acdd9012691730ba5bf7aa50edce556d7eab9cb 100644 (file)
@@ -1,6 +1,7 @@
 pub mod borrow;
 pub mod format;
 pub mod fs;
+pub mod nom;
 pub mod str;
 
 mod command;
diff --git a/pbs-tools/src/nom.rs b/pbs-tools/src/nom.rs
new file mode 100644 (file)
index 0000000..62d8c9a
--- /dev/null
@@ -0,0 +1,79 @@
+use anyhow::{bail, Error};
+
+use nom::{
+    error::{ParseError, VerboseError},
+    bytes::complete::{take_while, take_while1},
+    combinator::{map_res, all_consuming, recognize},
+    character::complete::{digit1},
+};
+
+pub type IResult<I, O, E = VerboseError<I>> = Result<(I, O), nom::Err<E>>;
+
+pub fn parse_error<'a>(i: &'a str, context: &'static str) -> nom::Err<VerboseError<&'a str>> {
+    let err = VerboseError { errors: Vec::new() };
+    let err = VerboseError::add_context(i, context, err);
+    nom::Err::Error(err)
+}
+
+pub fn parse_failure<'a>(i: &'a str, context: &'static str) -> nom::Err<VerboseError<&'a str>> {
+    let err = VerboseError { errors: Vec::new() };
+    let err = VerboseError::add_context(i, context, err);
+    nom::Err::Failure(err)
+}
+
+/// Recognizes zero or more spaces and tabs (but not carage returns or line feeds)
+pub fn multispace0(i: &str)  -> IResult<&str, &str> {
+    take_while(|c| c == ' ' || c == '\t')(i)
+}
+
+/// Recognizes one or more spaces and tabs (but not carage returns or line feeds)
+pub fn multispace1(i: &str)  -> IResult<&str, &str> {
+    take_while1(|c| c == ' ' || c == '\t')(i)
+}
+
+/// Recognizes one or more non-whitespace-characters
+pub fn notspace1(i: &str)  -> IResult<&str, &str> {
+    take_while1(|c| !(c == ' ' || c == '\t' || c == '\n'))(i)
+}
+
+/// Parse a 64 bit unsigned integer
+pub fn parse_u64(i: &str) -> IResult<&str, u64> {
+    map_res(recognize(digit1), str::parse)(i)
+}
+
+/// Parse complete input, generate verbose error message with line numbers
+pub fn parse_complete<'a, F, O>(what: &str, i: &'a str, parser: F) -> Result<O, Error>
+    where F: Fn(&'a str) -> IResult<&'a str, O>,
+{
+    match all_consuming(parser)(i) {
+        Err(nom::Err::Error(err)) |
+        Err(nom::Err::Failure(err)) => {
+            bail!("unable to parse {} - {}", what, nom::error::convert_error(i, err));
+        }
+        Err(err) => {
+            bail!("unable to parse {} - {}", what, err);
+        }
+        Ok((_, data)) => Ok(data),
+    }
+
+}
+
+/// Parse complete input, generate simple error message (use this for sinple line input).
+pub fn parse_complete_line<'a, F, O>(what: &str, i: &'a str, parser: F) -> Result<O, Error>
+    where F: Fn(&'a str) -> IResult<&'a str, O>,
+{
+    match all_consuming(parser)(i) {
+        Err(nom::Err::Error(VerboseError { errors })) |
+        Err(nom::Err::Failure(VerboseError { errors })) => {
+            if errors.is_empty() {
+                bail!("unable to parse {}", what);
+            } else {
+                bail!("unable to parse {} at '{}' - {:?}", what, errors[0].0, errors[0].1);
+            }
+        }
+        Err(err) => {
+            bail!("unable to parse {} - {}", what, err);
+        }
+        Ok((_, data)) => Ok(data),
+    }
+}
index 21d333659123e2bb0d20eadb1deca0599e9c0466..1e1ea878f55ae904be6cb77b15181939ad23b51b 100644 (file)
@@ -23,6 +23,7 @@ use proxmox_http::{
     ProxyConfig,
 };
 
+pub use pbs_tools::nom;
 pub use pbs_tools::{run_command, command_output, command_output_as_string};
 
 pub mod acl;
@@ -44,7 +45,6 @@ pub mod logrotate;
 pub mod loopdev;
 pub mod lru_cache;
 pub mod async_lru_cache;
-pub mod nom;
 pub mod serde_filter;
 pub mod statistics;
 pub mod subscription;
diff --git a/src/tools/nom.rs b/src/tools/nom.rs
deleted file mode 100644 (file)
index 62d8c9a..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-use anyhow::{bail, Error};
-
-use nom::{
-    error::{ParseError, VerboseError},
-    bytes::complete::{take_while, take_while1},
-    combinator::{map_res, all_consuming, recognize},
-    character::complete::{digit1},
-};
-
-pub type IResult<I, O, E = VerboseError<I>> = Result<(I, O), nom::Err<E>>;
-
-pub fn parse_error<'a>(i: &'a str, context: &'static str) -> nom::Err<VerboseError<&'a str>> {
-    let err = VerboseError { errors: Vec::new() };
-    let err = VerboseError::add_context(i, context, err);
-    nom::Err::Error(err)
-}
-
-pub fn parse_failure<'a>(i: &'a str, context: &'static str) -> nom::Err<VerboseError<&'a str>> {
-    let err = VerboseError { errors: Vec::new() };
-    let err = VerboseError::add_context(i, context, err);
-    nom::Err::Failure(err)
-}
-
-/// Recognizes zero or more spaces and tabs (but not carage returns or line feeds)
-pub fn multispace0(i: &str)  -> IResult<&str, &str> {
-    take_while(|c| c == ' ' || c == '\t')(i)
-}
-
-/// Recognizes one or more spaces and tabs (but not carage returns or line feeds)
-pub fn multispace1(i: &str)  -> IResult<&str, &str> {
-    take_while1(|c| c == ' ' || c == '\t')(i)
-}
-
-/// Recognizes one or more non-whitespace-characters
-pub fn notspace1(i: &str)  -> IResult<&str, &str> {
-    take_while1(|c| !(c == ' ' || c == '\t' || c == '\n'))(i)
-}
-
-/// Parse a 64 bit unsigned integer
-pub fn parse_u64(i: &str) -> IResult<&str, u64> {
-    map_res(recognize(digit1), str::parse)(i)
-}
-
-/// Parse complete input, generate verbose error message with line numbers
-pub fn parse_complete<'a, F, O>(what: &str, i: &'a str, parser: F) -> Result<O, Error>
-    where F: Fn(&'a str) -> IResult<&'a str, O>,
-{
-    match all_consuming(parser)(i) {
-        Err(nom::Err::Error(err)) |
-        Err(nom::Err::Failure(err)) => {
-            bail!("unable to parse {} - {}", what, nom::error::convert_error(i, err));
-        }
-        Err(err) => {
-            bail!("unable to parse {} - {}", what, err);
-        }
-        Ok((_, data)) => Ok(data),
-    }
-
-}
-
-/// Parse complete input, generate simple error message (use this for sinple line input).
-pub fn parse_complete_line<'a, F, O>(what: &str, i: &'a str, parser: F) -> Result<O, Error>
-    where F: Fn(&'a str) -> IResult<&'a str, O>,
-{
-    match all_consuming(parser)(i) {
-        Err(nom::Err::Error(VerboseError { errors })) |
-        Err(nom::Err::Failure(VerboseError { errors })) => {
-            if errors.is_empty() {
-                bail!("unable to parse {}", what);
-            } else {
-                bail!("unable to parse {} at '{}' - {:?}", what, errors[0].0, errors[0].1);
-            }
-        }
-        Err(err) => {
-            bail!("unable to parse {} - {}", what, err);
-        }
-        Ok((_, data)) => Ok(data),
-    }
-}