type types =
| Int
| String
| Float
| Char
| Bool
| Option of types
| List of types
| Tuple of types list
the function I need should return something like List (Tuple ([Int;
Option(String)]))
Before starting with low level sscanf functions I looked at the Genlex
module, but it wasn't so inspiring. Then I tried with Camlp4 but the
documentation doesn't really shine :-)
So is there a simple way to write this function using some standard module?
TIA,
--
Paolo
~
~
:wq
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
David
> For a serializer I'm writing I need to parse simple OCaml type
> expressions composed by OCaml basic types, tuples, options and lists.
This is pretty easy with Camlp4, although as you say there isn't much in the
docs to point the way. You might take a look at how orpc does it--see the
parse_type function in
http://code.google.com/p/orpc2/source/browse/trunk/src/generator/parse.ml
(I'm going to cover using Camlp4 in this way on the blog I posted yesterday,
but not for another week or two.)
You might also look at some other Camlp4-based serialization tools, like
bin-prot/type-conv at
http://www.ocaml.info/home/ocaml_sources.html
Jake
Thanks for this pointer!
Our json-wheel library is a complete example:
http://martin.jambon.free.fr/json-wheel.html
Martin
At the end, Camlp4 was the right solution to my simple problem, as I
suspected from the beginning. Camlp4 is an extremely powerful tool and
it's a pity it couldn't be used by everyone for lack of documentation.
What is really needed, in my opinion, is a description of *what* one
can do with Camlp4 without being an expert. For example a list of all
syntax extension available out of the box might spread the use of
Camlp4 among common programmers.
Searching in the source code I can see things named:
Camlp4ExceptionTracer, Camlp4FoldGenerator, Camlp4MetaGenerator, and
so on. The names sounds great but... what is it? The source code is
cryptic to every "regular" OCaml programmer like me. The same
considerations apply to all the (many!) libraries available and
related to Camlp4.
What is needed to spread the use of this tool are some... recipes,
like those available for ocamlbuild in its wiki pages.
--
Paolo
~
~
:wq
_______________________________________________