Commit 392bef9b authored by bguillaum's avatar bguillaum

improve syntax error localization

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/semagramme/libcaml-grew/trunk@8890 7838e531-6607-4d57-9587-6c381814729c
parent b62ed354
......@@ -596,11 +596,11 @@ end (* module Timeout *)
(* ================================================================================ *)
module Global = struct
let current_file = ref "Not a file"
let current_line = ref 0
let current_line = ref 1
let label_flag = ref false
let init file =
current_file := file;
current_line := 0;
current_line := 1;
label_flag := false;
end
......@@ -146,7 +146,7 @@ and label_parser target = parse
| "]-" { Global.label_flag := false; RTL_EDGE_RIGHT }
| "]=>" { Global.label_flag := false; ARROW_RIGHT }
| _ as c { raise (Error (sprintf "At line %d: unexpected character '%c'" (lexbuf.Lexing.lex_start_p.Lexing.pos_lnum) c)) }
| _ as c { raise (Error (sprintf "unexpected character '%c'" c)) }
and standard target = parse
| [' ' '\t'] { global lexbuf }
......@@ -234,4 +234,4 @@ and standard target = parse
| '"' { Buffer.clear buff; string_lex global lexbuf }
| eof { EOF }
| _ as c { raise (Error (sprintf "At line %d: unexpected character '%c'" (lexbuf.Lexing.lex_start_p.Lexing.pos_lnum) c)) }
| _ as c { raise (Error (sprintf "unexpected character '%c'" c)) }
......@@ -21,19 +21,19 @@ module Loader = struct
let parse_handle file fct lexbuf =
try fct lexbuf with
| Grew_lexer.Error msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
let cp = !Global.current_line in
raise (Error ("Lexing error:"^msg, Some (Loc.file_line file cp)))
| Grew_parser.Error ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
let cp = !Global.current_line in
raise (Error ("Syntax error:"^(Lexing.lexeme lexbuf), Some (Loc.file_line file cp)))
| Failure msg ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
let cp = !Global.current_line in
raise (Error ("Failure:"^msg, Some (Loc.file_line file cp)))
| Error.Build (msg,_) ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
let cp = !Global.current_line in
raise (Error ("Syntax error:"^msg, Some (Loc.file_line file cp)))
| err ->
let cp = lexbuf.Lexing.lex_curr_p.Lexing.pos_lnum in
let cp = !Global.current_line in
raise (Error ("Unexpected error:"^(Printexc.to_string err), Some (Loc.file_line file cp)))
(* ------------------------------------------------------------------------------------------*)
......
......@@ -24,7 +24,7 @@ type graph_item =
| Graph_node of Ast.node
| Graph_edge of Ast.edge
let get_loc () = Loc.file_line !Global.current_file (!Global.current_line+1)
let get_loc () = Loc.file_line !Global.current_file !Global.current_line
let localize t = (t,get_loc ())
%}
......
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