Advise-me-0.1: Assessment services for the Advise-Me project

Maintainerbastiaan.heeren@ou.nl
Stabilityprovisional
Portabilityportable (depends on ghc)
Safe HaskellNone
LanguageHaskell98

Recognize.Parsing.Derived

Description

This module exports a set of functions that build upon the primitives from Recognizer.Common.Parsing.Parse

Synopsis

Documentation

choice :: Parse m s => [m a] -> m a Source #

Fold over |

skip :: Parse m s => m s Source #

Skips a single input

peek :: Parse m s => m s Source #

Returns the head of input. Fails if there is none.

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.

choice' :: Parse m s => [m a] -> m a Source #

Fold over |>

choiceFor :: Parse m s => [a] -> (a -> m b) -> m b Source #

Combination of choice and for

choiceFor' :: Parse m s => [a] -> (a -> m b) -> m b Source #

Combination of choice' and for

succeedIf :: Parse m s => (a -> Bool) -> a -> m a Source #

Fails if predicate doesn't hold

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.

getBinary :: Parse m Math => Expr -> m (Expr, Expr) Source #

Parse an expression that has exactly two children

many1 :: Parse m s => m a -> m [a] Source #

Perform one parsing followed by many

pSkipUntil :: Parse m s => m a -> m (a, [s]) Source #

Continuously skip input until parsing succeeds.

many' :: Parse m s => m a -> m [a] Source #

Greedy version of many

many1' :: Parse m s => m a -> m [a] Source #

Greedy version of many1

pAnyExpr :: Parse m Math => m Expr Source #

Parses any Expr

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.

nonEmpty :: Parse m s => m [a] -> m [a] Source #

Fails if the resulting list is empty

pRewrite :: Parse m s => a -> m a Source #

Skip an input and return a different value instead

peekExpr :: Parse m Math => m Expr Source #

Specialised version of peek for Expr

peekEq :: Parse m Math => m (Equation Expr) Source #

Specialised version of peek for `Equation Expr`

pExprWith :: Parse m Math => (Expr -> (Expr, [Attribute])) -> Expr -> m (Expr, [Attribute]) Source #

Parse an Expr that is equal to the argument Expr.

Also takes a function that may be applied to both the argument and input Expr.

succeed :: Parse m s => a -> m a Source #

Synonym for pure and return

pEq :: Parse m Math => Equation Expr -> m () Source #

Parse an Equation that is equal to the argument Equation

pEqCom :: Parse m Math => Equation Expr -> m () Source #

Parse an equation that matches the argument expression modulo commutativity

pExprCom :: Parse m Math => Expr -> m () Source #

Parse an expression that matches the argument expression modulo commutativity

pExpr :: Parse m Math => Expr -> m () Source #

Parse an Expr that is equal to the argument Expr