Initial import.

This commit is contained in:
Jerry James 2020-09-14 14:48:28 -06:00
parent 2bc55eefcf
commit b146a8b0b9
4 changed files with 269 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/csexp-*.tbz

92
ocaml-csexp-result.patch Normal file
View File

@ -0,0 +1,92 @@
--- a/csexp.opam
+++ b/csexp.opam
@@ -33,7 +33,6 @@ depends: [
"dune" {>= "2.5"}
"ocaml" {>= "4.02.3"}
"ppx_expect" {with-test}
- "result" {>= "1.5"}
]
build: [
["dune" "subst"] {pinned}
--- a/src/csexp.ml
+++ b/src/csexp.ml
@@ -15,12 +15,6 @@ end
module Make (Sexp : Sexp) = struct
open Sexp
- (* This is to keep compatibility with 4.02 without writing [Result.]
- everywhere *)
- type ('a, 'b) result = ('a, 'b) Result.result =
- | Ok of 'a
- | Error of 'b
-
module Parser = struct
exception Parse_error of string
@@ -283,9 +277,9 @@ module Make (Sexp : Sexp) = struct
module Monad : Monad
- val read_string : t -> int -> (string, string) Result.t Monad.t
+ val read_string : t -> int -> (string, string) result Monad.t
- val read_char : t -> (char, string) Result.t Monad.t
+ val read_char : t -> (char, string) result Monad.t
end
module Make_parser (Input : Input) = struct
--- a/src/csexp.mli
+++ b/src/csexp.mli
@@ -33,24 +33,24 @@ module Make (Sexp : Sexp) : sig
[s]. It is an error for [s] to contain a S-expression followed by more
data. In case of error, the offset of the error as well as an error
message is returned. *)
- val parse_string : string -> (Sexp.t, int * string) Result.t
+ val parse_string : string -> (Sexp.t, int * string) result
(** [parse_string s] parses a sequence of S-expressions encoded in canonical
form in [s] *)
- val parse_string_many : string -> (Sexp.t list, int * string) Result.t
+ val parse_string_many : string -> (Sexp.t list, int * string) result
(** Read exactly one canonical S-expressions from the given channel. Note that
this function never raises [End_of_file]. Instead, it returns [Error]. *)
- val input : in_channel -> (Sexp.t, string) Result.t
+ val input : in_channel -> (Sexp.t, string) result
(** Same as [input] but returns [Ok None] if the end of file has already been
reached. If some more characters are available but the end of file is
reached before reading a complete S-expression, this function returns
[Error]. *)
- val input_opt : in_channel -> (Sexp.t option, string) Result.t
+ val input_opt : in_channel -> (Sexp.t option, string) result
(** Read many S-expressions until the end of input is reached. *)
- val input_many : in_channel -> (Sexp.t list, string) Result.t
+ val input_many : in_channel -> (Sexp.t list, string) result
(** {2 Serialising} *)
@@ -352,18 +352,18 @@ module Make (Sexp : Sexp) : sig
val bind : 'a t -> ('a -> 'b t) -> 'b t
end
- val read_string : t -> int -> (string, string) Result.t Monad.t
+ val read_string : t -> int -> (string, string) result Monad.t
- val read_char : t -> (char, string) Result.t Monad.t
+ val read_char : t -> (char, string) result Monad.t
end
[@@deprecated "Use Parser module instead"]
[@@@warning "-3"]
module Make_parser (Input : Input) : sig
- val parse : Input.t -> (Sexp.t, string) Result.t Input.Monad.t
+ val parse : Input.t -> (Sexp.t, string) result Input.Monad.t
- val parse_many : Input.t -> (Sexp.t list, string) Result.t Input.Monad.t
+ val parse_many : Input.t -> (Sexp.t list, string) result Input.Monad.t
end
[@@deprecated "Use Parser module instead"]
end

175
ocaml-csexp.spec Normal file
View File

@ -0,0 +1,175 @@
%ifnarch %{ocaml_native_compiler}
%global debug_package %{nil}
%endif
%global srcname csexp
# This package is needed to build dune. To avoid circular dependencies, this
# package cannot depend on dune, or any package that depends on dune.
# Therefore, we:
# - hack up our own build, rather than using dune to do the build
# - bypass the need for ocaml-result (which requires dune to build)
# - skip tests, which require ppx_expect, which is built with dune
# - skip building documentation, which requires odoc, which is built with dune
# If you know what you are doing, build with dune anyway using this conditional.
%bcond_with dune
Name: ocaml-%{srcname}
Version: 1.3.1
Release: 1%{?dist}
Summary: Parsing and printing of S-expressions in canonical form
License: MIT
URL: https://github.com/ocaml-dune/csexp
Source0: %{url}/releases/download/%{version}/%{srcname}-%{version}.tbz
# Depend on Stdlib.Result instead of ocaml-result. See comment above.
# This patch is not appropriate for upstream, which needs to keep compatibility
# with older OCaml versions.
Patch0: %{name}-result.patch
BuildRequires: ocaml >= 4.02.3
%if %{with dune}
BuildRequires: ocaml-dune
BuildRequires: ocaml-odoc
BuildRequires: ocaml-result-devel
%endif
%description
This project provides minimal support for parsing and printing
S-expressions in canonical form, which is a very simple and canonical
binary encoding of S-expressions.
%package devel
Summary: Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
%if %{with dune}
Requires: ocaml-result-devel%{?_isa}
%endif
%description devel
The %{name}-devel package contains libraries and signature files for
developing applications that use %{name}.
%prep
%autosetup -N -n %{srcname}-%{version}
%if %{without dune}
%autopatch -p1
%endif
%build
%if %{with dune}
dune build %{?_smp_mflags} --display=verbose @install
dune build %{?_smp_mflags} @doc
%else
OFLAGS="-strict-sequence -strict-formats -short-paths -keep-locs -g -opaque"
OCFLAGS="$OFLAGS -bin-annot"
cd src
ocamlc $OCFLAGS -output-obj csexp.mli
ocamlc $OCFLAGS -a -o csexp.cma csexp.ml
%ifarch %{ocaml_native_compiler}
ocamlopt $OFLAGS -ccopt "%{optflags}" -cclib "$RPM_LD_FLAGS" -a \
-o csexp.cmxa csexp.ml
ocamlopt $OFLAGS -ccopt "%{optflags}" -cclib "$RPM_LD_FLAGS" -shared \
-o csexp.cmxs csexp.ml
%endif
cd -
%endif
%install
%if %{with dune}
dune install --destdir=%{buildroot}
# We do not want the dune markers
find _build/default/_doc/_html -name .dune-keep -delete
# We do not want the ml files
find %{buildroot}%{_libdir}/ocaml -name \*.ml -delete
# We install the documentation with the doc macro
rm -fr %{buildroot}%{_prefix}/doc
%ifarch %{ocaml_native_compiler}
# Add missing executable bits
find %{buildroot}%{_libdir}/ocaml -name \*.cmxs -exec chmod a+x {} \+
%endif
%else
# Install without dune. See comment at the top.
mkdir -p %{buildroot}%{_libdir}/ocaml/%{srcname}
cp -p src/csexp.{cma,cmi,cmt,cmti,mli} %{buildroot}%{_libdir}/ocaml/%{srcname}
%ifarch %{ocaml_native_compiler}
cp -p src/csexp.{a,cmx,cmxa,cmxs} %{buildroot}%{_libdir}/ocaml/%{srcname}
%endif
cp -p csexp.opam %{buildroot}%{_libdir}/ocaml/%{srcname}/opam
cat >> %{buildroot}%{_libdir}/ocaml/%{srcname}/META << EOF
version = "%{version}"
description = "Parsing and printing of S-expressions in canonical form"
archive(byte) = "csexp.cma"
%ifarch %{ocaml_native_compiler}
archive(native) = "csexp.cmxa"
%endif
plugin(byte) = "csexp.cma"
%ifarch %{ocaml_native_compiler}
plugin(native) = "csexp.cmxs"
%endif
EOF
cat >> %{buildroot}%{_libdir}/ocaml/%{srcname}/dune-package << EOF
(lang dune 2.5)
(name csexp)
(version %{version})
(library
(name csexp)
(kind normal)
%ifarch %{ocaml_native_compiler}
(archives (byte csexp.cma) (native csexp.cmxa))
(plugins (byte csexp.cma) (native csexp.cmxs))
(native_archives csexp.a)
%else
(archives (byte csexp.cma))
(plugins (byte csexp.cma))
%endif
(main_module_name Csexp)
%ifarch %{ocaml_native_compiler}
(modes byte native)
%else
(modes byte)
%endif
(modules
(singleton (name Csexp) (obj_name csexp) (visibility public) (impl) (intf))))
EOF
%endif
# Cannot do this until ocaml-ppx-expect is available in Fedora.
#%%if %%{with dune}
#%%check
#dune runtest
#%%endif
%files
%doc README.md
%license LICENSE.md
%dir %{_libdir}/ocaml/%{srcname}/
%{_libdir}/ocaml/%{srcname}/META
%{_libdir}/ocaml/%{srcname}/*.cma
%{_libdir}/ocaml/%{srcname}/*.cmi
%ifarch %{ocaml_native_compiler}
%{_libdir}/ocaml/%{srcname}/*.cmxs
%endif
%files devel
%{_libdir}/ocaml/%{srcname}/dune-package
%{_libdir}/ocaml/%{srcname}/opam
%ifarch %{ocaml_native_compiler}
%{_libdir}/ocaml/%{srcname}/*.a
%{_libdir}/ocaml/%{srcname}/*.cmx
%{_libdir}/ocaml/%{srcname}/*.cmxa
%endif
%{_libdir}/ocaml/%{srcname}/*.cmt
%{_libdir}/ocaml/%{srcname}/*.cmti
%{_libdir}/ocaml/%{srcname}/*.mli
%changelog
* Thu Sep 10 2020 Jerry James <loganjerry@gmail.com> - 1.3.1-1
- Initial RPM

1
sources Normal file
View File

@ -0,0 +1 @@
SHA512 (csexp-1.3.1.tbz) = dd6b3894529c828926ee05070548125822ad3bee8324623de0188d49655439286343f8cbc2ede8a27e01af5715e3bc1e643d6a0d770061b384d6dcefdb545eb2