boomerang-1.3.3: Library for invertible parsing and printing

Safe HaskellNone

Text.Boomerang.Strings

Contents

Description

a PrinterParser library for working with '[String]'

Synopsis

Types

Combinators

alpha :: PrinterParser StringsError [String] r (Char :- r)Source

matches alphabetic Unicode characters (lower-case, upper-case and title-case letters, plus letters of caseless scripts and modifiers letters). (Uses isAlpha)

char :: Char -> PrinterParser StringsError [String] r (Char :- r)Source

matches the specified character

digit :: PrinterParser StringsError [String] r (Char :- r)Source

ascii digits '0'..'9'

int :: PrinterParser StringsError [String] r (Int :- r)Source

matches an Int

Note that the combinator (rPair . int . int) is ill-defined because the parse can not tell where it is supposed to split the sequence of digits to produced two ints.

integer :: PrinterParser StringsError [String] r (Integer :- r)Source

matches an Integer

Note that the combinator (rPair . integer . integer) is ill-defined because the parse can not tell where it is supposed to split the sequence of digits to produced two ints.

lit :: String -> PrinterParser StringsError [String] r rSource

a constant string

readshow :: (Read a, Show a) => PrinterParser StringsError [String] r (a :- r)Source

lift 'Read'/'Show' to a PrinterParser

There are a few restrictions here:

  1. Error messages are a bit fuzzy. Read does not tell us where or why a parse failed. So all we can do it use the the position that we were at when we called read and say that it failed.
  2. it is (currently) not safe to use readshow on integral values because the Read instance for Int, Integer, etc,

satisfy :: (Char -> Bool) -> PrinterParser StringsError [String] r (Char :- r)Source

statisfy a Char predicate

satisfyStr :: (String -> Bool) -> PrinterParser StringsError [String] r (String :- r)Source

satisfy a String predicate.

Note: must match the entire remainder of the String in this segment

space :: PrinterParser StringsError [String] r (Char :- r)Source

matches white-space characters in the Latin-1 range. (Uses isSpace)

Running the PrinterParser

isComplete :: [String] -> BoolSource

Predicate to test if we have parsed all the strings. Typically used as argument to parse1

see also: parseStrings

parseStrings :: PrinterParser StringsError [String] () (r :- ()) -> [String] -> Either StringsError rSource

run the parser

Returns the first complete parse or a parse error.

 parseStrings (rUnit . lit "foo") ["foo"]

unparseStrings :: PrinterParser e [String] () (r :- ()) -> r -> Maybe [String]Source

run the printer

 unparseStrings (rUnit . lit "foo") ()