htoml-megaparsec 1.1.0.2 → 1.1.0.3
raw patch · 8 files changed
+45/−64 lines, 8 filesdep −old-localedep ~basesetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies removed: old-locale
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- CHANGES.md +1/−4
- Setup.hs +2/−0
- Setup.lhs +0/−8
- htoml-megaparsec.cabal +3/−4
- src/Text/Toml/Parser.hs +13/−12
- test/Test.hs +1/−5
- test/Text/Toml/Parser/Spec.hs +20/−26
- test/Text/TomlSpec.hs +5/−5
CHANGES.md view
@@ -1,12 +1,9 @@ Change log ========== -#### dev-* ...- ### 1.0.0.3 -Switched to megaparsec, resulting in double the speed of the old parser.+* Switched to megaparsec, resulting in double the speed of the old parser. ### 1.0.0.1 * Improve docs
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
− Setup.lhs
@@ -1,8 +0,0 @@-#!/usr/bin/env runghc--> module Main where--> import Distribution.Simple--> main :: IO ()-> main = defaultMain
htoml-megaparsec.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: htoml-megaparsec-version: 1.1.0.2+version: 1.1.0.3 license: BSD3 license-file: LICENSE copyright: (c) 2013-2016 Cies Breijs, 2017-2018 Vanessa McHale@@ -48,8 +48,7 @@ mtl >=2.2, composition-prelude >=0.1.1.0, deepseq -any,- time >=1.5.0,- old-locale -any+ time >=1.5.0 if impl(ghc >=8.0) ghc-options: -Wincomplete-uni-patterns -Wincomplete-record-updates@@ -66,7 +65,7 @@ default-language: Haskell2010 ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N build-depends:- base -any,+ base >=4.9 && <5, megaparsec -any, containers -any, hspec -any,
src/Text/Toml/Parser.hs view
@@ -12,6 +12,7 @@ import Control.Applicative hiding (many, optional, some, (<|>)) import Control.Monad import Control.Monad.State (evalState)+import Data.Functor import qualified Data.HashMap.Lazy as M import qualified Data.Set as S import Data.Text (Text, pack, unpack)@@ -24,12 +25,12 @@ parseTimeM) import Numeric (readHex)-import Text.Megaparsec hiding (runParser)+import Text.Megaparsec import Text.Toml.Types -- Imported last to fix redundancy warning-import Prelude hiding (concat, takeWhile)+import Prelude type TomlError = ParseError (Token Text) Void@@ -147,8 +148,8 @@ boolean :: (TomlM m) => Parser m Node-boolean = VBoolean <$> ( string "true" *> return True <|>- string "false" *> return False )+boolean = VBoolean <$> ( string "true" $> True <|>+ string "false" $> False ) anyStr :: (TomlM m) => Parser m Node@@ -227,7 +228,7 @@ -- | Parses the elements of an array, while restricting them to a certain type. arrayOf :: (TomlM m) => Parser m Node -> Parser m Node-arrayOf p = (VArray . V.fromList) <$>+arrayOf p = VArray . V.fromList <$> between (char '[') (char ']') (skipBlanks *> separatedValues) where separatedValues = sepEndBy (skipBlanks *> try p <* skipBlanks) comma <* skipBlanks@@ -241,13 +242,13 @@ escSeqChar = char '"' <|> char '\\' <|> char '/'- <|> char 'n' *> return '\n'- <|> char 't' *> return '\t'- <|> char 'r' *> return '\r'- <|> char 'b' *> return '\b'- <|> char 'f' *> return '\f'- <|> char 'u' *> unicodeHex 4- <|> char 'U' *> unicodeHex 8+ <|> char 'n' $> '\n'+ <|> char 't' $> '\t'+ <|> char 'r' $> '\r'+ <|> char 'b' $> '\b'+ <|> char 'f' $> '\f'+ <|> char 'u' *> unicodeHex 4+ <|> char 'U' *> unicodeHex 8 <?> "escaped character"
test/Test.hs view
@@ -1,6 +1,4 @@ module Main where--import Prelude hiding (readFile) import Test.Tasty (defaultMain, testGroup) import qualified BurntSushi@@ -15,9 +13,7 @@ parserSpec <- tomlParserSpec bsTests <- BurntSushi.tests - defaultMain $ testGroup "" $+ defaultMain $ testGroup "" [ parserSpec , bsTests- --, quickCheckSuite- -- A QuickCheck suite for a parser is possible. The internet knows. ]
test/Text/Toml/Parser/Spec.hs view
@@ -1,6 +1,6 @@ {-# LANGUAGE OverloadedStrings #-} -module Text.Toml.Parser.Spec where+module Text.Toml.Parser.Spec (tomlParserSpec) where import Data.HashMap.Strict (fromList) import Data.Time.Calendar (Day (..))@@ -212,10 +212,10 @@ describe "Parser.basicStr" $ do it "should parse the common escape sequences in basic strings" $- testParser basicStr "\"123\\b\\t\\n\\f\\r\\\"\\/\\\\\"" $ "123\b\t\n\f\r\"/\\"+ testParser basicStr "\"123\\b\\t\\n\\f\\r\\\"\\/\\\\\"" "123\b\t\n\f\r\"/\\" it "should parse the simple unicode value from the example" $- testParser basicStr "\"中国\"" $ "中国"+ testParser basicStr "\"中国\"" "中国" it "should parse escaped 4 digit unicode values" $ testParser assignment "special_k = \"\\u0416\"" ("special_k", VString "Ж")@@ -230,19 +230,19 @@ describe "Parser.multiBasicStr" $ do it "should parse simple example" $- testParser multiBasicStr "\"\"\"thorrough\"\"\"" $ "thorrough"+ testParser multiBasicStr "\"\"\"thorrough\"\"\"" "thorrough" it "should parse text containing a quote" $- testParser multiBasicStr "\"\"\"is \"it\" complete\"\"\"" $ "is \"it\" complete"+ testParser multiBasicStr "\"\"\"is \"it\" complete\"\"\"" "is \"it\" complete" it "should parse with newlines" $- testParser multiBasicStr "\"\"\"One\nTwo\"\"\"" $ "One\nTwo"+ testParser multiBasicStr "\"\"\"One\nTwo\"\"\"" "One\nTwo" it "should parse with escaped newlines" $- testParser multiBasicStr "\"\"\"One\\\nTwo\"\"\"" $ "OneTwo"+ testParser multiBasicStr "\"\"\"One\\\nTwo\"\"\"" "OneTwo" it "should parse newlines, ignoring 1 leading newline" $- testParser multiBasicStr "\"\"\"\nOne\\\nTwo\"\"\"" $ "OneTwo"+ testParser multiBasicStr "\"\"\"\nOne\\\nTwo\"\"\"" "OneTwo" it "should parse with espaced whitespace" $ testParser multiBasicStr "\"\"\"\\\n\@@ -250,28 +250,27 @@ \\\\n\ \Jumped \\\n\ \Lazy\\\n\- \ \"\"\"" $ "Quick Jumped Lazy"+ \ \"\"\"" "Quick Jumped Lazy" it "should parse espaced on first" $- testParser multiBasicStr "\"\"\"\\\nQuick \\\n\\\nJumped \\\nLazy\\\n\"\"\"" $ "Quick Jumped Lazy"+ testParser multiBasicStr "\"\"\"\\\nQuick \\\n\\\nJumped \\\nLazy\\\n\"\"\"" "Quick Jumped Lazy" describe "Parser.literalStr" $ do it "should parse literally" $- testParser literalStr "'\"Your\" folder: \\\\User\\new\\tmp\\'" $+ testParser literalStr "'\"Your\" folder: \\\\User\\new\\tmp\\'" "\"Your\" folder: \\\\User\\new\\tmp\\" it "has no notion of 'escaped single quotes'" $ testParserFails tomlDoc "q = 'I don\\'t know.'" -- string terminates before the "t" - describe "Parser.multiLiteralStr" $ do+ describe "Parser.multiLiteralStr" $ it "should parse literally" $- testParser multiLiteralStr- "'''\nFirst newline is dropped.\n Other whitespace,\n is preserved -- isn't it?'''"- $ "First newline is dropped.\n Other whitespace,\n is preserved -- isn't it?"+ testParser multiLiteralStr+ "'''\nFirst newline is dropped.\n Other whitespace,\n is preserved -- isn't it?'''" "First newline is dropped.\n Other whitespace,\n is preserved -- isn't it?" describe "Parser.datetime" $ do@@ -369,33 +368,28 @@ testParser array "[ \n[ ]\n ,\n [ \n ] ,\n ]" $ mkVArray [ mkVArray [], mkVArray [] ] it "should parse nested arrays" $- testParser assignment "d = [ ['gamma', 'delta'], [1, 2] ]"- $ ("d", mkVArray [ mkVArray [ VString "gamma"+ testParser assignment "d = [ ['gamma', 'delta'], [1, 2] ]" ("d", mkVArray [ mkVArray [ VString "gamma" , VString "delta" ] , mkVArray [ VInteger 1 , VInteger 2 ] ]) it "should allow linebreaks in an array" $- testParser assignment "hosts = [\n'alpha',\n'omega'\n]"- $ ("hosts", mkVArray [VString "alpha", VString "omega"])+ testParser assignment "hosts = [\n'alpha',\n'omega'\n]" ("hosts", mkVArray [VString "alpha", VString "omega"]) it "should allow some linebreaks in an array" $- testParser assignment "hosts = ['alpha' ,\n'omega']"- $ ("hosts", mkVArray [VString "alpha", VString "omega"])+ testParser assignment "hosts = ['alpha' ,\n'omega']" ("hosts", mkVArray [VString "alpha", VString "omega"]) it "should allow linebreaks in an array, with comments" $ testParser assignment "hosts = [\n\ \'alpha', # the first\n\ \'omega' # the last\n\- \]"- $ ("hosts", mkVArray [VString "alpha", VString "omega"])+ \]" ("hosts", mkVArray [VString "alpha", VString "omega"]) it "should allow linebreaks in an array, with comments, and terminating comma" $ testParser assignment "hosts = [\n\ \'alpha', # the first\n\ \'omega', # the last\n\- \]"- $ ("hosts", mkVArray [VString "alpha", VString "omega"])+ \]" ("hosts", mkVArray [VString "alpha", VString "omega"]) it "inside an array, all element should be of the same type" $ testParserFails array "[1, 2.0]"@@ -405,7 +399,7 @@ mkVArray [ mkVArray [VInteger 1], mkVArray [VFloat 2.0], mkVArray [VString "a"] ] it "all string variants are of the same type of the same type" $- testParser assignment "data = [\"a\", \"\"\"b\"\"\", 'c', '''d''']" $+ testParser assignment "data = [\"a\", \"\"\"b\"\"\", 'c', '''d''']" ("data", mkVArray [ VString "a", VString "b", VString "c", VString "d" ])
test/Text/TomlSpec.hs view
@@ -9,8 +9,8 @@ import Text.Toml hspecTests :: Spec-hspecTests = do- describe "parser" $ do- it "should not parse re-assignment of key" $ do- let actual = parseTomlDoc "noSrc" "q={k=42, k=43}\nd=str"- actual `shouldBe` Left (FancyError ((SourcePos "noSrc" (mkPos 1) (mkPos 15)) :| []) (Set.fromList [(ErrorFail "Cannot redefine key k")]))+hspecTests =+ describe "parser" $+ it "should not parse re-assignment of key" $ do+ let actual = parseTomlDoc "noSrc" "q={k=42, k=43}\nd=str"+ actual `shouldBe` Left (FancyError (SourcePos "noSrc" (mkPos 1) (mkPos 15) :| []) (Set.fromList [ErrorFail "Cannot redefine key k"]))