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

Spurious (?) camlp4 error #6221

Closed
vicuna opened this issue Nov 2, 2013 · 4 comments
Closed

Spurious (?) camlp4 error #6221

vicuna opened this issue Nov 2, 2013 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Nov 2, 2013

Original bug ID: 6221
Reporter: kosik
Assigned to: @yallop
Status: closed (set by @xavierleroy on 2015-12-11T18:27:48Z)
Resolution: fixed
Priority: low
Severity: minor
Version: 3.12.1
Target version: later
Category: -for Camlp4 use https://github.com/ocaml/camlp4/issues
Tags: patch

Bug description

By looking at:

http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree#Types

there is a line:

 <:ctyp< t : t >>   ....... Field declaration
                    ........ TyCol of Loc.t and ctyp and ctyp

so it seems that it should also be somehow posible to get a quote for "field declaration", i.e.:

<:ctypfoo1:bar1>

However, if I try that, I get an error:

While expanding quotation "ctyp" in a position of "expr":
Parse error: "->" expected after [ctyp level star] (in [ctyp]

That might not be the expected camlp4 behavior.
Instead, it should expand that quotation to something like:

Ast.TyCol (_loc,
(Ast.TyId (_loc, (Ast.IdLid (_loc, "foo1")))),
(Ast.TyId (_loc, (Ast.IdLid (_loc, "bar1")))))

File attachments

@vicuna
Copy link
Author

vicuna commented Nov 3, 2013

Comment author: @bobzhang

I think the documentation may be incorrect. where do you expect 'foo1:bar' appear?
If it appears in record, then it should be recognized as type representation, not type expression.

@vicuna
Copy link
Author

vicuna commented Nov 3, 2013

Comment author: kosik

Hi,

This suggestion:

<:ctyp< t : t >>

I have found here:

http://brion.inria.fr/gallium/index.php/Abstract_Syntax_Tree#Types

It appears on the line that contains

TyCol

.

@vicuna
Copy link
Author

vicuna commented Nov 4, 2013

Comment author: @yallop

It looks like camlp4 is committing to parsing x:y as a labeled argument rather than a record field as soon as it's seen the colon. I've attached a patch that changes the parser so that it waits until it's seen the function arrow before committing.

Examples:
$ cat labeled_arg.ml
let _ = <:ctyp< x:y -> int >>

$ cat record_field.ml
let _ = <:ctyp< x:y >>

Without the patch:

$ camlp4of labeled_arg.ml
Ast.TyArr (_loc,
Ast.TyLab (_loc, "x", Ast.TyId (_loc, Ast.IdLid (_loc, "y"))),
Ast.TyId (_loc, Ast.IdLid (_loc, "int")))

$ camlp4of record_field.ml
File "record_field.ml", line 1, characters 20-21:
While expanding quotation "ctyp" in a position of "expr":
Parse error: [ctyp level star] expected after [lident_colon] (in [ctyp])

With the patch:

$ camlp4of labeled_arg.ml
Ast.TyArr (_loc,
(Ast.TyLab (_loc, "x", (Ast.TyId (_loc, (Ast.IdLid (_loc, "y")))))),
(Ast.TyId (_loc, (Ast.IdLid (_loc, "int")))))

$ camlp4of record_field.ml
Ast.TyCol (_loc, (Ast.TyId (_loc, (Ast.IdLid (_loc, "x")))),
(Ast.TyId (_loc, (Ast.IdLid (_loc, "y")))))

@vicuna
Copy link
Author

vicuna commented May 30, 2014

Comment author: @yallop

Fixed in Camlp4 trunk:

camlp4/camlp4@ce59218a

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