Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module exposes the internals of the package: its API may change independently of the PVP-compliant version number.
- data Rule s r e t a = Rule {}
- type ProdR s r e t a = Prod (Rule s r) e t a
- nullable :: Rule s r e t a -> ST s [a]
- nullableProd :: ProdR s r e t a -> ST s [a]
- resetConts :: Rule s r e t a -> ST s ()
- type Args s f a = f -> ST s [a]
- noArgs :: Args s a a
- funArg :: (f -> a) -> Args s f a
- pureArg :: x -> Args s f a -> Args s (x -> f) a
- impureArgs :: ST s [x] -> Args s f a -> Args s (x -> f) a
- mapArgs :: (a -> b) -> Args s f a -> Args s f b
- composeArgs :: Args s a b -> Args s b c -> Args s a c
- type Pos = Int
- data State s r e t a where
- data Cont s r e t a b where
- data Conts s r e t a c = Conts {}
- newConts :: STRef s [Cont s r e t a c] -> ST s (Conts s r e t a c)
- contraMapCont :: Args s b a -> Cont s r e t a c -> Cont s r e t b c
- contToState :: ST s [a] -> Cont s r e t a c -> State s r e t c
- simplifyCont :: Conts s r e t b a -> ST s [Cont s r e t b a]
- grammar :: Grammar (Rule s r) e a -> ST s a
- initialState :: ProdR s a e t a -> ST s (State s a e t a)
- data Report e i = Report {
- position :: Int
- expected :: [e]
- unconsumed :: i
- data Result s e i a
- safeHead :: ListLike i t => i -> Maybe t
- safeTail :: ListLike i t => i -> i
- parse :: ListLike i t => [State s a e t a] -> [ST s [a]] -> [State s a e t a] -> ST s () -> [e] -> Pos -> i -> ST s (Result s e i a)
- parser :: ListLike i t => (forall r. Grammar r e (Prod r e t a)) -> i -> ST s (Result s e i a)
- allParses :: (forall s. ST s (Result s e i a)) -> ([(a, Int)], Report e i)
- fullParses :: ListLike i t => (forall s. ST s (Result s e i a)) -> ([a], Report e i)
- report :: ListLike i t => (forall s. ST s (Result s e i a)) -> Report e i
Concrete rules and productions
The concrete rule type that the parser uses
nullableProd :: ProdR s r e t a -> ST s [a] Source
resetConts :: Rule s r e t a -> ST s () Source
type Args s f a = f -> ST s [a] Source
If we have something of type f
,
is what we need to do to
Args
s f af
to produce a
s.
impureArgs :: ST s [x] -> Args s f a -> Args s (x -> f) a Source
composeArgs :: Args s a b -> Args s b c -> Args s a c Source
States and continuations
contraMapCont :: Args s b a -> Cont s r e t a c -> Cont s r e t b c Source
contToState :: ST s [a] -> Cont s r e t a c -> State s r e t c Source
simplifyCont :: Conts s r e t b a -> ST s [Cont s r e t b a] Source
Strings of non-ambiguous continuations can be optimised by removing indirections.
Grammars
initialState :: ProdR s a e t a -> ST s (State s a e t a) Source
Given a grammar, construct an initial state.
Parsing
A parsing report, which contains fields that are useful for presenting errors to the user if a parse is deemed a failure. Note however that we get a report even when we successfully parse something.
Report | |
|
The result of a parse.
Ended (Report e i) | The parser ended. |
Parsed (ST s [a]) Int i (ST s (Result s e i a)) | The parser parsed a number of |
:: ListLike i t | |
=> [State s a e t a] | States to process at this position |
-> [ST s [a]] | Results ready to be reported (when this position has been processed) |
-> [State s a e t a] | States to process at the next position |
-> ST s () | Computation that resets the continuation refs of productions |
-> [e] | Named productions encountered at this position |
-> Pos | The current position in the input string |
-> i | The input string |
-> ST s (Result s e i a) |
The internal parsing routine
parser :: ListLike i t => (forall r. Grammar r e (Prod r e t a)) -> i -> ST s (Result s e i a) Source
Create a parser from the given grammar.
allParses :: (forall s. ST s (Result s e i a)) -> ([(a, Int)], Report e i) Source
Return all parses from the result of a given parser. The result may
contain partial parses. The Int
s are the position at which a result was
produced.
fullParses :: ListLike i t => (forall s. ST s (Result s e i a)) -> ([a], Report e i) Source
Return all parses that reached the end of the input from the result of a given parser.