uu-parsinglib-2.7.0.1: Fast, online, error-correcting, monadic, applicative, merging, permuting, idiomatic parser combinators.

Text.ParserCombinators.UU.BasicInstances

Contents

Description

This module contains basic instances for the class interface described in the Text.ParserCombinators.UU.Core module. It demonstates how to construct and maintain a state during parsing. In the state we store error messages, positional information and the actual input that is being parsed. Unless you have very specific wishes the module can be used as such. Since we make use of the Data.ListLike interface a wide variety of input structures can be handled.

The main part of this module is made up from the various instances for the class Provides.

Synopsis

Data Types

data Error pos Source

The data type Error describes the various kinds of errors which can be generated by the instances in this module

Constructors

Inserted String pos Strings

String was inserted at pos-ition, where we expected Strings

Deleted String pos Strings

String was deleted at pos-ition, where we expected Strings

Replaced String String pos Strings

for future use

DeletedAtEnd String

the unconsumed part of the input was deleted

Instances

Show pos => Show (Error pos) 
StoresErrors (Str a s loc) (Error loc) 

data Str a s loc Source

The data type Str holds the input data to be parsed, the current location, the error messages generated and whether it is ok to delete elements from the input. Since an insert/delete action is the same as a delete/insert action we try to avoid the first one. So: no deletes after an insert.

Constructors

Str 

Fields

input :: s

the unconsumed part of the input

msgs :: [Error loc]

the accumulated error messages

pos :: loc

the current input position

deleteOk :: !Bool

we want to avoid deletions after insertions

Instances

(Show a, ListLike s a) => Eof (Str a s loc) 
HasPosition (Str a s loc) loc 
(Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, ListLike state Char) => Idiomatic (Str Char state loc) f (Char -> g) 
(Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, ListLike state Char) => Idiomatic (Str Char state loc) f (String -> g) 
Idiomatic (Str Char state loc) x (Ii -> P (Str Char state loc) x) 
StoresErrors (Str a s loc) (Error loc) 
(Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, ListLike state Char) => Idiomatic (Str Char state loc) (a -> f) (P (Str Char state loc) a -> g) 

data Insertion a Source

Constructors

Insertion String a Cost 

Types

type Parser a = (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) aSource

A Parser is a parser that is prepared to accept Data.Listlike input; hence we can deal with String's, ByteString's, etc.

type ParserTrafo a b = (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a -> P (Str Char state loc) bSource

A ParserTrafo a b maps a Parser a onto a Parser b.

Classes

class Show loc => IsLocationUpdatedBy loc str Source

The input state may maintain a location which can be used in generating error messages. Since we do not want to fix our input to be just a String we provide an interface which can be used to advance this location by passing information about the part recognised. This function is typically called in the splitState functions.

Functions

createStr :: ListLike s a => loc -> s -> Str a s locSource

createStr initialises the input stream with the input data and the initial position. There are no error messages yet.

show_expecting :: Show pos => pos -> [String] -> StringSource

pSatisfy :: forall loc state a. (Show a, IsLocationUpdatedBy loc a, ListLike state a) => (a -> Bool) -> Insertion a -> P (Str a state loc) aSource

pRangeInsert :: (Ord a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => (a, a) -> Insertion a -> P (Str a state loc) aSource

pRange :: (IsLocationUpdatedBy loc a, ListLike state a, Show a, Ord a) => (a, a) -> P (Str a state loc) aSource

pSymInsert :: (Eq a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => a -> Insertion a -> P (Str a state loc) aSource

pSym :: (Eq a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => a -> P (Str a state loc) aSource

pToken :: (IsLocationUpdatedBy loc a, ListLike state a, Show a, Eq a) => [a] -> P (Str a state loc) [a]Source

pTokenCost :: forall loc state a. (Show a, Eq a, IsLocationUpdatedBy loc a, ListLike state a) => [a] -> Int -> P (Str a state loc) [a]Source

pMunch :: (IsLocationUpdatedBy loc a, ListLike state a, Show a) => (a -> Bool) -> P (Str a state loc) [a]Source