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

Safe HaskellNone

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.

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) 
StoresErrors (Str a s loc) (Error loc) 

data Insertion a Source

the String describes what is being inserted, the a parameter the value which is to be inserted and the cost the prices to be paid.

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, loc `IsLocationUpdatedBy` a, ListLike state a) => (a -> Bool) -> Insertion a -> P (Str a state loc) aSource

pSatisfy describes and elementary parsing step. Its first parameter check whether the head element of the input can be recognised, and the second parameter how to proceed in case an element recognised by this parser is absent, and parsing may proceed by pretending such an element was present in the input anayway.

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

pRangeInsert recognises an element between a lower and an upper bound. Furthermore it can be specified what element is to be inserted in case such an element is not at the head of the input.

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

pRange uses the information from the bounds to compute the Insertion information.

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

pSymInsert recognises a specific element. Furthermore it can be specified what element is to be inserted in case such an element is not at the head of the input.

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

pSym recognises a specific element. Furthermore it can be specified what element. Information about Insertion is derived from the parameter. is to be inserted in case such an element is not at the head of the input.

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

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

pTokenCost succeeds if its parameter is a prefix of the input.

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

pMunch recognises the longest prefix of the input for which the passed predicate holds.

pMunchL :: forall loc state a. (Show a, loc `IsLocationUpdatedBy` a, ListLike state a) => (a -> Bool) -> String -> P (Str a state loc) [a]Source

pMunchL recognises the longest prefix of the input for which the passed predicate holds. The message parameter is used when tracing has been switched on.