Version française
Home     About     Download     Resources     Contact us    
Browse thread
what do I need to know to understand camlp4
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Michael Ekstrand <michael@e...>
Subject: Re: [Caml-list] what do I need to know to understand camlp4
On Thu, 2010-09-23 at 16:56 +0200, ben kuin wrote:
> Could someone give any idea how I can begin to understand how to write
> simple camlp4 extensions?

Shameless self-plug, but I wrote a blog post this summer about my
experience figuring out how to do it.  I provide a walk-through and
explanation of a minimal syntax extension which adds lazy list pattern
matching support based on Batteries.  The URL:

http://www.elehack.net/michael/blog/2010/06/ocaml-syntax-extension

I do assume a basic knowledge of parsing context-free grammars, but a
generic tutorial on parsing with a tool such as Yacc can fill in that
gap.  The Wikipedia article[1] may also be helpful.

Once you've lept the hurdle of figuring out what pieces you need to
write and build a syntax extension, the remaining tricky part is to
figure out what pieces of the grammar you need to extend to accomplish
your objective.  For that, I consult the definition of the OCaml parser
in Camlp4OCamlParser.ml in the OCaml source tree.

- Michael

1. http://en.wikipedia.org/wiki/Context-free_grammar

-- 
Web/blog: http://elehack.net/michael
Jabber/Google Talk: this e-mail address
Twitter: http://twitter.com/elehack
mouse, n: a device for pointing at the xterm in which you want to type