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)
#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.
#notFollowedBy Source
notFollowedBy :: forall s a m. Monad m => ParserT s m a -> ParserT s m Unit
Fail if the specified parser matches.