From b34394509aefdcfc011f5f2d711fb96f2c3d67b3 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 21 Aug 2018 18:59:47 +0300 Subject: [PATCH] Start moving dune related sexp stuff to Dsexp Signed-off-by: Rudi Grinberg --- src/build_system.ml | 2 +- src/config.ml | 2 +- src/dune_file.ml | 46 ++++++++++++++++++++++---------------------- src/jbuild_load.ml | 2 +- src/stdune/dsexp.ml | 6 ++++++ src/stdune/io.ml | 5 ----- src/stdune/io.mli | 4 ---- src/stdune/stdune.ml | 1 + src/workspace.ml | 2 +- 9 files changed, 34 insertions(+), 36 deletions(-) create mode 100644 src/stdune/dsexp.ml diff --git a/src/build_system.ml b/src/build_system.ml index f1e59f63..6854dcdb 100644 --- a/src/build_system.ml +++ b/src/build_system.ml @@ -1276,7 +1276,7 @@ let update_universe t = let n = if Path.exists universe_file then Sexp.Of_sexp.(parse int) Univ_map.empty - (Io.Sexp.load ~mode:Single universe_file) + 1 + (Dsexp.Io.load ~mode:Single universe_file) + 1 else 0 in diff --git a/src/config.ml b/src/config.ml index 94bb43a3..d1914454 100644 --- a/src/config.ml +++ b/src/config.ml @@ -135,7 +135,7 @@ let load_config_file p = | None -> parse (enter t) (Univ_map.singleton (Syntax.key syntax) (0, 0)) - (Io.Sexp.load p ~mode:Many_as_one ~lexer:Sexp.Lexer.jbuild_token) + (Dsexp.Io.load p ~mode:Many_as_one ~lexer:Sexp.Lexer.jbuild_token) | Some first_line -> parse_contents lb first_line ~f:(fun _lang -> t)) diff --git a/src/dune_file.ml b/src/dune_file.ml index 951d6222..0b2b76ac 100644 --- a/src/dune_file.ml +++ b/src/dune_file.ml @@ -53,7 +53,7 @@ module Lib_name : sig val validate : (Loc.t * result) -> wrapped:bool -> t - val t : (Loc.t * result) Sexp.Of_sexp.t + val t : (Loc.t * result) Dsexp.Of_sexp.t end = struct type t = string @@ -350,11 +350,11 @@ module Bindings = struct ~dune:(dune elem) let sexp_of_t sexp_of_a bindings = - Sexp.List ( + Dsexp.List ( List.map bindings ~f:(function | Unnamed a -> sexp_of_a a | Named (name, bindings) -> - Sexp.List (Sexp.atom (":" ^ name) :: List.map ~f:sexp_of_a bindings)) + Dsexp.List (Dsexp.atom (":" ^ name) :: List.map ~f:sexp_of_a bindings)) ) end @@ -393,28 +393,28 @@ module Dep_conf = struct ~then_:t ~else_:(String_with_vars.t >>| fun x -> File x) - open Sexp + open Dsexp let sexp_of_t = function | File t -> - List [ Sexp.unsafe_atom_of_string "file" + List [ Dsexp.unsafe_atom_of_string "file" ; String_with_vars.sexp_of_t t ] | Alias t -> - List [ Sexp.unsafe_atom_of_string "alias" + List [ Dsexp.unsafe_atom_of_string "alias" ; String_with_vars.sexp_of_t t ] | Alias_rec t -> - List [ Sexp.unsafe_atom_of_string "alias_rec" + List [ Dsexp.unsafe_atom_of_string "alias_rec" ; String_with_vars.sexp_of_t t ] | Glob_files t -> - List [ Sexp.unsafe_atom_of_string "glob_files" + List [ Dsexp.unsafe_atom_of_string "glob_files" ; String_with_vars.sexp_of_t t ] | Source_tree t -> - List [ Sexp.unsafe_atom_of_string "files_recursively_in" + List [ Dsexp.unsafe_atom_of_string "files_recursively_in" ; String_with_vars.sexp_of_t t ] | Package t -> - List [ Sexp.unsafe_atom_of_string "package" + List [ Dsexp.unsafe_atom_of_string "package" ; String_with_vars.sexp_of_t t] | Universe -> - Sexp.unsafe_atom_of_string "universe" + Dsexp.unsafe_atom_of_string "universe" end module Preprocess = struct @@ -474,7 +474,7 @@ module Blang = struct Compare (op, x, y)))) in let t = - fix begin fun (t : String_with_vars.t Blang.t Sexp.Of_sexp.t) -> + fix begin fun (t : String_with_vars.t Blang.t Dsexp.Of_sexp.t) -> if_list ~then_:( [ "or", repeat t >>| (fun x -> Or x) @@ -803,7 +803,7 @@ module Sub_system_info = struct val name : Sub_system_name.t val loc : t -> Loc.t val syntax : Syntax.t - val parse : t Sexp.Of_sexp.t + val parse : t Dsexp.Of_sexp.t end let all = Sub_system_name.Table.create ~default_value:None @@ -862,7 +862,7 @@ module Mode_conf = struct Format.pp_print_string fmt (to_string t) let sexp_of_t t = - Sexp.unsafe_atom_of_string (to_string t) + Dsexp.unsafe_atom_of_string (to_string t) module Set = struct include Set.Make(T) @@ -1038,7 +1038,7 @@ module Install_conf = struct | List (_, [Atom (_, A src); Atom (_, A "as"); Atom (_, A dst)]) -> junk >>> return { src; dst = Some dst } | sexp -> - of_sexp_error (Sexp.Ast.loc sexp) + of_sexp_error (Dsexp.Ast.loc sexp) "invalid format, or ( as ) expected" type t = @@ -1105,7 +1105,7 @@ module Executables = struct ] let simple = - Sexp.Of_sexp.enum simple_representations + Dsexp.Of_sexp.enum simple_representations let t = if_list @@ -1121,7 +1121,7 @@ module Executables = struct compare candidate link_mode = Eq in match List.find ~f:is_ok simple_representations with - | Some (s, _) -> Some (Sexp.unsafe_atom_of_string s) + | Some (s, _) -> Some (Dsexp.unsafe_atom_of_string s) | None -> None let sexp_of_t link_mode = @@ -1129,7 +1129,7 @@ module Executables = struct | Some s -> s | None -> let { mode; kind } = link_mode in - Sexp.To_sexp.pair Mode_conf.sexp_of_t Binary_kind.sexp_of_t (mode, kind) + Dsexp.To_sexp.pair Mode_conf.sexp_of_t Binary_kind.sexp_of_t (mode, kind) module Set = struct include Set.Make(T) @@ -1240,7 +1240,7 @@ module Executables = struct match Link_mode.Set.best_install_mode t.modes with | None when has_public_name -> let mode_to_string mode = - " - " ^ Sexp.to_string ~syntax:Dune (Link_mode.sexp_of_t mode) in + " - " ^ Dsexp.to_string ~syntax:Dune (Link_mode.sexp_of_t mode) in let mode_strings = List.map ~f:mode_to_string Link_mode.installable_modes in Loc.fail buildable.loc @@ -1472,7 +1472,7 @@ module Rule = struct | Some Action -> short_form end | sexp -> - of_sexp_errorf (Sexp.Ast.loc sexp) + of_sexp_errorf (Dsexp.Ast.loc sexp) "S-expression of the form ( ...) expected" let t = @@ -1756,7 +1756,7 @@ module Stanzas = struct type Stanza.t += Include of Loc.t * string - type constructors = (string * Stanza.t list Sexp.Of_sexp.t) list + type constructors = (string * Stanza.t list Dsexp.Of_sexp.t) list let stanzas : constructors = [ "library", @@ -1837,7 +1837,7 @@ module Stanzas = struct exception Include_loop of Path.t * (Loc.t * Path.t) list let rec parse stanza_parser ~lexer ~current_file ~include_stack sexps = - List.concat_map sexps ~f:(Sexp.Of_sexp.parse stanza_parser Univ_map.empty) + List.concat_map sexps ~f:(Dsexp.Of_sexp.parse stanza_parser Univ_map.empty) |> List.concat_map ~f:(function | Include (loc, fn) -> let include_stack = (loc, current_file) :: include_stack in @@ -1848,7 +1848,7 @@ module Stanzas = struct (Path.to_string_maybe_quoted current_file); if List.exists include_stack ~f:(fun (_, f) -> Path.equal f current_file) then raise (Include_loop (current_file, include_stack)); - let sexps = Io.Sexp.load ~lexer current_file ~mode:Many in + let sexps = Dsexp.Io.load ~lexer current_file ~mode:Many in parse stanza_parser sexps ~lexer ~current_file ~include_stack | stanza -> [stanza]) diff --git a/src/jbuild_load.ml b/src/jbuild_load.ml index dee5569a..fceb1d51 100644 --- a/src/jbuild_load.ml +++ b/src/jbuild_load.ml @@ -207,7 +207,7 @@ end Did you forgot to call [Jbuild_plugin.V*.send]?" (Path.to_string file); Fiber.return - (Io.Sexp.load generated_jbuild ~mode:Many + (Dsexp.Io.load generated_jbuild ~mode:Many ~lexer:(File_tree.Dune_file.Kind.lexer kind) |> Jbuild.parse ~dir ~file ~project ~kind ~ignore_promoted_rules)) >>| fun dynamic -> diff --git a/src/stdune/dsexp.ml b/src/stdune/dsexp.ml new file mode 100644 index 00000000..32c1d729 --- /dev/null +++ b/src/stdune/dsexp.ml @@ -0,0 +1,6 @@ +include Sexp + +module Io = struct + let load ?lexer path ~mode = + Io.with_lexbuf_from_file path ~f:(Usexp.Parser.parse ~mode ?lexer) +end diff --git a/src/stdune/io.ml b/src/stdune/io.ml index 1a5bcb34..1450b273 100644 --- a/src/stdune/io.ml +++ b/src/stdune/io.ml @@ -123,8 +123,3 @@ let compare_text_files fn1 fn2 = let s1 = read_file_and_normalize_eols fn1 in let s2 = read_file_and_normalize_eols fn2 in String.compare s1 s2 - -module Sexp = struct - let load ?lexer path ~mode = - with_lexbuf_from_file path ~f:(Usexp.Parser.parse ~mode ?lexer) -end diff --git a/src/stdune/io.mli b/src/stdune/io.mli index 31ca8143..9c767804 100644 --- a/src/stdune/io.mli +++ b/src/stdune/io.mli @@ -27,7 +27,3 @@ val copy_channels : in_channel -> out_channel -> unit val copy_file : ?chmod:(int -> int) -> src:Path.t -> dst:Path.t -> unit -> unit val read_all : in_channel -> string - -module Sexp : sig - val load : ?lexer:Usexp.Lexer.t -> Path.t -> mode:'a Sexp.Parser.Mode.t -> 'a -end diff --git a/src/stdune/stdune.ml b/src/stdune/stdune.ml index bf38fdb9..215a374c 100644 --- a/src/stdune/stdune.ml +++ b/src/stdune/stdune.ml @@ -20,6 +20,7 @@ module String = String module Char = Char module Bool = Bool module Sexp = Sexp +module Dsexp = Dsexp module Path = Path module Fmt = Fmt module Interned = Interned diff --git a/src/workspace.ml b/src/workspace.ml index aec4cf56..455d58bf 100644 --- a/src/workspace.ml +++ b/src/workspace.ml @@ -224,7 +224,7 @@ let load ?x ?profile p = parse_contents lb first_line ~f:(fun _lang -> t ?x ?profile ())) | Jbuilder -> let sexp = - Io.Sexp.load p ~mode:Many_as_one ~lexer:Sexp.Lexer.jbuild_token + Dsexp.Io.load p ~mode:Many_as_one ~lexer:Sexp.Lexer.jbuild_token in parse (enter (t ?x ?profile ()))