substring-parser 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+25/−14 lines, 4 files
Files
- ChangeLog.md +8/−0
- src/Text/Parser/Substring.hs +8/−12
- substring-parser.cabal +4/−1
- test/Spec.hs +5/−1
+ ChangeLog.md view
@@ -0,0 +1,8 @@+# 0.2.0.0++- Fix: forgot to specify exposed-modules.+- Fix: returns the source text if parser doesn't match.++# 0.1.0.0++- Initial release.
src/Text/Parser/Substring.hs view
@@ -6,8 +6,7 @@ import Control.Applicative ((<|>)) import Data.Attoparsec.Text-import Data.Maybe (fromMaybe)-import Data.Monoid ((<>), mempty)+import Data.Monoid ((<>)) import Data.Text (Text) import qualified Data.Text.Lazy as Text import qualified Data.Text.Lazy.Builder as TextBuilder@@ -22,17 +21,14 @@ Text.writeFile filePath =<< replaceOnceWithParser p <$> Text.readFile filePath --- TODO: 失敗した場合に元のテキストを返す replaceOnceWithParser :: Parser Text -> Text -> Text-replaceOnceWithParser p =- Text.toStrict- . TextBuilder.toLazyText- . fromMaybe mempty- . maybeResult- . traceId "fed"- . flip feed ""- . traceId "parsed"- . parse (onceReplacify p)+replaceOnceWithParser p t =+ maybe t (Text.toStrict . TextBuilder.toLazyText)+ $ maybeResult+ $ traceId "fed"+ $ flip feed ""+ $ traceId "parsed"+ $ parse (onceReplacify p) t onceReplacify :: Parser Text -> Parser Builder
substring-parser.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: substring-parser-version: 0.1.0.0+version: 0.2.0.0 synopsis: Match / replace substrings with a parser combinators. description: See README.md category: Text, Parsing@@ -17,6 +17,7 @@ cabal-version: >= 1.10 extra-source-files:+ ChangeLog.md README.md library@@ -30,6 +31,8 @@ , text exposed-modules: Text.Parser.Substring+ other-modules:+ Paths_substring_parser default-language: Haskell2010 test-suite add-env-config-test
test/Spec.hs view
@@ -10,7 +10,11 @@ main :: IO () main = hspec $- describe "replaceWithParser" $+ describe "replaceWithParser" $ do it "replace first matching text by parser" $ replaceOnceWithParser (string "abc" *> pure "def") "--abc-abc-" `shouldBe` "--def-abc-"++ it "returns the source text if parser doesn't match" $ do+ let src = "--abc-abc-"+ replaceOnceWithParser mempty src `shouldBe` src