Skip to content

Commit

Permalink
Merge bb171d2 into 53f9188
Browse files Browse the repository at this point in the history
  • Loading branch information
rvantonder committed May 28, 2019
2 parents 53f9188 + bb171d2 commit 0f0c56c
Show file tree
Hide file tree
Showing 9 changed files with 922 additions and 281 deletions.
6 changes: 6 additions & 0 deletions lib/match/match.mli
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ type t =
[@@deriving yojson]

val create : unit -> t

val pp_json_pretty : Format.formatter -> string option * t list -> unit

val pp_json_lines : Format.formatter -> string option * t list -> unit

val pp_match_result : Format.formatter -> string option * t list -> unit
32 changes: 32 additions & 0 deletions lib/match/match_context.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Core

type t =
{ range : Range.t
; environment : Environment.t
Expand All @@ -10,3 +12,33 @@ let create () =
; environment = Environment.create ()
; matched = ""
}

let to_json source_path matches =
let json_matches matches = `List (List.map ~f:(fun x -> to_yojson x) matches) in
match source_path with
| None -> `Assoc [("uri", `Null); ("matches", json_matches matches)]
| Some path -> `Assoc [("uri", `String path); ("matches", json_matches matches)]

let pp_json_pretty ppf (source_path, matches) =
let f = Yojson.Safe.pretty_to_string in
let json_string = f @@ to_json source_path matches in
Format.fprintf ppf "%s" json_string

let pp_json_lines ppf (source_path, matches) =
let f = Yojson.Safe.to_string in
let json_string = f @@ to_json source_path matches in
Format.fprintf ppf "%s" json_string

let pp_match_result ppf (source_path, matches) =
let pp_source_path ppf source_path =
match source_path with
| Some path -> Format.fprintf ppf " in %s " path
| None -> Format.fprintf ppf "%s" " "
in
(* FIXME *)
let spec_number = 0 in
Format.fprintf ppf
"%d matches%afor spec %d (use -json-pretty for json format)\n"
(List.length matches)
pp_source_path source_path
(spec_number + 1)
Loading

0 comments on commit 0f0c56c

Please sign in to comment.