attoparsec-parsec 0.0.2 → 0.1.1
raw patch · 2 files changed
+18/−6 lines, 2 filesdep ~hspec
Dependency ranges changed: hspec
Files
attoparsec-parsec.cabal view
@@ -1,5 +1,5 @@ name: attoparsec-parsec-version: 0.0.2+version: 0.1.1 license: MIT license-file: LICENSE copyright: (c) 2011, 2012 Simon Hengel@@ -60,7 +60,7 @@ base , attoparsec-parsec , text- , hspec >= 1.3+ , hspec >= 1.5 , QuickCheck test-suite readme-parsec
src/Data/Attoparsec/Text/Parsec.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE TypeFamilies, FlexibleInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-} -- | -- This module implements "Data.Attoparsec.Text" in terms of Parsec. It can be -- used to write parsers that can be compiled against both Attoparsec and@@ -99,7 +101,7 @@ -- * Numeric parsers , decimal--- , hexadecimal+, hexadecimal -- , signed -- , double -- , Number(..)@@ -113,6 +115,7 @@ import Prelude hiding (take, takeWhile) import Data.Char+import Data.String (IsString (..)) import Data.Text (Text) import qualified Data.Text as Text import qualified Data.Text.Lazy as L@@ -128,6 +131,9 @@ parseOnly :: Parser a -> Text -> Either String a parseOnly p = either (Left . show) (Right) . Parsec.parse p "" +instance (a ~ Text) => IsString (Parser a) where+ fromString = fmap Text.pack . Parsec.string+ -- | -- Name the parser, in case failure occurs. --@@ -258,11 +264,17 @@ -- | Parse and decode an unsigned decimal number. decimal :: Integral a => Parser a-decimal = Text.foldl' step 0 `fmap` takeWhile1 isDecimal+decimal = Text.foldl' step 0 `fmap` takeWhile1 isDigit where step a c = a * 10 + fromIntegral (ord c - 48) -isDecimal :: Char -> Bool-isDecimal c = c >= '0' && c <= '9'+--+-- | Parse and decode an unsigned hexadecimal number.+hexadecimal :: Integral a => Parser a+hexadecimal= Text.foldl' step 0 `fmap` takeWhile1 isHexDigit+ where step a c = a * 16 + hexDigit c+ hexDigit c+ | isLetter c = fromIntegral . (+(-87)) . ord . toLower $ c+ | otherwise = fromIntegral (ord c - 48) -- | Match only if all input has been consumed. endOfInput :: Parser ()