ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.64k stars 409 forks source link

Support multiple extensions in (dialect) patterns #7777

Closed aantron closed 1 year ago

aantron commented 1 year ago

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 https://github.com/aantron/dream/pull/228#issuecomment-1557242558.

nojb commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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