Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003926OCamlCamlp4public2005-12-16 10:462009-03-31 13:07
Reporteralexbaretta 
Assigned Toertai 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version3.09.0 
Target VersionFixed in Version3.10.0 
Summary0003926: Unneeded limitation on the CamplP4 quotation system
DescriptionI use the CamlP4 quotation system to embed languages completely different from Ocaml in Ocaml code. Namely, I use the quotation system to compile SQL queries towards Ocaml *module* definitions. Thus, for example, the SQL code of a SELECT query called Select_foos is accessible from Ocaml namespace as

Select_foos.query_text ()

and the recordset can be obtained with

Select_foos.records ().

The Embedded SQL provides many other features which justify packaging the generated Ocaml code within a module definition. Sadly, camlp4 does not allow quotations to expand to module definitions. IIRC, only expressions and patterns are allowed as results of a quotation expander. This is not an insurmountable problem, since, instead of preprocessing my source files with camlp4, I can preprocess them with ocpp, which is not so picky about what quotations expand to. Yet, this, too, is not an adequate solution, as it does not produce the appropriate hash-directives for ocamlc to figure out where a preprocessed line of code actually appears in the original source file.

These seems to be a limitation of the pa_o original Ocaml syntax for Camlp4. Here are my reasons. The quotation result is parsed by the following code in pcaml.ml

value parse_quotation_result entry loc shift name str =
  let cs = Stream.of_string str in
  try Grammar.Entry.parse entry cs with
    ...

As I would expect, the mechanimism seems to be completely agnostic about the kind of subtree that is being parsed, as Grammar.Entry.parse knows the grammar being recognized only through the entry parameter. By perusing pa_o.ml, I have been able to verify that the QUOTATION symbol appears only in the productions pertaining to the expr and patt nonterminals.

In my opinion this is a spurious limitation, which could easily be overcome by allowing the the QUOTATION symbol to appear in productions of other nonterminals, such as module_expr and str_iterm, thus allowing respectively the following constructs:

module Foo_query = <:sql< SELECT * FROM foo >>

and

<:sql< QUERY Foo_query IS SELECT * FROM foo>>

I am willing to write the necessary glue code in pa_o.ml. Will the caml team accept the patch?

Alex
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0003996)
ertai (developer)
2007-03-29 16:42

This is will be available in OCaml 3.10.

- Issue History
Date Modified Username Field Change
2005-12-16 10:46 alexbaretta New Issue
2006-01-05 14:03 doligez Assigned To => mauny
2006-01-05 14:03 doligez Severity major => feature
2006-01-05 14:03 doligez Status new => acknowledged
2007-03-29 16:42 ertai Note Added: 0003996
2007-03-29 16:43 ertai Assigned To mauny => ertai
2007-03-29 16:43 ertai Status acknowledged => resolved
2007-03-29 16:43 ertai Resolution open => fixed
2007-03-29 16:43 ertai Fixed in Version => 3.10+dev
2009-03-31 13:07 xleroy Status resolved => closed
2009-03-31 13:07 xleroy Fixed in Version 3.10+dev => 3.10.0


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker