diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2020-12-23 19:11:31 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2020-12-23 19:11:31 +0100 |
commit | ec812521b31471ce9ac3d9bdf1288b1569defbc8 (patch) | |
tree | d384c959b9e9bb2a04141ab56077026fe6e7c7f3 /ppx_hash | |
parent | 6354358caa1dfbf2fe1d481f6ac5fba3775938fc (diff) |
Add svg output
Diffstat (limited to 'ppx_hash')
-rwxr-xr-x | ppx_hash/dune | 6 | ||||
-rwxr-xr-x | ppx_hash/ppx_hash.ml | 32 |
2 files changed, 38 insertions, 0 deletions
diff --git a/ppx_hash/dune b/ppx_hash/dune new file mode 100755 index 0000000..7cb4bc8 --- /dev/null +++ b/ppx_hash/dune @@ -0,0 +1,6 @@ +(library + (name ppx_hash) + (kind ppx_deriver) + (libraries ppxlib ) + (preprocess (pps ppxlib.metaquot)) + ) diff --git a/ppx_hash/ppx_hash.ml b/ppx_hash/ppx_hash.ml new file mode 100755 index 0000000..59584d5 --- /dev/null +++ b/ppx_hash/ppx_hash.ml @@ -0,0 +1,32 @@ +open Ppxlib + +(** + + This is a simple ppx which evaluate hash for string at compilation time. + + [%static_hash "deadbeef"] is equivalent to [Hashtbl.hash "deadbeef"] + + the ppx only evaluate strings. +*) + +let name = "static_hash" + +let expand ~loc ~path:_ (value : string) = + let h = Hashtbl.hash value in + Ast_builder.Default.eint ~loc h + +let extension = + Extension.declare + name + Extension.Context.expression + Ast_pattern.(single_expr_payload (estring __)) + expand + + + +let rule = Ppxlib.Context_free.Rule.extension extension + +let () = + Driver.register_transformation + ~rules:[rule] + name |