summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs5
-rw-r--r--src/parser.rs17
-rw-r--r--src/pattern.rs72
3 files changed, 43 insertions, 51 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 897618b..27d6c30 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -87,6 +87,7 @@
 //!
 //! # Examples
 //!
+// FIXME check if this is actually the case :v
 //! The Datafu pattern
 //!
 //! ```datafu
@@ -111,7 +112,6 @@
 
 pub mod errors;
 mod graph;
-//pub mod type_tree;
 mod parser;
 mod pattern;
 mod vm;
@@ -119,6 +119,7 @@ mod vm;
 pub use pattern::Pattern;
 pub use pattern::PatternBuilder;
 
+// TODO remove/redesign
 /// A predicate.
 type Predicate = dyn (Fn(
     &mut dyn erased_serde::Deserializer<'_>
@@ -139,7 +140,7 @@ type Predicate = dyn (Fn(
 ///
 /// But this does:
 ///
-/// ```rust
+/// ```rust,ignore
 /// use serde::Deserialize;
 ///
 /// let x = datafu::pred(|v| String::deserialize(v).is_ok());
diff --git a/src/parser.rs b/src/parser.rs
index 744ab0f..e58107e 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -33,13 +33,6 @@ macro_rules! bry {
     };
 }
 
-// the following macros rely on unlabeled-break-through-labeled-block being an
-// error.
-// NOTE: always test changes to this module on nightly!
-// still waiting for label-break-value stabilization...
-
-#[cfg(not(feature = "stable"))]
-/// labeled block. on nightly: better compile errors. but also works on stable.
 macro_rules! lblock {
     // unfortunately ($l:lifetime : $b:block) => { $l: $b } didn't work.
     ($($t:tt)+) => {
@@ -47,16 +40,6 @@ macro_rules! lblock {
     }
 }
 
-#[cfg(feature = "stable")]
-/// labeled block. on nightly: better compile errors. but also works on stable.
-macro_rules! lblock {
-    ($l:lifetime : $b:block) => {
-        $l: loop {
-            break $b
-        }
-    }
-}
-
 /// Attempts to shift `s` forward by removing `prefix`.
 ///
 /// Returns whether `s` has had `prefix` removed.
diff --git a/src/pattern.rs b/src/pattern.rs
index 38cdcda..23d427e 100644
--- a/src/pattern.rs
+++ b/src/pattern.rs
@@ -24,12 +24,11 @@ use crate::vm::MAX_CALLS;
 /// # Examples
 ///
 /// ```
-/// use datafu::Pattern;
+/// use datafu::PatternBuilder;
 ///
-/// let pattern = Pattern::<()>::compile::<&str, &str>(
+/// let pattern = PatternBuilder::for_pattern(
 ///     "->['value']'hello'",
-///     None, None
-/// ).expect("failed to compile pattern");
+/// ).compile().expect("failed to compile pattern");
 /// ```
 pub struct Pattern<O: Serialize> {
     consts: PatternConstants<O>,
@@ -77,34 +76,43 @@ impl<'s> PatternBuilder<'s> {
     /// # Examples
     ///
     /// ```
-    /// use datafu::Pattern;
-    /// use serde::Deserialize;
-    /// use charx;
-    ///
-    /// let preds = vec![
-    ///     ("dict", datafu::pred(|v| { todo!() })),
-    ///     ("str", datafu::pred(|v| { String::deserialize(v).is_ok() })),
-    ///     ("commit", datafu::pred(|v| {
-    ///         if let Ok(v) = String::deserialize(v) {
-    ///             v.len() == 40 && v.trim_start_matches(
-    ///                 charx::is_ascii_hexdigit
-    ///             ).is_empty()
-    ///         } else {
-    ///             false
-    ///         }
-    ///     })),
-    ///     ("uri", datafu::pred(|v| { todo!() })),
-    ///     ("bool", datafu::pred(|v| { todo!() })),
-    /// ].into_iter().collect();
-    /// let pattern = Pattern::<()>::compile::<&str, &str>("
-    ///        ->'projects':$dict
-    ///          ->commit[:?$str:?$commit]:?$dict
-    ///            ->url[:?$str:?$uri]:?$dict
-    ///              ->branch:?$dict
-    ///                (->active'active'?:?$bool)
-    ///                (->federate'federate'?:?$bool)?",
-    ///     Some(preds), None
-    /// ).expect("failed to compile pattern");
+    /// use datafu::PatternBuilder;
+    ///// use serde::Deserialize;
+    ///// use charx;
+    /////
+    ///// let preds = vec![
+    /////     ("dict", datafu::pred(|v| { todo!() })),
+    /////     ("str", datafu::pred(|v| { String::deserialize(v).is_ok() })),
+    /////     ("commit", datafu::pred(|v| {
+    /////         if let Ok(v) = String::deserialize(v) {
+    /////             v.len() == 40 && v.trim_start_matches(
+    /////                 charx::is_ascii_hexdigit
+    /////             ).is_empty()
+    /////         } else {
+    /////             false
+    /////         }
+    /////     })),
+    /////     ("uri", datafu::pred(|v| { todo!() })),
+    /////     ("bool", datafu::pred(|v| { todo!() })),
+    ///// ].into_iter().collect();
+    ///// let pattern = PatternBuilder::for_pattern("
+    /////        ->'projects':$dict
+    /////          ->commit[:?$str:?$commit]:?$dict
+    /////            ->url[:?$str:?$uri]:?$dict
+    /////              ->branch:?$dict
+    /////                (->active'active'?:?$bool)
+    /////                (->federate'federate'?:?$bool)?"
+    ///// ).compile().expect("failed to compile pattern");
+    /// let pattern = PatternBuilder::for_pattern("
+    ///     :map
+    ///     ->['projects'?]:map
+    ///       ->[commit:?str]:?map
+    ///         ->[url:?str]:?map
+    ///           ->[branch:?str]:?map
+    ///             (->['active'?]active:?bool)?
+    ///             (->['federate'?]?federate:?bool)?
+    ///             (->['pinned'?]?pinned:?bool)?
+    /// ").compile().expect("failed to compile pattern");
     /// ```
     pub fn for_pattern(pattern: &'s str) -> Self {
         Self {