Maintainer | bastiaan.heeren@ou.nl |
---|---|
Stability | provisional |
Portability | portable (depends on ghc) |
Safe Haskell | None |
Language | Haskell98 |
This module exports a set of functions that build upon the primitives from Recognizer.Common.Parsing.Parse
Synopsis
- choice :: Parse m s => [m a] -> m a
- skip :: Parse m s => m s
- peek :: Parse m s => m s
- maybeToParse :: Parse m s => Maybe a -> m a
- peek2 :: Parse m s => m (s, s)
- choice' :: Parse m s => [m a] -> m a
- choiceFor :: Parse m s => [a] -> (a -> m b) -> m b
- choiceFor' :: Parse m s => [a] -> (a -> m b) -> m b
- succeedIf :: Parse m s => (a -> Bool) -> a -> m a
- pFoldAlt :: (Parse m s, Show a) => Bool -> (a -> m a) -> a -> m a
- few :: Parse m s => m a -> m [a]
- satisfyEq :: Parse m Math => (Expr -> Bool) -> (Expr -> Bool) -> m (Equation Expr)
- pInOrder :: (ParseLog m, Parse m Math) => [Maybe (Expr, [r]) -> m (Expr, [r])] -> m (Expr, [r], [Math])
- pRepeat :: Parse m Math => m (Expr, [r]) -> m ([Expr], [r], [Math])
- withInput :: Parse m s => ([s] -> a) -> m a
- pInOrderAll :: Parse m Math => [Maybe (Expr, [r]) -> m (Expr, [r])] -> m (Expr, [r], [Math])
- getInputSize :: Parse m s => m Int
- getBinary :: Parse m Math => Expr -> m (Expr, Expr)
- many1 :: Parse m s => m a -> m [a]
- pSkipUntil :: Parse m s => m a -> m (a, [s])
- many' :: Parse m s => m a -> m [a]
- many1' :: Parse m s => m a -> m [a]
- pAnyExpr :: Parse m Math => m Expr
- pReplicate :: Parse m s => Int -> m a -> m [a]
- pAnyOf :: Parse m s => [m a] -> m [a]
- pSomewhere :: Parse m s => m a -> m a
- pAnywhere :: Parse m s => m a -> m a
- nonEmpty :: Parse m s => m [a] -> m [a]
- pRewrite :: Parse m s => a -> m a
- peekExpr :: Parse m Math => m Expr
- peekEq :: Parse m Math => m (Equation Expr)
- pExprWith :: Parse m Math => (Expr -> (Expr, [Attribute])) -> Expr -> m (Expr, [Attribute])
- succeed :: Parse m s => a -> m a
- pEq :: Parse m Math => Equation Expr -> m ()
- pEqCom :: Parse m Math => Equation Expr -> m ()
- pExprCom :: Parse m Math => Expr -> m ()
- pExpr :: Parse m Math => Expr -> m ()
Documentation
maybeToParse :: Parse m s => Maybe a -> m a Source #
Fails on Nothing. Succeeds on Just.
peek2 :: Parse m s => m (s, s) Source #
Returns the top two inputs. Fails if there are less than 2 input remaining.
choiceFor' :: Parse m s => [a] -> (a -> m b) -> m b Source #
Combination of choice' and for
pFoldAlt :: (Parse m s, Show a) => Bool -> (a -> m a) -> a -> m a Source #
Only calls pFoldAlt'
if the predicate is True. Otherwise parses once.
few :: Parse m s => m a -> m [a] Source #
Alternative to many
where the order of the branches is reversed.
Here the first branch is an always successful parsing, the 2nd branch does one parsing
The third does two parsings and so on..
A common usage:
>>>
p >> few skip >> q
We want to parse q
and close as possible to p
, but we do not mind skipping as much as necessary.
satisfyEq :: Parse m Math => (Expr -> Bool) -> (Expr -> Bool) -> m (Equation Expr) Source #
Parse an input as an `Equation Expr` whose both sides must satisfy their respective predicates.
pInOrder :: (ParseLog m, Parse m Math) => [Maybe (Expr, [r]) -> m (Expr, [r])] -> m (Expr, [r], [Math]) Source #
This function is given a list of parsers that are executed in order of the list.
Input may be skipped as much as necessary. A parser may fail (none of the remaining input could be parsed) and thus is skipped.
The result of each previous successful parsing is available.
pRepeat :: Parse m Math => m (Expr, [r]) -> m ([Expr], [r], [Math]) Source #
Repeatedly execute a parser until we can no longer find any input for a successful parsing.
Input may be skipped as much as necessary between executions.
The remaining input is determined by the remaining input after the last successful parsing.
withInput :: Parse m s => ([s] -> a) -> m a Source #
Apply a function to the remaining input and return the result
Does not parse input.
pInOrderAll :: Parse m Math => [Maybe (Expr, [r]) -> m (Expr, [r])] -> m (Expr, [r], [Math]) Source #
This function is given a list of parsers that must all succeed in the order of the list.
Input may be skipped as much as necessary. The result of the previous parsing is also available.
getInputSize :: Parse m s => m Int Source #
getBinary :: Parse m Math => Expr -> m (Expr, Expr) Source #
Parse an expression that has exactly two children
pSkipUntil :: Parse m s => m a -> m (a, [s]) Source #
Continuously skip input until parsing succeeds.
pReplicate :: Parse m s => Int -> m a -> m [a] Source #
Execute a parser N times.
pAnyOf :: Parse m s => [m a] -> m [a] Source #
Skip input until one of the parsers succeeds. Applies this procedure many times.
pSomewhere :: Parse m s => m a -> m a Source #
Skip input until a successful parsing
pAnywhere :: Parse m s => m a -> m a Source #
Skip input until a successful parsing. Skip all remaining input.
pExprWith :: Parse m Math => (Expr -> (Expr, [Attribute])) -> Expr -> m (Expr, [Attribute]) Source #
pEqCom :: Parse m Math => Equation Expr -> m () Source #
Parse an equation that matches the argument expression modulo commutativity