ocaml-core / base / core / extended / lib / extra_fields.ml

The branch 'bash' does not exist.
open Core.Std

exception Not_a_record_type of Sexp.t with sexp

let fields sexp =
  match sexp with
  | Sexp.Atom _ -> raise (Not_a_record_type sexp)
  | Sexp.List l ->
    List.map l ~f:(function
      | Sexp.List (Sexp.Atom field::_) -> field
      | _ -> raise (Not_a_record_type sexp)

module Make (M:Sexpable) = struct
  type t = {
    value : M.t;
    extra_fields : string list

  let sexp_of_t t = M.sexp_of_t t.value

  let t_of_sexp sexp =
    let ef_ref = Sexplib.Conv.record_check_extra_fields in
    let prev_ef = !ef_ref in
    ef_ref := false;
    let value = M.t_of_sexp sexp in
    ef_ref := prev_ef;
    let used_fields = fields (M.sexp_of_t value) in
    let all_fields = fields sexp in
    let extra_fields = List.filter all_fields ~f:(fun field ->
      not (List.mem used_fields field)
      value = value;
      extra_fields = extra_fields;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.