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

MetaOCaml: reserved >. token #10130

Closed
wants to merge 1 commit into from
Closed

Conversation

Octachron
Copy link
Member

Submitted on behalf of Oleg, cc @yallop .

This PR is part of a series of patches sent to me by Oleg that proposes to reduce the difference between OCaml and MetaOCaml at the syntactic level.

This first PR modifies OCaml lexer to make sure that all OCaml program are syntactically valid in MetaOCaml.
In particular, it removes ">." from the set of infix operators:

let (>.) _ _ = ()
let () = 1 >. 2

emits a syntax error after this PR.
Similarly, the tokenisation of >.>. is modified to >. >..

@Octachron
Copy link
Member Author

After some more discussion with Oleg and @yallop , removing >. from the set of infix operators create some incompatibility with the existing ocaml libraries (like Core). A more compatible option is probably to have two lexing modes: mainline and MetaOCaml and make the lexer switches between the two modes. The question is then how to trigger thus switch. After some back and forth, it seems that there is three possible options:

  • implicit: the first .< token triggers the switch
  • explicit: a boolean -metaocaml (metaocaml_lexing?) Clflags controls the lexing mode.
  • hybrid: the -metaocamlflag can be either implicit (aka switch on first .<, true, or false (same as explicit above).
    Mainline OCaml would use false as default, whereas MetaOCaml would set the default to implicit.

@yallop
Copy link
Member

yallop commented Jul 6, 2021

I think any of these three solutions could be made to work. Do any of them actually require changes to OCaml, or is it sufficient in each case to change MetaOCaml?

@johnyob
Copy link
Contributor

johnyob commented Jan 7, 2023

One issue with the proposed solution is we don't provide a method of escaping this "MetaOCaml mode".
For example, one could imagine writing something like:

open Core

module Float : Robustly_comparable with type t = float = struct ... end
let true_ = .< Float.(2. >. 1.) >.

@yallop
Copy link
Member

yallop commented Jan 9, 2023

That's true, and I'm not sure there's a reasonable way to treat >. both as an operator and as a closing delimiter. There's an easy workaround (aliasing >.), but it's not really ideal. It might be better to use extension points, like this:

let true_ = [%code Float.(x >. y)]

(as is under consideration) rather than building in the slightly fragile .< >. syntax.

@Octachron
Copy link
Member Author

With the syntax proposed in ocaml/RFCs#27, MetaOCaml, users that would have activated >. as a keyword could still used the escaped syntax Float.(\#>.) 2. 1.. Nowadays, I tend to think that registering >. as an optional keyword along the lines proposed by ocaml/RFCs#27 is the most principled alternative.

@gasche gasche mentioned this pull request Aug 5, 2023
@gasche
Copy link
Member

gasche commented Aug 5, 2023

I believe that this PR is superseded by #12470, which includes MetaOCaml's new "adaptative lexing" mode to avoid incompatibilities pointed out by @yallop.

@gasche gasche closed this Aug 5, 2023
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.

4 participants