Thursday, May 14th, 2009
Jens Schmidt pointed us to an interesting project by “Mu Dynamics Research Labs” called p4js:
p4js is a monadic parser library that provides the basic monadic operators return and bind
The announcement blog post explains some of the motivations behind the project:
For the uninitiated to monadic styles and syntax, the introduction blog post has a short tutorial explaining the basics; the key bits to understand are that:
- The function $P() creates a parser object that can be executed on an input using the parse(input) function
- Each function on the parser (called combinators) returns an instance of the parser to make invocation chaining easy
- Once you define an interesting chain, you can register it with the parser for easy reference, as in
p.register(’nat’)and use it from now on as
The current library provides only a dozen combinators, but it is enough to have quite some fun already. Following are few examples:
* a CSV parser,
* a small calculator and
* the tiny math processor that uses the parser not only to parse the input into expression tree, but also to perform expression evaluation and function derivation on the tree, and to draw function graphs (on browsers that support the canvas tag).
In the comments of the announcement post, a couple of people also point at Chris Double’s implementation of the same concept.
Posted by Ben Galbraith at 10:32 am