Skip to content

Commit

Permalink
Move warning management to Location
Browse files Browse the repository at this point in the history
  • Loading branch information
let-def committed Feb 20, 2013
1 parent ec90438 commit 29f9954
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
7 changes: 2 additions & 5 deletions chunk.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ type t = item History.t

exception Malformed_module of Location.t
exception Invalid_chunk
exception Warning of Location.t * string

let wrap_warnings = List.rev_map (fun (l,s) -> Warning (l,s))

let eof_lexer _ = Chunk_parser.EOF
let fail_lexer _ = failwith "lexer ended"
Expand Down Expand Up @@ -130,8 +127,8 @@ let sync outlines chunks =
| Some ({ Outline.kind ; Outline.tokens },outlines') ->
let chunk =
match Location.catch_warnings (fun () -> sync_step kind tokens chunks) with
| warnings, Misc.Inr item -> wrap_warnings warnings, item
| warnings, Misc.Inl exn -> exn :: wrap_warnings warnings, None
| warnings, Misc.Inr item -> warnings, item
| warnings, Misc.Inl exn -> exn :: warnings, None
in
let chunks' = History.(insert (Sync.at outlines', chunk) chunks) in
aux outlines' chunks'
Expand Down
1 change: 0 additions & 1 deletion chunk.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ and t = item History.t

exception Malformed_module of Location.t
exception Invalid_chunk
exception Warning of Location.t * string

val sync_step : Outline_utils.kind -> Outline.token list -> t -> item_desc option
val sync : Outline.t -> t -> t
Expand Down
2 changes: 1 addition & 1 deletion error_report.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ let strict_to_json = function
Some (format ~valid:true ~where:"parser" ~loc (to_string ()))
| Outline.Parse_error loc ->
Some (format ~valid:true ~where:"parser" ~loc "Parse error")
| Chunk.Warning (loc, msg) ->
| Location.Warning (loc, msg) ->
Some (format ~valid:true ~where:"warning" ~loc msg)
| Chunk.Malformed_module loc ->
Some (format ~valid:true ~where:"warning" ~loc "Malformed module")
Expand Down
6 changes: 4 additions & 2 deletions parsing/location.ml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,9 @@ let print_warning loc ppf w =
end
;;

let warnings : (t * string) list ref option ref = ref None
exception Warning of t * string

let warnings : exn list ref option ref = ref None

let prerr_warning loc w =
match !warnings with
Expand All @@ -280,7 +282,7 @@ let prerr_warning loc w =
print_warning loc ppf w;
match to_string () with
| "" -> ()
| s -> l := (loc,s) :: !l
| s -> l := Warning (loc,s) :: !l

let catch_warnings f =
let caught = ref [] in
Expand Down
3 changes: 2 additions & 1 deletion parsing/location.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ val print_error_cur_file: formatter -> unit
val print_warning: t -> formatter -> Warnings.t -> unit

val prerr_warning : t -> Warnings.t -> unit
val catch_warnings : (unit -> 'a) -> (t * string) list * (exn, 'a) Misc.sum
exception Warning of t * string
val catch_warnings : (unit -> 'a) -> exn list * (exn, 'a) Misc.sum

val echo_eof: unit -> unit
val reset: unit -> unit
Expand Down

0 comments on commit 29f9954

Please sign in to comment.