HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulepolyparse-1.13Haskell98

Text.Parse.ByteString

  • 1 type
  • 1 class
  • 22 values
  • Packagepolyparse-1.13
  • Exports24
  • LanguageHaskell98
  • LicenceLicenseRef-LGPL
  • SourceByteString.hs

The Parse class is a replacement for the standard Read class.

5 declarations

The Parse class is a replacement for the standard Read class. It is a specialisation of the (poly) Parser monad for ByteString input. There are instances defined for all Prelude types. For user-defined types, you can write your own instance, or use DrIFT to generate them automatically, e.g. {-! derive : Parse !-}

typetype TextParser a = Parser a
#

A synonym for a ByteString Parser, i.e. bytestring input (no state)

classclass Parse a where
#

The class Parse is a replacement for Read, operating over String input. Essentially, it permits better error messages for why something failed to parse. It is rather important that parse can read back exactly what is generated by the corresponding instance of show. To apply a parser to some text, use runParser.

Methods

  • parse :: TextParser a

    A straightforward parser for an item. (A minimal definition of a class instance requires either |parse| or |parsePrec|. In general, for a type that never needs parens, you should define |parse|, but for a type that _may_ need parens, you should define |parsePrec|.)

  • parsePrec :: Int -> TextParser a

    A straightforward parser for an item, given the precedence of any surrounding expression. (Precedence determines whether parentheses are mandatory or optional.)

  • parseList :: TextParser [a]

    Parsing a list of items by default accepts the [] and comma syntax, except when the list is really a character string using "".

Instances13Parse, …
  • Parse IntegerDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse BoolDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse CharDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse DoubleDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse FloatDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse IntDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse OrderingDefined in polyparse-1.13 · Text.Parse.ByteString
  • Parse ()Defined in polyparse-1.13 · Text.Parse.ByteString
  • Parse a => Parse (Maybe a)Defined in polyparse-1.13 · Text.Parse.ByteString
  • Parse a => Parse [a]Defined in polyparse-1.13 · Text.Parse.ByteString
  • (Parse a, Parse b) => Parse (Either a b)Defined in polyparse-1.13 · Text.Parse.ByteString
  • (Parse a, Parse b) => Parse (a, b)Defined in polyparse-1.13 · Text.Parse.ByteString
  • (Parse a, Parse b, Parse c) => Parse (a, b, c)Defined in polyparse-1.13 · Text.Parse.ByteString
valueparseByRead :: Read a => String -> TextParser a
#

If there already exists a Read instance for a type, then we can make a Parser for it, but with only poor error-reporting. The string argument is the expected type or value (for error-reporting only). Use of this wrapper function is NOT recommended with ByteString, because there is a lot of inefficiency in repeated conversions to/from String.

valuereadByParse :: TextParser a -> ReadS a
#

If you have a TextParser for a type, you can easily make it into a Read instance, by throwing away any error messages. Use of this wrapper function is NOT recommended with ByteString, because there is a lot of inefficiency in conversions to/from String.

valuereadsPrecByParsePrec :: (Int -> TextParser a) -> Int -> ReadS a
#

If you have a TextParser for a type, you can easily make it into a Read instance, by throwing away any error messages. Use of this wrapper function is NOT recommended with ByteString, because there is a lot of inefficiency in conversions to/from String.

Combinators specific to bytestring input, lexed haskell-style

Ensure that the next input word is the given string. (Note the input is lexed as haskell, so wordbreaks at spaces, symbols, etc.)

Ensure that the next input word is the given string. (No lexing, so mixed spaces, symbols, are accepted.)

valuefield :: Parse a => String -> TextParser a
#

Deal with named field syntax. The string argument is the field name, and the parser returns the value of the field.

valueconstructors :: [(String, TextParser a)] -> TextParser a
#

Parse one of a bunch of alternative constructors. In the list argument, the first element of the pair is the constructor name, and the second is the parser for the rest of the value. The first matching parse is returned.

valueenumeration :: Show a => String -> [a] -> TextParser a
#

Parse one of the given nullary constructors (an enumeration). The string argument is the name of the type, and the list argument should contain all of the possible enumeration values.

Parsers for literal numerics and characters

parseUnsignedInteger uses the underlying ByteString readInteger, so will be a lot faster than the generic character-by-character parseInt.

Re-export all the more general combinators from Poly too

ByteStrings and Strings as whole entities