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

Formatting of OCaml and Dune #158

Merged
merged 4 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,19 +276,19 @@ jobs:

- name: Install Nix dependencies
run: |
nix develop .github/nix#${{ matrix.package }} --command true
nix develop .#${{ matrix.package }} --command true

- name: Build in development Shell
run: |
nix develop .github/nix#${{ matrix.package }} --command make
nix develop .#${{ matrix.package }} --command make

- name: Run tests in development Shell
run: |
nix develop .github/nix#${{ matrix.package }} --command make check
nix develop .#${{ matrix.package }} --command make check

- name: Build with Nix
run: |
nix build .github/nix#${{ matrix.package }} --print-build-logs
nix build .#${{ matrix.package }} --print-build-logs

nix-flake-checks:
runs-on: ubuntu-latest
Expand All @@ -305,4 +305,4 @@ jobs:
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}

- name: Run flake checks
run: nix flake check .github/nix --print-build-logs
run: nix flake check . --print-build-logs
6 changes: 3 additions & 3 deletions .github/nix/with-nixpkgs.nix → .nix/with-nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
in {
packages.with-nixpkgs = pkgs.stdenv.mkDerivation {
name = "morbig";
## NOTE: The use of `../..` matters because the path is taken as relative to
## the current file, and therefore to `.github/nix/`.
src = ../..;
## NOTE: The use of `./..` matters because the path is taken as relative to
## the current file, and therefore to `.nix/`.
src = ./..;

nativeBuildInputs = with opkgs; [
## Basic ones, always necessary
Expand Down
6 changes: 3 additions & 3 deletions .github/nix/with-opam-nix.nix → .nix/with-opam-nix.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ ... }: {
perSystem = { inputs', pkgs, ... }:
## NOTE: The use of `../..` matters because the path is taken as relative to
## the current file, and therefore to `.github/nix/`.
## NOTE: The use of `./..` matters because the path is taken as relative to
## the current file, and therefore to `.nix/`.
let
scope =
inputs'.opam-nix.lib.buildOpamProject { inherit pkgs; } "morbig" ../.. {
inputs'.opam-nix.lib.buildOpamProject { inherit pkgs; } "morbig" ./.. {
ocaml-base-compiler = "*";
};
in { packages.with-opam-nix = scope.morbig // { inherit scope; }; };
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@

(generate_opam_files true)
(using menhir 2.0)
(formatting (enabled_for dune))
6 changes: 3 additions & 3 deletions .github/nix/flake.lock → flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions .github/nix/flake.nix → flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
systems = [ "x86_64-linux" ];

imports = [
./with-nixpkgs.nix
./with-opam-nix.nix
.nix/with-nixpkgs.nix
.nix/with-opam-nix.nix
inputs.pre-commit-hooks.flakeModule
];

Expand All @@ -38,6 +38,25 @@
ocp-indent.enable = true;
nixfmt.enable = true;
deadnix.enable = true;

## NOTE: The version of the `dune-fmt` hook in `pre-commit-hooks.nix`
## forgets to bring OCaml in the environment. In the meantime, we use
## our own; will change back to `dune-fmt.enable = true` later.
tmp-dune-fmt = {
enable = true;
name = "dune-fmt";
description = "Runs Dune's formatters on the code tree.";
entry = let
dune-fmt = pkgs.writeShellApplication {
name = "dune-fmt";
text = ''
export PATH=${pkgs.ocaml}/bin:$PATH
exec ${pkgs.dune_3}/bin/dune fmt "$@"
'';
};
in "${dune-fmt}/bin/dune-fmt";
pass_filenames = false;
};
};
};

Expand Down
26 changes: 13 additions & 13 deletions src/API.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,41 @@
(** {3 Parsing shell scripts} *)

(** [parse_file filename] performs the syntactic analysis of
[filename] and returns a concrete syntax tree if [filename] content
is syntactically correct.
[filename] and returns a concrete syntax tree if [filename] content
is syntactically correct.

Raises exceptions from {!Errors}. *)
Raises exceptions from {!Errors}. *)
val parse_file: string -> CST.program

(** [parse_string filename content] is similar to [parse_file] except
the script source code is provided as a string. *)
the script source code is provided as a string. *)
val parse_string: string -> string -> CST.program

(** {3 Serialization of CST} *)

(** [load_binary_cst cin] retrieves a serialized CST from
input_channel [cin]. *)
input_channel [cin]. *)
val load_binary_cst: in_channel -> CST.program

(** [save_binary_cst cout cst] stores a serialized [cst] in [cout]. *)
val save_binary_cst: out_channel -> CST.program -> unit

(** [load_json_cst cin] retrieves a CST in JSON format from
input_channel [cin]. *)
input_channel [cin]. *)
val load_json_cst: in_channel -> CST.program

(** [save_json_cst cout cst] stores a [cst] using JSON format in
[cout]. *)
[cout]. *)
val save_json_cst: out_channel -> CST.program -> unit

(** [save_dot_cst cout cst] stores a [cst] using DOT format in
[cout]. *)
[cout]. *)
val save_dot_cst: out_channel -> CST.program -> unit

(** {3 CST helpers} *)

(** [on_located f] applies [f] on a located value, preserving its
location. *)
location. *)
val on_located : ('a -> 'b) -> 'a CST.located -> 'b

(** [start_of_position p] returns the beginning of a position [p]. *)
Expand All @@ -58,16 +58,16 @@ val start_of_position : CST.position -> Lexing.position
val end_of_position : CST.position -> Lexing.position

(** [filename_of_position p] returns the filename of a position
[p]. *)
[p]. *)
val filename_of_position : CST.position -> string

(** [string_of_lexing_position p] returns a human-readable
representation of the lexing position [p], using a format
recognized by Emacs, and other decent editors. *)
representation of the lexing position [p], using a format
recognized by Emacs, and other decent editors. *)
val string_of_lexing_position : Lexing.position -> string

(** {3 POSIX related helpers} *)

(** [remove_quotes s] yields a copy of string [s], with all quotes
removed as described in the POSIX specification.*)
removed as described in the POSIX specification.*)
val remove_quotes : string -> string
2 changes: 1 addition & 1 deletion src/CST.mli
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ and filename =
(** The two IoHere constructors have two arguments. The second argument is
the word holding the contents of the here document, which does not figure
in the grammar.
*)
*)
and io_here =
| IoHere_DLess_HereEnd of here_end' * word' ref
| IoHere_DLessDash_HereEnd of here_end' * word' ref
Expand Down
Loading