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

Initial support for metaocaml #2630

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Initial support for metaocaml #2630

wants to merge 5 commits into from

Conversation

hhugo
Copy link
Collaborator

@hhugo hhugo commented Nov 26, 2024

This PR is the result of a quick experiment to add support for metaocaml.
You should feel free to take over it and push it through.

Fix #1211

This PR

  • The parser rules are already present (here and upstream)
  • This PR patches lexers to emit metaocaml tokens if requested (inspired from MetaOCaml parsing mode ocaml/ocaml#12470)
  • The metaocaml syntax is preserved. The corresponding extension points are not automatically converted to metaocaml syntax.
  • This PR introduce a new config flag to switch metaocaml mode on

Testing

I've not added tests yet.

This PR was manually tested with the following example

$ cat meta.ml

   let rec spower n x =
      if n = 0 then .<1>.
      else if n mod 2 = 0 then .<square .~(spower (n/2) x)>.
      else .<.~x * .~(spower (n-1) x)>.
    (* val spower : int -> int code -> int code = <fun> *)

$ dune exec ocamlformat -- --metaocaml meta.ml

let rec spower n x =                   
  if n = 0 then .< 1 >.
  else if n mod 2 = 0 then .< square .~(spower (n / 2) x) >.
  else .< .~x * .~(spower (n - 1) x) >.
(* val spower : int -> int code -> int code = <fun> *)

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

Successfully merging this pull request may close these issues.

Feature request: support BER MetaOCaml
1 participant