package js_of_ocaml-ppx

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file compat.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
open StdLabels
open Migrate_parsetree
open OCaml_406.Ast
open! Ast_mapper
open Ast_helper
open Asttypes
open Parsetree
open! Ast_convenience_406

module Ast_mapper = struct
  let extension_of_error ({kind; main; sub} : Location.error) =
    if kind <> Location.Report_error
    then raise (Invalid_argument "extension_of_error: expected kind Report_error");
    let str_of_pp pp_msg = Format.asprintf "%t" pp_msg in
    let extension_of_sub (sub : Location.msg) =
      ( {Location.loc = sub.loc; txt = "ocaml.error"}
      , Parsetree.(
          PStr [Str.eval (Exp.constant (Pconst_string (str_of_pp sub.txt, None)))]) )
    in
    (* Remove the duplicated error bellow once switching to Ast 4.08 *)
    ( {loc = main.loc; txt = "ocaml.error"}
    , PStr
        (Str.eval (Exp.constant (Pconst_string (str_of_pp main.txt, None)))
        :: Str.eval (Exp.constant (Pconst_string (str_of_pp main.txt, None)))
        :: List.map ~f:(fun msg -> Str.extension (extension_of_sub msg)) sub) )
end

module Location = struct
  let msg = Location.msg
end
OCaml

Innovation. Community. Security.