Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
camlp4 stream parser syntax
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-03-07 (23:47)
From: Jon Harrop <jon@f...>
Subject: Re: [Caml-list] camlp4 stream parser syntax
On Saturday 07 March 2009 22:38:14 Joel Reymont wrote:
> Where can I read up on the syntax of the following in a camlp4 stream
> parser?
>    | [<' INT n >] -> Int n
> For example, where are [< ... >] described and why is the ' needed in
> between?

The grammar is described formally here:

You may find one of my free articles on parsing to be of interest because it 
covers the stream parser camlp4 extension:

There is also a slightly bigger parser here:

The [< .. >] denote a stream when matching over one using the "parser" keyword 
and the tick ' denotes a kind of literal to identify a single token in the 
stream. So:

    | [< 'Kwd "if"; p=parse_expr; 'Kwd "then"; t=parse_expr;
         'Kwd "else"; f=parse_expr >] ->

uses ' to parse three individual keywords but also requests that parts of the 
stream are parsed using the parse_expr function and each result is named 

Dr Jon Harrop, Flying Frog Consultancy Ltd.