module Data.Attoparsec.Incremental.Char8
(
Parser
, Result(..)
, parse
, parseWith
, parseTest
, (<?>)
, try
, satisfy
, letter
, digit
, anyChar
, space
, char
, notChar
, inClass
, notInClass
, string
, skipSpace
, skipWhile
, takeCount
, takeTill
, takeWhile
, endOfLine
, int
, integer
, double
, endOfInput
, pushBack
, yield
, module Data.Attoparsec.Combinator
) where
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.ByteString.Internal (w2c)
import Data.Char (isDigit, isLetter, isSpace)
import Data.Attoparsec.FastSet (charClass, memberChar)
import qualified Data.Attoparsec.Incremental as I
import Data.Attoparsec.Incremental
(Parser, Result(..), (<?>), endOfInput, parse, parseWith, parseTest,
pushBack, string, takeCount, try, yield)
import Data.ByteString.Lex.Lazy.Double (readDouble)
import Prelude hiding (takeWhile)
import Data.Attoparsec.Combinator
numeric :: String -> (Char -> Bool)
-> (LB.ByteString -> Maybe (a,LB.ByteString)) -> Parser r a
numeric desc p f = do
s <- takeWhile p
case f s of
Nothing -> pushBack s >> fail desc
Just (i,s') -> pushBack s' >> return i
isIntegral :: Char -> Bool
isIntegral c = isDigit c || c == '-'
int :: Parser r Int
int = numeric "Int" isIntegral LB.readInt
integer :: Parser r Integer
integer = numeric "Integer" isIntegral LB.readInteger
double :: Parser r Double
double = numeric "Double" isDouble readDouble
where isDouble c = isIntegral c || c == 'e' || c == '+'
endOfLine :: Parser r ()
endOfLine = (char '\n' *> pure ()) <|> (string crlf *> pure ())
where crlf = LB.pack "\r\n"
#define PARSER Parser r
#include "../Char8Boilerplate.h"