Created
March 2, 2016 20:43
-
-
Save j0sh/8d6504d11070d842a8dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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