SHARE
TWEET

Untitled

a guest Feb 16th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 404e5c0253274c4c01845d856233e447bf0411de Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rapha=C3=ABl=20Proust?= <raphlalou@gmail.com>
  3. Date: Tue, 30 Jul 2013 22:03:39 +0100
  4. Subject: [PATCH] Print only filename when only filename is available
  5.  
  6. Previous behaviour was to print a dummy line number (line 1).
  7.  
  8. Prints
  9.     File "error.ml":
  10. instead of
  11.     File "error.ml", line 1:
  12. ---
  13.  parsing/location.ml  | 22 +++++++++++++---------
  14.  parsing/location.mli |  6 +++---
  15.  parsing/syntaxerr.ml | 12 ++++++------
  16.  tools/ocamldep.ml    |  2 +-
  17.  tools/ocamlprof.ml   |  2 +-
  18.  toplevel/toploop.mli |  4 ++--
  19.  typing/includemod.ml |  2 +-
  20.  7 files changed, 27 insertions(+), 23 deletions(-)
  21.  
  22. diff --git a/parsing/location.ml b/parsing/location.ml
  23. index d3f89f4..87fb3a4 100644
  24. --- a/parsing/location.ml
  25. +++ b/parsing/location.ml
  26. @@ -233,7 +233,7 @@ let get_pos_info pos =
  27.    (pos.pos_fname, pos.pos_lnum, pos.pos_cnum - pos.pos_bol)
  28.  ;;
  29.  
  30. -let print_loc ppf loc =
  31. +let print_loc ?no_line ppf loc =
  32.    let (file, line, startchar) = get_pos_info loc.loc_start in
  33.    let endchar = loc.loc_end.pos_cnum - loc.loc_start.pos_cnum + startchar in
  34.    if file = "//toplevel//" then begin
  35. @@ -241,24 +241,28 @@ let print_loc ppf loc =
  36.        fprintf ppf "Characters %i-%i"
  37.                loc.loc_start.pos_cnum loc.loc_end.pos_cnum
  38.    end else begin
  39. -    fprintf ppf "%s%a%s%i" msg_file print_filename file msg_line line;
  40. -    if startchar >= 0 then
  41. -      fprintf ppf "%s%i%s%i" msg_chars startchar msg_to endchar
  42. +    match no_line with
  43. +    | None ->
  44. +      fprintf ppf "%s%a%s%i" msg_file print_filename file msg_line line;
  45. +      if startchar >= 0 then
  46. +        fprintf ppf "%s%i%s%i" msg_chars startchar msg_to endchar
  47. +    | Some () ->
  48. +      fprintf ppf "%s%a\"" msg_file print_filename file;
  49.    end
  50.  ;;
  51.  
  52. -let print ppf loc =
  53. +let print ?no_line ppf loc =
  54.    if loc.loc_start.pos_fname = "//toplevel//"
  55.    && highlight_locations ppf loc none then ()
  56. -  else fprintf ppf "%a%s@." print_loc loc msg_colon
  57. +  else fprintf ppf "%a%s@." (print_loc ?no_line) loc msg_colon
  58.  ;;
  59.  
  60. -let print_error ppf loc =
  61. -  print ppf loc;
  62. +let print_error ?no_line ppf loc =
  63. +  print ?no_line ppf loc;
  64.    fprintf ppf "Error: ";
  65.  ;;
  66.  
  67. -let print_error_cur_file ppf = print_error ppf (in_file !input_name);;
  68. +let print_error_cur_file ppf = print_error ~no_line:() ppf (in_file !input_name);;
  69.  
  70.  let print_warning loc ppf w =
  71.    if Warnings.is_active w then begin
  72. diff --git a/parsing/location.mli b/parsing/location.mli
  73. index bae9090..6e67cf9 100644
  74. --- a/parsing/location.mli
  75. +++ b/parsing/location.mli
  76. @@ -48,8 +48,8 @@ val input_name: string ref
  77.  val input_lexbuf: Lexing.lexbuf option ref
  78.  
  79.  val get_pos_info: Lexing.position -> string * int * int (* file, line, char *)
  80. -val print_loc: formatter -> t -> unit
  81. -val print_error: formatter -> t -> unit
  82. +val print_loc: ?no_line:unit -> formatter -> t -> unit
  83. +val print_error: ?no_line:unit -> formatter -> t -> unit
  84.  val print_error_cur_file: formatter -> unit
  85.  val print_warning: t -> formatter -> Warnings.t -> unit
  86.  val prerr_warning: t -> Warnings.t -> unit
  87. @@ -66,7 +66,7 @@ type 'a loc = {
  88.  val mknoloc : 'a -> 'a loc
  89.  val mkloc : 'a -> t -> 'a loc
  90.  
  91. -val print: formatter -> t -> unit
  92. +val print: ?no_line:unit -> formatter -> t -> unit
  93.  val print_filename: formatter -> string -> unit
  94.  
  95.  val show_filename: string -> string
  96. diff --git a/parsing/syntaxerr.ml b/parsing/syntaxerr.ml
  97. index 5c17a99..836a43d 100644
  98. --- a/parsing/syntaxerr.ml
  99. +++ b/parsing/syntaxerr.ml
  100. @@ -34,26 +34,26 @@ let report_error ppf = function
  101.                     the highlighted '%s' might be unmatched" closing opening
  102.        else begin
  103.          fprintf ppf "%aSyntax error: '%s' expected@."
  104. -          Location.print_error closing_loc closing;
  105. +          (Location.print_error ?no_line:None) closing_loc closing;
  106.          fprintf ppf "%aThis '%s' might be unmatched"
  107. -          Location.print_error opening_loc opening
  108. +          (Location.print_error ?no_line:None) opening_loc opening
  109.        end
  110.    | Expecting (loc, nonterm) ->
  111.        fprintf ppf
  112.          "%a@[Syntax error: %s expected.@]"
  113. -        Location.print_error loc nonterm
  114. +        (Location.print_error ?no_line:None) loc nonterm
  115.    | Applicative_path loc ->
  116.        fprintf ppf
  117.          "%aSyntax error: applicative paths of the form F(X).t \
  118.           are not supported when the option -no-app-func is set."
  119. -        Location.print_error loc
  120. +        (Location.print_error ?no_line:None) loc
  121.    | Variable_in_scope (loc, var) ->
  122.        fprintf ppf
  123.          "%a@[In this scoped type, variable '%s@ \
  124.           is reserved for the local type %s.@]"
  125. -        Location.print_error loc var var
  126. +        (Location.print_error ?no_line:None) loc var var
  127.    | Other loc ->
  128. -      fprintf ppf "%aSyntax error" Location.print_error loc
  129. +      fprintf ppf "%aSyntax error" (Location.print_error ?no_line:None) loc
  130.  
  131.  
  132.  let location_of_error = function
  133. diff --git a/tools/ocamldep.ml b/tools/ocamldep.ml
  134. index 1742df3..9371375 100644
  135. --- a/tools/ocamldep.ml
  136. +++ b/tools/ocamldep.ml
  137. @@ -210,7 +210,7 @@ let report_err source_file exn =
  138.    match exn with
  139.      | Lexer.Error(err, range) ->
  140.          Format.fprintf Format.err_formatter "@[%a%a@]@."
  141. -        Location.print_error range  Lexer.report_error err
  142. +        (Location.print_error ?no_line:None) range  Lexer.report_error err
  143.      | Syntaxerr.Error err ->
  144.          Format.fprintf Format.err_formatter "@[%a@]@."
  145.          Syntaxerr.report_error err
  146. diff --git a/tools/ocamlprof.ml b/tools/ocamlprof.ml
  147. index 72c9900..9d5a01e 100644
  148. --- a/tools/ocamlprof.ml
  149. +++ b/tools/ocamlprof.ml
  150. @@ -482,7 +482,7 @@ let main () =
  151.      let report_error ppf = function
  152.      | Lexer.Error(err, range) ->
  153.          fprintf ppf "@[%a%a@]@."
  154. -        Location.print_error range  Lexer.report_error err
  155. +        (Location.print_error ?no_line:None) range  Lexer.report_error err
  156.      | Syntaxerr.Error err ->
  157.          fprintf ppf "@[%a@]@."
  158.          Syntaxerr.report_error err
  159. diff --git a/toplevel/toploop.mli b/toplevel/toploop.mli
  160. index da607de..0670c7e 100644
  161. --- a/toplevel/toploop.mli
  162. +++ b/toplevel/toploop.mli
  163. @@ -79,8 +79,8 @@ val max_printer_steps: int ref
  164.  
  165.  val parse_toplevel_phrase : (Lexing.lexbuf -> Parsetree.toplevel_phrase) ref
  166.  val parse_use_file : (Lexing.lexbuf -> Parsetree.toplevel_phrase list) ref
  167. -val print_location : formatter -> Location.t -> unit
  168. -val print_error : formatter -> Location.t -> unit
  169. +val print_location : ?no_line:unit -> formatter -> Location.t -> unit
  170. +val print_error : ?no_line:unit -> formatter -> Location.t -> unit
  171.  val print_warning : Location.t -> formatter -> Warnings.t -> unit
  172.  val input_name : string ref
  173.  
  174. diff --git a/typing/includemod.ml b/typing/includemod.ml
  175. index 086dfe4..9934143 100644
  176. --- a/typing/includemod.ml
  177. +++ b/typing/includemod.ml
  178. @@ -359,7 +359,7 @@ open Printtyp
  179.  let show_loc msg ppf loc =
  180.    let pos = loc.Location.loc_start in
  181.    if List.mem pos.Lexing.pos_fname [""; "_none_"; "//toplevel//"] then ()
  182. -  else fprintf ppf "@\n@[<2>%a:@ %s@]" Location.print_loc loc msg
  183. +  else fprintf ppf "@\n@[<2>%a:@ %s@]" (Location.print_loc ?no_line:None) loc msg
  184.  
  185.  let show_locs ppf (loc1, loc2) =
  186.    show_loc "Expected declaration" ppf loc2;
  187. --
  188. 1.8.3.4
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top