Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 404e5c0253274c4c01845d856233e447bf0411de Mon Sep 17 00:00:00 2001
- From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= <raphlalou@gmail.com>
- Date: Tue, 30 Jul 2013 22:03:39 +0100
- Subject: [PATCH] Print only filename when only filename is available
- Previous behaviour was to print a dummy line number (line 1).
- Prints
- File "error.ml":
- instead of
- File "error.ml", line 1:
- ---
- parsing/location.ml | 22 +++++++++++++---------
- parsing/location.mli | 6 +++---
- parsing/syntaxerr.ml | 12 ++++++------
- tools/ocamldep.ml | 2 +-
- tools/ocamlprof.ml | 2 +-
- toplevel/toploop.mli | 4 ++--
- typing/includemod.ml | 2 +-
- 7 files changed, 27 insertions(+), 23 deletions(-)
- diff --git a/parsing/location.ml b/parsing/location.ml
- index d3f89f4..87fb3a4 100644
- --- a/parsing/location.ml
- +++ b/parsing/location.ml
- @@ -233,7 +233,7 @@ let get_pos_info pos =
- (pos.pos_fname, pos.pos_lnum, pos.pos_cnum - pos.pos_bol)
- ;;
- -let print_loc ppf loc =
- +let print_loc ?no_line ppf loc =
- let (file, line, startchar) = get_pos_info loc.loc_start in
- let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in
- if file = "//toplevel//" then begin
- @@ -241,24 +241,28 @@ let print_loc ppf loc =
- fprintf ppf "Characters %i-%i"
- loc.loc_start.pos_cnum loc.loc_end.pos_cnum
- end else begin
- - fprintf ppf "%s%a%s%i" msg_file print_filename file msg_line line;
- - if startchar >= 0 then
- - fprintf ppf "%s%i%s%i" msg_chars startchar msg_to endchar
- + match no_line with
- + | None ->
- + fprintf ppf "%s%a%s%i" msg_file print_filename file msg_line line;
- + if startchar >= 0 then
- + fprintf ppf "%s%i%s%i" msg_chars startchar msg_to endchar
- + | Some () ->
- + fprintf ppf "%s%a\"" msg_file print_filename file;
- end
- ;;
- -let print ppf loc =
- +let print ?no_line ppf loc =
- if loc.loc_start.pos_fname = "//toplevel//"
- && highlight_locations ppf loc none then ()
- - else fprintf ppf "%a%s@." print_loc loc msg_colon
- + else fprintf ppf "%a%s@." (print_loc ?no_line) loc msg_colon
- ;;
- -let print_error ppf loc =
- - print ppf loc;
- +let print_error ?no_line ppf loc =
- + print ?no_line ppf loc;
- fprintf ppf "Error: ";
- ;;
- -let print_error_cur_file ppf = print_error ppf (in_file !input_name);;
- +let print_error_cur_file ppf = print_error ~no_line:() ppf (in_file !input_name);;
- let print_warning loc ppf w =
- if Warnings.is_active w then begin
- diff --git a/parsing/location.mli b/parsing/location.mli
- index bae9090..6e67cf9 100644
- --- a/parsing/location.mli
- +++ b/parsing/location.mli
- @@ -48,8 +48,8 @@ val input_name: string ref
- val input_lexbuf: Lexing.lexbuf option ref
- val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
- -val print_loc: formatter -> t -> unit
- -val print_error: formatter -> t -> unit
- +val print_loc: ?no_line:unit -> formatter -> t -> unit
- +val print_error: ?no_line:unit -> formatter -> t -> unit
- val print_error_cur_file: formatter -> unit
- val print_warning: t -> formatter -> Warnings.t -> unit
- val prerr_warning: t -> Warnings.t -> unit
- @@ -66,7 +66,7 @@ type 'a loc = {
- val mknoloc : 'a -> 'a loc
- val mkloc : 'a -> t -> 'a loc
- -val print: formatter -> t -> unit
- +val print: ?no_line:unit -> formatter -> t -> unit
- val print_filename: formatter -> string -> unit
- val show_filename: string -> string
- diff --git a/parsing/syntaxerr.ml b/parsing/syntaxerr.ml
- index 5c17a99..836a43d 100644
- --- a/parsing/syntaxerr.ml
- +++ b/parsing/syntaxerr.ml
- @@ -34,26 +34,26 @@ let report_error ppf = function
- the highlighted '%s' might be unmatched" closing opening
- else begin
- fprintf ppf "%aSyntax error: '%s' expected@."
- - Location.print_error closing_loc closing;
- + (Location.print_error ?no_line:None) closing_loc closing;
- fprintf ppf "%aThis '%s' might be unmatched"
- - Location.print_error opening_loc opening
- + (Location.print_error ?no_line:None) opening_loc opening
- end
- | Expecting (loc, nonterm) ->
- fprintf ppf
- "%a@[Syntax error: %s expected.@]"
- - Location.print_error loc nonterm
- + (Location.print_error ?no_line:None) loc nonterm
- | Applicative_path loc ->
- fprintf ppf
- "%aSyntax error: applicative paths of the form F(X).t \
- are not supported when the option -no-app-func is set."
- - Location.print_error loc
- + (Location.print_error ?no_line:None) loc
- | Variable_in_scope (loc, var) ->
- fprintf ppf
- "%a@[In this scoped type, variable '%s@ \
- is reserved for the local type %s.@]"
- - Location.print_error loc var var
- + (Location.print_error ?no_line:None) loc var var
- | Other loc ->
- - fprintf ppf "%aSyntax error" Location.print_error loc
- + fprintf ppf "%aSyntax error" (Location.print_error ?no_line:None) loc
- let location_of_error = function
- diff --git a/tools/ocamldep.ml b/tools/ocamldep.ml
- index 1742df3..9371375 100644
- --- a/tools/ocamldep.ml
- +++ b/tools/ocamldep.ml
- @@ -210,7 +210,7 @@ let report_err source_file exn =
- match exn with
- | Lexer.Error(err, range) ->
- Format.fprintf Format.err_formatter "@[%a%a@]@."
- - Location.print_error range Lexer.report_error err
- + (Location.print_error ?no_line:None) range Lexer.report_error err
- | Syntaxerr.Error err ->
- Format.fprintf Format.err_formatter "@[%a@]@."
- Syntaxerr.report_error err
- diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml
- index 72c9900..9d5a01e 100644
- --- a/tools/ocamlprof.ml
- +++ b/tools/ocamlprof.ml
- @@ -482,7 +482,7 @@ let main () =
- let report_error ppf = function
- | Lexer.Error(err, range) ->
- fprintf ppf "@[%a%a@]@."
- - Location.print_error range Lexer.report_error err
- + (Location.print_error ?no_line:None) range Lexer.report_error err
- | Syntaxerr.Error err ->
- fprintf ppf "@[%a@]@."
- Syntaxerr.report_error err
- diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli
- index da607de..0670c7e 100644
- --- a/toplevel/toploop.mli
- +++ b/toplevel/toploop.mli
- @@ -79,8 +79,8 @@ val max_printer_steps: int ref
- val parse_toplevel_phrase : (Lexing.lexbuf -> Parsetree.toplevel_phrase) ref
- val parse_use_file : (Lexing.lexbuf -> Parsetree.toplevel_phrase list) ref
- -val print_location : formatter -> Location.t -> unit
- -val print_error : formatter -> Location.t -> unit
- +val print_location : ?no_line:unit -> formatter -> Location.t -> unit
- +val print_error : ?no_line:unit -> formatter -> Location.t -> unit
- val print_warning : Location.t -> formatter -> Warnings.t -> unit
- val input_name : string ref
- diff --git a/typing/includemod.ml b/typing/includemod.ml
- index 086dfe4..9934143 100644
- --- a/typing/includemod.ml
- +++ b/typing/includemod.ml
- @@ -359,7 +359,7 @@ open Printtyp
- let show_loc msg ppf loc =
- let pos = loc.Location.loc_start in
- if List.mem pos.Lexing.pos_fname [""; "_none_"; "//toplevel//"] then ()
- - else fprintf ppf "@\n@[<2>%a:@ %s@]" Location.print_loc loc msg
- + else fprintf ppf "@\n@[<2>%a:@ %s@]" (Location.print_loc ?no_line:None) loc msg
- let show_locs ppf (loc1, loc2) =
- show_loc "Expected declaration" ppf loc2;
- --
- 1.8.3.4
Add Comment
Please, Sign In to add comment