packages feed

megaparsec 4.0.0 → 4.1.0

raw patch · 28 files changed

+189/−84 lines, 28 filesdep ~basedep ~megaparsec

Dependency ranges changed: base, megaparsec

Files

AUTHORS.md view
@@ -28,6 +28,7 @@ * Artyom (@neongreen) * Auke Booij * Ben Pence+* Benjamin Kästner * Björn Buckwalter * Bryan O'Sullivan * Cies Breijs
CHANGELOG.md view
@@ -1,3 +1,17 @@+## Megaparsec 4.1.0++* Relaxed dependency on `base`, so that minimal required version of `base`+  is now 4.6.0.0. This allows Megaparsec to compile with GHC 7.6.x.++* `Text.Megaparsec` and `Text.Megaparsec.Prim` do not export data types+  `Consumed` and `Reply` anymore because they are rather low-level+  implementation details that should not be visible to end-user.++* Representation of file name and textual position in error messages was+  made conventional.++* Fixed some typos is documentation and other materials.+ ## Megaparsec 4.0.0  ### General changes@@ -41,7 +55,7 @@ ### Error messages  * Introduced type class `ShowToken` and improved representation of-  characters and stings in error messages, see #12.+  characters and strings in error messages, see #12.  * Greatly improved quality of error messages. Fixed entire   `Text.Megaparsec.Error` module, see #14 for more information. Made
Text/Megaparsec.hs view
@@ -136,8 +136,6 @@   , sourceColumn     -- * Low-level operations   , Stream (..)-  , Consumed (..)-  , Reply (..)   , State (..)   , getInput   , setInput
Text/Megaparsec/ByteString.hs view
@@ -38,4 +38,4 @@ -- >     Right xs -> print (sum xs)  parseFromFile :: Parser a -> String -> IO (Either ParseError a)-parseFromFile p fname = runParser p fname <$> C.readFile fname+parseFromFile p fname = runParser p fname `fmap` C.readFile fname
Text/Megaparsec/ByteString/Lazy.hs view
@@ -38,4 +38,4 @@ -- >     Right xs -> print (sum xs)  parseFromFile :: Parser a -> String -> IO (Either ParseError a)-parseFromFile p fname = runParser p fname <$> C.readFile fname+parseFromFile p fname = runParser p fname `fmap` C.readFile fname
Text/Megaparsec/Char.hs view
@@ -7,7 +7,7 @@ -- -- Maintainer  :  Mark Karpov <markkarpov@opmbx.org> -- Stability   :  experimental--- Portability :  portable+-- Portability :  non-portable -- -- Commonly used character parsers. @@ -63,6 +63,10 @@ import Text.Megaparsec.Prim import Text.Megaparsec.ShowToken +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), pure)+#endif+ -- | Parses a newline character.  newline :: MonadParsec s m Char => m Char@@ -252,7 +256,7 @@ -- >>> parseTest (char' 'e') "E" -- 'E' -- >>> parseTest (char' 'e') "G"--- parse error at line 1, column 1:+-- 1:1: -- unexpected 'G' -- expecting 'E' or 'e' 
Text/Megaparsec/Combinator.hs view
@@ -39,6 +39,10 @@ import Control.Monad (void) import Data.Foldable (asum) +#if !MIN_VERSION_base(4,8,0)+import Data.Foldable (Foldable)+#endif+ -- | @between open close p@ parses @open@, followed by @p@ and @close@. -- Returns the value returned by @p@. --
Text/Megaparsec/Error.hs view
@@ -28,11 +28,23 @@   , showMessages ) where +#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.List (intercalate) import Data.Maybe (fromMaybe)  import Text.Megaparsec.Pos++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>))+import Data.Foldable (foldMap)+#endif+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif  -- | This data type represents parse error messages. There are three kinds -- of messages:
Text/Megaparsec/Lexer.hs view
@@ -7,12 +7,12 @@ -- -- Maintainer  :  Mark Karpov <markkarpov@opmbx.org> -- Stability   :  experimental--- Portability :  non-portable (uses local universal quantification: PolymorphicComponents)+-- Portability :  non-portable -- -- High-level parsers to help you write your lexer. The module doesn't -- impose how you should write your parser, but certain approaches may be--- more elegant than others. Especially important theme is parsing of write--- space, comments and indentation.+-- more elegant than others. Especially important theme is parsing of white+-- space, comments, and indentation. -- -- This module is intended to be imported qualified: --@@ -50,6 +50,10 @@ import Text.Megaparsec.ShowToken import qualified Text.Megaparsec.Char as C +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*), (*>), (<*>), pure)+#endif+ -- White space and indentation  -- | @space spaceChar lineComment blockComment@ produces parser that can@@ -197,7 +201,7 @@ -- | Parse an integer in hexadecimal representation. Representation of -- hexadecimal number is expected to be according to Haskell report except -- for the fact that this parser doesn't parse “0x” or “0X” prefix. It is--- reponsibility of the programmer to parse correct prefix before parsing+-- responsibility of the programmer to parse correct prefix before parsing -- the number itself. -- -- For example you can make it conform to Haskell report like this:
Text/Megaparsec/Perm.hs view
@@ -7,13 +7,15 @@ -- -- Maintainer  :  Mark Karpov <markkarpov@opmbx.org> -- Stability   :  experimental--- Portability :  non-portable (uses existentially quantified data constructors)+-- Portability :  non-portable -- -- This module implements permutation parsers. The algorithm is described -- in: /Parsing Permutation Phrases/, by Arthur Baars, Andres Loh and -- Doaitse Swierstra. Published as a functional pearl at the Haskell -- Workshop 2001. +{-# LANGUAGE ExistentialQuantification #-}+ module Text.Megaparsec.Perm   ( PermParser   , makePermParser@@ -25,6 +27,10 @@  import Text.Megaparsec.Combinator (choice) import Text.Megaparsec.Prim++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*>))+#endif  infixl 1 <||>, <|?> infixl 2 <$$>, <$?>
Text/Megaparsec/Pos.hs view
@@ -49,8 +49,8 @@ instance Show SourcePos where   show (SourcePos n l c)     | null n    = showLC-    | otherwise = "\"" ++ n ++ "\" " ++ showLC-    where showLC = "line " ++ show l ++ ", column " ++ show c+    | otherwise = n ++ ":" ++ showLC+      where showLC = show l ++ ":" ++ show c  -- | Create a new 'SourcePos' with the given source name, line number and -- column number.
Text/Megaparsec/Prim.hs view
@@ -7,7 +7,7 @@ -- -- Maintainer  :  Mark Karpov <markkarpov@opmbx.org> -- Stability   :  experimental--- Portability :  portable+-- Portability :  non-portable (MPTC with FD) -- -- The primitive parser combinators. @@ -17,8 +17,6 @@   ( -- * Used data-types     State (..)   , Stream (..)-  , Consumed (..)-  , Reply (..)   , Parsec   , ParsecT     -- * Primitive combinators@@ -40,7 +38,9 @@   , parseTest ) where +#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.Monoid  import Control.Monad@@ -67,6 +67,15 @@ import Text.Megaparsec.Pos import Text.Megaparsec.ShowToken +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*))+#endif+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif+ -- | This is Megaparsec state, it's parametrized over stream type @s@.  data State s = State@@ -130,14 +139,14 @@ -- For example, without hints you could get: -- -- >>> parseTest (many (char 'r') <* eof) "ra"--- parse error at line 1, column 2:+-- 1:2: -- unexpected 'a' -- expecting end of input -- -- We're getting better error messages with help of hints: -- -- >>> parseTest (many (char 'r') <* eof) "ra"--- parse error at line 1, column 2:+-- 1:2: -- unexpected 'a' -- expecting 'r' or end of input @@ -375,7 +384,7 @@   -- parse word “let” or “lexical”:   --   -- >>> parseTest (string "let" <|> string "lexical") "lexical"-  -- parse error at line 1, column 1:+  -- 1:1:   -- unexpected "lex"   -- expecting "let"   --@@ -391,7 +400,7 @@   -- because Megaparsec's hint system can be used:   --   -- >>> parseTest (try (string "let") <|> string "lexical") "le"-  -- parse error at line 1, column 1:+  -- 1:1:   -- unexpected "le"   -- expecting "let" or "lexical" @@ -652,7 +661,7 @@ parseTest :: (Stream s t, Show a) => Parsec s a -> s -> IO () parseTest p input =   case parse p "" input of-    Left err -> putStr "parse error at " >> print err+    Left err -> print err     Right x  -> print x  -- | The most general way to run a parser over the 'Identity' monad.
Text/Megaparsec/String.hs view
@@ -36,4 +36,4 @@ -- >     Right xs -> print (sum xs)  parseFromFile :: Parser a -> String -> IO (Either ParseError a)-parseFromFile p fname = runParser p fname <$> readFile fname+parseFromFile p fname = runParser p fname `fmap` readFile fname
Text/Megaparsec/Text.hs view
@@ -38,4 +38,4 @@ -- >     Right xs -> print (sum xs)  parseFromFile :: Parser a -> String -> IO (Either ParseError a)-parseFromFile p fname = runParser p fname <$> T.readFile fname+parseFromFile p fname = runParser p fname `fmap` T.readFile fname
Text/Megaparsec/Text/Lazy.hs view
@@ -38,4 +38,4 @@ -- >     Right xs -> print (sum xs)  parseFromFile :: Parser a -> String -> IO (Either ParseError a)-parseFromFile p fname = runParser p fname <$> T.readFile fname+parseFromFile p fname = runParser p fname `fmap` T.readFile fname
benchmarks/Main.hs view
@@ -1,6 +1,6 @@ -- -*- Mode: Haskell; -*- ----- Criterion benmarks for Megaparsec, main module.+-- Criterion benchmarks for Megaparsec, main module. -- -- Copyright © 2015 Megaparsec contributors --
megaparsec.cabal view
@@ -28,7 +28,7 @@ -- possibility of such damage.  name:                megaparsec-version:             4.0.0+version:             4.1.0 cabal-version:       >= 1.10 license:             BSD3 license-file:        LICENSE.md@@ -46,47 +46,18 @@      This is industrial-strength monadic parser combinator library. Megaparsec is     a fork of Parsec library originally written by Daan Leijen.-    .-    Megaparsec is different from Parsec in the following ways:-    .-    * Better error messages. We test our error messages using dense QuickCheck-      tests. Good error messages are just as important for us as correct return-      values of our parsers. Megaparsec will be especially useful if you write-      compiler or interpreter for some language.-    .-    * Some quirks and “buggy features” (as well as plain bugs) of original-      Parsec are fixed. There is no undocumented surprising stuff in Megaparsec.-    .-    * Better support for Unicode parsing in "Text.Megaparsec.Char".-    .-    * Megaparsec has more powerful combinators and can parse languages where-      indentation matters.-    .-    * Comprehensive QuickCheck test suite covering nearly 100% of our code.-    .-    * We have benchmarks to detect performance regressions.-    .-    * Better documentation, with 100% of functions covered, without typos and-      obsolete information, with working examples. Megaparsec's documentation is-      well-structured and doesn't contain things useless to end user.-    .-    * Megaparsec's code is clearer and doesn't contain “magic” found in original-      Parsec.-    .-    * Megaparsec looks into the future, it does not contain code that serves for-      compatibility purposes, it also requires more recent version of `base`.  extra-source-files:  AUTHORS.md, CHANGELOG.md  library-  build-depends:     base                   >= 4.8 && < 5+  build-depends:     base                   >= 4.6 && < 5                    , mtl                    == 2.*                    , transformers           == 0.4.*                    , bytestring                    , text                   >= 0.2 && < 1.3   default-extensions:-                     DeriveDataTypeable-                   , ExistentialQuantification+                     CPP+                   , DeriveDataTypeable                    , FlexibleContexts                    , FlexibleInstances                    , FunctionalDependencies@@ -125,13 +96,14 @@                    , Bugs.Bug35                    , Bugs.Bug39                    , Util-  build-depends:     base                   >= 4.8 && < 5-                   , megaparsec             >= 4.0.0+  build-depends:     base                   >= 4.6 && < 5+                   , megaparsec             >= 4.1.0                    , HUnit                  >= 1.2 && < 1.4                    , test-framework         >= 0.6 && < 1                    , test-framework-hunit   >= 0.2 && < 0.4   default-extensions:-                     FlexibleContexts+                     CPP+                   , FlexibleContexts   default-language:  Haskell2010  test-suite tests@@ -148,15 +120,16 @@                    , Pos                    , Prim                    , Util-  build-depends:     base                   >= 4.8 && < 5-                   , megaparsec             >= 4.0.0+  build-depends:     base                   >= 4.6 && < 5+                   , megaparsec             >= 4.1.0                    , mtl                    == 2.*                    , transformers           == 0.4.*                    , QuickCheck             >= 2.4 && < 3                    , test-framework         >= 0.6 && < 1                    , test-framework-quickcheck2 >= 0.3 && < 0.4   default-extensions:-                     FlexibleContexts+                     CPP+                   , FlexibleContexts                    , FlexibleInstances   default-language:  Haskell2010 @@ -165,8 +138,8 @@   hs-source-dirs:    benchmarks   type:              exitcode-stdio-1.0   ghc-options:       -O2 -Wall -rtsopts-  build-depends:     base                   >= 4.8 && < 5-                   , megaparsec             >= 4.0.0+  build-depends:     base                   >= 4.6 && < 5+                   , megaparsec             >= 4.1.0                    , criterion              >= 0.6.2.1 && < 1.2                    , text                   >= 1.2 && < 2                    , bytestring             >= 0.10 && < 2
old-tests/Bugs/Bug39.hs view
@@ -3,7 +3,9 @@  import Control.Applicative (empty) import Control.Monad (void)+#if MIN_VERSION_base(4,7,0) import Data.Either (isLeft, isRight)+#endif  import Text.Megaparsec import Text.Megaparsec.String@@ -12,6 +14,14 @@ import Test.Framework import Test.Framework.Providers.HUnit import Test.HUnit hiding (Test)++#if !MIN_VERSION_base(4,7,0)+isRight, isLeft :: Either a b -> Bool+isRight (Right _) = True+isRight _         = False+isLeft  (Left _ ) = True+isLeft  _         = False+#endif  shouldFail :: [String] shouldFail = [" 1", " +1", " -1"]
old-tests/Bugs/Bug9.hs view
@@ -15,6 +15,10 @@  import Util +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*), (<$))+#endif+ data Expr = Const Integer | Op Expr Expr deriving Show  main :: Test
tests/Char.hs view
@@ -42,6 +42,10 @@  import Util +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>))+#endif+ tests :: Test tests = testGroup "Character parsers"         [ testProperty "newline"         prop_newline@@ -75,7 +79,8 @@         , testProperty "noneOf"          prop_noneOf         , testProperty "noneOf'"         prop_noneOf'         , testProperty "string"          prop_string-        , testProperty "string'"         prop_string' ]+        , testProperty "string'"         prop_string'_0+        , testProperty "string' (case)"  prop_string'_1 ]  instance Arbitrary GeneralCategory where   arbitrary = elements@@ -234,8 +239,21 @@ prop_string :: String -> String -> Property prop_string a = checkString (string a) a (==) (showToken a) -prop_string' :: String -> String -> Property-prop_string' a = checkString (string' a) a casei (showToken a)+prop_string'_0 :: String -> String -> Property+prop_string'_0 a = checkString (string' a) a casei (showToken a)++-- | Randomly change the case in the given string.++fuzzyCase :: String -> Gen String+fuzzyCase s = do+    b <- vector (length s)+    return $ zipWith f s b+  where f k True  = if isLower k then toUpper k else toLower k+        f k False = k++prop_string'_1 :: String -> Property+prop_string'_1 a = forAll (fuzzyCase a) $ \s ->+  checkString (string' a) a casei (showToken a) s  -- | Case-insensitive equality test for characters. 
tests/Combinator.hs view
@@ -121,7 +121,6 @@           | c == '-' && n == 0 = posErr 0 s [uneCh '-', exCh 'a']           | c /= '-'           = posErr (g n) s $ uneCh c :                                  [exCh '-' | n > 0] ++-                                 -- [exEof    | n > 1] ++                                  [exCh 'a' | n == 0]           | otherwise = Right (replicate n 'a')         s = intersperse '-' (replicate n 'a') ++ [c]
tests/Error.hs view
@@ -31,7 +31,9 @@  module Error (tests) where +#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.List (isPrefixOf, isInfixOf)  import Test.Framework@@ -41,6 +43,15 @@ import Pos () import Text.Megaparsec.Error import Text.Megaparsec.Pos++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*>))+#endif+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif  tests :: Test tests = testGroup "Parse errors"
tests/Expr.hs view
@@ -30,7 +30,9 @@ module Expr (tests) where  import Control.Applicative (some, (<|>))+#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif  import Test.Framework import Test.Framework.Providers.QuickCheck2 (testProperty)@@ -43,6 +45,16 @@  import Util +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*), (<*>), (*>), pure)+#endif++#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif+ tests :: Test tests = testGroup "Expression parsers"         [ testProperty "correctness of expression parser" prop_correctness ]@@ -118,7 +130,7 @@ arbitraryN2 n = elements [Sum,Sub,Pro,Div,Exp] <*> leaf <*> leaf   where leaf = arbitraryN0 (n `div` 2) --- Some helpers put here since we don't want to depend on+-- Some helpers are put here since we don't want to depend on -- "Text.Megaparsec.Lexer".  lexeme :: MonadParsec s m Char => m a -> m a
tests/Lexer.hs view
@@ -31,7 +31,9 @@  import Control.Applicative (empty) import Control.Monad (void)+#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.Char   ( readLitChar   , showLitChar@@ -55,6 +57,15 @@ import qualified Text.Megaparsec.Char as C  import Util++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*), (<*>))+#endif+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif  tests :: Test tests = testGroup "Lexer"
tests/Perm.hs view
@@ -30,7 +30,9 @@ module Perm (tests) where  import Control.Applicative+#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.List (nub, elemIndices)  import Test.Framework@@ -41,6 +43,11 @@ import Text.Megaparsec.Perm  import Util+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif  tests :: Test tests = testGroup "Permutation phrases parsers"
tests/Pos.hs view
@@ -40,6 +40,10 @@  import Text.Megaparsec.Pos +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*>), pure)+#endif+ tests :: Test tests = testGroup "Textual source positions"         [ testProperty "components" prop_components@@ -71,20 +75,13 @@   where copy = newPos (sourceName pos) (sourceLine pos) (sourceColumn pos)  prop_showFileName :: SourcePos -> Bool-prop_showFileName pos =-  if null name-  then '"'`notElem` shown-  else ("\"" ++ name ++ "\"") `isInfixOf` shown-  where name  = sourceName pos-        shown = show pos+prop_showFileName pos = sourceName pos `isInfixOf` show pos  prop_showLine :: SourcePos -> Bool-prop_showLine pos = ("line " ++ line) `isInfixOf` show pos-  where line = show $ sourceLine pos+prop_showLine pos = show (sourceLine pos) `isInfixOf` show pos  prop_showColumn :: SourcePos -> Bool-prop_showColumn pos = ("column " ++ column) `isInfixOf` show pos-  where column = show $ sourceColumn pos+prop_showColumn pos = show (sourceColumn pos) `isInfixOf` show pos  prop_initialPos :: String -> Bool prop_initialPos n =
tests/Prim.hs view
@@ -32,7 +32,9 @@ module Prim (tests) where  import Control.Applicative+#if MIN_VERSION_base(4,7,0) import Data.Bool (bool)+#endif import Data.Char (isLetter, toUpper) import Data.Foldable (asum) import Data.List (isPrefixOf)@@ -57,6 +59,11 @@  import Pos () import Util+#if !MIN_VERSION_base(4,7,0)+bool :: a -> a -> Bool -> a+bool f _ False = f+bool _ t True  = t+#endif  tests :: Test tests = testGroup "Primitive parser combinators"
tests/Util.hs view
@@ -58,6 +58,10 @@ import Text.Megaparsec.ShowToken import Text.Megaparsec.String +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*))+#endif+ -- | @checkParser p r s@ tries to run parser @p@ on input @s@ to parse -- entire @s@. Result of the parsing is compared with expected result @r@, -- it should match, otherwise the property doesn't hold and the test fails.@@ -97,7 +101,7 @@ checkString :: Parser String -> String -> (Char -> Char -> Bool)             -> String -> String -> Property checkString p a' test l s' = checkParser p (w a' 0 s') s'-  where w [] _ []    = Right a'+  where w [] _ []    = Right s'         w [] i (s:_) = posErr i s' [uneCh s, exEof]         w _  0 []    = posErr 0 s' [uneEof, exSpec l]         w _  i []    = posErr 0 s' [uneStr (take i s'), exSpec l]@@ -106,7 +110,7 @@           | otherwise = posErr 0 s' [uneStr (take i' s'), exSpec l]             where i'  = succ i -infix 4 /=\+infix 4 /=\   -- preserve whitespace on automatic trim  -- | @p /=\\ x@ runs parser @p@ on empty input and compares its result -- (which should be successful) with @x@. Succeeds when the result is equal