Commit c024d98a authored by bguillaum's avatar bguillaum

improve error messages

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6791 7838e531-6607-4d57-9587-6c381814729c
parent a5015c10
......@@ -107,9 +107,8 @@ module G_fs = struct
let get_atom = List_.sort_assoc
let to_gr t = List_.to_string G_feature.to_string ", " t
let to_string t = List_.to_string G_feature.to_string "\\n" t
let to_string t = List_.to_string G_feature.to_string "," t
let to_gr = to_string
let build ast_fs =
let unsorted = List.map (fun feat -> G_feature.build feat) ast_fs in
......
......@@ -423,13 +423,10 @@ module G_graph = struct
(function
| Feat (node_gid, feat_name) ->
let node = Gid_map.find node_gid graph.map in
(try
match G_fs.get_atom feat_name (G_node.get_fs node) with
| Some atom -> atom
| None -> Log.fcritical "[BUG] [Graph.update_feat] Feature not atomic"
with Not_found ->
Log.fcritical "[RUN] [Graph.update_feat] no feature \"%s\" in node \"%s\""
feat_name (G_node.to_string node))
(match G_fs.get_atom feat_name (G_node.get_fs node) with
| Some atom -> atom
| None -> Error.run ?loc "Some feature (named \"%s\") is not defined" feat_name
)
| String s -> s
) item_list in
let new_feature_value = List_.to_string (fun s->s) "" strings_to_concat in
......
......@@ -21,7 +21,7 @@ module G_node = struct
let empty = { fs = G_fs.empty; pos = None; next = Massoc.empty }
let to_string t =
Printf.sprintf "[fs=%s ; next=%s]"
Printf.sprintf " fs=[%s]\n next=%s\n"
(G_fs.to_string t.fs)
(Massoc.to_string G_edge.to_string t.next)
......
......@@ -13,9 +13,9 @@ open HTMLer
exception Parsing_err of string
exception File_dont_exists of string
exception Parsing_err of string
exception Build of string * (string * int) option
exception Run of string * (string * int) option
exception Bug of string * (string * int) option
......@@ -39,7 +39,10 @@ let load_grs ?doc_output_dir file =
| Some dir -> HTMLer.proceed dir grs_ast);
Grs.build grs_ast
with
| Grew_parser.Parse_error msg -> raise (Parsing_err msg)
| Grew_parser.Parse_error (msg,Some l) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg))
| Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc))
| Error.Bug (msg, loc) -> raise (Bug (msg,loc))
| exc -> raise (Bug (sprintf "[Libgrew.load_grs] UNCATCHED EXCEPTION: %s" (Printexc.to_string exc), None))
......@@ -55,7 +58,10 @@ let load_gr file =
let gr_ast = Grew_parser.gr_of_file file in
Instance.build gr_ast
with
| Grew_parser.Parse_error msg -> raise (Parsing_err msg)
| Grew_parser.Parse_error (msg,Some l) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg))
| Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc))
| Error.Bug (msg, loc) -> raise (Bug (msg,loc))
| exc -> raise (Bug (sprintf "[Libgrew.load_gr] UNCATCHED EXCEPTION: %s" (Printexc.to_string exc), None))
......@@ -69,7 +75,10 @@ let load_conll file =
let lines = File.read file in
Instance.of_conll (List.map Conll.parse lines)
with
| Grew_parser.Parse_error msg -> raise (Parsing_err msg)
| Grew_parser.Parse_error (msg,Some l) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg))
| Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc))
| Error.Bug (msg, loc) -> raise (Bug (msg,loc))
| exc -> raise (Bug (sprintf "[Libgrew.load_conll] UNCATCHED EXCEPTION: %s" (Printexc.to_string exc), None))
......
......@@ -3,20 +3,25 @@ open Grew_ast
module Grew_parser = struct
exception Parse_error of string
(* message and line number *)
exception Parse_error of (string * int option)
(* ------------------------------------------------------------------------------------------*)
(** general fucntion to handle parse errors *)
let parse_handle fct lexbuf =
let parse_handle fct lexbuf =
try fct lexbuf with
| Lexer.Error msg -> raise (Parse_error msg)
| Lexer.Error msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Lexing error:"^msg, Some cp))
| Gr_grs_parser.Error ->
let cp = lexbuf.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d : %s\n%!" cp.Lexing.pos_lnum (Lexing.lexeme lexbuf)))
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Syntax error:"^(Lexing.lexeme lexbuf), Some cp))
| Failure msg ->
let cp = lexbuf.Lexing.lex_curr_p in
raise (Parse_error (Printf.sprintf "Syntax error\nLine %d\n%s\n%!" cp.Lexing.pos_lnum msg))
| err -> raise (Parse_error (Printexc.to_string err))
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Failure:"^msg, Some cp))
| err ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Unexpected error:"^(Printexc.to_string err), Some cp))
(* ------------------------------------------------------------------------------------------*)
(**
......@@ -35,7 +40,7 @@ let parse_handle fct lexbuf =
let grs = parse_handle (Gr_grs_parser.grs_with_include Lexer.global) lexbuf in
close_in in_ch;
grs
with Sys_error msg-> raise (Parse_error msg)
with Sys_error msg-> raise (Parse_error (msg, None))
(* ------------------------------------------------------------------------------------------*)
let parse_file_to_module_list loc file =
......@@ -46,7 +51,7 @@ let parse_handle fct lexbuf =
let module_list = parse_handle (Gr_grs_parser.included Lexer.global) lexbuf in
close_in in_ch;
module_list
with Sys_error msg-> raise (Parse_error msg)
with Sys_error msg-> raise (Parse_error (msg, None))
(* ------------------------------------------------------------------------------------------*)
(**
......@@ -91,5 +96,5 @@ let parse_handle fct lexbuf =
let gr = parse_handle (Gr_grs_parser.gr Lexer.global) lexbuf in
close_in in_ch;
gr
with Sys_error msg-> raise (Parse_error msg)
with Sys_error msg-> raise (Parse_error (msg, None))
end
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