-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary support for dune-project files
- Loading branch information
Jeremie Dimino
committed
Apr 24, 2018
1 parent
07d3605
commit bb3e241
Showing
7 changed files
with
148 additions
and
10 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
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,69 @@ | ||
open Import | ||
open Sexp.Of_sexp | ||
|
||
type t = | ||
{ name : string | ||
} | ||
|
||
let filename = "dune-project" | ||
|
||
type lang = | ||
| Dune_0_1 | ||
|
||
let lang = | ||
let version ver = | ||
match string ver with | ||
| "0.1" -> Dune_0_1 | ||
| _ -> | ||
of_sexp_error ver "unsupported version of the dune language" | ||
in | ||
let name = | ||
enum | ||
[ ("dune", ()) ] | ||
in | ||
sum | ||
[ cstr "lang" (name @> version @> nil) (fun () v -> v) ] | ||
|
||
module Acc = struct | ||
type t = | ||
{ name : string option | ||
} | ||
|
||
let init = | ||
{ name = None } | ||
end | ||
|
||
let load ~dir = | ||
let fname = Path.to_string (Path.relative dir filename) in | ||
let sexps = Sexp.load ~fname ~mode:Many in | ||
let langs, sexps = | ||
List.partition_map sexps ~f:(function | ||
| List (loc, Atom (_, A "lang") :: _) as sexp -> | ||
Left (lang sexp, loc) | ||
| sexp -> Right sexp) | ||
in | ||
let _lang = | ||
match langs with | ||
| [] -> | ||
Loc.fail (Loc.in_file fname) | ||
"language not specified, you need to add (lang dune 0.1)" | ||
| [(v, _)] -> v | ||
| _ :: (_, loc) :: _ -> | ||
Loc.fail loc "language specified too many times" | ||
in | ||
let acc = | ||
List.fold_left sexps ~init:Acc.init ~f:(fun (acc : Acc.t) sexp -> | ||
sum | ||
[ cstr "lang" nil acc | ||
; cstr_loc "name" (string @> nil) (fun loc name -> | ||
match acc.name with | ||
| None -> { Acc.name = Some name } | ||
| Some _ -> Loc.fail loc "name specified too many times") | ||
] | ||
sexp) | ||
in | ||
{ name = | ||
match acc.name with | ||
| Some s -> s | ||
| None -> "_" ^ String.concat ~sep:"_" (Path.explode_exn dir) | ||
} |
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,10 @@ | ||
(** dune-project files *) | ||
|
||
type t = | ||
{ name : string | ||
} | ||
|
||
val load : dir:Path.t -> t | ||
|
||
(** "dune-project" *) | ||
val filename : string |
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