Skip to content

Commit 8147c58

Browse files
committed
Check regular expressions at compile-time.
1 parent ed71014 commit 8147c58

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

jbuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
(kind ppx_rewriter)
77
(modules (ppx_regexp))
88
(preprocess (pps (ppx_metaquot)))
9-
(libraries (ocaml-migrate-parsetree))))
9+
(libraries (re re.pcre ocaml-migrate-parsetree))))
1010

1111
(executables
1212
((names (test_ppx_regexp))

ppx_regexp.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ let transform_cases ~loc e cases =
103103
(Exp.constant (Const.string ""), 0, [], case.pc_rhs)
104104
| {ppat_desc = Ppat_constant (Pconst_string (re_src,_)); ppat_loc = loc} ->
105105
let re_str, bs, nG = extract_bindings ~loc re_src in
106+
(try ignore (Re_pcre.regexp re_str) with
107+
| Re_perl.Not_supported -> error ~loc "Unsupported regular expression."
108+
| Re_perl.Parse_error -> error ~loc "Invalid regular expression.");
106109
(Exp.constant (Const.string re_str), nG, bs, case.pc_rhs)
107110
| {ppat_loc = loc} ->
108111
error ~loc "Regular expression pattern should be a string.")

0 commit comments

Comments
 (0)