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

Safe HaskellNone
LanguageHaskell98

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

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) Source 
HasPosition (Str a s loc) loc Source 
(Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, ListLike state Char) => Idiomatic (Str Char state loc) f (Char -> g) Source 
(Idiomatic (Str Char state loc) f g, IsLocationUpdatedBy loc Char, ListLike state Char) => Idiomatic (Str Char state loc) f (String -> g) Source 
StoresErrors (Str a s loc) (Error loc) Source 

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 = forall loc state. (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a Source

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 = forall loc state. (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a -> P (Str Char state loc) b Source

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.

Minimal complete definition

advance

Functions

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

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] -> String Source

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

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) a Source

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) a Source

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) a Source

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) a Source

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.