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

Support multiple extensions in (dialect) patterns #7777

Closed
aantron opened this issue May 22, 2023 · 4 comments · Fixed by #7782 or ocaml/opam-repository#24013
Closed

Support multiple extensions in (dialect) patterns #7777

aantron opened this issue May 22, 2023 · 4 comments · Fixed by #7782 or ocaml/opam-repository#24013

Comments

@aantron
Copy link
Collaborator

aantron commented May 22, 2023

Desired Behavior

Dream currently recommends .eml.ml files, to take advantage of partial syntax highlighting of their ML parts. This is currently not possible with (dialect):

(lang dune 2.0)

(dialect
 (name eml)
 (implementation
  (extension eml.ml)
  (preprocess (run %{bin:dream_eml} --stdout %{input-file})))
 (interface
  (extension emli)
  (format (run cat))))

results in

Entering directory '/home/antron/code/dreamworld'
File "dream/example/7-template/dune-project", line 6, characters 13-19:
6 |   (extension eml.ml)
                 ^^^^^^
Error: extension must not contain '.'

Is it possible to support such extensions?

Example

(lang dune 2.0)

(dialect
 (name eml)
 (implementation
  (extension eml.ml)
  (preprocess (run %{bin:dream_eml} --stdout %{input-file})))
 (interface
  (extension emli)
  (format (run cat))))

See aantron/dream#228 (comment).

@nojb
Copy link
Collaborator

nojb commented May 22, 2023

Is it possible to support such extensions?

I don't see any problem technically. The existing warning should be changed to "extension should not start with a dot".

@emillon
Copy link
Collaborator

emillon commented May 22, 2023

Another use case is for cppo as it would allow defining .cppo.ml as an extension for a cppo dialect (in the case where the preprocessing command only depends on static info like the ocaml version number).

@nojb
Copy link
Collaborator

nojb commented May 22, 2023

Another use case is for cppo as it would allow defining .cppo.ml as an extension for a cppo dialect (in the case where the preprocessing command only depends on static info like the ocaml version number).

Thinking a bit more about this, there is a choice to make because today Dune decides what is the dialect of a file just by looking at its extension (ie the stuff after the last dot), so .cppo.ml is interepreted as being an OCaml file (not a dialect). If we want to do what is suggested here, we will have to change this logic a bit. Perhaps it is enough to to look at everything that comes after the first dot (instead of the last one), but it will be a breaking change.

@nojb
Copy link
Collaborator

nojb commented May 22, 2023

Another use case is for cppo as it would allow defining .cppo.ml as an extension for a cppo dialect (in the case where the preprocessing command only depends on static info like the ocaml version number).

Thinking a bit more about this, there is a choice to make because today Dune decides what is the dialect of a file just by looking at its extension (ie the stuff after the last dot), so .cppo.ml is interepreted as being an OCaml file (not a dialect). If we want to do what is suggested here, we will have to change this logic a bit. Perhaps it is enough to to look at everything that comes after the first dot (instead of the last one), but it will be a breaking change.

Actually I was a bit confused; I think everything should work without too much trouble, see #7782

emillon added a commit to emillon/opam-repository that referenced this issue Jun 23, 2023
CHANGES:

- Validate file extension for `$ dune ocaml top-module`. (ocaml/dune#8005, fixes ocaml/dune#8004, @3Rafal)

- Include the time it takes to read/write state files when `--trace-file` is
  enabled (ocaml/dune#7960, @rgrinberg)

- Add `dune show` command group which is an alias of `dune describe`. (ocaml/dune#7946,
  @Alizter)

- Include source tree scans in the traces produced by `--trace-file` (ocaml/dune#7937,
  @rgrinberg)

- Cinaps: The promotion rules for cinaps would only offer one file at a time no
  matter how many promotions were available. Now we offer all the promotions at
  once (ocaml/dune#7901, @rgrinberg)

- Do not re-run OCaml syntax files on every iteration of the watch mode. This
  is too memory consuming. (ocaml/dune#7894, fix ocaml/dune#6900, @rgrinberg)

- Remove some compatibility code for old version of dune that generated
  `.merlin` files. Now dune will never remove `.merlin` files automatically
  (ocaml/dune#7562)

- Add `dune show env` command and make `dune printenv` an alias of it. (ocaml/dune#7985,
  @Alizter)

- Add additional metadata to the traces provided by `--trace-file` whenever
  `--trace-extended` is passed (ocaml/dune#7778, @rleshchinskiy)

- Extensions used in `(dialect)` can contain periods (e.g., `cppo.ml`). (ocaml/dune#7782,
  fixes ocaml/dune#7777, @nojb)

- Allow `(include_subdirs qualified)` to be used when libraries define a
  `(modules ...)` field (ocaml/dune#7797, fixes ocaml/dune#7597, @anmonteiro)

- `$ dune describe` is now a command group, so arguments to subcommands must be
  passed after subcommand itself. (ocaml/dune#7919, @Alizter)

- The `interface` and `implementation` fields of a `(dialect)` are now optional
  (ocaml/dune#7757, @gpetiot)

- Add commands `dune show targets` and `dune show aliases` that display all the
  available targets and aliases in a given directory respectively. (ocaml/dune#7770,
  grants ocaml/dune#265, @Alizter)

- Allow multiple globs in library's `(stdlib (internal_modules ..))`
  (@anmonteiro, ocaml/dune#7878)

- Attach melange rules to the default alias (ocaml/dune#7926, @haochenx)

- In opam constraints, reject `(and)` and `(or)` with no arguments at parse
  time (ocaml/dune#7730, @emillon)

- Compute digests and manage sandboxes in background threads (ocaml/dune#7947,
  @rgrinberg)

- Add `(build_if)` to the `(test)` stanza. When it evaluates to false, the
  executable is not built. (ocaml/dune#7899, fixes ocaml/dune#6938, @emillon)

- Add necessary parentheses in generated opam constraints (ocaml/dune#7682, fixes ocaml/dune#3431,
  @Lucccyo)
emillon added a commit to emillon/opam-repository that referenced this issue Jun 28, 2023
CHANGES:

- Validate file extension for `$ dune ocaml top-module`. (ocaml/dune#8005, fixes ocaml/dune#8004, @3Rafal)

- Include the time it takes to read/write state files when `--trace-file` is
  enabled (ocaml/dune#7960, @rgrinberg)

- Add `dune show` command group which is an alias of `dune describe`. (ocaml/dune#7946,
  @Alizter)

- Include source tree scans in the traces produced by `--trace-file` (ocaml/dune#7937,
  @rgrinberg)

- Cinaps: The promotion rules for cinaps would only offer one file at a time no
  matter how many promotions were available. Now we offer all the promotions at
  once (ocaml/dune#7901, @rgrinberg)

- Do not re-run OCaml syntax files on every iteration of the watch mode. This
  is too memory consuming. (ocaml/dune#7894, fix ocaml/dune#6900, @rgrinberg)

- Add `--all` option to `dune rpc status` to show all Dune RPC servers running.
  (ocaml/dune#8011, fix ocaml/dune#7902, @Alizter)

- Remove some compatibility code for old version of dune that generated
  `.merlin` files. Now dune will never remove `.merlin` files automatically
  (ocaml/dune#7562)

- Add `dune show env` command and make `dune printenv` an alias of it. (ocaml/dune#7985,
  @Alizter)

- Add additional metadata to the traces provided by `--trace-file` whenever
  `--trace-extended` is passed (ocaml/dune#7778, @rleshchinskiy)

- Extensions used in `(dialect)` can contain periods (e.g., `cppo.ml`). (ocaml/dune#7782,
  fixes ocaml/dune#7777, @nojb)

- Allow `(include_subdirs qualified)` to be used when libraries define a
  `(modules ...)` field (ocaml/dune#7797, fixes ocaml/dune#7597, @anmonteiro)

- `$ dune describe` is now a command group, so arguments to subcommands must be
  passed after subcommand itself. (ocaml/dune#7919, @Alizter)

- The `interface` and `implementation` fields of a `(dialect)` are now optional
  (ocaml/dune#7757, @gpetiot)

- Add commands `dune show targets` and `dune show aliases` that display all the
  available targets and aliases in a given directory respectively. (ocaml/dune#7770,
  grants ocaml/dune#265, @Alizter)

- Allow multiple globs in library's `(stdlib (internal_modules ..))`
  (@anmonteiro, ocaml/dune#7878)

- Attach melange rules to the default alias (ocaml/dune#7926, @haochenx)

- In opam constraints, reject `(and)` and `(or)` with no arguments at parse
  time (ocaml/dune#7730, @emillon)

- Compute digests and manage sandboxes in background threads (ocaml/dune#7947,
  @rgrinberg)

- Add `(build_if)` to the `(test)` stanza. When it evaluates to false, the
  executable is not built. (ocaml/dune#7899, fixes ocaml/dune#6938, @emillon)

- Add necessary parentheses in generated opam constraints (ocaml/dune#7682, fixes ocaml/dune#3431,
  @Lucccyo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants