uulib-0.9.15: Haskell Utrecht Tools Library

Safe Haskell | None

UU.Parsing.Interface

Synopsis

- data AnaParser state result s p a
- pWrap :: OutputState result => (forall r r''. (b -> r -> r'') -> state -> Steps (a, r) s p -> (state -> Steps r s p) -> (state, Steps r'' s p, state -> Steps r s p)) -> (forall r. state -> Steps r s p -> (state -> Steps r s p) -> (state, Steps r s p, state -> Steps r s p)) -> AnaParser state result s p a -> AnaParser state result s p b
- pMap :: OutputState result => (forall r r''. (b -> r -> r'') -> state -> Steps (a, r) s p -> (state, Steps r'' s p)) -> (forall r. state -> Steps r s p -> (state, Steps r s p)) -> AnaParser state result s p a -> AnaParser state result s p b
- module UU.Parsing.MachineInterface
- type Parser s = AnaParser [s] Pair s (Maybe s)
- class IsParser p s | p -> s where
  - (<*>) :: p (a -> b) -> p a -> p b
  - (<*) :: p a -> p b -> p a
  - (*>) :: p a -> p b -> p b
  - (<$>) :: (a -> b) -> p a -> p b
  - (<$) :: b -> p a -> p b
  - pSucceed :: a -> p a
  - pLow :: a -> p a
  - (<|>) :: p a -> p a -> p a
  - pFail :: p a
  - pCostRange :: Int# -> s -> SymbolR s -> p s
  - pCostSym :: Int# -> s -> s -> p s
  - pSym :: s -> p s
  - pRange :: s -> SymbolR s -> p s
  - getfirsts :: p v -> Expecting s
  - setfirsts :: Expecting s -> p v -> p v
  - getzerop :: p v -> Maybe (p v)
  - getonep :: p v -> Maybe (p v)
- pCost :: (OutputState out, InputState inp sym pos, Symbol sym, Ord sym) => Int# -> AnaParser inp out sym pos ()
- getInputState :: (InputState a c d, Symbol c, Ord c, OutputState b) => AnaParser a b c d a
- handleEof :: (Symbol s, InputState a s pos) => a -> Steps (Pair a ()) s pos
- parse :: (Symbol s, InputState inp s pos) => AnaParser inp Pair s pos a -> inp -> Steps (Pair a (Pair inp ())) s pos
- parseIOMessage :: (Symbol s, InputState inp s p) => (Message s p -> String) -> AnaParser inp Pair s p a -> inp -> IO a
- parseIOMessageN :: (Symbol s, InputState inp s p) => (Message s p -> String) -> Int -> AnaParser inp Pair s p a -> inp -> IO a
- data Pair a r = Pair a r
- evalStepsIO :: (Message s p -> String) -> Steps b s p -> IO b
- evalStepsIO' :: (Message s p -> String) -> Int -> Steps b s p -> IO b

# Documentation

data AnaParser state result s p a Source

Instances

(InputState inp s p, OutputState out) => StateParser (AnaParser (inp, st) out s p) st |

(Ord s, Symbol s, InputState state s p, OutputState result) => IsParser (AnaParser state result s p) s

The fast `AnaParser` instance of the `IsParser` class. Note that this requires a functioning `Ord` for the symbol type s, as tokens are often compared using the `compare` function in `Ord` rather than always using `==` rom `Eq`. The two do need to be consistent though, that is for any two `x1`, `x2` such that `x1 == x2` you must have `compare x1 x2 == EQ`.

pWrap :: OutputState result => (forall r r''. (b -> r -> r'') -> state -> Steps (a, r) s p -> (state -> Steps r s p) -> (state, Steps r'' s p, state -> Steps r s p)) -> (forall r. state -> Steps r s p -> (state -> Steps r s p) -> (state, Steps r s p, state -> Steps r s p)) -> AnaParser state result s p a -> AnaParser state result s p bSource

pMap :: OutputState result => (forall r r''. (b -> r -> r'') -> state -> Steps (a, r) s p -> (state, Steps r'' s p)) -> (forall r. state -> Steps r s p -> (state, Steps r s p)) -> AnaParser state result s p a -> AnaParser state result s p bSource

module UU.Parsing.MachineInterface

type Parser s = AnaParser [s] Pair s (Maybe s)Source

class IsParser p s | p -> s where Source

The `IsParser` class contains the base combinators with which to write parsers. A minimal complete instance definition consists of definitions for '(*)', '(|)', `pSucceed`, `pLow`, `pFail`, `pCostRange`, `pCostSym`, `getfirsts`, `setfirsts`, and `getzerop`.

Methods

(<*>) :: p (a -> b) -> p a -> p bSource

Sequential composition. Often used in combination with $. The function returned by parsing the left-hand side is applied to the value returned by parsing the right-hand side. Note: Implementations of this combinator should lazily match on and evaluate the right-hand side parser. The derived combinators for list parsing will explode if they do not.

(<*) :: p a -> p b -> p aSource

Value ignoring versions of sequential composition. These ignore either the value returned by the parser on the right-hand side or the left-hand side, depending on the visual direction of the combinator.

(*>) :: p a -> p b -> p bSource

(<$>) :: (a -> b) -> p a -> p bSource

Applies the function f to the result of p after parsing p.

(<$) :: b -> p a -> p bSource

pSucceed :: a -> p aSource

Two variants of the parser for empty strings. `pSucceed` parses the empty string, and fully counts as an alternative parse. It returns the value passed to it.

pLow :: a -> p aSource

`pLow` parses the empty string, but alternatives to pLow are always preferred over `pLow` parsing the empty string.

(<|>) :: p a -> p a -> p aSource

Alternative combinator. Succeeds if either of the two arguments succeed, and returns the result of the best success parse.

pFail :: p aSource

This parser always fails, and never returns any value at all.

pCostRange :: Int# -> s -> SymbolR s -> p sSource

Parses a range of symbols with an associated cost and the symbol to insert if no symbol in the range is present. Returns the actual symbol parsed.

pCostSym :: Int# -> s -> s -> p sSource

Parses a symbol with an associated cost and the symbol to insert if the symbol to parse isn't present. Returns either the symbol parsed or the symbol inserted.

pSym :: s -> p sSource

Parses a symbol. Returns the symbol parsed.

pRange :: s -> SymbolR s -> p sSource

getfirsts :: p v -> Expecting sSource

Get the firsts set from the parser, i.e. the symbols it expects.

setfirsts :: Expecting s -> p v -> p vSource

Set the firsts set in the parser.

getzerop :: p v -> Maybe (p v)Source

`getzerop` returns `Nothing` if the parser can not parse the empty string, and returns `Just p` with `p` a parser that parses the empty string and returns the appropriate value.

getonep :: p v -> Maybe (p v)Source

`getonep` returns `Nothing` if the parser can only parse the empty string, and returns `Just p` with `p` a parser that does not parse any empty string.

Instances

(Ord s, Symbol s, InputState state s p, OutputState result) => IsParser (AnaParser state result s p) s

The fast `AnaParser` instance of the `IsParser` class. Note that this requires a functioning `Ord` for the symbol type s, as tokens are often compared using the `compare` function in `Ord` rather than always using `==` rom `Eq`. The two do need to be consistent though, that is for any two `x1`, `x2` such that `x1 == x2` you must have `compare x1 x2 == EQ`.

(Symbol s, Ord s, InputState i s p, OutputState o) => IsParser (OffsideParser i o s p) s |

pCost :: (OutputState out, InputState inp sym pos, Symbol sym, Ord sym) => Int# -> AnaParser inp out sym pos ()Source

getInputState :: (InputState a c d, Symbol c, Ord c, OutputState b) => AnaParser a b c d aSource

handleEof :: (Symbol s, InputState a s pos) => a -> Steps (Pair a ()) s posSource

parse :: (Symbol s, InputState inp s pos) => AnaParser inp Pair s pos a -> inp -> Steps (Pair a (Pair inp ())) s posSource

parseIOMessage :: (Symbol s, InputState inp s p) => (Message s p -> String) -> AnaParser inp Pair s p a -> inp -> IO aSource

parseIOMessageN :: (Symbol s, InputState inp s p) => (Message s p -> String) -> Int -> AnaParser inp Pair s p a -> inp -> IO aSource

data Pair a r Source

Constructors

Pair a r |

Instances

OutputState Pair |

evalStepsIO :: (Message s p -> String) -> Steps b s p -> IO bSource

evalStepsIO' :: (Message s p -> String) -> Int -> Steps b s p -> IO bSource