Spintax 0.1.0.1 → 0.2.0.0
raw patch · 2 files changed
+24/−22 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.Spintax: spintax :: Text -> IO (Either Text Text)
+ Text.Spintax: spintax :: Text -> IO (Either String Text)
Files
- Spintax.cabal +11/−11
- src/Text/Spintax.hs +13/−11
Spintax.cabal view
@@ -1,5 +1,5 @@ name: Spintax-version: 0.1.0.1+version: 0.2.0.0 synopsis: Random text generation based on spintax description: Random text generation based on spintax with nested alternatives and empty options. homepage: https://github.com/MichelBoucey/spintax@@ -7,21 +7,21 @@ license-file: LICENSE author: Michel Boucey maintainer: michel.boucey@cybervisible.fr-copyright: Copyright (c) 2016 - Michel Boucey+copyright: (c) 2016 - Michel Boucey category: Text build-type: Simple cabal-version: >=1.10 library- hs-source-dirs: src- exposed-modules: Text.Spintax- build-depends: base >= 4.7 && < 5- , text- , attoparsec- , mwc-random- , extra- default-language: Haskell2010- GHC-Options: -Wall+ hs-source-dirs: src+ exposed-modules: Text.Spintax+ build-depends: base >= 4.7 && < 5+ , text+ , attoparsec+ , mwc-random+ , extra+ default-language: Haskell2010+ GHC-Options: -Wall source-repository head type: git
src/Text/Spintax.hs view
@@ -11,10 +11,10 @@ -- | Generate random texts based on a spinning syntax template, with nested alternatives and empty options. ----- >λ> spintax {{Oh my God|Awesome}, {a|the}|A|The} {quick {and dirty |||}||}{brown |pink |grey |}{fox|flea|elephant} jumps over {the|a} {lazy |smelly |sleepy |}{dog|cat|whale}{.|!|...}+-- >λ> spintax "{{Oh my God|Awesome}, {a|the}|A|The} {quick {and dirty |||}||}{brown |pink |grey |}{fox|flea|elephant} jumps over {the|a} {lazy |smelly |sleepy |}{dog|cat|whale}{.|!|...}" -- > Right "Awesome, the quick pink fox jumps over a sleepy whale." ---spintax :: T.Text -> IO (Either T.Text T.Text)+spintax :: T.Text -> IO (Either String T.Text) spintax template = createSystemRandom >>= flip runParse template where@@ -37,13 +37,15 @@ Done r m -> case m of "{" -> go g o (add as m) r (l+1)- "}" -> do r' <- runParse g =<< randAlter g as- case r' of- Left _ -> failure- Right t -> go g (o <> t) [] r (l-1)- "|" -> if E.null as- then go g o ["",""] r l- else go g o (E.snoc as "") r l+ "}" -> do+ r' <- runParse g =<< randAlter g as+ case r' of+ Left _ -> failure+ Right t -> go g (o <> t) [] r (l-1)+ "|" ->+ if E.null as+ then go g o ["",""] r l+ else go g o (E.snoc as "") r l _ -> go g o (add as m) r l Partial _ -> failure Fail {} -> failure@@ -78,6 +80,6 @@ ctt _ = True go _ _ _ _ _ = failure -failure :: IO (Either T.Text b)-failure = return $ Left "Spintax template parsing failure"+failure :: IO (Either String b)+failure = fail "Spintax template parsing failure"