Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0005508OCaml-for Camlp4 use 16:122016-12-07 18:27
ReporterHendrik Tews 
Assigned Todim 
PlatformOSOS Version
Product Version3.12.1 
Target VersionlaterFixed in Version 
Summary0005508: camlp4o differs from ocamlc because it has quotations enabled
Descriptioncamlp4o has quotations enabled by default, therefore it dies on legal ocaml code such as

let ( << ) a b = a + b in
print_int (4 << 5)

I believe Camlp4_config.quotations should be false by default and
the modules Camlp4QuotationExpander,
Camlp4OCamlRevisedQuotationExpander and
Camlp4OCamlOriginalQuotationExpander should set it to true when
they are loaded.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
dim (developer)
2012-02-17 11:57

None of these modules is loaded when you use custom quotations.
gerd (reporter)
2012-02-27 19:43

I think the issue deserves to think twice about it. Quotations are one of the camlp4 features that could also be ported to the standard parser, and having a clean syntax seems to be desirable.

We have both <:name< ... >> and << ... >>. It's only the latter form that makes problems here. One solution could be to disable this latter form by default, and to define a new command-line switch for enabling it (e.g. "-anon-quote name" for choosing the quotation "name" as the anonmyous one). This would work for both built-in and for custom quotations.

Of course, it would introduce a slight incompatibility with current code, but I think it's worth it for cleaning a messy corner of the language up.
dim (developer)
2012-02-27 20:26

Actually there is a problem with the first form too. For example this is legal with the standard parser:

let ( <: ) x y = x + y
let x = 1
let y = 1<:x<2

but not with camlp4.

By the way it is already possible to tell camlp4o not to parse quotations: there is the -no_quot option.
gerd (reporter)
2012-02-27 21:14

This is only a spacing problem, let y = 1 <: y < 2 is accepted. This is the same sort of problems as e.g. let (*) x y = x+y, and I don't think it needs fixing.

-no_quot opens the path to a paractical workaround, but IMHO the existence of this switch is only the proof that something is broken in the (lexical) design.
Hendrik Tews (reporter)
2012-02-27 21:42

I don't understand the remark about custom quotations. What do
you mean by that?

I would like to note that the problem is also present without
strange infix operators:

  let a = (* << *) 5

is legal OCaml, but not if you parse with camlp4o.

I don't agree that 1 <:y< 2 is a spacing problem. The point is
that 1 <:y< 2 is legal OCaml but is not accepted by camlp4o. In
contrast, let (*) x y = ... is not legal OCaml (without spaces)
and ocamlc and camlp4o agree on that fact.

There is not so much documentation available about camlp4o. But
what is available says camlp4o parses standard OCaml plus stream
parsers. It is nowhere stated that you should use -no_quot or
that "<<" is not permitted inside comments in standard OCaml.

As long as the documentation claims that camlp4o is standard
OCaml, quotations should be disabled by default. Note that there
is a similar flag for lexing antiquotations. It is off by default
and turned on by those parsing extensions that add antiquotations
to the grammar.
dim (developer)
2012-02-27 22:02

> I don't understand the remark about custom quotations. What do you mean by that?

Camlp4*QuotationExpander modules are not loaded when you use a syntax extension that defines quotations (other than the ones distributed with ocaml), and so quotations won't be parsed if Camlp4_config.quotations defaults to false. This is going to break a lot of code.
Hendrik Tews (reporter)
2012-02-27 22:10

Could you name a typical example for this custom quotation code?

Does it use Camlp4QuotationCommon?
dim (developer)
2012-02-27 22:29

> Could you name a typical example for this custom quotation code?

The tyxml project from ocsigen uses quotations for example.

> Does it use Camlp4QuotationCommon?

No. All theses modules are for expanding camlp4 ast quotations ("expr", "str_item", ...).

I think the doc need to be fixed. Where is it stated that camlp4o parses standard OCaml plus stream parsers ?
gerd (reporter)
2012-02-27 22:36

An example for a custom quotation parser is my pxp-pp XML preprocessor, see [^] for code and [^] for the manual. Generally, quotations are a good choice for any DSL you want to include and that ís totally foreign to OCaml.

The parsers I wrote just added the quotations with Quotation.add, and sometimes they recursively invoked the OCaml parser with Syntax.Gram.parse.

So yes, these custom quotation expanders exist, and they have nothing to do with Camlp4's internal use of quotations (for generating OCaml ASTs).

Btw, I don't think camlp4 must be absolutely compatible with the standard parser. It must just be predictable where it deviates, and it is better when the chance for surprises is low. However, camlp4 is too much of a hack to allow a full specification of it. (I guess this is the reason why the standard parser still exists.)
Hendrik Tews (reporter)
2012-02-27 22:55

I don't think adding one line to all custom quotation parsers (to
set Camlp4_config.quotations) is asking too much. There have been
much bigger incompatible changes in the camlp4 past.

Besides ... why not letting Quotation.add set the flag?

I know of 3 places that state/suggest that camlp4o and
camlp4o.cma are compatible with standard OCaml:

- camlp4 wiki [^]

- OCaml users manual 1.8

- OCaml users manual 7.2
dim (developer)
2012-02-28 09:19

> Besides ... why not letting Quotation.add set the flag?

I don't know, the user may want to explicitly disable quotations...

But i don't really see the problem here, when you use camlp4 you must expect camlp4 syntax, and quotations are part of the camlp4 syntax. If you want to parse regular ocaml with camlp4, just disable quotations. And quotations are not the only difference between the two parsers, for example:

- ocaml silently convert (max_int+1) literals to min_int but not camlp4,
- camlp4 accept { f x with ... } but ocaml requires parenthesis,
doligez (administrator)
2012-09-21 11:47

Note that section 6.1 of the manual also says that <<, <:, and >> should not be used as identifiers if you're concerned with camlp4 compatibility.
dim (developer)
2016-12-07 18:27

Camlp4 is now a separate project. Please re-open a ticket on github [1] if you are still interested in seeing the original issue fixed.

  [1] [^]

- Issue History
Date Modified Username Field Change
2012-02-16 16:12 Hendrik Tews New Issue
2012-02-17 11:56 dim Assigned To => dim
2012-02-17 11:56 dim Status new => feedback
2012-02-17 11:57 dim Note Added: 0006932
2012-02-27 19:43 gerd Note Added: 0006976
2012-02-27 20:26 dim Note Added: 0006977
2012-02-27 21:14 gerd Note Added: 0006978
2012-02-27 21:42 Hendrik Tews Note Added: 0006979
2012-02-27 21:42 Hendrik Tews Status feedback => assigned
2012-02-27 22:02 dim Note Added: 0006980
2012-02-27 22:10 Hendrik Tews Note Added: 0006981
2012-02-27 22:29 dim Note Added: 0006982
2012-02-27 22:36 gerd Note Added: 0006983
2012-02-27 22:55 Hendrik Tews Note Added: 0006985
2012-02-28 09:19 dim Note Added: 0006989
2012-07-10 11:40 doligez Target Version => 4.01.0+dev
2012-07-31 13:36 doligez Target Version 4.01.0+dev => 4.00.1+dev
2012-09-21 11:47 doligez Note Added: 0008134
2012-09-21 11:47 doligez Target Version 4.00.1+dev => 4.01.0+dev
2013-07-27 06:40 gasche Target Version 4.01.0+dev => later
2016-02-08 12:49 doligez Category Camlp4 => for Camlp4 use [^]
2016-02-08 12:50 doligez Category for Camlp4 use [^] => for Camlp4 use [^]
2016-12-07 18:27 dim Note Added: 0016776
2016-12-07 18:27 dim Status assigned => closed
2017-02-23 16:43 doligez Category for Camlp4 use [^] => -for Camlp4 use [^]

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker