Version française
Home     About     Download     Resources     Contact us    
Browse thread
Camlp4: extending syntax of record definitions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus.mottl@g...>
Subject: Camlp4: extending syntax of record definitions
Hi,

I'd like to add annotations to record definitions that allow the automatic
generation of validation functions.  Here is a simplified example:

  let float_range lower upper x = lower <= x && x <= upper
  let int_positive x = x >= 0

  type some_record =
    {
      foo : float validate float_range 1.0 2.0;
      bar : int validate int_positive;
    }

The "validate" keyword would essentially allow attaching a function to
each record field, which is called to assert some properties.  E.g. the
following function would be automatically generated from the above
type definition:

  let validate__some_record r =
    float_range 1.0 2.0 r.foo &&
    int_positive r.bar

Not being a camlp4-expert my problem is that I'm not sure how to go about
extending the grammar.  What would be the most convenient starting point?
Extending existing grammars, starting one from scratch, etc.?  Some rough
outline on what to do would be nice.  Thanks in advance!

Best regards,
Markus

--
Markus Mottl        http://www.ocaml.info        markus.mottl@gmail.com