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-08 (10:27)
From: Daniel de Rauglaudre <daniel.de_rauglaudre@i...>
Subject: Re : [Caml-list] Re: camlp4 stream parser syntax

On Sun, Mar 08, 2009 at 09:51:26AM +0000, Joel Reymont wrote:

> I would prefer to use the #2 approach but I'm using a custom lexer  
> built by ocamllex.

Mmm... I am not eventually sure that what I said was correct... I should
test it myself, what I generally do before asserting things... :-)

But I was not clear: I said that you had to program *both* items. It
was not an "or" but an "and"...

But... it was false...

Bsakjfvouveoussasj.... I said nothing... I restart...

A change in the lexer should be sufficient.

If you cannot (or if you don't want):

Only changing the "tok_match" record field (2nd point) would not work
for keywords (defined by "just a string" in Camlp* grammars), because
the lexer *must* recognize all combinations of the identifier as
keywords, implying a change, anyway, in the lexer.

On the other hand, if you can accept that these identifiers are not
keywords (i.e. not reserved names), and if there a token for identifiers,
like "LIDENT" of "UIDENT" in Camlp* proposed lexer (module Plexer in
Camlp5), you can put them in your grammar as (for example):
     LIDENT "delay"
instead of:

In this case, a change of the "tok_match" record field should work.
Define the function:

let my_tok_match =
    (p_con, "") ->
       begin function (con, prm) ->
         if con = p_con then prm else raise Stream.Failure
  | (p_con, p_prm) ->
       begin function (con, prm) ->
         if String.lowercase con = p_con && prm = p_prm then prm
         else raise Stream.Failure

Then look for an identifier named "tok_match" in your code, which
should be a record field, and define that "tok_match" record field as

If you don't find it, perhaps it is implicitely used by another Camlp*
library function. In this case, well, more work may have been done.

Daniel de Rauglaudre