Text.Parsing.Parser.Combinators
- Package
- purescript-parsing
- Repository
- purescript-contrib/purescript-parsing
Combinators for creating parsers.
Notes
A few of the known combinators from Parsec are missing in this module. That is because they have already been defined in other libraries.
Text.Parsec.many = Data.(Array|List).many
Text.Parsec.(<|>) = Control.Alt.alt (<|>)
Because Strings are not Char Arrays in PureScript many
and some
on Char Parsers need to
be used in conjunction with Data.String.CodeUnits.fromCharArray
to achieve "Parsec-like" results.
Text.Parsec.many (char 'x') <=> fromCharArray <$> Data.Array.many (char 'x')
Note that Data.(Array|List).(many|some)
are not stack safe. If you need to parse
large numbers of items then consider using Data.List.(manyRec|someRec)
instead.
#withErrorMessage Source
withErrorMessage :: forall m s a. Monad m => ParserT s m a -> String -> ParserT s m a
Provide an error message in the case of failure.
#(<?>) Source
Operator alias for Text.Parsing.Parser.Combinators.withErrorMessage (left-associative / precedence 3)
#withLazyErrorMessage Source
withLazyErrorMessage :: forall m s a. Monad m => ParserT s m a -> (Unit -> String) -> ParserT s m a
Provide an error message in the case of failure, but lazily. This is handy in cases where constructing the error message is expensive, so it's preferable to defer it until an error actually happens.
parseBang :: Parser Char
parseBang = char '!' <~?> \_ -> "Expected a bang"
#(<~?>) Source
Operator alias for Text.Parsing.Parser.Combinators.withLazyErrorMessage (left-associative / precedence 3)
#asErrorMessage Source
asErrorMessage :: forall m s a. Monad m => String -> ParserT s m a -> ParserT s m a
Flipped (<?>)
.
#(<??>) Source
Operator alias for Text.Parsing.Parser.Combinators.asErrorMessage (left-associative / precedence 3)
#optionMaybe Source
optionMaybe :: forall m s a. Monad m => ParserT s m a -> ParserT s m (Maybe a)
pure Nothing
in the case where a parser fails without consuming input.
#tryRethrow Source
tryRethrow :: forall m s a. Monad m => ParserT s m a -> ParserT s m a
Like try
, but will reannotate the error location to the try
point.
#many1 Source
many1 :: forall m s a. Monad m => ParserT s m a -> ParserT s m (NonEmptyList a)
Match one or more times.
#many1Rec Source
many1Rec :: forall m s a. MonadRec m => ParserT s m a -> ParserT s m (NonEmptyList a)
Stack-safe version of many1
at the expense of MonadRec
constraint
#sepEndBy1Rec Source
sepEndBy1Rec :: forall m s a sep. MonadRec m => ParserT s m a -> ParserT s m sep -> ParserT s m (NonEmptyList a)
Stack-safe version of sepEndBy1
at the expense of MonadRec
constraint
#chainl1Rec Source
chainl1Rec :: forall m s a. MonadRec m => ParserT s m a -> ParserT s m (a -> a -> a) -> ParserT s m a
Stack-safe version of chainl1
at the expense of MonadRec
constraint.
#chainr1Rec Source
chainr1Rec :: forall m s a. MonadRec m => ParserT s m a -> ParserT s m (a -> a -> a) -> ParserT s m a
Stack-safe version of chainr1
at the expense of MonadRec
constraint.
#skipManyRec Source
skipManyRec :: forall s a m. MonadRec m => ParserT s m a -> ParserT s m Unit
Stack-safe version of skipMany
at the expense of MonadRec
constraint.
#skipMany1Rec Source
skipMany1Rec :: forall s a m. MonadRec m => ParserT s m a -> ParserT s m Unit
Stack-safe version of skipMany1
at the expense of MonadRec
constraint.
#notFollowedBy Source
notFollowedBy :: forall s a m. Monad m => ParserT s m a -> ParserT s m Unit
Fail if the specified parser matches.
#many1TillRec Source
many1TillRec :: forall s a m e. MonadRec m => ParserT s m a -> ParserT s m e -> ParserT s m (NonEmptyList a)
Stack-safe version of many1Till
at the expense of MonadRec
constraint