LParse 0.1.2.0 → 0.1.3.0
raw patch · 5 files changed
+76/−6 lines, 5 filesdep +LParsePVP ok
version bump matches the API change (PVP)
Dependencies added: LParse
API changes (from Hackage documentation)
+ Text.LParse.Parser: check :: Parser Bool t a -> t -> Bool
Files
- CHANGELOG.md +6/−1
- LParse.cabal +2/−1
- README.md +2/−2
- src/Text/LParse/Parser.hs +4/−0
- test/Test.hs +62/−2
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Changelog +## 0.1.3.0 + +* Added `check` function +* Improved testing facilities + ## 0.1.2.0 -Adding `peek` function+* Added `peek` function
LParse.cabal view
@@ -1,5 +1,5 @@ name: LParse-version: 0.1.2.0+version: 0.1.3.0 synopsis: A continuation-based parser library description: A parser library using continuations with a possibility for failure to build parsers in a clear and concise manner. homepage: https://github.com/MarcusVoelker/LParse#readme@@ -27,4 +27,5 @@ type: exitcode-stdio-1.0 main-is: test/Test.hs build-depends: base+ , LParse default-language: Haskell2010
README.md view
@@ -1,4 +1,4 @@-# λParse+# λParse  +A parser library using monads and arrows. -
src/Text/LParse/Parser.hs view
@@ -59,6 +59,10 @@ arr f = Parser (\s -> return (f s, undefined)) (***) p1 p2 = Parser (\(a,b) -> DCont (\btr etr -> run (pFunc p1 a) (\(a',ra) -> run (pFunc p2 b) (\(b',rb) -> btr ((a',b'),(ra,rb))) etr) etr)) +-- | Runs the parser on the tokens and returns whether the parse succeeded. Results are discarded.+check :: Parser Bool t a -> t -> Bool+check p s = parse p s (const True) (const False)+ -- | Runs the parser on the tokens, using two functions to run the contained continuation parse :: Parser r t a -> t -> (a -> r) -> (String -> r) -> r parse p s = run (pFunc p s) . (. fst)
test/Test.hs view
@@ -1,7 +1,67 @@ module Main where -import System.Exit (exitSuccess) +import Text.LParse.Parser +import Text.LParse.Atomics +import Text.LParse.Transformers +import Control.Applicative +import Control.Monad +import Data.Either +import Data.List +import Data.Maybe +import System.Exit (exitSuccess,exitFailure) + +succCases :: [(Parser r String (),String)] +succCases = [ + (noop,""), + (eoi,""), + (discard,"lel"), + (discard >> eoi,"lorem ipsum"), + (consume "prefix","prefixed"), + (consume "", "foo"), + (consume "", ""), + (word >> eoi, "banana") + ] + +failCases :: [(Parser r String (),String)] +failCases = [ + (eoi,"foo"), + (consume "prefix", "freepix"), + (consume "prefix", ""), + (word >> eoi, "banana bread") + ] + +stringCases :: [(Parser r String String, String, String)] +stringCases = [ + (word,"sufficient example","sufficient") + ] + +intCases :: [(Parser r String Integer, String, Integer)] +intCases = [ + (integer,"123 is a nice number",123), + (sum <$> sepMany (consume " ") integer,"1 4 12 61 192",1+4+12+61+192) + ] + +runTests :: [(Parser (Either String a) t a,t)] -> [Either String a] +runTests = map (uncurry doParse) + +eqTest :: (Eq a, Show a) => (Parser (Either String ()) t a, t, a) -> Either String () +eqTest (p,i,e) = parse p i (\r -> if r == e then Right () else Left ("Expected " ++ show e ++ ", but got " ++ show r)) (const $ Left "Parser error") + +succTest :: [Either String a] -> IO () +succTest res = if all isRight res then return () else putStrLn (head $ lefts res) >> exitFailure + +failTest :: [Either String a] -> IO () +failTest res = if all isLeft res then return () else putStrLn "Fail Test Succeeded" >> exitFailure + +main ::IO () main = do - putStrLn "Hier entsteht eine neue Testpräsenz" + let sres = runTests succCases + let fres = runTests failCases + let seres = map eqTest stringCases + let ieres = map eqTest intCases + succTest sres + failTest fres + succTest seres + succTest ieres exitSuccess