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
camlp4o differs from ocamlc because it has quotations enabled #5508
Comments
Comment author: @diml None of these modules is loaded when you use custom quotations. |
Comment author: gerd 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. |
Comment author: @diml Actually there is a problem with the first form too. For example this is legal with the standard parser: let ( <: ) x y = x + y but not with camlp4. By the way it is already possible to tell camlp4o not to parse quotations: there is the -no_quot option. |
Comment author: gerd 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. |
Comment author: Hendrik Tews I don't understand the remark about custom quotations. What do I would like to note that the problem is also present without 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 There is not so much documentation available about camlp4o. But As long as the documentation claims that camlp4o is standard |
Comment author: @diml
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. |
Comment author: Hendrik Tews Could you name a typical example for this custom quotation code? Does it use Camlp4QuotationCommon? |
Comment author: @diml
The tyxml project from ocsigen uses quotations for example.
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 ? |
Comment author: gerd An example for a custom quotation parser is my pxp-pp XML preprocessor, see https://godirepo.camlcity.org/svn/lib-pxp/trunk/src/pxp-pp/ for code and http://projects.camlcity.org/projects/dl/pxp-1.2.2/doc/manual/html/ref/Intro_preprocessor.html 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.) |
Comment author: Hendrik Tews I don't think adding one line to all custom quotation parsers (to Besides ... why not letting Quotation.add set the flag? I know of 3 places that state/suggest that camlp4o and
|
Comment author: @diml
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:
|
Comment author: @damiendoligez 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. |
Comment author: @diml 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. |
Original bug ID: 5508
Reporter: Hendrik Tews
Assigned to: @diml
Status: closed (set by @diml on 2016-12-07T17:27:38Z)
Resolution: open
Priority: normal
Severity: minor
Version: 3.12.1
Target version: later
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Monitored by: @bobzhang
Bug description
camlp4o 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.
The text was updated successfully, but these errors were encountered: