Copyright | (c) Andrey Mulik 2019 |
---|---|
License | BSD-style |
Maintainer | work.a.mulik@gmail.com |
Portability | portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Text.Read.SDP provides common ReadPrec
parsers and related stuff.
Synopsis
- module Text.Read
- expect :: Lexeme -> ReadP ()
- appPrec :: Int
- linearPrec :: (Linear l e, Read e) => String -> ReadPrec l
- indexedPrec :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v
- indexedPrec' :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v
- readZeroPrec :: Linear l e => ReadPrec l
- readAsList :: (Linear l e, Read e) => ReadPrec l
- readAsListN :: (Linear l e, Read e) => ReadPrec l
- readAssocsPrec :: (Indexed v i e, Read i, Read e) => ReadPrec v
- allPrec :: Read e => ReadPrec [e]
- allPrecWith :: ReadPrec e -> ReadPrec [e]
- expectPrec :: Lexeme -> ReadPrec ()
- namedPrec :: ReadPrec e -> String -> ReadPrec e
- readDef :: (Read e, Default e) => String -> e
- readBy :: ReadPrec e -> String -> e
- readMaybeBy :: ReadPrec e -> String -> Maybe e
- readEitherBy :: ReadPrec e -> String -> Either String e
- readDefBy :: Default e => ReadPrec e -> String -> e
- readAsEnum :: (Linear l e, Read e, Enum e) => ReadPrec l
- enumFromPrec :: (Linear l e, Read e, Enum e) => ReadPrec l
- enumFromToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l
- enumFromThenPrec :: (Linear l e, Read e, Enum e) => ReadPrec l
- enumFromThenToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l
Exports
module Text.Read
Common parsers
linearPrec :: (Linear l e, Read e) => String -> ReadPrec l Source #
is common parser of linearPrec
identLinear
structure with name
ident
:
read "Z" == read "[]" == [] read "['l','g','p','l']" == fromList "lgpl" read "4 [1,5,-1,45,12,6,0,0,12]" == fromListN 4 [1,5,-1,45,12,6,0,0,12]
indexedPrec :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v Source #
is common parser of indexedPrec
identIndexed
structure with name
ident
:
read "ident (0,1) [(0,0),(1,1)]" == read "(0,1) [(0,0),(1,1)]" == assoc (0,1) [(0,0),(1,1)]
indexedPrec' :: (Indexed v i e, Read i, Read e) => String -> ReadPrec v Source #
indexedPrec'
is common Linear
and Indexed
parser (recommended).
readZeroPrec :: Linear l e => ReadPrec l Source #
readZeroPrec
is just Z
parser, see linearPrec
.
readAsList :: (Linear l e, Read e) => ReadPrec l Source #
readAsList
is fromList
-based parser, see linearPrec
.
readAsListN :: (Linear l e, Read e) => ReadPrec l Source #
readAsListN
is fromListN
-based parser, see linearPrec
.
readAssocsPrec :: (Indexed v i e, Read i, Read e) => ReadPrec v Source #
readAssocsPrec
is sdp
recommended format ReadPrec
parser for Indexed
.
Common parser combinators
allPrecWith :: ReadPrec e -> ReadPrec [e] Source #
allPrecWith is manyTill
-based combinator, which reads a sequence of elements
without any separators:
readBy allPrecWith readPrec "1 2 3 4 5 6 7" :: [Int] == [1 .. 7]
Generalized readers
readMaybeBy :: ReadPrec e -> String -> Maybe e Source #
readMaybeBy
is generalized readMaybe
.
readEitherBy :: ReadPrec e -> String -> Either String e Source #
readEitherBy
is generalized readEither
.
Enum parsers
enumFromPrec :: (Linear l e, Read e, Enum e) => ReadPrec l Source #
enumFrom
parser:
take 5 (readBy enumFromPrec "[1 ..]") == take 5 [1 ..] = [1,2,3,4,5]
enumFromToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l Source #
enumFromTo
parser:
readBy enumFromToPrec "[9 .. 12]" == [9 .. 12] == [9,10,11,12]
enumFromThenPrec :: (Linear l e, Read e, Enum e) => ReadPrec l Source #
enumFromThen
parser:
take 4 (readBy enumFromThenPrec "[17, -6 .. ]") == take 4 [17, -6 ..] == [17,-6,-29,-52]
enumFromThenToPrec :: (Linear l e, Read e, Enum e) => ReadPrec l Source #
enumFromThenTo
parser:
take 4 (readBy enumFromThenToPrec "[17, -6 .. 4]") == [17, -6 .. 4] == [17]