Move Sexp to stdune

In the process, change all the Loc.fail's to Of_sexp exceptions
This commit is contained in:
Rudi Grinberg 2018-04-24 01:47:54 +07:00
parent 77af5b3a88
commit 10c01ac741
8 changed files with 21 additions and 11 deletions

View File

@ -1,3 +1,5 @@
open Stdune
type t = type t =
| Exe | Exe
| Object | Object

View File

@ -1,5 +1,7 @@
(** Linking modes for binaries *) (** Linking modes for binaries *)
open Stdune
type t = type t =
| Exe | Exe
| Object | Object

View File

@ -1,5 +1,7 @@
(** Opam install file *) (** Opam install file *)
open Stdune
module Section : sig module Section : sig
type t = type t =
| Lib | Lib

View File

@ -1,4 +1,6 @@
(** Dune files that are installed on the system *) (** Dune files that are installed on the system *)
open Stdune
val load : fname:string -> Jbuild.Sub_system_info.t Sub_system_name.Map.t val load : fname:string -> Jbuild.Sub_system_info.t Sub_system_name.Map.t
val gen : (Syntax.Version.t * Sexp.t) Sub_system_name.Map.t -> Sexp.t val gen : (Syntax.Version.t * Sexp.t) Sub_system_name.Map.t -> Sexp.t

View File

@ -1,7 +1,4 @@
open Stdune include Usexp
include (Usexp : module type of struct include Usexp end
with module Loc := Usexp.Loc)
let buf_len = 65_536 let buf_len = 65_536
@ -137,6 +134,9 @@ module Of_sexp = struct
let of_sexp_error ?hint sexp str = raise (Of_sexp (Ast.loc sexp, str, hint)) let of_sexp_error ?hint sexp str = raise (Of_sexp (Ast.loc sexp, str, hint))
let of_sexp_errorf ?hint sexp fmt = Printf.ksprintf (of_sexp_error ?hint sexp) fmt let of_sexp_errorf ?hint sexp fmt = Printf.ksprintf (of_sexp_error ?hint sexp) fmt
let of_sexp_errorf_loc loc fmt =
Printf.ksprintf (fun s -> raise (Of_sexp (loc, s, None))) fmt
let raw x = x let raw x = x
let unit = function let unit = function
@ -262,14 +262,15 @@ module Of_sexp = struct
match match
Name_map.values parsed Name_map.values parsed
|> List.map ~f:(fun f -> Ast.loc f.entry) |> List.map ~f:(fun f -> Ast.loc f.entry)
|> List.sort ~compare:(fun a b -> compare a.Loc.start.pos_cnum b.start.pos_cnum) |> List.sort ~compare:(fun a b ->
Int.compare a.Loc.start.pos_cnum b.start.pos_cnum)
with with
| [] -> state.loc | [] -> state.loc
| first :: l -> | first :: l ->
let last = List.fold_left l ~init:first ~f:(fun _ x -> x) in let last = List.fold_left l ~init:first ~f:(fun _ x -> x) in
{ first with stop = last.stop } { first with stop = last.stop }
in in
Loc.fail loc "%s" msg of_sexp_errorf_loc loc "%s" msg
module Short_syntax = struct module Short_syntax = struct
type 'a t = type 'a t =
@ -279,8 +280,7 @@ module Of_sexp = struct
let parse t entry name = let parse t entry name =
match t with match t with
| Not_allowed -> | Not_allowed -> of_sexp_errorf entry "field %s needs a value" name
Loc.fail (Ast.loc entry) "field %s needs a value" name
| This x -> x | This x -> x
| Located f -> f (Ast.loc entry) | Located f -> f (Ast.loc entry)
end end
@ -297,7 +297,7 @@ module Of_sexp = struct
match default with match default with
| Some v -> (v, add_known name state) | Some v -> (v, add_known name state)
| None -> | None ->
Loc.fail state.loc "field %s missing" name of_sexp_errorf_loc state.loc "field %s missing" name
let field_o name ?(short=Short_syntax.Not_allowed) value_of_sexp state = let field_o name ?(short=Short_syntax.Not_allowed) value_of_sexp state =
match Name_map.find state.unparsed name with match Name_map.find state.unparsed name with

View File

@ -1,5 +1,3 @@
open Stdune
include module type of struct include Usexp end with module Loc := Usexp.Loc include module type of struct include Usexp end with module Loc := Usexp.Loc
val load : fname:string -> mode:'a Parser.Mode.t -> 'a val load : fname:string -> mode:'a Parser.Mode.t -> 'a
@ -59,6 +57,8 @@ module To_sexp : sig
val record_fields : field list t val record_fields : field list t
end with type sexp := t end with type sexp := t
module Loc = Usexp.Loc
module Of_sexp : sig module Of_sexp : sig
type ast = Ast.t = type ast = Ast.t =
| Atom of Loc.t * Atom.t | Atom of Loc.t * Atom.t

View File

@ -18,6 +18,7 @@ module Set = Set
module Staged = Staged module Staged = Staged
module String = String module String = String
module Char = Char module Char = Char
module Sexp = Sexp
external reraise : exn -> _ = "%reraise" external reraise : exn -> _ = "%reraise"

View File

@ -1,3 +1,4 @@
open Stdune
(** Versioned syntaxes *) (** Versioned syntaxes *)
module Version : sig module Version : sig