Commit ba0b3dce authored by bguillaum's avatar bguillaum
Browse files

* Fix bug in dot output

* Improve error localisation
* progress counter in corpus mode

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@6808 7838e531-6607-4d57-9587-6c381814729c
parent f1f01cfe
...@@ -43,9 +43,7 @@ module G_feature = struct ...@@ -43,9 +43,7 @@ module G_feature = struct
(name, atom) (name, atom)
| _ -> Error.build "Illegal feature declaration in Graph (must be '=' and atomic)" | _ -> Error.build "Illegal feature declaration in Graph (must be '=' and atomic)"
let to_string (feat_name, value) = sprintf "%s=\"%s\"" feat_name value let to_string (feat_name, value) = sprintf "%s=%s" feat_name value
let to_dep (feat_name, value) = sprintf "%s=%s" feat_name value
end end
(* ==================================================================================================== *) (* ==================================================================================================== *)
...@@ -152,7 +150,7 @@ module G_fs = struct ...@@ -152,7 +150,7 @@ module G_fs = struct
let (main_opt, sub) = get_main ?main_feat t in let (main_opt, sub) = get_main ?main_feat t in
sprintf " word=\"%s\"; subword=\"%s\"; " sprintf " word=\"%s\"; subword=\"%s\"; "
(match main_opt with Some atom -> atom | None -> "") (match main_opt with Some atom -> atom | None -> "")
(List_.to_string G_feature.to_dep "#" sub) (List_.to_string G_feature.to_string "#" sub)
end end
(* ==================================================================================================== *) (* ==================================================================================================== *)
......
...@@ -514,11 +514,11 @@ module Lex_par = struct ...@@ -514,11 +514,11 @@ module Lex_par = struct
| [args] when nb_c = 0 -> | [args] when nb_c = 0 ->
(match Str.split (Str.regexp "#") args with (match Str.split (Str.regexp "#") args with
| l when List.length l = nb_p -> (l,[]) | l when List.length l = nb_p -> (l,[])
| _ -> Error.bug "Illegal param line in file '%s' line '%s' hasn't %d args" file line nb_p) | _ -> Error.bug "Illegal param line in file \"%s\", the line \"%s\" doesn't contain %d args" file line nb_p)
| [args; values] -> | [args; values] ->
(match (Str.split (Str.regexp "#") args, Str.split (Str.regexp "#") values) with (match (Str.split (Str.regexp "#") args, Str.split (Str.regexp "#") values) with
| (lp,lc) when List.length lp = nb_p && List.length lc = nb_c -> (lp,lc) | (lp,lc) when List.length lp = nb_p && List.length lc = nb_c -> (lp,lc)
| _ -> Error.bug "Illegal param line in file '%s' line '%s' hasn't %d args and %d values" file line nb_p nb_c) | _ -> Error.bug "Illegal param line in file \"%s\", the line \"%s\" doesn't contain %d args and %d values" file line nb_p nb_c)
| _ -> Error.bug "Illegal param line in file '%s' line '%s'" file line | _ -> Error.bug "Illegal param line in file '%s' line '%s'" file line
) lines ) lines
) in ) in
......
...@@ -39,8 +39,8 @@ let load_grs ?doc_output_dir file = ...@@ -39,8 +39,8 @@ let load_grs ?doc_output_dir file =
| Some dir -> HTMLer.proceed dir grs_ast); | Some dir -> HTMLer.proceed dir grs_ast);
Grs.build grs_ast Grs.build grs_ast
with with
| Grew_parser.Parse_error (msg,Some l) -> | Grew_parser.Parse_error (msg,Some (sub_file,l)) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg)) raise (Parsing_err (sprintf "[file:%s, line:%d] %s" sub_file l msg))
| Grew_parser.Parse_error (msg,None) -> | Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg)) raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc)) | Error.Build (msg,loc) -> raise (Build (msg,loc))
...@@ -58,8 +58,8 @@ let load_gr file = ...@@ -58,8 +58,8 @@ let load_gr file =
let gr_ast = Grew_parser.gr_of_file file in let gr_ast = Grew_parser.gr_of_file file in
Instance.build gr_ast Instance.build gr_ast
with with
| Grew_parser.Parse_error (msg,Some l) -> | Grew_parser.Parse_error (msg,Some (sub_file,l)) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg)) raise (Parsing_err (sprintf "[file:%s, line:%d] %s" sub_file l msg))
| Grew_parser.Parse_error (msg,None) -> | Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg)) raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc)) | Error.Build (msg,loc) -> raise (Build (msg,loc))
...@@ -75,8 +75,8 @@ let load_conll file = ...@@ -75,8 +75,8 @@ let load_conll file =
let lines = File.read file in let lines = File.read file in
Instance.of_conll (List.map Conll.parse lines) Instance.of_conll (List.map Conll.parse lines)
with with
| Grew_parser.Parse_error (msg,Some l) -> | Grew_parser.Parse_error (msg,Some (sub_file,l)) ->
raise (Parsing_err (sprintf "[file:%s, line:%d] %s" file l msg)) raise (Parsing_err (sprintf "[file:%s, line:%d] %s" sub_file l msg))
| Grew_parser.Parse_error (msg,None) -> | Grew_parser.Parse_error (msg,None) ->
raise (Parsing_err (sprintf "[file:%s] %s" file msg)) raise (Parsing_err (sprintf "[file:%s] %s" file msg))
| Error.Build (msg,loc) -> raise (Build (msg,loc)) | Error.Build (msg,loc) -> raise (Build (msg,loc))
......
...@@ -4,24 +4,24 @@ open Grew_ast ...@@ -4,24 +4,24 @@ open Grew_ast
module Grew_parser = struct module Grew_parser = struct
(* message and line number *) (* message and line number *)
exception Parse_error of (string * int option) exception Parse_error of (string * Loc.t option)
(* ------------------------------------------------------------------------------------------*) (* ------------------------------------------------------------------------------------------*)
(** general fucntion to handle parse errors *) (** general fucntion to handle parse errors *)
let parse_handle fct lexbuf = let parse_handle file fct lexbuf =
try fct lexbuf with try fct lexbuf with
| Lexer.Error msg -> | Lexer.Error msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Lexing error:"^msg, Some cp)) raise (Parse_error ("Lexing error:"^msg, Some (file,cp)))
| Gr_grs_parser.Error -> | Gr_grs_parser.Error ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Syntax error:"^(Lexing.lexeme lexbuf), Some cp)) raise (Parse_error ("Syntax error:"^(Lexing.lexeme lexbuf), Some (file,cp)))
| Failure msg -> | Failure msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Failure:"^msg, Some cp)) raise (Parse_error ("Failure:"^msg, Some (file,cp)))
| err -> | err ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
raise (Parse_error ("Unexpected error:"^(Printexc.to_string err), Some cp)) raise (Parse_error ("Unexpected error:"^(Printexc.to_string err), Some (file,cp)))
(* ------------------------------------------------------------------------------------------*) (* ------------------------------------------------------------------------------------------*)
(** (**
...@@ -29,7 +29,7 @@ let parse_handle fct lexbuf = ...@@ -29,7 +29,7 @@ let parse_handle fct lexbuf =
@param str the string to parse @param str the string to parse
@return a syntactic tree of the parsed file @return a syntactic tree of the parsed file
*) *)
let parse_string_to_grs str = parse_handle (Gr_grs_parser.grs Lexer.global) (Lexing.from_string str) let parse_string_to_grs str = parse_handle "" (Gr_grs_parser.grs Lexer.global) (Lexing.from_string str)
(* ------------------------------------------------------------------------------------------*) (* ------------------------------------------------------------------------------------------*)
let parse_file_to_grs_with_includes file = let parse_file_to_grs_with_includes file =
...@@ -37,10 +37,11 @@ let parse_handle fct lexbuf = ...@@ -37,10 +37,11 @@ let parse_handle fct lexbuf =
Parser_global.init file; Parser_global.init file;
let in_ch = open_in file in let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in let lexbuf = Lexing.from_channel in_ch in
let grs = parse_handle (Gr_grs_parser.grs_with_include Lexer.global) lexbuf in let grs = parse_handle file (Gr_grs_parser.grs_with_include Lexer.global) lexbuf in
close_in in_ch; close_in in_ch;
grs grs
with Sys_error msg-> raise (Parse_error (msg, None)) with Sys_error msg->
raise (Parse_error (msg, None))
(* ------------------------------------------------------------------------------------------*) (* ------------------------------------------------------------------------------------------*)
let parse_file_to_module_list loc file = let parse_file_to_module_list loc file =
...@@ -48,7 +49,7 @@ let parse_handle fct lexbuf = ...@@ -48,7 +49,7 @@ let parse_handle fct lexbuf =
Parser_global.init file; Parser_global.init file;
let in_ch = open_in file in let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in let lexbuf = Lexing.from_channel in_ch in
let module_list = parse_handle (Gr_grs_parser.included Lexer.global) lexbuf in let module_list = parse_handle file (Gr_grs_parser.included Lexer.global) lexbuf in
close_in in_ch; close_in in_ch;
module_list module_list
with Sys_error msg-> raise (Parse_error (msg, None)) with Sys_error msg-> raise (Parse_error (msg, None))
...@@ -84,7 +85,7 @@ let parse_handle fct lexbuf = ...@@ -84,7 +85,7 @@ let parse_handle fct lexbuf =
@param str the string to parse @param str the string to parse
@return a syntactic tree of the parsed file @return a syntactic tree of the parsed file
*) *)
let parse_string_to_gr str = parse_handle (Gr_grs_parser.gr Lexer.global) (Lexing.from_string str) let parse_string_to_gr str = parse_handle "" (Gr_grs_parser.gr Lexer.global) (Lexing.from_string str)
(* ------------------------------------------------------------------------------------------*) (* ------------------------------------------------------------------------------------------*)
...@@ -93,7 +94,7 @@ let parse_handle fct lexbuf = ...@@ -93,7 +94,7 @@ let parse_handle fct lexbuf =
Parser_global.init file; Parser_global.init file;
let in_ch = open_in file in let in_ch = open_in file in
let lexbuf = Lexing.from_channel in_ch in let lexbuf = Lexing.from_channel in_ch in
let gr = parse_handle (Gr_grs_parser.gr Lexer.global) lexbuf in let gr = parse_handle file (Gr_grs_parser.gr Lexer.global) lexbuf in
close_in in_ch; close_in in_ch;
gr gr
with Sys_error msg-> raise (Parse_error (msg, None)) with Sys_error msg-> raise (Parse_error (msg, None))
......
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