Simplify error handling
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
01163776ad
commit
9005ca8998
|
@ -43,20 +43,18 @@ let of_sexp =
|
||||||
let load fname =
|
let load fname =
|
||||||
Io.with_lexbuf_from_file fname ~f:(fun lexbuf ->
|
Io.with_lexbuf_from_file fname ~f:(fun lexbuf ->
|
||||||
let (version_loc, version) =
|
let (version_loc, version) =
|
||||||
let bad_dune_file = "Unable to read (dune x.y ..) line file" in
|
|
||||||
let rec loop = function
|
let rec loop = function
|
||||||
| [_; _; _] as a -> List.rev a
|
| [_; _; _] as a -> List.rev a
|
||||||
| acc ->
|
| acc ->
|
||||||
begin match (Sexp.Lexer.token lexbuf : Sexp.Lexer.Token.t) with
|
begin match (Sexp.Lexer.token lexbuf : Sexp.Lexer.Token.t) with
|
||||||
| Eof ->
|
| Eof -> List.rev acc
|
||||||
Loc.fail (Loc.in_file (Path.to_string fname)) "%s" bad_dune_file
|
|
||||||
| t -> loop (t :: acc)
|
| t -> loop (t :: acc)
|
||||||
end
|
end
|
||||||
in
|
in
|
||||||
let loc = Sexp.Loc.of_lexbuf lexbuf in
|
let loc = Sexp.Loc.of_lexbuf lexbuf in
|
||||||
match loop [] with
|
match loop [] with
|
||||||
| [Lparen; Atom (A "dune"); Atom s] -> (loc, Sexp.Atom.to_string s)
|
| [Lparen; Atom (A "dune"); Atom s] -> (loc, Sexp.Atom.to_string s)
|
||||||
| _ -> Loc.fail loc "%s" bad_dune_file
|
| _ -> Loc.fail loc "Unable to read (dune x.y ..) line file"
|
||||||
in
|
in
|
||||||
let (lexer, syntax) =
|
let (lexer, syntax) =
|
||||||
match version with
|
match version with
|
||||||
|
|
Loading…
Reference in New Issue