Skip to content

Instantly share code, notes, and snippets.

@j0sh
Created March 2, 2016 20:43
Show Gist options
  • Select an option

  • Save j0sh/8d6504d11070d842a8dd to your computer and use it in GitHub Desktop.

Select an option

Save j0sh/8d6504d11070d842a8dd to your computer and use it in GitHub Desktop.
diff --git a/_oasis b/_oasis
index 5dcf0cc..bd22d8f 100644
--- a/_oasis
+++ b/_oasis
@@ -1,6 +1,7 @@
OASISFormat: 0.3
Name: ocaml-sqlexpr
Version: 0.7.0
+OcamlVersion: >= 4.02
Synopsis: Type-safe, convenient SQLite database access.
Authors: Mauricio Fernandez <mfp@acm.org>
Maintainers: Mauricio Fernandez <mfp@acm.org>
@@ -62,7 +63,7 @@ Library "ppx"
Executable "ppx_sqlexpr"
Path: src/ppx/
MainIs: ppx_sqlexpr.ml
- BuildDepends: unix, re.pcre, compiler-libs.common, ppx_tools.metaquot
+ BuildDepends: unix, re.pcre, compiler-libs.common, ppx_tools.metaquot, ppx_core, ppx_driver
CompiledObject: best
Install: true
+<**/*.ml{,i}>: predicate(ppx_driver)
# OASIS_START
-# DO NOT EDIT (digest: 8c33eb34542ae662c8d9b52b2978ec0d)
+# DO NOT EDIT (digest: b3462a1e21bb04b8d345bbf3a07bf8fc)
# Ignore VCS directories, you can use the same kind of rule outside
# OASIS_START/STOP if you want to exclude directories that contains
# useless stuff for the build process
@@ -16,53 +17,57 @@ true: annot, bin_annot
"_darcs": not_hygienic
# Library sqlexpr
"src/sqlexpr.cmxs": use_sqlexpr
-<src/*.ml{,i,y}>: pkg_csv
-<src/*.ml{,i,y}>: pkg_estring
-<src/*.ml{,i,y}>: pkg_lwt
-<src/*.ml{,i,y}>: pkg_lwt.syntax
-<src/*.ml{,i,y}>: pkg_lwt.unix
-<src/*.ml{,i,y}>: pkg_sqlite3
-<src/*.ml{,i,y}>: pkg_threads
-<src/*.ml{,i,y}>: pkg_unix
+<src/*.ml{,i,y}>: package(csv)
+<src/*.ml{,i,y}>: package(estring)
....
diff --git a/src/ppx/ppx_sqlexpr.ml b/src/ppx/ppx_sqlexpr.ml
index 89ae40a..763681f 100644
--- a/src/ppx/ppx_sqlexpr.ml
+++ b/src/ppx/ppx_sqlexpr.ml
@@ -4,6 +4,9 @@ open Parsetree
module AC = Ast_convenience
+open Ppx_core.Std
+open Ast_builder.Default
+
let new_id =
let n = ref 0 in
fun () ->
@@ -127,6 +130,12 @@ let call_sqlcheck loc = function
let shared_exprs = Hashtbl.create 25
+let shared_expr_id = function
+ | Pexp_ident {txt} ->
+ let id = Longident.last txt in
+ if Hashtbl.mem shared_exprs id then Some id else None
+ | _ -> None
+
let register_shared_expr expr =
let id = new_id () in
Hashtbl.add shared_exprs id expr;
@@ -155,6 +164,16 @@ let map_expr mapper expr =
Longident.last txt | _ -> raise Not_found end in
[%expr let [%p AC.pvar id] = [%e get_shared_expr id] in [%e expr]]
+let shared_bindings = object
+ inherit [string list] Ast_traverse.fold as super
+
+ method! expression e acc =
+ let acc = super#expression e acc in
+ match shared_expr_id e.pexp_desc with
+ | Some id -> id::acc
+ | None -> acc
+end
+
let new_mapper argv = Ast_mapper.({
default_mapper with
expr = (fun mapper expr ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment