-
Notifications
You must be signed in to change notification settings - Fork 17
Understanding the API
Jamie Willis edited this page Dec 26, 2022
·
12 revisions
In Parsley, everything resides within the parsley
package, and the major entry point is
parsley.Parsley
.
There are a few modules of note:
-
parsley.Parsley
: contains some of the basic and primitive combinators (at least those that aren't methods on parsers). -
parsley.combinator
: contains handy combinators, this should be your first port of call when you want to do something but are not sure a combinator exists for it. At the very least, theeof
combinator is very common. -
parsley.character
: contains a variety of combinators which deal with characters, key ones includechar
,satisfy
andstring
. -
parsley.implicits
: contains the very useful implicit conversion combinators. In particular, importingcharLift
andstringLift
allows you write character and string literals as if they were parsers themselves. There are also implicit classes here which extend functions of any arity with a corresponding.lift
method, instead of using theliftN
functions. -
parsley.expr
: contains the machinery needed to generate expression parsers for you based, at its simplest, on a table of operators in order of precedence. This is well worth a look (this is covered in detail in: Building Expression Parsers). -
parsley.token
: contains a bunch of functionality for performing common lexing tasks, which is very configurable. These parsers may also be optimised for performance.
Unlike Haskell libraries like megaparsec
and parsec
, parsley
does not
tie the lexing functionality to the Haskell Report, instead supporting a superset of the functionality. The functionality is provided to the user by parsley.token.Lexer
, and this must be provided an value of type parsley.token.descriptions.LexicalDesc
, which provides all the configuration necessary to describe the language and make the parsers.
The Wiki refers to the latest version in the parsley-4.x.y
series.