packages feed

regex-applicative 0.1.2 → 0.1.3

raw patch · 4 files changed

+65/−6 lines, 4 filesdep ~base

Dependency ranges changed: base

Files

CHANGES.md view
@@ -1,6 +1,11 @@ Changes ======= +0.1.3+-----+* Fix a .cabal-file issue introduced in 0.1.2+* Change the fixity of =~+ 0.1.2 ----- * Relax the constraint on the containers version
Text/Regex/Applicative/Interface.hs view
@@ -68,3 +68,4 @@ -- | Attempts to match a string of symbols against the regular expression (=~) :: [s] -> RE s a -> Maybe a s =~ (RE r) = priorityToMaybe $ match r s+infix 2 =~
+ Text/Regex/Applicative/Priorities.hs view
@@ -0,0 +1,51 @@+{-# LANGUAGE DeriveFunctor #-}+module Text.Regex.Applicative.Priorities+    ( Priority+    , PrNum+    , withPriority+    , priorityToMaybe+    , isOK+    ) where+import Control.Applicative+import qualified Data.Sequence as Sequence++-- | An applicative functor similar to Maybe, but it's '<|>' method honors+-- priority.+data Priority a = Priority { priority :: !PrSeq, pValue :: a } | Fail+    deriving (Functor, Show)+type PrSeq = Sequence.Seq PrNum+type PrNum = Int++instance Applicative Priority where+    pure x = Priority Sequence.empty x+    Priority p1 f <*> Priority p2 x = Priority (p1 Sequence.>< p2) (f x)+    _ <*> _ = Fail++instance Alternative Priority where+    empty = Fail+    p@Priority {} <|> Fail = p+    Fail <|> p@Priority {} = p+    Fail <|> Fail = Fail+    p1@Priority {} <|> p2@Priority {} = {-# SCC "compare_priorities" #-}+        case compare (priority p1) (priority p2) of+            LT -> p2+            GT -> p1+            EQ -> error $+                "Two priorities are the same! Should not happen.\n" ++ show (priority p1)++-- | Adds priority to the end+withPriority :: PrNum -> Priority a -> Priority a+withPriority p (Priority ps x) = Priority (ps Sequence.|> p) x+withPriority _ Fail = Fail++-- | Discards priority information+priorityToMaybe :: Priority a -> Maybe a+priorityToMaybe p =+    case p of+        Priority { pValue = x } -> Just x+        Fail -> Nothing++isOK p =+    case p of+        Fail -> False+        Priority {} -> True
regex-applicative.cabal view
@@ -9,7 +9,7 @@ -- standards guiding when and how versions should be incremented.  -- DO NOT FORGET TO UPDATE THE GIT TAG BELOW!!!-Version:             0.1.2+Version:             0.1.3  -- A short (one-line) description of the package. Synopsis:            Regex-based parsing with applicative interface@@ -56,19 +56,21 @@ Source-repository this   type:     git   location: git://github.com/feuerbach/regex-applicative.git-  tag:      v0.1.2+  tag:      v0.1.3  Library-  -- Modules exported by the library.-  Exposed-modules:     Text.Regex.Applicative, Text.Regex.Applicative.Reference-     -- Packages needed in order to build this package.   Build-depends:       base == 4.3.*,                        containers >= 0.3 && < 0.5++  -- Modules exported by the library.+  Exposed-modules:     Text.Regex.Applicative+                       Text.Regex.Applicative.Reference      -- Modules not exported by this package.-  Other-modules:       Text.Regex.Applicative.Interface,+  Other-modules:       Text.Regex.Applicative.Interface                        Text.Regex.Applicative.Implementation+                       Text.Regex.Applicative.Priorities      -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source.   -- Build-tools: