packages feed

subtitleParser 0.4.1 → 0.5

raw patch · 4 files changed

+23/−34 lines, 4 filesdep ~attoparsecPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: attoparsec

API changes (from Hackage documentation)

Files

CHANGELOG view
@@ -1,3 +1,6 @@+0.5+  - the hack of avoiding peekChar in attoparsec was fixed upstream, now we can+    deprecate the hack. This changed the API so we had to bump. 0.4   - Optional flags for SRT added, this modify where the text is displayed   - Optional flags for SUB added.
Text/Subtitles/SRT.hs view
@@ -10,9 +10,6 @@  module Text.Subtitles.SRT    (-  -- * Don't use parseOnly!-  -- $noParseOnly -     -- * Terminology of the module   -- $example   @@ -23,27 +20,18 @@   parseSRT,   parseSingleLine, -  -- * Temporal solutions+  -- * Deprecated   parseOnly'   ) where  import Prelude hiding (takeWhile) import Control.Applicative import Data.Attoparsec.Text hiding (parseOnly)+import qualified Data.Attoparsec.Text as DAT import qualified Data.Text as T -- in project modules import Text.Subtitles.SRT.Datatypes --- $noParseOnly------ This module uses now peekChar in parseDialog, which replaces the ad-hoc--- method used before. As a consequence it doesn't play well with--- Data.Attoparsec.Text.parseOnly on some conditions.------ You should use just 'parse' or the parseOnly' function I provide to avoid--- problems until further notice. /Hopefully/ in the next version of attoparsec--- this will be solved , so keep an eye for removal!.- -- $example -- -- All the sections of a Line have their corresponding ADT in@@ -76,7 +64,7 @@ -- corresponding Line representation parseSingleLine :: Parser Line parseSingleLine = -  Line <$> parseIndex <*> parseRange <*> optionalGeometry <*> parseDialog T.empty+  Line <$> parseIndex <*> parseRange <*> optionalGeometry <*> parseDialog []  parseIndex :: Parser Int parseIndex = decimal <* eol@@ -84,10 +72,9 @@ eol :: Parser () eol = endOfLine  --- |This version avoid the problems associated with peekChar and thus is safe to--- use in this module. Subject to removal once parseOnly is fixed.+{-# DEPRECATED parseOnly' "AttoParsec's parseOnly was broken before v0.10.2.1" #-} parseOnly' :: Parser a -> Text -> Either String a-parseOnly' p t = eitherResult $ feed (parse p t) T.empty+parseOnly' = DAT.parseOnly  {- Is clear that this just aplies parseTime breaking down the "-->" string -} parseRange :: Parser Range@@ -112,17 +99,15 @@  {- return the dialog checking for newlines that could be in there. That why is  - written in a monad instead of applicative. More efficient version welcome -}-parseDialog :: Text -> Parser Text-parseDialog stateLine = do +parseDialog :: [Text] -> Parser Text+parseDialog stateLines = do    line <- takeWhile1 (not . isEndOfLine)   endOfLine-  let stateCurrent = T.append stateLine line-      lineState = T.snoc stateCurrent '\n' --takeWhile1 didn't consume \n-  next <- peekChar-  case next of-    Nothing     -> return stateCurrent  -- the end of the file-    (Just '\n') -> eol >> return stateCurrent -- End of this Line, new Line coming.-    (Just _)    -> parseDialog lineState {- in between lines, the next one belong to this Line-                                         explicit eol required -}--+  let stateLines' = line : stateLines+      dialog_complete = return $ T.concat $ reverse stateLines' +  -- the end of the file+  (endOfInput *> dialog_complete) +    -- End of this Line, new Line coming.+    <|> (endOfLine *> dialog_complete)+    -- In between lines, the next one belong to this Line,explicit eol required+    <|> parseDialog (T.singleton '\n' : stateLines')
subtitleParser.cabal view
@@ -1,12 +1,12 @@ name:            subtitleParser-version:         0.4.1+version:         0.5 license:         BSD3 license-file:    LICENSE category:        Text, Parsing author:          Ruben Astudillo  <ruben.astud@gmail.com> maintainer:      Ruben Astudillo  <ruben.astud@gmail.com> stability:       experimental-tested-with:     GHC == 7.4.2+tested-with:     GHC == 7.6.2 synopsis:        A parser for .srt and .sub files cabal-version:   >= 1.8 homepage:        https://patch-tag.com/r/rubenAst/subtitleParser/home@@ -31,7 +31,7 @@   build-depends: base < 5,                  containers,                  text >= 0.11.1.5,-                 attoparsec >= 0.10.2.0+                 attoparsec >= 0.10.2.1    exposed-modules: Text.Subtitles.SRT                    Text.Subtitles.SRT.Datatypes
test/TestSRT.hs view
@@ -4,6 +4,7 @@ import Test.HUnit.Text import Data.Text.IO as TI  import Data.Text (pack)+import Data.Attoparsec.Text import Text.Subtitles.SRT  main :: IO ()@@ -12,7 +13,7 @@ srtAssert :: Assertion srtAssert = do   srtContents <- TI.readFile "./test/example.srt"-  case parseOnly' parseSRT srtContents of+  case parseOnly parseSRT srtContents of     Left _ -> assertFailure "Error while parsing the example .srt"     Right r -> assertEqual "Parser didn't produce the expected value" expectedValue r