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

merlin gives syntax error on #use directive (or #require) #1708

Open
SleepyMug opened this issue Nov 17, 2023 · 1 comment
Open

merlin gives syntax error on #use directive (or #require) #1708

SleepyMug opened this issue Nov 17, 2023 · 1 comment

Comments

@SleepyMug
Copy link

I tried to write an Ocaml program in a scripting style, but I realized merlin (version 4.12-501) does not work with toplevel directives. The simplest example would be

$ cat a.ml
#use "topfind"
let () = print_endline "Hello, world!";;
$ ocaml a.ml
Hello, world!
$ ocamlmerlin single errors -filename a.ml < a.ml
{"class":"return","value":[{"start":{"line":1,"col":0},"end":{"line":1,"col":1},"type":"parser","sub":[],"valid":true,"message":"Syntax error"}],"notifications":[],"timing":{"clock":4,"cpu":3,"query":0,"pp":0,"reader":0,"ppx":0,"typer":3,"error":0}}

The program I was trying to do looks like this

$ cat b.ml
#use "topfind"
#thread
#require "core"
open Core;;
let today = Date.create_exn ~y:2023 ~m:Month.Nov ~d:17;;
let yesterday = Date.create_exn ~y:2023 ~m:Month.Nov ~d:16;;
let () =
  Printf.printf "%d\n" (Date.diff today yesterday);;
$ ocaml b.ml
1
$ ocamlmerlin single errors -filename b.ml < b.ml
{"class":"return","value":[{"start":{"line":1,"col":0},"end":{"line":1,"col":1},"type":"parser","sub":[],"valid":true,"message":"Syntax error"}],"notifications":[],"timing":{"clock":6,"cpu":5,"query":0,"pp":0,"reader":0,"ppx":0,"typer":5,"error":0}}

I'm new to the language, and I have the feeling that this isn't how serious ocaml projects are designed to be run. But it's still useful for simple scripts and test out things.

The problem is similar to #1023 .

@SleepyMug SleepyMug changed the title merlin give syntax error on #use directive (or #require) merlin gives syntax error on #use directive (or #require) Nov 18, 2023
@ysalmon
Copy link

ysalmon commented Feb 6, 2024

I second this : using merlin in Emacs+Tuareg is a thing, and this fails if there is a directive.

Note however that many directives can be replaced by their definition from https://github.com/ocaml/ocaml/blob/trunk/toplevel/topdirs.ml.

For instance, #use "thing" seems to be replaceable with Topdirs.dir_use Format.std_formatter "thing".

In fact this is even better because you can use OCaml expressions, including variables, to build the file name : I am a fan of Topdirs.dir_directory ("/path-to-precompiled-files/ ^ Sys.ocaml_version), which lets me put *.cmo files for different OCaml versions in their respectives directories.

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

3 participants