Module
Text.Parsing.Parser
- Package
- purescript-parsing
- Repository
- purescript-contrib/purescript-parsing
#ParseError Source
data ParseErrorA parsing error, consisting of a message and position information.
Constructors
Instances
Show ParseErrorEq ParseErrorOrd ParseError(Monad m) => MonadThrow ParseError (ParserT s m)(Monad m) => MonadError ParseError (ParserT s m)
#ParseState Source
data ParseState sContains the remaining input and current position.
Constructors
Instances
(Monad m) => MonadState (ParseState s) (ParserT s m)
#ParserT Source
newtype ParserT :: Type -> (Type -> Type) -> Type -> Typenewtype ParserT s m a
The Parser monad transformer.
The first type argument is the stream type. Typically, this is either String,
or some sort of token stream.
Constructors
ParserT (ExceptT ParseError (StateT (ParseState s) m) a)
Instances
Newtype (ParserT s m a) _Lazy (ParserT s m a)(Monad m, Semigroup a) => Semigroup (ParserT s m a)(Monad m, Monoid a) => Monoid (ParserT s m a)(Functor m) => Functor (ParserT s m)(Monad m) => Apply (ParserT s m)(Monad m) => Applicative (ParserT s m)(Monad m) => Bind (ParserT s m)(Monad m) => Monad (ParserT s m)(MonadRec m) => MonadRec (ParserT s m)(Monad m) => MonadState (ParseState s) (ParserT s m)(Monad m) => MonadThrow ParseError (ParserT s m)(Monad m) => MonadError ParseError (ParserT s m)(Monad m) => Alt (ParserT s m)(Monad m) => Plus (ParserT s m)(Monad m) => Alternative (ParserT s m)(Monad m) => MonadZero (ParserT s m)(Monad m) => MonadPlus (ParserT s m)MonadTrans (ParserT s)
#runParser Source
runParser :: forall s a. s -> Parser s a -> Either ParseError aApply a parser, keeping only the parsed result.
#runParserT Source
runParserT :: forall m s a. Monad m => s -> ParserT s m a -> m (Either ParseError a)Apply a parser, keeping only the parsed result.
#mapParserT Source
mapParserT :: forall b n s a m. (m (Tuple (Either ParseError a) (ParseState s)) -> n (Tuple (Either ParseError b) (ParseState s))) -> ParserT s m a -> ParserT s n bChange the underlying monad action and data type in a ParserT monad action.
#failWithPosition Source
failWithPosition :: forall m s a. Monad m => String -> Position -> ParserT s m aFail with a message and a position.
#region Source
region :: forall m s a. Monad m => (ParseError -> ParseError) -> ParserT s m a -> ParserT s m aContextualize parsing failures inside a region. If a parsing failure
occurs, then the ParseError will be transformed by each containing
region as the parser backs out the call stack.
The alternative
Altinstance provides thealtcombinator<|>.The expression
p_left <|> p_rightwill first try thep_leftparser and if that fails and consumes no input then it will try thep_rightparser.While we are parsing down the
p_leftbranch we may reach a point where we know this is the correct branch, but we cannot parse further. At that point we want to fail the entire parse instead of trying thep_rightbranch.For example, consider this
fileParserwhich can parse either an HTML file that begins with<html>or a shell script file that begins with#!.If we read a file from disk and run this
fileParseron it and thestring "<html>"parser succeeds, then we know that the first branch is the correct branch. Even if theparseTheRestOfTheHtmlparser fails we don’t want to try the other branch.To control the point at which we commit to the
p_leftbranch use thetrycombinator and thelookAheadcombinator and theconsumefunction.The
altcombinator works this way because it gives us good localized error messages while also allowing an efficient implementation.