package ppxlib

  1. Overview
  2. Docs
Standard library for ppx rewriters

Install

Dune Dependency

Authors

Maintainers

Sources

ppxlib-0.25.1.tbz
sha256=a51b3868029e62ff14a0f2bd8d278dacfc0c3fc5b22d484a296be90c53e4ffd7
sha512=6a6d9af49344e901cc9e6da7bcf38c2973705c8cee4cff1c64c0393e9ccc55a6abec1f58d5b56d0807939a3741bec722ee7bfc244f94619167a30438f182488a

doc/src/ppxlib.print_diff/ppxlib_print_diff.ml.html

Source file ppxlib_print_diff.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
open StdLabels

let patdiff_cmd ~use_color ~extra_patdiff_args =
  let args =
    List.concat
      [
        [ "-keep-whitespace" ];
        [ "-location-style omake" ];
        (if use_color then [] else [ "-ascii" ]);
        extra_patdiff_args;
      ]
  in
  String.concat ~sep:" " ("patdiff" :: args)

let print ?diff_command ?(extra_patdiff_args = []) ?(use_color = false) ~file1
    ~file2 () =
  let exec cmd =
    let cmd =
      Printf.sprintf "%s %s %s 1>&2" cmd (Filename.quote file1)
        (Filename.quote file2)
    in
    match Sys.command cmd with
    | 0 -> `Same
    | 1 -> `Different
    | n -> `Error (n, cmd)
  in
  match diff_command with
  | Some s -> ignore (exec s : [> `Same | `Different | `Error of int * string ])
  | None -> (
      match exec (patdiff_cmd ~use_color ~extra_patdiff_args) with
      | `Same ->
          (* patdiff produced no output, fallback to diff -u *)
          Printf.eprintf "File \"%s\", line 1, characters 0-0:\n%!" file1;
          ignore
            (exec "diff -u" : [> `Same | `Different | `Error of int * string ])
      | `Different ->
          (* patdiff successfully found a difference *)
          ()
      | `Error (err_code, cmd) ->
          (* patdiff threw an error... perhaps it wasn't installed? fallback to diff -u *)
          Printf.eprintf
            "Error:\n\
             > %S exited with code %d\n\
             > Perhaps patdiff is not installed? Hint, try: opam install patdiff\n\
             > Falling back to diff -u\n\n"
            cmd err_code;
          Printf.eprintf "File \"%s\", line 1, characters 0-0:\n%!" file1;
          ignore
            (exec "diff -u" : [> `Same | `Different | `Error of int * string ]))
OCaml

Innovation. Community. Security.