Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unneeded limitation on the CamplP4 quotation system #3926

Closed
vicuna opened this issue Dec 16, 2005 · 1 comment
Closed

Unneeded limitation on the CamplP4 quotation system #3926

vicuna opened this issue Dec 16, 2005 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Dec 16, 2005

Original bug ID: 3926
Reporter: alexbaretta
Assigned to: ertai
Status: closed (set by @xavierleroy on 2009-03-31T11:07:22Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.09.0
Fixed in version: 3.10.0
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues

Bug description

I 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

@vicuna
Copy link
Author

vicuna commented Mar 29, 2007

Comment author: ertai

This is will be available in OCaml 3.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant