effects-parser-0.1: Parser Effect for the Control.Effects Library

Safe HaskellSafe-Inferred

Control.Effects.Parser

Synopsis

Documentation

parse :: Monad m => [c] -> Handler (Parser c m a) (Maybe a) m aSource

Generates a Handler to parse input from the given list of items.

oneOf :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> [n b] -> n bSource

Tries each action from the given list in turn, stopping with the first one which successfully parses the input. A parse failure in the action or the continuation results in backtracking to the original location in the input, and reverts the state of any more deeply nested effects.

item :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n cSource

Returns and consumes the next item from the input. Fails if there is no more input to be consumed.

itemIf :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> (c -> Bool) -> n cSource

Returns and consumes the next item from the input, provided it satisfies a predicate. Fails if there is no more input, or if the predicate function evaluates to False.

lookahead :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n bSource

Zero-width positive lookahead assertion. Runs the given action against the current input without consuming it. A parse failure in the action causes the lookahead to fail; otherwise, the result of the action is returned.

noMatch :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n ()Source

Zero-width negative lookahead assertion. Runs the given action against the current input without consuming it. A parse failure in the action causes the lookahead to succeed; otherwise, the lookahead fails.

noBacktrack :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n bSource

Prevents backtracking into the middle of the given action. This can be used to create actions which always consume as much or as little of the input as possible, even if that would cause a later match to fail. Note that backtracking is still possible within the action, or across the entire noBacktrack action.

Examples:

  noBacktrack p $ oneOf [return (), item p >> return ()]  -- never consumes any input
  noBacktrack p $ parseMany p $ itemIf p (=='a')          -- always consumes all the 'a's

parseFail :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n bSource

A parser which always fails.

parseEnd :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n ()Source

A parser which succeeds only when there is no more input.

parseOpt :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n (Maybe b)Source

Try the given parser; returns Just the result on success, or Nothing otherwise.

parseMany :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n [b]Source

Apply the given parser zero or more times, and return a list of the results.

parseMany1 :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n [b]Source

Like parseMany, but fails if there isn't at least one match.

parseOpt' :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n (Maybe b)Source

A non-greedy version of parseOpt which prefers to match Nothing.

parseMany' :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n [b]Source

A non-greedy version of parseMany which matches as few times as possible.

parseMany1' :: AutoLift (Parser c m a) m n => Effect (Parser c m a) m -> n b -> n [b]Source

A non-greedy version of parseMany1 which matches as few times as possible (but at least once).