Safe Haskell | None |
---|
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.
- data Error pos
- data Str a s loc = Str {}
- data Insertion a = Insertion String a Cost
- data LineCol = LineCol !Int !Int
- data LineColPos = LineColPos !Int !Int !Int
- type Parser a = (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a
- type ParserTrafo a b = (IsLocationUpdatedBy loc Char, ListLike state Char) => P (Str Char state loc) a -> P (Str Char state loc) b
- class Show loc => IsLocationUpdatedBy loc str
- createStr :: ListLike s a => loc -> s -> Str a s loc
- show_expecting :: Show pos => pos -> [String] -> String
- pSatisfy :: forall loc state a. (Show a, loc `IsLocationUpdatedBy` a, ListLike state a) => (a -> Bool) -> Insertion a -> P (Str a state loc) a
- pRangeInsert :: (Ord a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => (a, a) -> Insertion a -> P (Str a state loc) a
- pRange :: (Ord a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => (a, a) -> P (Str a state loc) a
- pSymInsert :: (Eq a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => a -> Insertion a -> P (Str a state loc) a
- pSym :: (Eq a, Show a, IsLocationUpdatedBy loc a, ListLike state a) => a -> P (Str a state loc) a
- pToken :: forall loc state a. (Show a, Eq a, loc `IsLocationUpdatedBy` a, ListLike state a) => [a] -> P (Str a state loc) [a]
- pTokenCost :: forall loc state a. (Show a, Eq a, loc `IsLocationUpdatedBy` a, ListLike state a) => [a] -> Int -> P (Str a state loc) [a]
- pMunch :: forall loc state a. (Show a, loc `IsLocationUpdatedBy` a, ListLike state a) => (a -> Bool) -> P (Str a state loc) [a]
Data Types
The data type Error
describes the various kinds of errors which can be generated by the instances in this module
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.
(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) |
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.
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
maps a ParserTrafo
a b
onto a Parser
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
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
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.