Skip to content

Upgrade Parser to 4.06 AST#2036

Closed
anmonteiro wants to merge 15 commits intoreasonml:masterfrom
anmonteiro:upgrade-parser-to-406
Closed

Upgrade Parser to 4.06 AST#2036
anmonteiro wants to merge 15 commits intoreasonml:masterfrom
anmonteiro:upgrade-parser-to-406

Conversation

@anmonteiro
Copy link
Copy Markdown
Member

@anmonteiro anmonteiro commented Jun 30, 2018

This PR upgrades the parser to the 4.06 AST version.

This paves the way to solving a number of issues that are currently blocked because we use the 4.04 version of the AST. For example, this PR also fixes:

In addition, this PR introduces parsing / printing of some new syntactic constructs made possible by OCaml 4.06:

type x = {. a: int};
type y = {
  .
  b: string,
  ...x, /* <-- NEW */
};

@anmonteiro anmonteiro force-pushed the upgrade-parser-to-406 branch 2 times, most recently from fde4aa0 to 7d8b1e9 Compare June 30, 2018 23:54
%on_error_reduce structure_item let_binding_body
as_loc(attribute)+
type_longident
attribute+
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Menhir complains these are unreachable from a toplevel expression. Probably because there's as_loc(attribute)+ above.

@anmonteiro
Copy link
Copy Markdown
Member Author

Tests are now failing on versions of OCaml < 4.06 because I implemented parsing of Pcl_open (e.g. class x = { open M; as self; };.

Not sure what's the proper way to parse these on older versions of OCaml; or is it even supported?

@hcarty
Copy link
Copy Markdown
Contributor

hcarty commented Jul 1, 2018

It was only added in 4.06.0. See https://github.com/ocaml/ocaml/blob/trunk/Changes#L801

@anmonteiro
Copy link
Copy Markdown
Member Author

@hcarty I'm aware. I'm trying to see if there's a way to run those tests only against 4.06.0.

@anmonteiro
Copy link
Copy Markdown
Member Author

I can't find a way to do it with the current setup. In any case, after thinking about it, I don't see the value of exercising the OCaml parser, since it's something we don't control. I'll test Pcl_open and the new AST types in .re files.

@hcarty
Copy link
Copy Markdown
Contributor

hcarty commented Jul 1, 2018

@anmonteiro I apologize - I misunderstood the question

@anmonteiro
Copy link
Copy Markdown
Member Author

anmonteiro commented Jul 1, 2018

I think this PR is now ready. Code reviews very much appreciated!

@anmonteiro anmonteiro force-pushed the upgrade-parser-to-406 branch from b262010 to f2f01cc Compare July 1, 2018 18:20
Copy link
Copy Markdown
Contributor

@IwanKaramazow IwanKaramazow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add "type checked" tests covering the new ast constructs?

| Ovar_name (id, tyl) ->
fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id
| Ovar_typ o -> print_out_type ppf o
(* fprintf ppf "@[%a%a@]" print_typargs tyl print_ident id *)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out line can probably be omitted?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

| let_bindings SEMI class_expr_lets_and_rest
{ class_of_let_bindings $1 $3 }
| object_body { mkclass (Pcl_structure $1) }
| LET? OPEN override_flag as_loc(mod_longident) SEMI class_expr_lets_and_rest
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we still need to support let open ... vs just open ... in newly added syntax? I tend to favour just open in favour of less grammar complexity. Thoughts?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added these for consistency with the seq_expr_no_seq production.


class_sig_body_cty:
| class_sig_body { Pcty_signature $1 }
| LET? OPEN override_flag as_loc(mod_longident) SEMI as_loc(class_sig_body_cty)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark about let open as above.

let pcd_name = {
txt = label;
txt = label.txt;
loc = pcd_loc;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably become label.loc? (And finally fixes the comment duplication?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch.

@anmonteiro anmonteiro force-pushed the upgrade-parser-to-406 branch from 5694900 to 3b34a1e Compare July 1, 2018 18:52
@anmonteiro
Copy link
Copy Markdown
Member Author

Went through the code review items and:

@anmonteiro anmonteiro force-pushed the upgrade-parser-to-406 branch from 038161b to 3470c12 Compare July 2, 2018 01:18
@jordwalke
Copy link
Copy Markdown
Member

VERY cool.

@anmonteiro anmonteiro force-pushed the upgrade-parser-to-406 branch from 6a875d7 to 2b43907 Compare November 3, 2019 19:04
@anmonteiro
Copy link
Copy Markdown
Member Author

superseded by #2487

@anmonteiro anmonteiro closed this Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants