Skip to content
Browse files

initial ocamltarzan repo

  • Loading branch information...
0 parents commit fb4d299cacd6c5d683a540241955632a472cc301 pad committed Jul 24, 2010
Showing with 20,664 additions and 0 deletions.
  1. +41 −0 Makefile
  2. +5,937 −0 common.ml
  3. +22 −0 copyright.txt
  4. +5 −0 credits.txt
  5. +22 −0 lib-sexp/.depend
  6. +166 −0 lib-sexp/Makefile
  7. +342 −0 lib-sexp/conv.ml
  8. +348 −0 lib-sexp/conv.mli
  9. +138 −0 lib-sexp/conv_error.ml
  10. +19 −0 lib-sexp/copyright.txt
  11. +174 −0 lib-sexp/lexer.mll
  12. +26 −0 lib-sexp/license-tywith.txt
  13. +520 −0 lib-sexp/license.txt
  14. +223 −0 lib-sexp/modif-orig.txt
  15. +75 −0 lib-sexp/parser.mly
  16. +175 −0 lib-sexp/path.ml
  17. +116 −0 lib-sexp/path.mli
  18. +680 −0 lib-sexp/pre_sexp.ml
  19. +1 −0 lib-sexp/sexp.ml
  20. +27 −0 lib-sexp/sexp.mli
  21. +312 −0 lib-sexp/sexp_intf.ml
  22. +26 −0 lib-sexp/type.ml
  23. +26 −0 license-tywith.txt
  24. +520 −0 license.txt
  25. +602 −0 ocaml.ml
  26. +67 −0 ocaml.mli
  27. +222 −0 ocamltarzan.ml
  28. +39 −0 pa/.depend
  29. +71 −0 pa/Makefile
  30. +307 −0 pa/Pa_example.ml
  31. +42 −0 pa/modif-orig.txt
  32. +707 −0 pa/not-type-conv/pa_json_static.ml
  33. +352 −0 pa/old/pa_map.ml
  34. +32 −0 pa/old/pa_map.mli
  35. +290 −0 pa/old/pa_type_conv.ml
  36. +144 −0 pa/old/pa_type_conv.mli
  37. +1,324 −0 pa/pa_bin_prot.ml
  38. +32 −0 pa/pa_bin_prot.mli
  39. +306 −0 pa/pa_json_of.ml
  40. +305 −0 pa/pa_map.ml
  41. 0 pa/pa_matcher.ml
  42. +770 −0 pa/pa_ofs.ml
  43. +771 −0 pa/pa_ofv.ml
  44. +309 −0 pa/pa_rpc.ml
  45. +1,102 −0 pa/pa_sexp_conv.ml
  46. +32 −0 pa/pa_sexp_conv.mli
  47. +337 −0 pa/pa_sof.ml
  48. +219 −0 pa/pa_tof.ml
  49. +189 −0 pa/pa_type.ml
  50. +393 −0 pa/pa_type_conv.ml
  51. +169 −0 pa/pa_type_conv.mli
  52. +449 −0 pa/pa_value.ml
  53. +341 −0 pa/pa_visitor.ml
  54. +32 −0 pa/pa_visitor.mli
  55. +300 −0 pa/pa_vof.ml
  56. +1 −0 pa/pa_xxx_of.ml
  57. +277 −0 pa/type.ml
  58. +143 −0 readme.txt
  59. +8 −0 tests/builtins.ml
  60. +11 −0 tests/expr.ml
  61. +8 −0 tests/expr2.ml
  62. +9 −0 tests/mutually_recursive.ml
  63. +5 −0 tests/poly.ml
  64. +6 −0 tests/record.ml
41 Makefile
@@ -0,0 +1,41 @@
+MAKESUBDIRS=lib-sexp pa
+
+#pa
+#TARGET=ocamltarzan
+
+all:
+ $(MAKE) rec
+ $(MAKE) ocamltarzan
+
+opt:
+ $(MAKE) rec.opt
+all.opt: opt
+
+
+ocamltarzan: ocamltarzan.ml common.ml
+ ocamlc -o $@ unix.cma str.cma common.ml ocamltarzan.ml
+# ocamlc -o $@ -I ../commons unix.cma str.cma ../commons/commons.cma ocamltarzan.ml
+clean::
+ rm -f ocamltarzan
+
+rec:
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all; done
+rec.opt:
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all.opt; done
+
+clean::
+ rm -f *.cm[iox] *.o *.a *.cma *.cmxa *.annot
+
+clean::
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
+depend::
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
+distclean::
+ set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i distclean; done
+
+test:
+ echo "testing tof"
+ ./ocamltarzan -choice tof tests/expr.ml
+ echo "testing vof"
+ ./ocamltarzan -choice vof tests/expr.ml
+
5,937 common.ml
5,937 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
22 copyright.txt
@@ -0,0 +1,22 @@
+Most of this library was written by:
+
+ Markus Mottl <markus.mottl@gmail.com>
+
+Part of this work is derived from the library "Tywith", version 0.45.
+The library "Tywith" was written and is distributed by:
+
+ Martin Sandin <msandin@hotmail.com>
+
+The original license of "Tywith" can be found in the file
+"LICENSE.Tywith". Files that were derived from "Tywith" contain a
+reference to the original author.
+
+The following company has sponsored and has copyright in part of this work:
+
+ Jane Street Holding, LLC
+ 1 New York Plaza, 33rd Floor
+ New York, NY 10004
+ USA
+
+
+ocamltarzan.ml is copyrighted by Yoann Padioleau and is public domain.
5 credits.txt
@@ -0,0 +1,5 @@
+
+ - Richard Jones for his dumper module,
+ - Jane Street for the backtrace module and lib-sexp
+ - Martin Jambon, Mika Illouz and Gert Stolpmann for lib-json
+ - Thomas Gazagnaire for pa_type.ml
22 lib-sexp/.depend
@@ -0,0 +1,22 @@
+conv.cmi: sexp.cmi
+parser.cmi: type.cmo
+path.cmi: sexp.cmi
+sexp.cmi: sexp_intf.cmo
+conv.cmo: sexp.cmi conv.cmi
+conv.cmx: sexp.cmx conv.cmi
+conv_error.cmo: sexp.cmi conv.cmi
+conv_error.cmx: sexp.cmx conv.cmx
+lexer.cmo: parser.cmi
+lexer.cmx: parser.cmx
+parser.cmo: type.cmo parser.cmi
+parser.cmx: type.cmx parser.cmi
+path.cmo: sexp.cmi path.cmi
+path.cmx: sexp.cmx path.cmi
+pre_sexp.cmo: type.cmo parser.cmi lexer.cmo
+pre_sexp.cmx: type.cmx parser.cmx lexer.cmx
+sexp.cmo: pre_sexp.cmo sexp.cmi
+sexp.cmx: pre_sexp.cmx sexp.cmi
+sexp_intf.cmo: type.cmo pre_sexp.cmo
+sexp_intf.cmx: type.cmx pre_sexp.cmx
+type.cmo:
+type.cmx:
166 lib-sexp/Makefile
@@ -0,0 +1,166 @@
+##############################################################################
+# Variables
+##############################################################################
+
+SRC= \
+ type.ml \
+ parser.ml \
+ lexer.ml \
+ pre_sexp.ml \
+ sexp_intf.ml \
+ sexp.ml \
+ path.ml \
+ conv.ml \
+ conv_error.ml
+#SOURCES = \
+# parser.mly \
+# lexer.mll \
+# sexp.mli path.mli conv.mli
+
+
+TARGET=sexplib1
+TARGETPACK=sexplib
+#LIB_PACK_NAME = sexplib
+
+##############################################################################
+# Generic variables
+##############################################################################
+
+INCLUDES=
+#-I +camlp4
+SYSLIBS= str.cma unix.cma bigarray.cma num.cma
+#INCDIRS = +camlp4
+#pad: take care for bigarray otherwise get some caml_ba_get_1 error msg
+
+##############################################################################
+#OCAMLFLAGS = -for-pack Sexplib
+
+#PACKS = type-conv
+#RESULT = sexplib
+
+#TRASH = pa_sexp_conv.cmi pa_sexp_conv.cmo pa_sexp_conv.annot
+
+#all: \
+# pack-byte-code pack-native-code \
+# sexplib.cma sexplib.cmxa \
+# pa_sexp_conv.cmi pa_sexp_conv.cmo
+#
+#LIBINSTALL_FILES = \
+# sexp.mli path.mli conv.mli \
+# sexplib.cmi sexplib.cma sexplib.cmxa sexplib.a \
+# pa_sexp_conv.cmi pa_sexp_conv.cmo
+#
+#install: libinstall
+#uninstall: libuninstall
+#
+#clean:: clean-doc
+#
+#-include $(OCAMLMAKEFILE)
+
+##############################################################################
+
+##############################################################################
+# Generic variables
+##############################################################################
+
+#dont use -custom, it makes the bytecode unportable.
+OCAMLCFLAGS= -g -dtypes # -w A
+#-for-pack Sexplib
+
+# This flag is also used in subdirectories so don't change its name here.
+OPTFLAGS=
+
+
+OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES) $(SYSINCLUDES) -thread
+OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES) $(SYSINCLUDES) -thread
+OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
+OCAMLYACC=ocamlyacc -v
+OCAMLDEP=ocamldep $(INCLUDES)
+OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES) -thread
+
+#-ccopt -static
+STATIC=
+
+
+##############################################################################
+# Top rules
+##############################################################################
+
+OBJS = $(SRC:.ml=.cmo)
+OPTOBJS = $(SRC:.ml=.cmx)
+
+all: $(TARGET).cma $(TARGETPACK).cmo
+all.opt: $(TARGET).cmxa
+
+$(TARGET).cma: $(OBJS)
+ $(OCAMLC) -a -o $(TARGET).cma $(OBJS)
+
+$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
+ $(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
+
+$(TARGET).top: $(OBJS) $(LIBS)
+ $(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
+
+clean::
+ rm -f $(TARGET).top
+
+
+
+$(TARGETPACK).cmo: $(OBJS)
+ $(OCAMLC) -pack -o $(TARGETPACK).cmo $(OBJS)
+
+# special handling, fun that they use cpp whereas they claim camplp4 can do everything
+pre_sexp.cmo: pre_sexp.ml
+ $(OCAMLC) -pp "cpp -w" -c $<
+
+pre_sexp.cmx: pre_sexp.ml
+ $(OCAMLOPT) -pp "cpp -w" -c $<
+
+
+
+lexer.ml: lexer.mll
+ $(OCAMLLEX) $<
+clean::
+ rm -f lexer.ml
+beforedepend:: lexer.ml
+
+
+parser.ml parser.mli: parser.mly
+ $(OCAMLYACC) $<
+clean::
+ rm -f parser.ml parser.mli parser.output
+beforedepend:: parser.ml parser.mli
+
+
+
+##############################################################################
+# Generic rules
+##############################################################################
+
+.SUFFIXES: .ml .mli .cmo .cmi .cmx
+
+.ml.cmo:
+ $(OCAMLC) -c $<
+.mli.cmi:
+ $(OCAMLC) -c $<
+.ml.cmx:
+ $(OCAMLOPT) -c $<
+
+.ml.mldepend:
+ $(OCAMLC) -i $<
+
+clean::
+ rm -f *.cm[ioxa] *.o *.a *.cmxa *.annot
+clean::
+ rm -f *~ .*~ gmon.out #*#
+
+beforedepend::
+
+# need also -pp cpp here
+depend:: beforedepend
+ $(OCAMLDEP) -pp "cpp -w" *.mli *.ml > .depend
+
+distclean:
+ rm -f .depend
+
+-include .depend
342 lib-sexp/conv.ml
@@ -0,0 +1,342 @@
+(* File: conv.ml
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl\@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*)
+
+(* Conv: Utility Module for S-expression Conversions *)
+
+open Printf
+open Bigarray
+open Sexp
+
+type 'a sexp_option = 'a option
+
+(* Conversion of OCaml-values to S-expressions *)
+
+let default_string_of_float = ref (fun n -> sprintf "%.20G" n)
+let read_old_option_format = ref true
+let write_old_option_format = ref true
+
+let sexp_of_unit () = List []
+let sexp_of_bool b = Atom (string_of_bool b)
+let sexp_of_string str = Atom str
+let sexp_of_char c = Atom (String.make 1 c)
+let sexp_of_int n = Atom (string_of_int n)
+let sexp_of_float n = Atom (!default_string_of_float n)
+let sexp_of_int32 n = Atom (Int32.to_string n)
+let sexp_of_int64 n = Atom (Int64.to_string n)
+let sexp_of_nativeint n = Atom (Nativeint.to_string n)
+let sexp_of_big_int n = Atom (Big_int.string_of_big_int n)
+let sexp_of_nat n = Atom (Nat.string_of_nat n)
+let sexp_of_num n = Atom (Num.string_of_num n)
+let sexp_of_ratio n = Atom (Ratio.string_of_ratio n)
+let sexp_of_ref sexp_of__a rf = sexp_of__a !rf
+let sexp_of_lazy sexp_of__a lv = sexp_of__a (Lazy.force lv)
+
+let sexp_of_option sexp_of__a = function
+ | Some x when !write_old_option_format -> List [sexp_of__a x]
+ | Some x -> List [Atom "some"; sexp_of__a x]
+ | None when !write_old_option_format -> List []
+ | None -> Atom "none"
+
+let sexp_of_pair sexp_of__a sexp_of__b (a, b) =
+ List [sexp_of__a a; sexp_of__b b]
+
+let sexp_of_triple sexp_of__a sexp_of__b sexp_of__c (a, b, c) =
+ List [sexp_of__a a; sexp_of__b b; sexp_of__c c]
+
+let sexp_of_list sexp_of__a lst =
+ List (List.rev (List.rev_map sexp_of__a lst))
+
+let sexp_of_array sexp_of__a ar =
+ let lst_ref = ref [] in
+ for i = Array.length ar - 1 downto 0 do
+ lst_ref := sexp_of__a ar.(i) :: !lst_ref
+ done;
+ List !lst_ref
+
+let sexp_of_hashtbl sexp_of_key sexp_of_val htbl =
+ let coll k v acc = List [sexp_of_key k; sexp_of_val v] :: acc in
+ List (Hashtbl.fold coll htbl [])
+
+let sexp_of_float_vec vec =
+ let lst_ref = ref [] in
+ for i = Array1.dim vec downto 1 do
+ lst_ref := sexp_of_float vec.{i} :: !lst_ref
+ done;
+ List !lst_ref
+
+type vec32 = (float, float32_elt, fortran_layout) Array1.t
+type vec64 = (float, float64_elt, fortran_layout) Array1.t
+let sexp_of_float32_vec (vec : vec32) = sexp_of_float_vec vec
+let sexp_of_float64_vec (vec : vec64) = sexp_of_float_vec vec
+let sexp_of_vec (vec : vec64) = sexp_of_float_vec vec
+
+let sexp_of_float_mat mat =
+ let m = Array2.dim1 mat in
+ let n = Array2.dim2 mat in
+ let lst_ref = ref [] in
+ for col = n downto 1 do
+ let vec = Array2.slice_right mat col in
+ for row = m downto 1 do
+ lst_ref := sexp_of_float vec.{row} :: !lst_ref
+ done
+ done;
+ List (sexp_of_int m :: sexp_of_int n :: !lst_ref)
+
+type mat32 = (float, float32_elt, fortran_layout) Array2.t
+type mat64 = (float, float64_elt, fortran_layout) Array2.t
+let sexp_of_float32_mat (mat : mat32) = sexp_of_float_mat mat
+let sexp_of_float64_mat (mat : mat64) = sexp_of_float_mat mat
+let sexp_of_mat (mat : mat64) = sexp_of_float_mat mat
+
+let sexp_of_abstr _ = Atom "<abstr>"
+let sexp_of_fun _ = Atom "<fun>"
+
+type 'a opaque = 'a
+let sexp_of_opaque _ _ = Atom "<opaque>"
+
+let string_of__of__sexp_of to_sexp x = Sexp.to_string (to_sexp x)
+
+
+(* Conversion of S-expressions to OCaml-values *)
+
+exception Of_sexp_error of string * Sexp.t
+
+let record_check_extra_fields = ref true
+
+let of_sexp_error what sexp = raise (Of_sexp_error (what, sexp))
+
+let unit_of_sexp sexp = match sexp with
+ | List [] -> ()
+ | Atom _ | List _ -> of_sexp_error "unit_of_sexp: empty list needed" sexp
+
+let bool_of_sexp sexp = match sexp with
+ | Atom ("true" | "True") -> true
+ | Atom ("false" | "False") -> false
+ | Atom _ -> of_sexp_error "bool_of_sexp: unknown string" sexp
+ | List _ -> of_sexp_error "bool_of_sexp: atom needed" sexp
+
+let string_of_sexp sexp = match sexp with
+ | Atom str -> str
+ | List _ -> of_sexp_error "string_of_sexp: atom needed" sexp
+
+let char_of_sexp sexp = match sexp with
+ | Atom str ->
+ if String.length str <> 1 then
+ of_sexp_error
+ "char_of_sexp: atom string must contain one character only" sexp;
+ str.[0]
+ | List _ -> of_sexp_error "char_of_sexp: atom needed" sexp
+
+let int_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try int_of_string str
+ with exc -> of_sexp_error ("int_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "int_of_sexp: atom needed" sexp
+
+let float_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try float_of_string str
+ with exc ->
+ of_sexp_error ("float_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "float_of_sexp: atom needed" sexp
+
+let int32_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Int32.of_string str
+ with exc ->
+ of_sexp_error ("int32_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "int32_of_sexp: atom needed" sexp
+
+let int64_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Int64.of_string str
+ with exc ->
+ of_sexp_error ("int64_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "int64_of_sexp: atom needed" sexp
+
+let nativeint_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Nativeint.of_string str
+ with exc ->
+ of_sexp_error ("nativeint_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "nativeint_of_sexp: atom needed" sexp
+
+let big_int_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Big_int.big_int_of_string str
+ with exc ->
+ of_sexp_error ("big_int_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "big_int_of_sexp: atom needed" sexp
+
+let nat_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Nat.nat_of_string str
+ with exc ->
+ of_sexp_error ("nat_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "nat_of_sexp: atom needed" sexp
+
+let num_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Num.num_of_string str
+ with exc ->
+ of_sexp_error ("num_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "num_of_sexp: atom needed" sexp
+
+let ratio_of_sexp sexp = match sexp with
+ | Atom str ->
+ (try Ratio.ratio_of_string str
+ with exc ->
+ of_sexp_error ("ratio_of_sexp: " ^ Printexc.to_string exc) sexp)
+ | List _ -> of_sexp_error "ratio_of_sexp: atom needed" sexp
+
+let ref_of_sexp a__of_sexp sexp = ref (a__of_sexp sexp)
+let lazy_of_sexp a__of_sexp sexp = lazy (a__of_sexp sexp)
+
+let option_of_sexp a__of_sexp sexp =
+ if !read_old_option_format then
+ match sexp with
+ | List [] | Atom ("none" | "None") -> None
+ | List [el] | List [Atom ("some" | "Some"); el] -> Some (a__of_sexp el)
+ | List _ ->
+ of_sexp_error "option_of_sexp: list must represent optional value" sexp
+ | Atom _ -> of_sexp_error "option_of_sexp: only none can be atom" sexp
+ else
+ match sexp with
+ | Atom ("none" | "None") -> None
+ | List [Atom ("some" | "Some"); el] -> Some (a__of_sexp el)
+ | Atom _ -> of_sexp_error "option_of_sexp: only none can be atom" sexp
+ | List _ -> of_sexp_error "option_of_sexp: list must be (some el)" sexp
+
+let pair_of_sexp a__of_sexp b__of_sexp sexp = match sexp with
+ | List [a_sexp; b_sexp] ->
+ let a = a__of_sexp a_sexp in
+ let b = b__of_sexp b_sexp in
+ a, b
+ | List _ ->
+ of_sexp_error
+ "pair_of_sexp: list must contain exactly two elements only" sexp
+ | Atom _ -> of_sexp_error "pair_of_sexp: list needed" sexp
+
+let triple_of_sexp a__of_sexp b__of_sexp c__of_sexp sexp = match sexp with
+ | List [a_sexp; b_sexp; c_sexp] ->
+ let a = a__of_sexp a_sexp in
+ let b = b__of_sexp b_sexp in
+ let c = c__of_sexp c_sexp in
+ a, b, c
+ | List _ ->
+ of_sexp_error
+ "triple_of_sexp: list must contain exactly three elements only" sexp
+ | Atom _ -> of_sexp_error "triple_of_sexp: list needed" sexp
+
+let list_of_sexp a__of_sexp sexp = match sexp with
+ | List lst ->
+ let rev_lst = List.rev_map a__of_sexp lst in
+ List.rev rev_lst
+ | Atom _ -> of_sexp_error "list_of_sexp: list needed" sexp
+
+let array_of_sexp a__of_sexp sexp = match sexp with
+ | List [] -> [||]
+ | List (h :: t) ->
+ let len = List.length t + 1 in
+ let res = Array.create len (a__of_sexp h) in
+ let rec loop i = function
+ | [] -> res
+ | h :: t -> res.(i) <- a__of_sexp h; loop (i + 1) t in
+ loop 1 t
+ | Atom _ -> of_sexp_error "array_of_sexp: list needed" sexp
+
+let hashtbl_of_sexp key_of_sexp val_of_sexp sexp = match sexp with
+ | List lst ->
+ let htbl = Hashtbl.create 0 in
+ let act = function
+ | List [k_sexp; v_sexp] ->
+ Hashtbl.add htbl (key_of_sexp k_sexp) (val_of_sexp v_sexp)
+ | List _ | Atom _ ->
+ of_sexp_error "hashtbl_of_sexp: tuple list needed" sexp
+ in
+ List.iter act lst;
+ htbl
+ | Atom _ -> of_sexp_error "hashtbl_of_sexp: list needed" sexp
+
+let float_vec_of_sexp empty_float_vec create_float_vec sexp = match sexp with
+ | List [] -> empty_float_vec
+ | List lst ->
+ let len = List.length lst in
+ let res = create_float_vec len in
+ let rec loop i = function
+ | [] -> res
+ | h :: t -> res.{i} <- float_of_sexp h; loop (i + 1) t in
+ loop 1 lst
+ | Atom _ -> of_sexp_error "float_vec_of_sexp: list needed" sexp
+
+let create_float32_vec = Array1.create float32 fortran_layout
+let create_float64_vec = Array1.create float64 fortran_layout
+let empty_float32_vec = create_float32_vec 0
+let empty_float64_vec = create_float64_vec 0
+let float32_vec_of_sexp = float_vec_of_sexp empty_float32_vec create_float32_vec
+let float64_vec_of_sexp = float_vec_of_sexp empty_float64_vec create_float64_vec
+let vec_of_sexp = float_vec_of_sexp empty_float64_vec create_float64_vec
+
+let check_too_much_data sexp data res =
+ if data = [] then res
+ else of_sexp_error "float_mat_of_sexp: too much data" sexp
+
+let float_mat_of_sexp create_float_mat sexp = match sexp with
+ | List (sm :: sn :: data) ->
+ let m = int_of_sexp sm in
+ let n = int_of_sexp sn in
+ let res = create_float_mat m n in
+ if m = 0 || n = 0 then check_too_much_data sexp data res
+ else
+ let rec loop_cols col data =
+ let vec = Array2.slice_right res col in
+ let rec loop_rows row = function
+ | [] -> of_sexp_error "float_mat_of_sexp: not enough data" sexp
+ | h :: t ->
+ vec.{row} <- float_of_sexp h;
+ if row = m then
+ if col = n then check_too_much_data sexp t res
+ else loop_cols (col + 1) t
+ else loop_rows (row + 1) t in
+ loop_rows 1 data in
+ loop_cols 1 data
+ | List _ -> of_sexp_error "float_mat_of_sexp: list too short" sexp
+ | Atom _ -> of_sexp_error "float_mat_of_sexp: list needed" sexp
+
+let create_float32_mat = Array2.create float32 fortran_layout
+let create_float64_mat = Array2.create float64 fortran_layout
+
+let float32_mat_of_sexp = float_mat_of_sexp create_float32_mat
+let float64_mat_of_sexp = float_mat_of_sexp create_float64_mat
+let mat_of_sexp = float_mat_of_sexp create_float64_mat
+
+let fun_of_sexp sexp =
+ of_sexp_error "fun_of_sexp: cannot convert function values" sexp
+
+let of_string__of__of_sexp of_sexp s =
+ try
+ let sexp = Sexp.of_string s in
+ of_sexp sexp
+ with e ->
+ failwith (sprintf "of_string failed on %s with %s" s (Printexc.to_string e))
348 lib-sexp/conv.mli
@@ -0,0 +1,348 @@
+(* File: conv.mli
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl\@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*)
+
+(** Conv: Utility Module for S-expression Conversions *)
+
+open Bigarray
+
+(** Dummy definition for "optional" options *)
+type 'a sexp_option = 'a option
+
+
+(** {6 Conversion of OCaml-values to S-expressions} *)
+
+val default_string_of_float : (float -> string) ref
+(** [default_string_of_float] reference to the default function used
+ to convert floats to strings.
+
+ Initially set to [fun n -> sprintf "%.20G" n].
+*)
+
+val write_old_option_format : bool ref
+(** [write_old_option_format] reference for the default option format
+ used to write option values. If set to [true], the old-style option
+ format will be used, the new-style one otherwise.
+
+ Initially set to [true].
+*)
+
+val read_old_option_format : bool ref
+(** [read_old_option_format] reference for the default option format
+ used to read option values. [Of_sexp_error] will be raised with
+ old-style option values if this reference is set to [false].
+ Reading new-style option values is always supported.
+
+ Initially set to [true].
+*)
+
+val sexp_of_unit : unit -> Sexp.t
+(** [sexp_of_unit ()] converts a value of type [unit] to an S-expression. *)
+
+val sexp_of_bool : bool -> Sexp.t
+(** [sexp_of_bool b] converts the value [x] of type [bool] to an
+ S-expression. *)
+
+val sexp_of_string : string -> Sexp.t
+(** [sexp_of_bool str] converts the value [str] of type [string] to an
+ S-expression. *)
+
+val sexp_of_char : char -> Sexp.t
+(** [sexp_of_char c] converts the value [c] of type [char] to an
+ S-expression. *)
+
+val sexp_of_int : int -> Sexp.t
+(** [sexp_of_int n] converts the value [n] of type [int] to an
+ S-expression. *)
+
+val sexp_of_float : float -> Sexp.t
+(** [sexp_of_float n] converts the value [n] of type [float] to an
+ S-expression. *)
+
+val sexp_of_int32 : int32 -> Sexp.t
+(** [sexp_of_int32 n] converts the value [n] of type [int32] to an
+ S-expression. *)
+
+val sexp_of_int64 : int64 -> Sexp.t
+(** [sexp_of_int64 n] converts the value [n] of type [int64] to an
+ S-expression. *)
+
+val sexp_of_nativeint : nativeint -> Sexp.t
+(** [sexp_of_nativeint n] converts the value [n] of type [nativeint] to an
+ S-expression. *)
+
+val sexp_of_big_int : Big_int.big_int -> Sexp.t
+(** [sexp_of_big_int n] converts the value [n] of type [Big_int.big_int]
+ to an S-expression. *)
+
+val sexp_of_nat : Nat.nat -> Sexp.t
+(** [sexp_of_nat n] converts the value [n] of type [Nat.nat] to an
+ S-expression. *)
+
+val sexp_of_num : Num.num -> Sexp.t
+(** [sexp_of_num n] converts the value [n] of type [Num.num] to an
+ S-expression. *)
+
+val sexp_of_ratio : Ratio.ratio -> Sexp.t
+(** [sexp_of_ratio n] converts the value [n] of type [Ratio.ratio] to an
+ S-expression. *)
+
+val sexp_of_ref : ('a -> 'b) -> 'a ref -> 'b
+(** [sexp_of_ref conv r] converts the value [r] of type ['a ref] to
+ an S-expression. Uses [conv] to convert values of type ['a] to an
+ S-expression. *)
+
+val sexp_of_lazy : ('a -> 'b) -> 'a lazy_t -> 'b
+(** [sexp_of_ref conv l] converts the value [l] of type ['a lazy_t] to
+ an S-expression. Uses [conv] to convert values of type ['a] to an
+ S-expression. *)
+
+val sexp_of_option : ('a -> Sexp.t) -> 'a option -> Sexp.t
+(** [sexp_of_option conv opt] converts the value [opt] of type ['a
+ option] to an S-expression. Uses [conv] to convert values of type
+ ['a] to an S-expression. *)
+
+val sexp_of_pair : ('a -> Sexp.t) -> ('b -> Sexp.t) -> 'a * 'b -> Sexp.t
+(** [sexp_of_pair conv1 conv2 pair] converts a pair to an S-expression.
+ It uses its first argument to convert the first element of the pair,
+ and its second argument to convert the second element of the pair. *)
+
+val sexp_of_triple :
+ ('a -> Sexp.t) -> ('b -> Sexp.t) -> ('c -> Sexp.t) -> 'a * 'b * 'c -> Sexp.t
+(** [sexp_of_triple conv1 conv2 conv3 triple] converts a triple to
+ an S-expression using [conv1], [conv2], and [conv3] to convert its
+ elements. *)
+
+val sexp_of_list : ('a -> Sexp.t) -> 'a list -> Sexp.t
+(** [sexp_of_list conv lst] converts the value [lst] of type ['a
+ list] to an S-expression. Uses [conv] to convert values of type
+ ['a] to an S-expression. *)
+
+val sexp_of_array : ('a -> Sexp.t) -> 'a array -> Sexp.t
+(** [sexp_of_array conv ar] converts the value [ar] of type ['a
+ array] to an S-expression. Uses [conv] to convert values of type
+ ['a] to an S-expression. *)
+
+val sexp_of_hashtbl :
+ ('a -> Sexp.t) -> ('b -> Sexp.t) -> ('a, 'b) Hashtbl.t -> Sexp.t
+(** [sexp_of_hashtbl conv_key conv_value htbl] converts the value [htbl]
+ of type [('a, 'b) Hashtbl.t] to an S-expression. Uses [conv_key]
+ to convert the hashtable keys of type ['a], and [conv_value] to
+ convert hashtable values of type ['b] to S-expressions. *)
+
+val sexp_of_float32_vec :
+ (float, float32_elt, fortran_layout) Array1.t -> Sexp.t
+(** [sexp_of_float32_vec vec] converts the one-dimensional bigarray
+ [vec] of 32-bit floats in Fortran-layout to an S-expression. *)
+
+val sexp_of_float64_vec :
+ (float, float64_elt, fortran_layout) Array1.t -> Sexp.t
+(** [sexp_of_float64_vec vec] converts the one-dimensional bigarray
+ [vec] of 64-bit floats in Fortran-layout to an S-expression. *)
+
+val sexp_of_vec : (float, float64_elt, fortran_layout) Array1.t -> Sexp.t
+(** [sexp_of_vec vec] same as {!Conv.sexp_of_float64_vec}. *)
+
+val sexp_of_float32_mat :
+ (float, float32_elt, fortran_layout) Array2.t -> Sexp.t
+(** [sexp_of_float32_mat mat] converts the two-dimensional bigarray
+ [mat] of 32-bit floats in Fortran-layout to an S-expression. *)
+
+val sexp_of_float64_mat :
+ (float, float64_elt, fortran_layout) Array2.t -> Sexp.t
+(** [sexp_of_float64_mat mat] converts the two-dimensional bigarray
+ [mat] of 64-bit floats in Fortran-layout to an S-expression. *)
+
+val sexp_of_mat : (float, float64_elt, fortran_layout) Array2.t -> Sexp.t
+(** [sexp_of_mat mat] same as {!Conv.sexp_of_float64_mat}. *)
+
+val sexp_of_abstr : 'a -> Sexp.t
+(** [sexp_of_abstr x] converts the value [x] of abstract type to an
+ S-expression. *)
+
+val sexp_of_fun : ('a -> 'b) -> Sexp.t
+(** [sexp_of_fun f] converts the value [f] of function type to an
+ S-expression. *)
+
+(** Type used for declaring existing types as opaque to sexp converters,
+ i.e. even if there is a defined converter for ['a], it will not
+ be called. This is useful to e.g. suppress printing of extremely
+ large sub-structures for purely informational, human-readable output.
+*)
+type 'a opaque = 'a
+
+val sexp_of_opaque : ('a -> Sexp.t) -> 'a opaque -> Sexp.t
+(** [sexp_of_opaque _ _] converts opaque OCaml-values to S-expressions. *)
+
+val string_of__of__sexp_of : ('a -> Sexp.t) -> 'a -> string
+(** [string_of__of__sexp_of conv x] converts the OCaml-value [x] to
+ an S-expression represented as a string by using conversion function
+ [conv]. *)
+
+
+(** {6 Conversion of S-expressions to OCaml-values} *)
+
+exception Of_sexp_error of string * Sexp.t
+(** [Of_sexp_error (reason, sexp)] the exception raised when an
+ S-expression could not be successfully converted to an OCaml-value. *)
+
+val record_check_extra_fields : bool ref
+(** [record_check_extra_fields] checks for extra (= unknown) fields
+ in record S-expressions. *)
+
+val of_sexp_error : string -> Sexp.t -> 'a
+(** [of_sexp_error reason sexp] @raise the exception [Of_sexp_error
+ (reason, sexp)]. *)
+
+val unit_of_sexp : Sexp.t -> unit
+(** [unit_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [unit]. *)
+
+val bool_of_sexp : Sexp.t -> bool
+(** [bool_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [bool]. *)
+
+val string_of_sexp : Sexp.t -> string
+(** [string_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [string]. *)
+
+val char_of_sexp : Sexp.t -> char
+(** [char_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [char]. *)
+
+val int_of_sexp : Sexp.t -> int
+(** [int_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [int]. *)
+
+val float_of_sexp : Sexp.t -> float
+(** [float_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [float]. *)
+
+val int32_of_sexp : Sexp.t -> int32
+(** [int32_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [int32]. *)
+
+val int64_of_sexp : Sexp.t -> int64
+(** [int64_of_sexp sexp] converts S-expression [sexp] to a value of type
+ [int64]. *)
+
+val nativeint_of_sexp : Sexp.t -> nativeint
+(** [nativeint_of_sexp sexp] converts S-expression [sexp] to a value
+ of type [nativeint]. *)
+
+val big_int_of_sexp : Sexp.t -> Big_int.big_int
+(** [big_int_of_sexp sexp] converts S-expression [sexp] to a value
+ of type [Big_int.big_int]. *)
+
+val nat_of_sexp : Sexp.t -> Nat.nat
+(** [nat_of_sexp sexp] converts S-expression [sexp] to a value
+ of type [Nat.nat]. *)
+
+val num_of_sexp : Sexp.t -> Num.num
+(** [num_of_sexp sexp] converts S-expression [sexp] to a value
+ of type [Nat.num]. *)
+
+val ratio_of_sexp : Sexp.t -> Ratio.ratio
+(** [ratio_of_sexp sexp] converts S-expression [sexp] to a value
+ of type [Nat.ratio]. *)
+
+val ref_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a ref
+(** [ref_of_sexp conv sexp] converts S-expression [sexp] to a value
+ of type ['a ref] using conversion function [conv], which converts
+ an S-expression to a value of type ['a]. *)
+
+val lazy_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a lazy_t
+(** [lazy_of_sexp conv sexp] converts S-expression [sexp] to a value
+ of type ['a lazy_t] using conversion function [conv], which converts
+ an S-expression to a value of type ['a]. *)
+
+val option_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a option
+(** [option_of_sexp conv sexp] converts S-expression [sexp] to a value
+ of type ['a option] using conversion function [conv], which converts
+ an S-expression to a value of type ['a]. *)
+
+val pair_of_sexp : (Sexp.t -> 'a) -> (Sexp.t -> 'b) -> Sexp.t -> 'a * 'b
+(** [pair_of_sexp conv1 conv2 sexp] converts S-expression [sexp] to a pair
+ of type ['a * 'b] using conversion functions [conv1] and [conv2],
+ which convert S-expressions to values of type ['a] and ['b]
+ respectively. *)
+
+val triple_of_sexp :
+ (Sexp.t -> 'a) -> (Sexp.t -> 'b) -> (Sexp.t -> 'c) -> Sexp.t -> 'a * 'b * 'c
+(** [triple_of_sexp conv1 conv2 conv3 sexp] converts S-expression [sexp]
+ to a triple of type ['a * 'b * 'c] using conversion functions [conv1],
+ [conv2], and [conv3], which convert S-expressions to values of type
+ ['a], ['b], and ['c] respectively. *)
+
+val list_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a list
+(** [list_of_sexp conv sexp] converts S-expression [sexp] to a value
+ of type ['a list] using conversion function [conv], which converts
+ an S-expression to a value of type ['a]. *)
+
+val array_of_sexp : (Sexp.t -> 'a) -> Sexp.t -> 'a array
+(** [array_of_sexp conv sexp] converts S-expression [sexp] to a value
+ of type ['a array] using conversion function [conv], which converts
+ an S-expression to a value of type ['a]. *)
+
+val hashtbl_of_sexp :
+ (Sexp.t -> 'a) -> (Sexp.t -> 'b) -> Sexp.t -> ('a, 'b) Hashtbl.t
+(** [hashtbl_of_sexp conv_key conv_value sexp] converts S-expression
+ [sexp] to a value of type [('a, 'b) Hashtbl.t] using conversion
+ function [conv_key], which converts an S-expression to hashtable
+ key of type ['a], and function [conv_value], which converts an
+ S-expression to hashtable value of type ['b]. *)
+
+val float32_vec_of_sexp :
+ Sexp.t -> (float, float32_elt, fortran_layout) Array1.t
+(** [float32_vec_of_sexp sexp] converts S-expression [sexp] to a
+ one-dimensional bigarray of 32-bit floats in Fortran-layout. *)
+
+val float64_vec_of_sexp :
+ Sexp.t -> (float, float64_elt, fortran_layout) Array1.t
+(** [float64_vec_of_sexp sexp] converts S-expression [sexp] to a
+ one-dimensional bigarray of 64-bit floats in Fortran-layout. *)
+
+val vec_of_sexp : Sexp.t -> (float, float64_elt, fortran_layout) Array1.t
+(** [vec_of_sexp sexp] same as {!float64_vec_of_sexp}. *)
+
+val float32_mat_of_sexp :
+ Sexp.t -> (float, float32_elt, fortran_layout) Array2.t
+(** [float32_mat_of_sexp sexp] converts S-expression [sexp] to a
+ two-dimensional bigarray of 32-bit floats in Fortran-layout. *)
+
+val float64_mat_of_sexp :
+ Sexp.t -> (float, float64_elt, fortran_layout) Array2.t
+(** [float64_mat_of_sexp sexp] converts S-expression [sexp] to a
+ two-dimensional bigarray of 64-bit floats in Fortran-layout. *)
+
+val mat_of_sexp : Sexp.t -> (float, float64_elt, fortran_layout) Array2.t
+(** [mat_of_sexp sexp] same as {!Conv.float64_mat_of_sexp}. *)
+
+val fun_of_sexp : Sexp.t -> ('a -> 'b)
+(** [fun_of_sexp sexp] @raise a conversion error when attempting to
+ convert an S-expression to a function. *)
+
+val of_string__of__of_sexp : (Sexp.t -> 'a) -> string -> 'a
+(** [of_string__of__of_sexp conv str] converts the S-expression [str]
+ represented as a string to an OCaml-value by using conversion function
+ [conv]. *)
138 lib-sexp/conv_error.ml
@@ -0,0 +1,138 @@
+(* File: conv_error.ml
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl\@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*)
+
+(* Conv_error: Module for Handling Errors during Automated S-expression
+ Conversions *)
+
+open Printf
+open Conv
+
+(* Errors concerning tuples *)
+
+let tuple_of_size_n_expected loc n sexp =
+ of_sexp_error (sprintf "%s_of_sexp: tuple of size %d expected" loc n) sexp
+
+
+(* Errors concerning sum types *)
+
+let stag_no_args loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: sum tag does not take arguments") sexp
+
+let stag_incorrect_n_args loc tag sexp =
+ let msg =
+ sprintf "%s_of_sexp: sum tag %S has incorrect number of arguments" loc tag
+ in
+ of_sexp_error msg sexp
+
+let stag_takes_args loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: sum tag must be a structured value") sexp
+
+let nested_list_invalid_sum loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: a nested list is an invalid sum") sexp
+
+let empty_list_invalid_sum loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: the empty list is an invalid sum") sexp
+
+let unexpected_stag loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: unexpected sum tag") sexp
+
+
+(* Errors concerning records *)
+
+let record_only_pairs_expected loc sexp =
+ let msg =
+ loc ^
+ "_of_sexp: record conversion: only pairs expected, \
+ their first element must be an atom" in
+ of_sexp_error msg sexp
+
+let record_superfluous_fields ~what ~loc rev_fld_names sexp =
+ let fld_names_str = String.concat " " (List.rev rev_fld_names) in
+ let msg = sprintf "%s_of_sexp: %s: %s" loc what fld_names_str in
+ of_sexp_error msg sexp
+
+let record_duplicate_fields loc rev_fld_names sexp =
+ record_superfluous_fields ~what:"duplicate fields" ~loc rev_fld_names sexp
+
+let record_extra_fields loc rev_fld_names sexp =
+ record_superfluous_fields ~what:"extra fields" ~loc rev_fld_names sexp
+
+let rec record_get_undefined_loop fields = function
+ | [] -> String.concat " " (List.rev fields)
+ | (true, field) :: rest -> record_get_undefined_loop (field :: fields) rest
+ | _ :: rest -> record_get_undefined_loop fields rest
+
+let record_undefined_elements loc sexp lst =
+ let undefined = record_get_undefined_loop [] lst in
+ let msg =
+ sprintf "%s_of_sexp: the following record elements were undefined: %s"
+ loc undefined
+ in
+ of_sexp_error msg sexp
+
+let record_list_instead_atom loc sexp =
+ let msg = loc ^ "_of_sexp: list instead of atom for record expected" in
+ of_sexp_error msg sexp
+
+let record_poly_field_value loc sexp =
+ let msg =
+ loc ^
+ "_of_sexp: cannot convert values of types resulting from polymorphic \
+ record fields"
+ in
+ of_sexp_error msg sexp
+
+
+(* Errors concerning polymorphic variants *)
+
+exception No_variant_match of string * Sexp.t
+
+let no_variant_match loc sexp =
+ raise (No_variant_match (loc ^ "_of_sexp", sexp))
+
+let ptag_no_args loc sexp =
+ of_sexp_error (
+ loc ^ "_of_sexp: polymorphic variant does not take arguments") sexp
+
+let ptag_incorrect_n_args loc cnstr sexp =
+ let msg =
+ sprintf
+ "%s_of_sexp: polymorphic variant tag %S has incorrect number of arguments"
+ loc cnstr
+ in
+ of_sexp_error msg sexp
+
+let nested_list_invalid_poly_var loc sexp =
+ of_sexp_error (
+ loc ^ "_of_sexp: a nested list is an invalid polymorphic variant") sexp
+
+let empty_list_invalid_poly_var loc sexp =
+ of_sexp_error (
+ loc ^ "_of_sexp: the empty list is an invalid polymorphic variant") sexp
+
+let silly_type loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: trying to convert a silly type") sexp
+
+let empty_type loc sexp =
+ of_sexp_error (loc ^ "_of_sexp: trying to convert an empty type") sexp
19 lib-sexp/copyright.txt
@@ -0,0 +1,19 @@
+Most of this library was written by:
+
+ Markus Mottl <markus.mottl@gmail.com>
+
+This work is derived from the library "Tywith", version 0.45. The library
+"Tywith" was written and is distributed by:
+
+ Martin Sandin <msandin@hotmail.com>
+
+The original license of "Tywith" can be found in the file
+"LICENSE.Tywith". Files that were derived from "Tywith" contain a
+reference to the original author.
+
+The following company has sponsored and has copyright in part of this work:
+
+ Jane Street Holding, LLC
+ 1 New York Plaza, 33rd Floor
+ New York, NY 10004
+ USA
174 lib-sexp/lexer.mll
@@ -0,0 +1,174 @@
+{
+ (* File: lexer.mll
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+
+ (** Lexer: Lexer Specification for S-expressions *)
+
+ open Printf
+ open Lexing
+ open Parser
+
+ let char_for_backslash = function
+ | 'n' -> '\n'
+ | 't' -> '\t'
+ | 'b' -> '\b'
+ | 'r' -> '\r'
+ | c -> c
+
+ let double_nl = "\013\010"
+
+ let dec_code c1 c2 c3 =
+ 100 * (Char.code c1 - 48) + 10 * (Char.code c2 - 48) + (Char.code c3 - 48)
+
+ let hex_code c1 c2 =
+ let d1 = Char.code c1 in
+ let val1 =
+ if d1 >= 97 then d1 - 87
+ else if d1 >= 65 then d1 - 55
+ else d1 - 48 in
+ let d2 = Char.code c2 in
+ let val2 =
+ if d2 >= 97 then d2 - 87
+ else if d2 >= 65 then d2 - 55
+ else d2 - 48 in
+ val1 * 16 + val2
+
+ let found_newline lexbuf diff =
+ let curr_p = lexbuf.lex_curr_p in
+ lexbuf.lex_curr_p <-
+ {
+ curr_p with
+ pos_lnum = curr_p.pos_lnum + 1;
+ pos_bol = max 1 (curr_p.pos_cnum - diff);
+ }
+
+ let get_lexeme_len lexbuf = lexbuf.lex_curr_pos - lexbuf.lex_start_pos
+}
+
+let newline = ('\010' | '\013' | "\013\010")
+let space = [' ' '\009' '\012']
+let whitespace = [' ' '\010' '\013' '\009' '\012']
+let backslash_escapes = ['\\' '"' '\'' 'n' 't' 'b' 'r']
+
+rule main buf = parse
+ | newline { found_newline lexbuf 1; main buf lexbuf }
+ | space+ { main buf lexbuf }
+ | ';' [^ '\n' '\r']+ { main buf lexbuf }
+ | '(' { LPAREN }
+ | ')' { RPAREN }
+ | '"'
+ {
+ scan_string buf lexbuf;
+ let str = Buffer.contents buf in
+ Buffer.clear buf;
+ STRING str
+ }
+ | ([^ ';' '(' ')' '"'] # whitespace)+ as str { STRING str }
+ | eof { EOF }
+
+and scan_string buf = parse
+ | '"' { () }
+ | '\\' ['\010' '\013'] [' ' '\009']*
+ {
+ let len = get_lexeme_len lexbuf in
+ found_newline lexbuf (len - 2);
+ scan_string buf lexbuf
+ }
+ | '\\' "\013\010" [' ' '\009']*
+ {
+ let len = get_lexeme_len lexbuf in
+ found_newline lexbuf (len - 3);
+ scan_string buf lexbuf
+ }
+ | '\\' (backslash_escapes as c)
+ {
+ Buffer.add_char buf (char_for_backslash c);
+ scan_string buf lexbuf
+ }
+ | '\\' (['0'-'9'] as c1) (['0'-'9'] as c2) (['0'-'9'] as c3)
+ {
+ let v = dec_code c1 c2 c3 in
+ if v > 255 then (
+ let pos = lexbuf.lex_curr_p in
+ let msg =
+ sprintf
+ "Sexplib.Lexer.scan_string: \
+ illegal escape at line %d char %d: `\\%c%c%c'"
+ pos.pos_lnum (pos.pos_cnum - pos.pos_bol - 3)
+ c1 c2 c3 in
+ failwith msg);
+ Buffer.add_char buf (Char.chr v);
+ scan_string buf lexbuf
+ }
+ | '\\' 'x' (['0'-'9' 'a'-'f' 'A'-'F'] as c1) (['0'-'9' 'a'-'f' 'A'-'F'] as c2)
+ {
+ let v = hex_code c1 c2 in
+ if v > 255 then (
+ let pos = lexbuf.lex_curr_p in
+ let msg =
+ sprintf
+ "Sexplib.Lexer.scan_string: \
+ illegal escape at line %d char %d: `\\x%c%c'"
+ pos.pos_lnum (pos.pos_cnum - pos.pos_bol - 3)
+ c1 c2 in
+ failwith msg);
+ Buffer.add_char buf (Char.chr v);
+ scan_string buf lexbuf
+ }
+ | '\\' (_ as c)
+ {
+ Buffer.add_char buf '\\';
+ Buffer.add_char buf c;
+ scan_string buf lexbuf
+ }
+ | ['\010' '\013'] as c
+ {
+ found_newline lexbuf 1;
+ Buffer.add_char buf c;
+ scan_string buf lexbuf
+ }
+ | "\013\010"
+ {
+ found_newline lexbuf 2;
+ Buffer.add_string buf double_nl;
+ scan_string buf lexbuf
+ }
+ | [^ '\\' '"']+
+ {
+ let ofs = lexbuf.lex_start_pos in
+ let len = lexbuf.lex_curr_pos - ofs in
+ Buffer.add_substring buf lexbuf.lex_buffer ofs len;
+ scan_string buf lexbuf
+ }
+ | eof { failwith "Sexplib.Lexer.scan_string: unterminated string" }
+
+{
+ let main ?buf =
+ let buf =
+ match buf with
+ | None -> Buffer.create 64
+ | Some buf -> Buffer.clear buf; buf
+ in
+ main buf
+}
26 lib-sexp/license-tywith.txt
@@ -0,0 +1,26 @@
+---------------------------------------------------------------------------
+Copyright (c) 2004 Martin Sandin
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+---------------------------------------------------------------------------
520 lib-sexp/license.txt
@@ -0,0 +1,520 @@
+The Library is distributed under the terms of the GNU Lesser General
+Public License version 2.1 (included below).
+
+As a special exception to the GNU Lesser General Public License, you
+may link, statically or dynamically, a "work that uses the Library"
+with a publicly distributed version of the Library to produce an
+executable file containing portions of the Library, and distribute that
+executable file under terms of your choice, without any of the additional
+requirements listed in clause 6 of the GNU Lesser General Public License.
+By "a publicly distributed version of the Library", we mean either the
+unmodified Library as distributed by the authors, or a modified version
+of the Library that is distributed under the conditions defined in clause
+3 of the GNU Lesser General Public License. This exception does not
+however invalidate any other reasons why the executable file might be
+covered by the GNU Lesser General Public License.
+
+---------------------------------------------------------------------------
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
223 lib-sexp/modif-orig.txt
@@ -0,0 +1,223 @@
+I use in a different way sexplib. I don't like camlp4 but I like the
+metaprogramming facility it offers. So I've found a in-the-middle
+solution where I use camlp4 to generate code (via a small script
+I have written, not included here for the moment), save the generated code
+in a file (e.g commons/sexp_common.ml), which allows then to
+completely remove the dependency to camlp4. This means among
+other things that the file pa_sexp_conv.ml is not here, as
+I include here only the runtime library for sexp, not the
+camlp4 stuff. As I also didn't like their compilation process,
+with the need for findlib, -pack options, etc, I have rewritten a Makefile.
+
+-- pad
+
+Here are the modifications I've made to the sexplib lib/ directory.
+
+diff -u -p -b -B -r -x .semantic.cache -x .depend -x CVS -x .hg -x .svn -x .git -x _darcs -x *.cm[iao] -x *.[oa] -x *.class /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/ /home/pad/c-coccinelle/ocamlsexp
+Only in /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/: META
+diff -u -p -b -B -r -x .semantic.cache -x .depend -x CVS -x .hg -x .svn -x .git -x _darcs -x '*.cm[iao]' -x '*.[oa]' -x '*.class' /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/Makefile /home/pad/c-coccinelle/ocamlsexp/Makefile
+--- /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/Makefile 2009-03-09 19:52:09.000000000 -0500
++++ /home/pad/c-coccinelle/ocamlsexp/Makefile 2009-04-15 22:04:59.000000000 -0500
+@@ -1,36 +1,166 @@
+-OCAMLMAKEFILE = ../OCamlMakefile
++##############################################################################
++# Variables
++##############################################################################
+
+-SOURCES = \
++SRC= \
+ type.ml \
+- parser.mly \
+- lexer.mll \
++ parser.ml \
++ lexer.ml \
+ pre_sexp.ml \
+ sexp_intf.ml \
+- sexp.mli sexp.ml \
+- path.mli path.ml \
+- conv.mli conv.ml \
++ sexp.ml \
++ path.ml \
++ conv.ml \
+ conv_error.ml
+-LIB_PACK_NAME = sexplib
+-INCDIRS = +camlp4
+-OCAMLFLAGS = -for-pack Sexplib
+-PACKS = type-conv
+-RESULT = sexplib
+-
+-TRASH = pa_sexp_conv.cmi pa_sexp_conv.cmo pa_sexp_conv.annot
+-
+-all: \
+- pack-byte-code pack-native-code \
+- sexplib.cma sexplib.cmxa \
+- pa_sexp_conv.cmi pa_sexp_conv.cmo
+-
+-LIBINSTALL_FILES = \
+- sexp.mli path.mli conv.mli \
+- sexplib.cmi sexplib.cma sexplib.cmxa sexplib.a \
+- pa_sexp_conv.cmi pa_sexp_conv.cmo
++#SOURCES = \
++# parser.mly \
++# lexer.mll \
++# sexp.mli path.mli conv.mli
+
+-install: libinstall
+-uninstall: libuninstall
+
+-clean:: clean-doc
++TARGET=sexplib1
++TARGETPACK=sexplib
++#LIB_PACK_NAME = sexplib
+
+--include $(OCAMLMAKEFILE)
++##############################################################################
++# Generic variables
++##############################################################################
++
++INCLUDES=
++#-I +camlp4
++SYSLIBS= str.cma unix.cma bigarray.cma num.cma
++#INCDIRS = +camlp4
++#pad: take care for bigarray otherwise get some caml_ba_get_1 error msg
++
++##############################################################################
++#OCAMLFLAGS = -for-pack Sexplib
++
++#PACKS = type-conv
++#RESULT = sexplib
++
++#TRASH = pa_sexp_conv.cmi pa_sexp_conv.cmo pa_sexp_conv.annot
++
++#all: \
++# pack-byte-code pack-native-code \
++# sexplib.cma sexplib.cmxa \
++# pa_sexp_conv.cmi pa_sexp_conv.cmo
++#
++#LIBINSTALL_FILES = \
++# sexp.mli path.mli conv.mli \
++# sexplib.cmi sexplib.cma sexplib.cmxa sexplib.a \
++# pa_sexp_conv.cmi pa_sexp_conv.cmo
++#
++#install: libinstall
++#uninstall: libuninstall
++#
++#clean:: clean-doc
++#
++#-include $(OCAMLMAKEFILE)
++
++##############################################################################
++
++##############################################################################
++# Generic variables
++##############################################################################
++
++#dont use -custom, it makes the bytecode unportable.
++OCAMLCFLAGS= -g -dtypes # -w A
++#-for-pack Sexplib
++
++# This flag is also used in subdirectories so don't change its name here.
++OPTFLAGS=
++
++
++OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES) $(SYSINCLUDES) -thread
++OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES) $(SYSINCLUDES) -thread
++OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
++OCAMLYACC=ocamlyacc -v
++OCAMLDEP=ocamldep $(INCLUDES)
++OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES) -thread
++
++#-ccopt -static
++STATIC=
++
++
++##############################################################################
++# Top rules
++##############################################################################
++
++OBJS = $(SRC:.ml=.cmo)
++OPTOBJS = $(SRC:.ml=.cmx)
++
++all: $(TARGET).cma $(TARGETPACK).cmo
++all.opt: $(TARGET).cmxa
++
++$(TARGET).cma: $(OBJS)
++ $(OCAMLC) -a -o $(TARGET).cma $(OBJS)
++
++$(TARGET).cmxa: $(OPTOBJS) $(LIBS:.cma=.cmxa)
++ $(OCAMLOPT) -a -o $(TARGET).cmxa $(OPTOBJS)
++
++$(TARGET).top: $(OBJS) $(LIBS)
++ $(OCAMLMKTOP) -o $(TARGET).top $(SYSLIBS) $(LIBS) $(OBJS)
++
++clean::
++ rm -f $(TARGET).top
++
++
++
++$(TARGETPACK).cmo: $(OBJS)
++ $(OCAMLC) -pack -o $(TARGETPACK).cmo $(OBJS)
++
++# special handling, fun that they use cpp whereas they claim camplp4 can do everything
++pre_sexp.cmo: pre_sexp.ml
++ $(OCAMLC) -pp cpp -c $<
++
++pre_sexp.cmx: pre_sexp.ml
++ $(OCAMLOPT) -pp cpp -c $<
++
++
++
++lexer.ml: lexer.mll
++ $(OCAMLLEX) $<
++clean::
++ rm -f lexer.ml
++beforedepend:: lexer.ml
++
++
++parser.ml parser.mli: parser.mly
++ $(OCAMLYACC) $<
++clean::
++ rm -f parser.ml parser.mli parser.output
++beforedepend:: parser.ml parser.mli
++
++
++
++##############################################################################
++# Generic rules
++##############################################################################
++
++.SUFFIXES: .ml .mli .cmo .cmi .cmx
++
++.ml.cmo:
++ $(OCAMLC) -c $<
++.mli.cmi:
++ $(OCAMLC) -c $<
++.ml.cmx:
++ $(OCAMLOPT) -c $<
++
++.ml.mldepend:
++ $(OCAMLC) -i $<
++
++clean::
++ rm -f *.cm[ioxa] *.o *.a *.cmxa *.annot
++clean::
++ rm -f *~ .*~ gmon.out #*#
++
++beforedepend::
++
++# need also -pp cpp here
++depend:: beforedepend
++ $(OCAMLDEP) -pp cpp *.mli *.ml > .depend
++
++distclean:
++ rm -f .depend
++
++-include .depend
+Only in /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/: OMakefile
+Only in /home/pad/c-coccinelle/ocamlsexp: copyright.txt
+Only in /home/pad/c-coccinelle/ocamlsexp: license-tywith.txt
+Only in /home/pad/c-coccinelle/ocamlsexp: license.txt
+Only in /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/: pa_sexp_conv.ml
+Only in /home/pad/reference/dev-ocaml/orig/ocamljane-orig/sexplib310-3.7.4/lib/: pa_sexp_conv.mli
+
+Diff finished. Thu Apr 16 10:57:39 2009
75 lib-sexp/parser.mly
@@ -0,0 +1,75 @@
+%{
+ (* File: parser.mly
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *)
+
+ (** Parser: Grammar Specification for Parsing S-expressions *)
+
+ open Lexing
+
+ let parse_failure what =
+ let pos = symbol_start_pos () in
+ let msg =
+ Printf.sprintf "Sexplib.Parser: failed to parse line %d char %d: %s"
+ pos.pos_lnum (pos.pos_cnum - pos.pos_bol) what in
+ failwith msg
+%}
+
+%token <string> STRING
+%token LPAREN RPAREN EOF
+
+%start sexp
+%type <Type.t> sexp
+
+%start sexp_opt
+%type <Type.t option> sexp_opt
+
+%start sexps
+%type <Type.t list> sexps
+
+%start rev_sexps
+%type <Type.t list> rev_sexps
+
+%%
+
+sexp
+ : STRING { Type.Atom $1 }
+ | LPAREN RPAREN { Type.List [] }
+ | LPAREN rev_sexps_aux RPAREN { Type.List (List.rev $2) }
+ | error { parse_failure "sexp" }
+
+sexp_opt
+ : sexp { Some $1 }
+ | EOF { None }
+
+rev_sexps_aux
+ : sexp { [$1] }
+ | rev_sexps_aux sexp { $2 :: $1 }
+
+rev_sexps
+ : rev_sexps_aux { $1 }
+ | EOF { [] }
+
+sexps
+ : rev_sexps_aux { List.rev $1 }
+ | EOF { [] }
175 lib-sexp/path.ml
@@ -0,0 +1,175 @@
+(* File: path.ml
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl\@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*)
+
+(* Path: Module for Substitutions within S-expressions *)
+
+open Format
+
+open Sexp
+
+type el = Pos of int | Match of string * int | Rec of string
+type t = el list
+
+let illegal_atom loc sexp =
+ failwith (sprintf "Path.%s: illegal atom: %s" loc (Sexp.to_string sexp))
+
+let extract_pos_lst loc sexp ix lst =
+ let rec loop acc n = function
+ | [] ->
+ let sexp_str = Sexp.to_string sexp in
+ failwith (
+ sprintf "Path.%s: illegal index %d in: %s" loc ix sexp_str)
+ | h :: t ->
+ if n = 0 then
+ let subst = function
+ | None -> List.rev_append acc t
+ | Some x -> List.rev_append acc (x :: t) in
+ subst, h
+ else loop (h :: acc) (n - 1) t in
+ loop [] ix lst
+
+let extract_pos n = function
+ | List lst as sexp ->
+ let subst, el = extract_pos_lst "extract_pos" sexp n lst in
+ (fun x -> List (subst x)), el
+ | Atom _ as sexp -> illegal_atom "extract_pos" sexp
+
+let extract_match tag arg_ix = function
+ | List (Atom str as sexp :: args) when str = tag ->
+ let subst, el = extract_pos_lst "extract_match" (List args) arg_ix args in
+ (fun maybe_x -> List (sexp :: subst maybe_x)), el
+ | List _ as sexp ->
+ let sexp_str = Sexp.to_string sexp in
+ failwith ("Path.extract_match: unexpected nested list in: " ^ sexp_str)
+ | Atom _ as sexp -> illegal_atom "extract_match" sexp
+
+let extract_rec key = function
+ | List lst as sexp ->
+ let rec loop acc = function
+ | [] ->
+ let sexp_str = Sexp.to_string sexp in
+ failwith (
+ sprintf "Path.extract_rec: key \"%s\" not found in: %s"
+ key sexp_str)
+ | List [Atom str as sexp; v] :: rest when str = key ->
+ let subst x = List (List.rev_append acc (List [sexp; x] :: rest)) in
+ subst, v
+ | h :: t -> loop (h :: acc) t in
+ loop [] lst
+ | Atom _ as sexp -> illegal_atom "extract_rec" sexp
+
+let id x = x
+
+let rec subst_option (sup_subst, el) rest =
+ let sub_subst, sub_el = subst_path el rest in
+ let subst x = sup_subst (Some (sub_subst x)) in
+ subst, sub_el
+
+and subst_path sexp = function
+ | Pos n :: t -> subst_option (extract_pos n sexp) t
+ | Match (tag, arg_ix) :: t -> subst_option (extract_match tag arg_ix sexp) t
+ | Rec key :: rest ->
+ let rec_subst, el = extract_rec key sexp in
+ let sub_subst, sub_el = subst_path el rest in
+ let subst x = rec_subst (sub_subst x) in
+ subst, sub_el
+ | [] -> id, sexp
+
+let implode lst =
+ let len = List.length lst in
+ let str = String.create len in
+ let rec loop ix = function
+ | h :: t -> str.[ix] <- h; loop (ix + 1) t
+ | [] -> str in
+ loop 0 lst
+
+let fail_parse msg = failwith ("Path.parse: " ^ msg)
+
+let parse str =
+ let len = String.length str in
+ if len = 0 then fail_parse "path empty"
+ else
+ let rec loop acc dot_ix =
+ match str.[dot_ix] with
+ | '.' ->
+ let dot_ix1 = dot_ix + 1 in
+ if dot_ix1 = len then List.rev acc
+ else
+ let rec parse_dot acc str_acc ix =
+ if ix = len then
+ List.rev_append acc [Rec (implode (List.rev str_acc))]
+ else
+ match str.[ix] with
+ | '[' ->
+ let rec parse_index index_acc ix =
+ if ix = len then fail_parse "EOF reading index"
+ else
+ match str.[ix], index_acc with
+ | '0'..'9' as c, None ->
+ parse_index (Some (int_of_char c - 48)) (ix + 1)
+ | '0'..'9' as c, Some index_acc ->
+ let new_index_acc =
+ Some (10 * index_acc + int_of_char c - 48) in
+ parse_index new_index_acc (ix + 1)
+ | ']', None -> fail_parse "empty index"
+ | ']', Some index_acc ->
+ let path_el =
+ if str_acc = [] then Pos index_acc
+ else
+ Match (implode (List.rev str_acc), index_acc) in
+ let ix1 = ix + 1 in
+ if ix1 = len then List.rev_append acc [path_el]
+ else loop (path_el :: acc) ix1
+ | c, _ ->
+ fail_parse (
+ sprintf "illegal character in index: %c" c) in
+ parse_index None (ix + 1)
+ | '\\' ->
+ let ix1 = ix + 1 in
+ if ix1 = len then fail_parse "EOF after escape"
+ else parse_dot acc (str.[ix1] :: str_acc) (ix + 1)
+ | '.' ->
+ if str_acc = [] then fail_parse "double '.'";
+ let path_el = Rec (implode (List.rev str_acc)) in
+ parse_dot (path_el :: acc) [] (ix + 1)
+ | c -> parse_dot acc (c :: str_acc) (ix + 1) in
+ parse_dot acc [] dot_ix1
+ | c -> fail_parse (sprintf "'.' expected; got '%c'" c) in
+ loop [] 0
+
+let get_subst path str sexp =
+ let path =
+ match path, str with
+ | Some path, _ -> path
+ | None, Some str -> parse str
+ | None, None -> [] in
+ subst_path sexp path
+
+let get ?path ?str sexp = snd (get_subst path str sexp)
+
+let replace ?path ?str sexp ~subst =
+ let subst_fun, _ = get_subst path str sexp in
+ subst_fun subst
+
+let replace_no_path ~str sexp ~subst = replace ~str sexp ~subst
116 lib-sexp/path.mli
@@ -0,0 +1,116 @@
+(* File: path.mli
+
+ Copyright (C) 2005-
+
+ Jane Street Holding, LLC
+ Author: Markus Mottl
+ email: mmottl\@janestcapital.com
+ WWW: http://www.janestcapital.com/ocaml
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+