This is an automated email from the git hooks/post-receive script. glondu pushed a commit to branch master in repository cppo.
commit d69ac0be02a3e7b74ee5ace8ec81b92d197eeef4 Author: Stephane Glondu <st...@glondu.net> Date: Fri Jul 14 13:59:01 2017 +0200 New upstream version 1.5.0 --- Makefile | 8 +++++++- README.md | 18 ++++++++++++++++++ cppo_eval.ml | 29 +++++++++++++++++++++++++++-- cppo_types.ml | 1 + opam | 6 +++--- test/Makefile | 5 ++++- test/capital.cppo | 6 ++++++ test/capital.ref | 6 ++++++ 8 files changed, 72 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index d7b57c0..84218d4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 1.4.1 +VERSION = 1.5.0 ifeq "$(shell ocamlc -config |grep os_type)" "os_type: Win32" EXE=.exe @@ -45,6 +45,7 @@ endif endif OCAMLBUILD_INSTALL = ocamlbuild_plugin/_build/ocamlbuild_cppo.cmi \ + ocamlbuild_plugin/_build/ocamlbuild_cppo.cmx \ $(addprefix ocamlbuild_plugin/_build/,$(OCAMLBUILD_IMPL)) @@ -83,6 +84,11 @@ install-lib: ocamlfind install -patch-version ${VERSION} "cppo_ocamlbuild" \ META $(OCAMLBUILD_INSTALL) +uninstall-lib: + ocamlfind remove cppo_ocamlbuild + +reinstall-lib: uninstall-lib install-lib + cppo_version.ml: Makefile echo 'let cppo_version = "$(VERSION)"' > cppo_version.ml diff --git a/README.md b/README.md index 1c419f9..1bf57ef 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,24 @@ because 123z does not form a valid identifier. `CONCAT(a,b)` is roughly equivalent to `a##b` in cpp syntax. +CAPITALIZE +--------------- + +`CAPITALIZE()` is a predefined macro that takes one argument, +removes any leading and trailing whitespace, reduces each internal +whitespace sequence to a single space character and produces +a valid OCaml identifer with first character. + +For example, +```ocaml +#define EVENT(n,ty) external CONCAT(on,CAPITALIZE(n)) : ty = STRINGIFY(n) [@@bs.val] +EVENT(exit, unit -> unit) +``` +is expanded into: + +```ocaml +external onExit : unit -> unit = "exit" [@@bs.val] +``` Stringification --------------- diff --git a/cppo_eval.ml b/cppo_eval.ml index 0f077a8..a5d97ac 100644 --- a/cppo_eval.ml +++ b/cppo_eval.ml @@ -23,6 +23,13 @@ let builtins = [ `Ident (dummy_loc, "y", None))], env) ); + "CAPITALIZE", (fun env -> + `Defun (dummy_loc, "CAPITALIZE", + ["x"], + [`Capitalize (`Ident (dummy_loc, "x", None))], + env) + ); + ] let is_reserved s = @@ -84,7 +91,11 @@ let trim_and_compact_string s = let buf = Buffer.create (String.length s) in trim_and_compact buf s; Buffer.contents buf - +let trim_compact_and_capitalize_string s = + let buf = Buffer.create (String.length s) in + trim_and_compact buf s; + String.capitalize (Buffer.contents buf) + let is_ident s = let len = String.length s in len > 0 @@ -442,7 +453,7 @@ let rec include_file g loc rel_file env = and expand_list ?(top = false) g env l = List.fold_left (expand_node ~top g) env l -and expand_node ?(top = false) g env0 x = +and expand_node ?(top = false) g env0 (x : node) = match x with `Ident (loc, name, opt_args) -> @@ -610,6 +621,20 @@ and expand_node ?(top = false) g env0 x = g.enable_loc := enable_loc0; env0 + | `Capitalize (x : node) -> + let enable_loc0 = !(g.enable_loc) in + g.enable_loc := false; + let buf0 = g.buf in + let local_buf = Buffer.create 100 in + g.buf <- local_buf; + ignore (expand_node g env0 x); + let xs = Buffer.contents local_buf in + let s = trim_compact_and_capitalize_string xs in + (* stringify buf0 (Buffer.contents local_buf); *) + Buffer.add_string buf0 s ; + g.buf <- buf0; + g.enable_loc := enable_loc0; + env0 | `Concat (x, y) -> let enable_loc0 = !(g.enable_loc) in g.enable_loc := false; diff --git a/cppo_types.ml b/cppo_types.ml index a31529f..0dd7e34 100644 --- a/cppo_types.ml +++ b/cppo_types.ml @@ -58,6 +58,7 @@ and node = | `Text of (loc * bool * string) (* bool is true for space tokens *) | `Seq of node list | `Stringify of node + | `Capitalize of node | `Concat of (node * node) | `Line of (loc * string option * int) | `Current_line of loc diff --git a/opam b/opam index 9d13df5..632cc19 100644 --- a/opam +++ b/opam @@ -6,8 +6,8 @@ dev-repo: "https://github.com/mjambon/cppo.git" bug-reports: "https://github.com/mjambon/cppo/issues" license: "BSD-3-Clause" build: [ - [make "all"] {!ocaml_native} - [make "opt"] {ocaml_native} + [make "all"] {!ocaml-native} + [make "opt"] {ocaml-native} [make "ocamlbuild"] ] @@ -16,7 +16,7 @@ install: [ ] remove: [ - ["ocamlfind" "remove" "cppo_ocamlbuild"] + ["make" "uninstall-lib"] ] depends: [ diff --git a/test/Makefile b/test/Makefile index f56c27f..f5f4de5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,4 @@ -TESTS = ext comments cond tuple paren_arg unmatched version +TESTS = ext comments cond tuple paren_arg unmatched version capital .PHONY: all clean $(TESTS) all: $(TESTS) @@ -36,5 +36,8 @@ unmatched: version: ../cppo -V X:123.05.2-alpha.1+foo-2.1 version.cppo > version.out +capital: + ../cppo $@.cppo > $@.out + diff -u $@.ref $@.out clean: rm -f *~ *.out diff --git a/test/capital.cppo b/test/capital.cppo new file mode 100644 index 0000000..fa85caa --- /dev/null +++ b/test/capital.cppo @@ -0,0 +1,6 @@ + + +#define EVENT(n,ty) external CONCAT(on,CAPITALIZE(n)) : ty = STRINGIFY(n) [@@bs.val] + + +EVENT(exit, unit -> unit) \ No newline at end of file diff --git a/test/capital.ref b/test/capital.ref new file mode 100644 index 0000000..adcc26e --- /dev/null +++ b/test/capital.ref @@ -0,0 +1,6 @@ + + + + +# 6 "capital.cppo" + external onExit : unit -> unit = "exit" [@@bs.val] \ No newline at end of file -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/cppo.git _______________________________________________ Pkg-ocaml-maint-commits mailing list Pkg-ocaml-maint-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits