Commit 85c95a54 authored by Bruno Guillaume's avatar Bruno Guillaume

Catch error when lexicon file is not found

parent 0ea80b41
......@@ -492,8 +492,8 @@ module Rule = struct
let build_lex loc = function
| Ast.File filename ->
if Filename.is_relative filename
then Lexicon.load (Filename.concat (Global.get_dir ()) filename)
else Lexicon.load filename
then Lexicon.load loc (Filename.concat (Global.get_dir ()) filename)
else Lexicon.load loc filename
| Ast.Final (line_list) -> Lexicon.build loc line_list
......
......@@ -154,10 +154,12 @@ module Lexicon = struct
let loc = Loc.set_line linenum_h loc in
Error.build ~loc "[Lexicon.build] the field name \"%s\" is used twice" v
let load file =
let lines = File.read_ln file in
let loc = Loc.file file in
build loc lines
let load loc file =
try
let lines = File.read_ln file in
let loc = Loc.file file in
build loc lines
with Sys_error _ -> Error.build ~loc "[Lexicon.load] unable to load file %s" file
let reduce sub_list lexicon =
let sorted_sub_list = List.sort Pervasives.compare sub_list in
......
......@@ -84,7 +84,7 @@ module Lexicon : sig
(** [load file] build a lexicon from a file.
The file should contain same data than the ones in the build function
in separate lines, each line used tabulation as separator *)
val load: string -> t
val load: Loc.t -> string -> t
(** [reduce headers lexicon] build a smaller lexicon restricted to a subset of columns (defined in [headers]) *)
val reduce: string list -> t -> t
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment