Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bitstring.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "5.0.1"
version: "5.0.2"
synopsis: "Bitstrings and bitstring matching for OCaml"
description: """
The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.
Expand Down
4 changes: 2 additions & 2 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(name bitstring)

(version 5.0.1)
(version 5.0.2)

(generate_opam_files true)

Expand Down Expand Up @@ -34,7 +34,7 @@
)
(depends
(ocaml (>= 5.2.0))
(bitstring (>= 5.0.1))
(bitstring (>= 5.0.2))
(ocaml (and :with-test (>= 5.2.0)))
(ppxlib (>= 0.36.0))
(ounit :with-test)))
20 changes: 13 additions & 7 deletions ppx/ppx_bitstring.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ open Ppxlib
open Printf
open Ast_builder.Default

(* Exception *)

let location_exn ~loc msg =
Location.raise_errorf ~loc "%s" msg
;;

(* Type definition *)

module Entity = struct
Expand Down Expand Up @@ -167,13 +173,12 @@ module MatchField = struct
| Any of Parsetree.pattern
| Tuple of tuple
;;
end

(* Exception *)

let location_exn ~loc msg =
Location.raise_errorf ~loc "%s" msg
;;
let as_evar v =
match v.pat with
| {ppat_desc = Ppat_var(v); _} -> evar ~loc:v.loc v.txt
| {ppat_loc; _} -> location_exn ~loc:ppat_loc "Pattern is not a variable"
end

(* Helper functions *)

Expand Down Expand Up @@ -691,7 +696,8 @@ let gen_value ~loc fld res beh =
| Some b, None ->
[%expr let [%p fld.pat] = [%e b] in [%e beh]][@metaloc loc]
| None, Some m ->
[%expr let [%p fld.pat] = [%e m] [%e res] in [%e beh]][@metaloc loc]
let exp = MatchField.as_evar fld in
[%expr let [%p fld.pat] = [%e m] [%e exp] in [%e beh]][@metaloc loc]
| _, _ -> beh
;;

Expand Down
4 changes: 2 additions & 2 deletions ppx_bitstring.opam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "5.0.1"
version: "5.0.2"
synopsis: "Bitstrings and bitstring matching for OCaml - PPX extension"
description: """
The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.
Expand All @@ -15,7 +15,7 @@ bug-reports: "https://github.com/xguerin/bitstring/issues"
depends: [
"dune" {>= "2.7"}
"ocaml" {>= "5.2.0"}
"bitstring" {>= "5.0.1"}
"bitstring" {>= "5.0.2"}
"ocaml" {with-test & >= "5.2.0"}
"ppxlib" {>= "0.36.0"}
"ounit" {with-test}
Expand Down