scanf-0.1.0.0: Easy and type-safe format strings for parsing and printing

Safe HaskellNone
LanguageHaskell2010

Text.Scanf

Contents

Description

Dead simple and type-safe scanf/printf.

Synopsis

Main definitions

scanf :: Format t -> String -> Maybe t #

Parse a string according to a format string.

scanf [fmt|Hello %s|] "Hello world!" :: Maybe (Format :+ ())
  = ("world!" :+ ())

printf :: Format t -> t -> String #

Print a string according to a format string.

printf [fmt|Hello %s|] ("everyone!" :+ ())
  = "Hello everyone!" 

data a :+ b infixr 1 #

A pretty pair type to build lists with values of different types. Remember to close lists with ().

3 :+ "14" :+ () :: Int :+ Format :+ ()

Constructors

a :+ b infixr 1 
Instances
(Eq a, Eq b) => Eq (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

Methods

(==) :: (a :+ b) -> (a :+ b) -> Bool #

(/=) :: (a :+ b) -> (a :+ b) -> Bool #

(Ord a, Ord b) => Ord (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

Methods

compare :: (a :+ b) -> (a :+ b) -> Ordering #

(<) :: (a :+ b) -> (a :+ b) -> Bool #

(<=) :: (a :+ b) -> (a :+ b) -> Bool #

(>) :: (a :+ b) -> (a :+ b) -> Bool #

(>=) :: (a :+ b) -> (a :+ b) -> Bool #

max :: (a :+ b) -> (a :+ b) -> a :+ b #

min :: (a :+ b) -> (a :+ b) -> a :+ b #

(Show a, Show b) => Show (a :+ b) # 
Instance details

Defined in Text.Scanf.Internal

Methods

showsPrec :: Int -> (a :+ b) -> ShowS #

show :: (a :+ b) -> String #

showList :: [a :+ b] -> ShowS #

fmt :: QuasiQuoter #

Parse a typed Format string.

The following conversion strings are supported:

  • %d: signed integer (Int)
  • %l: signed integer (Integer, unbounded)
  • %f: floating point (Double)
  • %s: string of non-space characters (Format)
  • %c: single character (Format)
  • %%: parse/print a literal percent character

N.B.: in scanf, spaces in the format string match any number of whitespace character until the next nonspace character.

[fmt|%d lazy %s and %d strict %s|]
  :: Format (Int :+ Format :+ Int :+ Format :+ ())

fmt_ :: (Format () -> Format t) -> Format t #

Construct a format string. This is an alternative to fmt that doesn't rely on Template Haskell.

The components of a format string are composed using (.) (function composition) and (%) (wrapper for constant strings).

fmt_ (int . " lazy " % string . " and " % int . " strict " % string)
  :: Format (Int :+ Format :+ Int :+ Format :+ ())

data Format t #

Typed scanf/printf format strings. They can be built using the fmt quasiquote or with the fmt_ function and format combinators.

Instances
Show (Format t) # 
Instance details

Defined in Text.Scanf.Internal

Methods

showsPrec :: Int -> Format t -> ShowS #

show :: Format t -> String #

showList :: [Format t] -> ShowS #

Format constructors

(%) :: String -> (Format t -> Format q) -> Format t -> Format q infixr 9 #

Append a constant string to a format string component.

N.B.: in scanf, spaces in the format string match any number of whitespace character until the next nonspace character.

integer :: Format t -> Format (Integer :+ t) #

Format an Integer.

int :: Format t -> Format (Int :+ t) #

Format an Int.

double :: Format t -> Format (Double :+ t) #

Format a Double.

string :: Format t -> Format (String :+ t) #

Format a Format.

char :: Format t -> Format (Char :+ t) #

Format a Format.