parco-0.1: Generalised parser combinators

Safe HaskellSafe-Inferred



This module implements a general parser class that you should probably implement for any parsers using Parco - it encapsulates features that cannot be expressed using other standard classes. While some parser combinators (such as Text.Parco.Perm) can be expressed solely through Applicative and Alternative, others may need to do backtracking, which not all parser implementations can do automatically.

Before defining your own instance of the class, check if a package is available that does it for you. For example, parco-parsec defines an instance for Parsec.



class Alternative p => Parser p whereSource

Some parser combinators need special operations that are not captured in any of the standard typeclasses (backtracking, for example). For these, it is necessary to define an instance of this class.


try :: p a -> p aSource

If try p fails, no input should be consumed. The default method calls error.

expects :: p a -> String -> p aSource

If expects p s fails, the error message should note that s (a descriptive string) was expected, but has otherwise no semantic effect on the parser. The default method simply returns p.