sdp-0.2: Simple Data Processing
Copyright(c) Andrey Mulik 2019
LicenseBSD-style
Maintainerwork.a.mulik@gmail.com
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

Text.Read.SDP

Description

Text.Read.SDP provides common ReadPrec parsers and related stuff.

Synopsis

Exports

module Text.Read

expect :: Lexeme -> ReadP () #

Since: base-4.7.0.0

Common parsers

linearPrec :: (Linear l e, Read e) => String -> ReadPrec l Source #

linearPrec ident is common parser of Linear 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 #

indexedPrec ident is common parser of Indexed 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

allPrec :: Read e => ReadPrec [e] Source #

allPrec is just allPrecWith readPrec

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]

expectPrec :: Lexeme -> ReadPrec () Source #

Just lifted expect.

namedPrec :: ReadPrec e -> String -> ReadPrec e Source #

namedPrec readprec name is readPrec with optional name prefix.

Generalized readers

readDef :: (Read e, Default e) => String -> e Source #

read with implicit default value.

readBy :: ReadPrec e -> String -> e Source #

readBy is generalized read.

readDefBy :: Default e => ReadPrec e -> String -> e Source #

readBy with implicit default value.

Enum parsers

readAsEnum :: (Linear l e, Read e, Enum e) => ReadPrec l Source #

Common Enum parser.

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]