Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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:

  http://caml.inria.fr/pub/docs/manual-camlp4/manual003.html

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

  http://www.ffconsultancy.com/ocaml/benefits/parsing.html

There is also a slightly bigger parser here:

  http://www.ffconsultancy.com/ocaml/benefits/interpreter.html

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 
accordingly.

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e