Safe Haskell | None |
---|---|
Language | Haskell98 |
UU.Parsing.Interface
- 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 (Applicative p, Alternative p, Functor p) => IsParser p s | p -> s where
- 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 p) => a -> Steps (Pair a ()) s p
- 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
- (<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b
- (<*) :: Applicative f => forall a b. f a -> f b -> f a
- (*>) :: Applicative f => forall a b. f a -> f b -> f b
- (<$>) :: Functor f => (a -> b) -> f a -> f b
- (<$) :: Functor f => forall a b. a -> f b -> f a
- (<|>) :: Alternative f => forall a. f a -> f a -> f a
Documentation
data AnaParser state result s p a
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 |
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
class (Applicative p, Alternative p, Functor p) => IsParser p s | p -> s where
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
.
All operators available through Applicative
, 'Functor", and Alternative
have the same names suffixed with :
.
Methods
pSucceed :: a -> p a
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 a
pLow
parses the empty string, but alternatives to pLow are always
preferred over pLow
parsing the empty string.
pFail :: p a
This parser always fails, and never returns any value at all.
pCostRange :: Int# -> s -> SymbolR s -> p s
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 s
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 s
Parses a symbol. Returns the symbol parsed.
pRange :: s -> SymbolR s -> p s
getfirsts :: p v -> Expecting s
Get the firsts set from the parser, i.e. the symbols it expects.
setfirsts :: Expecting s -> p v -> p v
Set the firsts set in the parser.
getzerop :: p v -> Maybe (p v)
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
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 |
(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 ()
getInputState :: (InputState a c d, Symbol c, Ord c, OutputState b) => AnaParser a b c d a
handleEof :: (Symbol s, InputState a s p) => a -> Steps (Pair a ()) s p
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
evalStepsIO :: (Message s p -> String) -> Steps b s p -> IO b
(<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b
Sequential application.
(<*) :: Applicative f => forall a b. f a -> f b -> f a
Sequence actions, discarding the value of the second argument.
(*>) :: Applicative f => forall a b. f a -> f b -> f b
Sequence actions, discarding the value of the first argument.
(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4
An infix synonym for fmap
.
Examples
Convert from a
to a Maybe
Int
using Maybe
String
show
:
>>>
show <$> Nothing
Nothing>>>
show <$> Just 3
Just "3"
Convert from an
to an Either
Int
Int
Either
Int
String
using show
:
>>>
show <$> Left 17
Left 17>>>
show <$> Right 17
Right "17"
Double each element of a list:
>>>
(*2) <$> [1,2,3]
[2,4,6]
Apply even
to the second element of a pair:
>>>
even <$> (2,2)
(2,True)
(<|>) :: Alternative f => forall a. f a -> f a -> f a
An associative binary operation