-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2404 from nojb/dialects
Add support for "dialects"
- Loading branch information
Showing
48 changed files
with
668 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.. _dialects-main: | ||
|
||
******** | ||
Dialects | ||
******** | ||
|
||
A dialect is an alternative frontend to OCaml (such as ReasonML). It is | ||
described by a pair of file extensions, one corresponding to interfaces and one | ||
to implementations. | ||
|
||
The extensions are unique among all dialects of a given project, so that a given | ||
extension can be mapped back to the corresponding dialect. | ||
|
||
A dialect can use the standard OCaml syntax or it can specify an action to | ||
convert from a custom syntax to a binary OCaml abstract syntax tree. | ||
|
||
Similarly, a dialect can specify a custom formatter to implement the ``@fmt`` | ||
alias, see :ref:`formatting-main`. | ||
|
||
When not using a custom syntax or formatting action, a dialect is nothing but a | ||
way to specify custom file extensions for OCaml code. | ||
|
||
Defining a dialect | ||
================== | ||
|
||
A dialect can be defined by adding the following to the ``dune-project`` file: | ||
|
||
.. code:: | ||
(dialect | ||
(name <name>) | ||
(implementation | ||
(extension <string>) | ||
<optional fields>) | ||
(interface | ||
(extension <string>) | ||
<optional fields>)) | ||
``<name>`` is the name of the dialect being defined. It must be unique in a | ||
given project. | ||
|
||
``(extension <string>)`` specifies the file extension used for this dialect, for | ||
interfaces and implementations. The extension string must not contain any dots, | ||
and be unique in a given project. | ||
|
||
``<optional fields>`` are: | ||
|
||
- ``(preprocess <action>)`` is the action to run to produce a valid OCaml | ||
abstract syntax tree. It is expected to read the file given in the variable | ||
named ``input-file`` and output a *binary* abstract syntax tree on its | ||
standard output. See :ref:`preprocessing-actions` for more information. | ||
|
||
If the field is not present, it is assumed that the corresponding source code | ||
is already valid OCaml code and can be passed to the OCaml compiler as-is. | ||
|
||
|
||
- ``(format <action>)`` is the action to run to format source code for this | ||
dialect. The action is expected to read the file given in the variable named | ||
``input-file`` and output the formatted source code on its standard | ||
output. For more information. See :ref:`formatting-main` for more information. | ||
|
||
If the field is not present, then if ``(preprocess <action>)`` is not present | ||
(so that the dialect consists of valid OCaml code), then by default the | ||
dialect will be formatted as any other OCaml code. Otherwise no special | ||
formatting will be done. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ Welcome to dune's documentation! | |
jsoo | ||
opam | ||
variants | ||
dialects | ||
formatting | ||
coq | ||
faq | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
open! Stdune | ||
|
||
module Make | ||
(Src : Action_intf.Ast) | ||
(Dst : Action_intf.Ast) | ||
= struct | ||
let map_one_step f (t : Src.t) ~dir ~f_program ~f_string ~f_path : Dst.t = | ||
match t with | ||
| Run (prog, args) -> | ||
Run (f_program ~dir prog, List.map args ~f:(f_string ~dir)) | ||
| Chdir (fn, t) -> | ||
Chdir (f_path ~dir fn, f t ~dir:fn ~f_program ~f_string ~f_path) | ||
| Setenv (var, value, t) -> | ||
Setenv (f_string ~dir var, f_string ~dir value, f t ~dir ~f_program ~f_string ~f_path) | ||
| Redirect (outputs, fn, t) -> | ||
Redirect (outputs, f_path ~dir fn, f t ~dir ~f_program ~f_string ~f_path) | ||
| Ignore (outputs, t) -> | ||
Ignore (outputs, f t ~dir ~f_program ~f_string ~f_path) | ||
| Progn l -> Progn (List.map l ~f:(fun t -> f t ~dir ~f_program ~f_string ~f_path)) | ||
| Echo xs -> Echo (List.map xs ~f:(f_string ~dir)) | ||
| Cat x -> Cat (f_path ~dir x) | ||
| Copy (x, y) -> Copy (f_path ~dir x, f_path ~dir y) | ||
| Symlink (x, y) -> | ||
Symlink (f_path ~dir x, f_path ~dir y) | ||
| Copy_and_add_line_directive (x, y) -> | ||
Copy_and_add_line_directive (f_path ~dir x, f_path ~dir y) | ||
| System x -> System (f_string ~dir x) | ||
| Bash x -> Bash (f_string ~dir x) | ||
| Write_file (x, y) -> Write_file (f_path ~dir x, f_string ~dir y) | ||
| Rename (x, y) -> Rename (f_path ~dir x, f_path ~dir y) | ||
| Remove_tree x -> Remove_tree (f_path ~dir x) | ||
| Mkdir x -> Mkdir (f_path ~dir x) | ||
| Digest_files x -> Digest_files (List.map x ~f:(f_path ~dir)) | ||
| Diff ({ file1; file2 ; _ } as diff) -> | ||
Diff { diff with | ||
file1 = f_path ~dir file1 | ||
; file2 = f_path ~dir file2 | ||
} | ||
| Merge_files_into (sources, extras, target) -> | ||
Merge_files_into | ||
(List.map sources ~f:(f_path ~dir), | ||
List.map extras ~f:(f_string ~dir), | ||
f_path ~dir target) | ||
|
||
let rec map t ~dir ~f_program ~f_string ~f_path = | ||
map_one_step map t ~dir ~f_program ~f_string ~f_path | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.