File tree Expand file tree Collapse file tree 5 files changed +22
-14
lines changed
Expand file tree Collapse file tree 5 files changed +22
-14
lines changed Original file line number Diff line number Diff line change 11# This file is generated by dune, edit dune-project instead
22opam-version: "2.0"
3- version: "5.0.1 "
3+ version: "5.0.2 "
44synopsis: "Bitstrings and bitstring matching for OCaml"
55description: """
66The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.
Original file line number Diff line number Diff line change 22
33(name bitstring)
44
5- ( version 5 .0.1 )
5+ ( version 5 .0.2 )
66
77( generate_opam_files true )
88
3434 )
3535 ( depends
3636 ( ocaml ( >= 5 .2.0) )
37- ( bitstring ( >= 5 .0.1 ) )
37+ ( bitstring ( >= 5 .0.2 ) )
3838 ( ocaml ( and :with -test ( >= 5 .2.0) ) )
3939 ( ppxlib ( >= 0 .36.0) )
4040 ( ounit :with -test) ) )
Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ open Ppxlib
1818open Printf
1919open Ast_builder.Default
2020
21+ (* Exception *)
22+
23+ let location_exn ~loc msg =
24+ Location. raise_errorf ~loc " %s" msg
25+ ;;
26+
2127(* Type definition *)
2228
2329module Entity = struct
@@ -167,13 +173,12 @@ module MatchField = struct
167173 | Any of Parsetree .pattern
168174 | Tuple of tuple
169175 ;;
170- end
171176
172- (* Exception *)
173-
174- let location_exn ~ loc msg =
175- Location. raise_errorf ~loc " %s " msg
176- ;;
177+ let as_evar v =
178+ match v.pat with
179+ | { ppat_desc = Ppat_var ( v ); _} -> evar ~loc: v.loc v.txt
180+ | {ppat_loc; _} -> location_exn ~loc: ppat_loc " Pattern is not a variable "
181+ end
177182
178183(* Helper functions *)
179184
@@ -691,7 +696,8 @@ let gen_value ~loc fld res beh =
691696 | Some b , None ->
692697 [% expr let [% p fld.pat] = [% e b] in [% e beh]][@ metaloc loc]
693698 | None , Some m ->
694- [% expr let [% p fld.pat] = [% e m] [% e res] in [% e beh]][@ metaloc loc]
699+ let exp = MatchField. as_evar fld in
700+ [% expr let [% p fld.pat] = [% e m] [% e exp] in [% e beh]][@ metaloc loc]
695701 | _ , _ -> beh
696702;;
697703
Original file line number Diff line number Diff line change 11# This file is generated by dune, edit dune-project instead
22opam-version: "2.0"
3- version: "5.0.1 "
3+ version: "5.0.2 "
44synopsis: "Bitstrings and bitstring matching for OCaml - PPX extension"
55description: """
66The ocaml-bitstring project adds Erlang-style bitstrings and matching over bitstrings as a syntax extension and library for OCaml.
@@ -15,7 +15,7 @@ bug-reports: "https://github.com/xguerin/bitstring/issues"
1515depends: [
1616 "dune" {>= "2.7"}
1717 "ocaml" {>= "5.2.0"}
18- "bitstring" {>= "5.0.1 "}
18+ "bitstring" {>= "5.0.2 "}
1919 "ocaml" {with-test & >= "5.2.0"}
2020 "ppxlib" {>= "0.36.0"}
2121 "ounit" {with-test}
Original file line number Diff line number Diff line change @@ -22,16 +22,18 @@ open Bitstring
2222 *)
2323
2424let map_test context =
25- let source = [% bitstring {| 1 : 16 ; 2 : 16 | }] in
25+ let source = [% bitstring {| 1 : 16 ; 2 : 16 ; 0 : 16 | }] in
2626 match % bitstring source with
2727 | {| value0 : 16 : map (fun v -> v + 1)
2828 ; value1 : 16 : map (fun v -> Some v)
29+ ; value2 : 16 : map (fun v -> match v with | 0 -> false | _ -> true)
2930 |} ->
3031 assert_equal value0 2 ;
3132 begin match value1 with
3233 | Some v -> assert_equal v 2
3334 | _ -> assert_bool " Invalid map result" false
34- end
35+ end ;
36+ assert_bool " Invalid boolean value" (not value2)
3537 | {| _ |} -> assert_bool " Invalid pattern" false
3638
3739(*
You can’t perform that action at this time.
0 commit comments