[Pkg-ocaml-maint-commits] [atdgen] 01/09: Imported Upstream version 1.8.0

Stéphane Glondu glondu at moszumanska.debian.org
Thu Aug 4 09:37:58 UTC 2016


This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository atdgen.

commit 2bb1730df2cb9b163ddb1b46dd804b6ef0a80834
Author: Stephane Glondu <steph at glondu.net>
Date:   Thu Aug 4 11:14:45 2016 +0200

    Imported Upstream version 1.8.0
---
 Makefile                |  6 ++++
 atdgen-cppo/LICENSE     | 24 +++++++++++++++
 atdgen-cppo/Makefile    | 38 +++++++++++++++++++++++
 atdgen-cppo/README.md   | 81 +++++++++++++++++++++++++++++++++++++++++++++++++
 atdgen-cppo/atdgen-cppo | 74 ++++++++++++++++++++++++++++++++++++++++++++
 atdgen-cppo/cppo-json   | 56 ++++++++++++++++++++++++++++++++++
 atdgen-cppo/example.ml  |  5 +++
 atdgen.install          |  2 ++
 src/Makefile            |  2 +-
 9 files changed, 287 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index fde626b..76ad3ee 100644
--- a/Makefile
+++ b/Makefile
@@ -27,18 +27,23 @@ findlib-uninstall:
 .PHONY: exe-install exe-uninstall
 exe-install:
 	$(MAKE) -C src exe-install
+	$(MAKE) -C atdgen-cppo exe-install
 
 exe-uninstall:
 	$(MAKE) -C src exe-uninstall
+	$(MAKE) -C atdgen-cppo exe-uninstall
 
 install:
 	$(MAKE) -C src install
+	$(MAKE) -C atdgen-cppo install
 
 uninstall:
 	$(MAKE) -C src uninstall
+	$(MAKE) -C atdgen-cppo uninstall
 
 reinstall:
 	$(MAKE) -C src reinstall
+	$(MAKE) -C atdgen-cppo reinstall
 
 test:
 	$(MAKE) -C test
@@ -50,3 +55,4 @@ clean:
 	rm -f *~ util/*~ example/*~
 	$(MAKE) -C src clean
 	$(MAKE) -C test clean
+	$(MAKE) -C atdgen-cppo clean
diff --git a/atdgen-cppo/LICENSE b/atdgen-cppo/LICENSE
new file mode 100644
index 0000000..93b62ab
--- /dev/null
+++ b/atdgen-cppo/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2011-2012 Martin Jambon
+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.
diff --git a/atdgen-cppo/Makefile b/atdgen-cppo/Makefile
new file mode 100644
index 0000000..22940ac
--- /dev/null
+++ b/atdgen-cppo/Makefile
@@ -0,0 +1,38 @@
+ifndef PREFIX
+  PREFIX = $(shell dirname $$(dirname $$(which ocamlfind)))
+  export PREFIX
+endif
+
+ifndef BINDIR
+  BINDIR = $(PREFIX)/bin
+  export BINDIR
+endif
+
+.PHONY: default demo clean install uninstall reinstall
+.PHONY: exe-install exe-uninstall
+
+default: demo
+
+demo:
+	@echo "--- Demo ---"
+	ocamlfind opt -o example \
+          -pp cppo-json \
+          -package atdgen -linkpkg \
+          example.ml
+	./example
+
+exe-install:
+	cp atdgen-cppo cppo-json "$(BINDIR)"
+
+exe-uninstall:
+	rm -f "$(BINDIR)"/atdgen-cppo "$(BINDIR)"/cppo-json
+
+install: exe-install
+uninstall: exe-uninstall
+
+reinstall:
+	$(MAKE) uninstall BINDIR="$(BINDIR)"
+	$(MAKE) install BINDIR="$(BINDIR)"
+
+clean:
+	rm -f *.cm[iox] *.o *~ example
diff --git a/atdgen-cppo/README.md b/atdgen-cppo/README.md
new file mode 100644
index 0000000..1fb6790
--- /dev/null
+++ b/atdgen-cppo/README.md
@@ -0,0 +1,81 @@
+`cppo-json` is a preprocessor that replaces embedded type definition 
+directives with OCaml type definitions and JSON
+serialization/deserialization code.
+
+`atdgen-cppo` is the script that reads type definitions from stdin and
+generates OCaml code. It takes options allowing users to pick what
+kind of code needs to be generated (type definitions, JSON
+serialization, Biniou serialization, validators).
+
+Example
+-------
+
+Sample input:
+
+```
+$ cat example.ml
+#ext json
+type mytype = string list
+#endext
+let data = [ "Hello"; "world" ]
+let () = print_endline (J.string_of_mytype data)
+```
+
+How to view the OCaml code produced by cppo-json:
+
+```
+$ cppo-json < example.ml | less
+```
+
+How to compile an OCaml program:
+
+```
+$ ocamlfind opt -o example \
+    -pp cppo-json \
+    -package atdgen -linkpkg \
+    example.ml
+```
+
+cppo-json ships with atdgen-cppo and is shorthand for the following command:
+
+```
+cppo -x "json:atdgen-cppo t j v"
+```
+
+where `t` stands for "type definitions", `j` stands for "JSON", and
+`v` stands for "validators".
+
+See also:
+```
+$ cppo-json --help
+$ atdgen-cppo --help
+$ cppo --help
+```
+
+
+Documentation
+-------------
+
+Documentation is provided by the `--help` option of each command.
+
+Direct dependencies
+-------------------
+
+* [atdgen](https://github.com/MyLifeLabs/atdgen)
+* [cppo](https://github.com/mjambon/cppo)
+
+Installation
+------------
+
+It's just two shell scripts. You can copy them by hand to the
+directory of your choice or run:
+
+```
+$ make install   # installs into $HOME/bin
+```
+
+or
+
+```
+$ BINDIR=/path/to/bin make install
+```
diff --git a/atdgen-cppo/atdgen-cppo b/atdgen-cppo/atdgen-cppo
new file mode 100755
index 0000000..808f76e
--- /dev/null
+++ b/atdgen-cppo/atdgen-cppo
@@ -0,0 +1,74 @@
+#! /bin/sh -e
+version=1.0.0
+
+self="$0"
+usage () {
+    echo "\
+Usage: $self [t] [b] [j] [v]
+
+atdgen-cppo makes it possible to use atdgen to derive code from ATD 
+type definitions embedded in OCaml source files rather than in
+separate .atd files. This is similar to how json-static is used,
+except that the preprocessor is not camlp4 but the simpler program cppo.
+
+Modes:
+  t  produce a module T containing OCaml type definitions translated from ATD
+  b  produce a module B containing OCaml code for biniou serialization
+  j  produce a module J containing OCaml code JSON serialization
+  v  produce a module V containing OCaml code for validation
+
+Typical usage:
+
+  \$ cat example.ml
+  #ext json
+  type mytype = string list
+  #endext
+  let data = [ \"Hello\"; \"world\" ]
+  let () = print_endline (J.string_of_mytype data)
+
+  \$ ocamlfind opt -o example \\
+    -pp 'cppo -x \"json:$self t j\"' \\
+    -package atdgen -linkpkg example.ml
+
+  \$ ./example
+  [\"Hello\",\"world\"]
+" >&2
+}
+
+case "$1" in
+    -h|-help|--help) usage; exit 0 ;;
+    *) ;;
+esac
+
+tmp=$(tempfile -p ml- -s -atdgen-cppo.ml)
+cat > $tmp
+
+fail () {
+    rm -f $tmp
+    exit 1
+}
+
+# CPPO_FIRST_LINE is off by one in cppo 0.9.1.
+# Should be fixed in cppo rather than here.
+gen () {
+    echo "module $1 = ("
+    atdgen \
+      -pos-fname "$CPPO_FILE" \
+      -pos-lnum $(( $CPPO_FIRST_LINE + 1 )) \
+      -$2 < $tmp || fail
+    echo ")"
+}
+
+while [ $# != 0 ]; do
+    case "$1" in
+        t) gen T t ;;
+        b) gen B b ;;
+        j) gen J j ;;
+        v) gen V v ;;
+        --help|-help) usage; exit 0 ;;
+        *) usage; exit 2
+    esac
+    shift
+done
+
+rm -f $tmp
diff --git a/atdgen-cppo/cppo-json b/atdgen-cppo/cppo-json
new file mode 100755
index 0000000..c2b54d4
--- /dev/null
+++ b/atdgen-cppo/cppo-json
@@ -0,0 +1,56 @@
+#! /bin/sh
+
+usage () {
+    echo "\
+Usage: cppo-json [cppo arguments]
+
+cppo-json processes an OCaml file written with embedded type definitions
+directives and replaces them by OCaml type definitions and JSON
+serialization/deserialization code.
+
+Sample input:
+
+  \$ cat example.ml
+  #ext json
+  type mytype = string list
+  #endext
+  let data = [ \"Hello\"; \"world\" ]
+  let () = print_endline (J.string_of_mytype data)
+
+How to view the OCaml code produced by cppo-json:
+
+  \$ cppo-json < example.ml | less
+
+How to compile an OCaml program:
+
+  \$ ocamlfind opt -o example \\
+      -pp cppo-json \\
+      -package atdgen -linkpkg \\
+      example.ml
+
+cppo-json ships with atdgen-cppo and is shorthand for the following command:
+
+  cppo -x \"json:atdgen-cppo t j v\"
+
+where 't' stands for 'type definitions', 'j' stands for 'JSON', and
+'v' stands for \"validators\".
+
+See also:
+  atdgen-cppo --help
+  cppo --help
+" >&2
+}
+
+case "$1" in
+    --help|-help) usage; exit 0 ;;
+    *)
+esac
+
+cppo -x "json:atdgen-cppo t j v" "$@"
+
+case $? in
+    0) ;;
+    *)
+        echo "cppo-json failed" >&2
+        exit 2
+esac
diff --git a/atdgen-cppo/example.ml b/atdgen-cppo/example.ml
new file mode 100644
index 0000000..3e1238a
--- /dev/null
+++ b/atdgen-cppo/example.ml
@@ -0,0 +1,5 @@
+#ext json
+type mytype = string list
+#endext
+let data = [ "Hello"; "world" ]
+let () = print_endline (J.string_of_mytype data)
diff --git a/atdgen.install b/atdgen.install
index 1cc261b..1f5dc8c 100644
--- a/atdgen.install
+++ b/atdgen.install
@@ -1,4 +1,6 @@
 bin: [
   "src/atdgen.run"
   "src/atdgen"
+  "atdgen-cppo/atdgen-cppo"
+  "atdgen-cppo/cppo-json"
 ]
diff --git a/src/Makefile b/src/Makefile
index a067942..1daea7f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,4 +1,4 @@
-VERSION = 1.7.2
+VERSION = 1.8.0
 ifeq "$(shell ocamlc -config |grep os_type)" "os_type: Win32"
 EXE=.exe
 else

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/atdgen.git



More information about the Pkg-ocaml-maint-commits mailing list