boomerang-1.3.3: Library for invertible parsing and printing

Safe HaskellNone

Text.Boomerang.Texts

Contents

Description

a PrinterParser library for working with '[Text]'

Synopsis

Types

Combinators

(</>) :: PrinterParser TextsError [Text] b c -> PrinterParser TextsError [Text] a b -> PrinterParser TextsError [Text] a cSource

equivalent to f . eos . g

alpha :: PrinterParser TextsError [Text] 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 TextsError [Text] r (Char :- r)Source

matches the specified character

digit :: PrinterParser TextsError [Text] r (Char :- r)Source

ascii digits '0'..'9'

digits :: PrinterParser TextsError [Text] r (Text :- r)Source

a sequence of digits

signed :: PrinterParser TextsError [Text] a (Text :- r) -> PrinterParser TextsError [Text] a (Text :- r)Source

an optional - character

Typically used with digits to support signed numbers

 signed digits

eos :: PrinterParser TextsError [Text] r rSource

end of string

integral :: (Integral a, Show a) => PrinterParser TextsError [Text] r (a :- r)Source

matches an Integral value

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

int :: PrinterParser TextsError [Text] r (Int :- r)Source

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

integer :: PrinterParser TextsError [Text] 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 :: Text -> PrinterParser TextsError [Text] r rSource

a constant string

readshow :: (Read a, Show a) => PrinterParser TextsError [Text] 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 TextsError [Text] r (Char :- r)Source

statisfy a Char predicate

satisfyStr :: (Text -> Bool) -> PrinterParser TextsError [Text] r (Text :- r)Source

satisfy a Text predicate.

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

space :: PrinterParser TextsError [Text] r (Char :- r)Source

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

rTextCons :: PrinterParser e tok (Char :- (Text :- r)) (Text :- r)Source

the first character of a Text

rEmpty :: PrinterParser e [Text] r (Text :- r)Source

the empty string

rText :: PrinterParser e [Text] r (Char :- r) -> PrinterParser e [Text] r (Text :- r)Source

construct/parse some Text by repeatedly apply a Char 0 or more times parser

rText1 :: PrinterParser e [Text] r (Char :- r) -> PrinterParser e [Text] r (Text :- r)Source

construct/parse some Text by repeatedly apply a Char 1 or more times parser

Running the PrinterParser

isComplete :: [Text] -> BoolSource

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

see also: parseTexts

parseTexts :: PrinterParser TextsError [Text] () (r :- ()) -> [Text] -> Either TextsError rSource

run the parser

Returns the first complete parse or a parse error.

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

unparseTexts :: PrinterParser e [Text] () (r :- ()) -> r -> Maybe [Text]Source

run the printer

 unparseTexts (rUnit . lit "foo") ()